Package edu.harvard.hul.ois.jhove
Class JhoveBase
java.lang.Object
edu.harvard.hul.ois.jhove.JhoveBase
The JHOVE engine, providing all base services necessary to build an
application.
More than one JhoveBase may be instantiated and process files in concurrent
threads. Any one instance must not be multithreaded.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanFlag for aborting activity.protected intBuffer size for buffered I/O.protected booleanprotected StringConfiguration file pathname.protected URLConnectionCurrent URL connection.protected ThreadThread currently parsing a document.protected StringSelected encoding.protected List<OutputHandler>Ordered list of output handlers.protected Map<String,OutputHandler> Map of output handlers (for fast access by name).protected StringJHOVE home directory.protected LoggerLogger for this class.protected StringLogger resource bundle.protected StringMIX version.Ordered list of modules.Map of modules (for fast access by name).static final Stringprotected longByte count for digital objectprotected Stringprotected FileDirectory for saving files.protected StringSAX parser class.protected booleanprotected intNumber of bytes for fake signature checking.protected booleanprotected StringTemporary directory. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidabort()Aborts an activity.connToTempFile(URLConnection conn, RepInfo info) Saves a URLConnection's data stream to a temporary file.voiddispatch(App app, Module module, OutputHandler aboutHandler, OutputHandler handler, String outputFile, String[] dirFileOrUri) Processes a file or directory, or outputs information.booleangetAbort()Returns the abort flag.intReturns buffer size.booleanReturnstrueif checksums are requested.Returns the configuration file.static StringUses the user.home property to locate the configuration file.getDate()Returns the engine date (the date at which this instance was created).Returns the output encoding.static StringgetFromProperties(String name) Returns a named value from the properties file.getHandler(String name) Returns a handler by name.Returns the list of handlers.Returns map of handler names to handlers.Returns the JHOVE home directory.Returns the requested MIX schema version.Returns a module by name.Returns the list of modules.Returns the map of module names to modules.getName()Returns the engine name.Returns the output file.Returns the engine release.Returns the engine rights statement.Returns the directory designated for saving files.Returns the SAX class.static StringReturns the value of the propertyedu.harvard.hul.ois.jhove.saxClass, which should be the name of the main SAX class.booleanReturnstrueif raw output is requested.intReturns the maximum number of bytes to check, for modules that look for an indefinitely positioned signature or check the first sigBytes bytes in lieu of a signature.booleanReturns the "check signature only" flag.Returns the temporary directory path.voidInitializes the JHOVE engine.protected static PrintWritermakeWriter(String outputFile, String encoding) Creates an output PrintWriter.Creates a temporary file with a unique name.booleanprocess(App app, Module module, OutputHandler handler, String dirFileOrUri) Returnsfalseif processing should be aborted.booleanprocessFile(App app, Module module, boolean verbose, File file, RepInfo info) Processes the file.voidResets the abort flag.voidsetBufferSize(int bufferSize) Sets the buffer size.voidsetCallback(Callback callback) Sets a callback object for tracking progress.voidsetChecksumFlag(boolean checksum) Sets the value to be returned bydoChecksum.voidSets the current thread for parsing.voidsetEncoding(String encoding) Sets the output encoding.voidsetLogLevel(String level) Sets the log level.voidsetSaveDirectory(File dir) Sets the default directory for subsequent save operations.voidsetShowRawFlag(boolean raw) Sets the value to be returned bygetShowRawFlag, which determines if only raw numeric values should be output.voidsetSigBytes(int sigBytes) Sets the maximum number of bytes to check, for modules that look for an indefinitely positioned signature or check the first sigBytes bytes in lieu of a signature.voidsetSignatureFlag(boolean signature) Sets the "check signature only" flag.voidsetTempDirectory(String tempDir) Sets the temporary directory path.tempFile()Creates a temporary file with a unique name.
-
Field Details
-
_name
- See Also:
-
_abort
protected boolean _abortFlag for aborting activity. -
_bufferSize
protected int _bufferSizeBuffer size for buffered I/O. -
_checksum
protected boolean _checksum -
_configFile
Configuration file pathname. -
_encoding
Selected encoding. -
_handlerList
Ordered list of output handlers. -
_handlerMap
Map of output handlers (for fast access by name). -
_jhoveHome
JHOVE home directory. -
_moduleList
Ordered list of modules. -
_moduleMap
Map of modules (for fast access by name). -
_outputFile
-
_saxClass
SAX parser class. -
_showRaw
protected boolean _showRaw -
_signature
protected boolean _signature -
_tempDir
Temporary directory. -
_mixVsn
MIX version. -
_sigBytes
protected int _sigBytesNumber of bytes for fake signature checking. -
_saveDir
Directory for saving files. -
_nByte
protected long _nByteByte count for digital object -
_conn
Current URL connection. -
_currentThread
Thread currently parsing a document. -
_logger
Logger for this class. -
_logLevel
Logger resource bundle.
-
-
Constructor Details
-
JhoveBase
Class constructor. Instantiates aJhoveBaseobject.- Throws:
JhoveException- if invoked with a JVM lower than 1.8
-
-
Method Details
-
init
Initializes the JHOVE engine. This method parses the configuration file and initialises the JHOVE engine based on the values parsed. Version 1.11 would create the configuration file if not found. Version 1.12 changes this behaviour. The file path supplied must be resolvable to an existing JHOVE config file.- Parameters:
configFile- Configuration file pathnamesaxClass- a SAX parser class, will use JVM default if not supplied- Throws:
JhoveException- when anything goes wrong
-
setCallback
Sets a callback object for tracking progress. By default, the callback isnull. -
dispatch
public void dispatch(App app, Module module, OutputHandler aboutHandler, OutputHandler handler, String outputFile, String[] dirFileOrUri) throws Exception Processes a file or directory, or outputs information. IfdirFileOrUriis null, Does one of the following:- If module is non-null, provides information about the module.
- Otherwise if
aboutHandleris non-null, provides information about that handler. - If they're both null, provides information about the application.
- Parameters:
app- The App object for the applicationmodule- The module to be usedaboutHandler- If specified, the handler about which info is requestedhandler- The handler for processing the outputoutputFile- Name of the file to which output should godirFileOrUri- One or more file names or URI's to be analyzed- Throws:
Exception
-
process
public boolean process(App app, Module module, OutputHandler handler, String dirFileOrUri) throws Exception Returnsfalseif processing should be aborted. Calls itself recursively for directories.- Throws:
Exception
-
connToTempFile
Saves a URLConnection's data stream to a temporary file. This may be interrupted asynchronously by callingabort, in which case it will delete the temporary file and returnnull.- Throws:
IOException
-
abort
public void abort()Aborts an activity. This simply sets a flag; whether anything is aborted depends on what activity is happening. -
processFile
public boolean processFile(App app, Module module, boolean verbose, File file, RepInfo info) throws Exception Processes the file. Returnsfalseif aborted, or if the module is incapable of validation. This shouldn't be called if the module doesn't have the validation feature.- Throws:
Exception
-
tempFile
Creates a temporary file with a unique name. The file will be deleted when the application exits.- Throws:
IOException
-
getAbort
public boolean getAbort()Returns the abort flag. -
getBufferSize
public int getBufferSize()Returns buffer size. A value of -1 signifies that the invoking code should assume the default buffer size. -
getConfigFile
Returns the configuration file. -
getDate
Returns the engine date (the date at which this instance was created). -
getEncoding
Returns the output encoding. -
getHandler
Returns a handler by name. -
getHandlerMap
Returns map of handler names to handlers. -
getHandlerList
Returns the list of handlers. -
getJhoveHome
Returns the JHOVE home directory. -
getModule
Returns a module by name. -
getModuleMap
Returns the map of module names to modules. -
getModuleList
Returns the list of modules. -
getName
Returns the engine name. -
getOuputFile
Returns the output file. -
getRelease
Returns the engine release. -
getRights
Returns the engine rights statement. -
getSaxClass
Returns the SAX class. -
getTempDirectory
Returns the temporary directory path. -
getSigBytes
public int getSigBytes()Returns the maximum number of bytes to check, for modules that look for an indefinitely positioned signature or check the first sigBytes bytes in lieu of a signature. -
getSaveDirectory
Returns the directory designated for saving files. This is simply the directory most recently set bysetSaveDirectory. -
getChecksumFlag
public boolean getChecksumFlag()Returnstrueif checksums are requested. -
getShowRawFlag
public boolean getShowRawFlag()Returnstrueif raw output is requested. Raw output means numeric rather than symbolic output; its exact interpretation is up to the module, but generally applies to named flags. -
getSignatureFlag
public boolean getSignatureFlag()Returns the "check signature only" flag. -
getMixVersion
Returns the requested MIX schema version. -
setBufferSize
public void setBufferSize(int bufferSize) Sets the buffer size. A value of -1 signifies that the invoking code will assume the default buffer size. Any non-negative value less than 1024 will result in a buffer size of 1024. -
setEncoding
Sets the output encoding. -
setTempDirectory
Sets the temporary directory path. -
setLogLevel
Sets the log level. The value should be the name of a predefined instance of java.util.logging.Level, e.g., "WARNING", "INFO", "ALL". This will override the config file setting. -
setChecksumFlag
public void setChecksumFlag(boolean checksum) Sets the value to be returned bydoChecksum. -
setShowRawFlag
public void setShowRawFlag(boolean raw) Sets the value to be returned bygetShowRawFlag, which determines if only raw numeric values should be output. -
setSignatureFlag
public void setSignatureFlag(boolean signature) Sets the "check signature only" flag. -
setSaveDirectory
Sets the default directory for subsequent save operations. -
setCurrentThread
Sets the current thread for parsing. -
setSigBytes
public void setSigBytes(int sigBytes) Sets the maximum number of bytes to check, for modules that look for an indefinitely positioned signature or check the first sigBytes bytes in lieu of a signature.- Parameters:
sigBytes- max number of bytes to check
-
resetAbort
public void resetAbort()Resets the abort flag. This must be called at the beginning of any activity for which the abort flag may subsequently be set. -
getConfigFileFromProperties
Uses the user.home property to locate the configuration file. The file is expected to be in the subdirectory named by CONFIG_DIR under the home directory, and to be namedjhove.conf. Returnsnullif no such file is found. -
getSaxClassFromProperties
Returns the value of the propertyedu.harvard.hul.ois.jhove.saxClass, which should be the name of the main SAX class. Returnsnullif no such property has been set up. -
getFromProperties
Returns a named value from the properties file. -
makeWriter
Creates an output PrintWriter.- Parameters:
outputFile- Output filepath. If null, writer goes to System.out.encoding- Character encoding. Must not be null.- Throws:
JhoveException
-
newTempFile
Creates a temporary file with a unique name. The file will be deleted when the application exits.- Throws:
IOException
-