Package edu.harvard.hul.ois.jhove
Class JhoveBase
- java.lang.Object
-
- edu.harvard.hul.ois.jhove.JhoveBase
-
public class JhoveBase extends Object
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
Fields Modifier and Type Field Description protected boolean_abortFlag for aborting activity.protected int_bufferSizeBuffer size for buffered I/O.protected boolean_checksumprotected String_configFileConfiguration file pathname.protected URLConnection_connCurrent URL connection.protected Thread_currentThreadThread currently parsing a document.protected String_encodingSelected encoding.protected List<OutputHandler>_handlerListOrdered list of output handlers.protected Map<String,OutputHandler>_handlerMapMap of output handlers (for fast access by name).protected String_jhoveHomeJHOVE home directory.protected Logger_loggerLogger for this class.protected String_logLevelLogger resource bundle.protected String_mixVsnMIX version.protected List<Module>_moduleListOrdered list of modules.protected Map<String,Module>_moduleMapMap of modules (for fast access by name).static String_nameprotected long_nByteByte count for digital objectprotected String_outputFileprotected File_saveDirDirectory for saving files.protected String_saxClassSAX parser class.protected boolean_showRawprotected int_sigBytesNumber of bytes for fake signature checking.protected boolean_signatureprotected String_tempDirTemporary directory.
-
Constructor Summary
Constructors Constructor Description JhoveBase()Class constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabort()Aborts an activity.FileconnToTempFile(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.intgetBufferSize()Returns buffer size.booleangetChecksumFlag()Returnstrueif checksums are requested.StringgetConfigFile()Returns the configuration file.static StringgetConfigFileFromProperties()Uses the user.home property to locate the configuration file.DategetDate()Returns the engine date (the date at which this instance was created).StringgetEncoding()Returns the output encoding.static StringgetFromProperties(String name)Returns a named value from the properties file.OutputHandlergetHandler(String name)Returns a handler by name.List<OutputHandler>getHandlerList()Returns the list of handlers.Map<String,OutputHandler>getHandlerMap()Returns map of handler names to handlers.StringgetJhoveHome()Returns the JHOVE home directory.StringgetMixVersion()Returns the requested MIX schema version.ModulegetModule(String name)Returns a module by name.List<Module>getModuleList()Returns the list of modules.Map<String,Module>getModuleMap()Returns the map of module names to modules.StringgetName()Returns the engine name.StringgetOuputFile()Returns the output file.StringgetRelease()Returns the engine release.StringgetRights()Returns the engine rights statement.FilegetSaveDirectory()Returns the directory designated for saving files.StringgetSaxClass()Returns the SAX class.static StringgetSaxClassFromProperties()Returns the value of the propertyedu.harvard.hul.ois.jhove.saxClass, which should be the name of the main SAX class.booleangetShowRawFlag()Returnstrueif raw output is requested.intgetSigBytes()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.booleangetSignatureFlag()Returns the "check signature only" flag.StringgetTempDirectory()Returns the temporary directory path.voidinit(String configFile, String saxClass)Initializes the JHOVE engine.protected static PrintWritermakeWriter(String outputFile, String encoding)Creates an output PrintWriter.FilenewTempFile()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.voidresetAbort()Resets 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.voidsetCurrentThread(Thread t)Sets 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.FiletempFile()Creates a temporary file with a unique name.
-
-
-
Field Detail
-
_name
public static final String _name
- See Also:
- Constant Field Values
-
_abort
protected boolean _abort
Flag for aborting activity.
-
_bufferSize
protected int _bufferSize
Buffer size for buffered I/O.
-
_checksum
protected boolean _checksum
-
_configFile
protected String _configFile
Configuration file pathname.
-
_encoding
protected String _encoding
Selected encoding.
-
_handlerList
protected List<OutputHandler> _handlerList
Ordered list of output handlers.
-
_handlerMap
protected Map<String,OutputHandler> _handlerMap
Map of output handlers (for fast access by name).
-
_jhoveHome
protected String _jhoveHome
JHOVE home directory.
-
_outputFile
protected String _outputFile
-
_saxClass
protected String _saxClass
SAX parser class.
-
_showRaw
protected boolean _showRaw
-
_signature
protected boolean _signature
-
_tempDir
protected String _tempDir
Temporary directory.
-
_mixVsn
protected String _mixVsn
MIX version.
-
_sigBytes
protected int _sigBytes
Number of bytes for fake signature checking.
-
_saveDir
protected File _saveDir
Directory for saving files.
-
_nByte
protected long _nByte
Byte count for digital object
-
_conn
protected URLConnection _conn
Current URL connection.
-
_currentThread
protected Thread _currentThread
Thread currently parsing a document.
-
_logger
protected Logger _logger
Logger for this class.
-
_logLevel
protected String _logLevel
Logger resource bundle.
-
-
Constructor Detail
-
JhoveBase
public JhoveBase() throws JhoveExceptionClass constructor. Instantiates aJhoveBaseobject.- Throws:
JhoveException- if invoked with a JVM lower than 1.8
-
-
Method Detail
-
init
public void init(String configFile, String saxClass) throws JhoveException
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
public void setCallback(Callback callback)
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
public File connToTempFile(URLConnection conn, RepInfo info) throws IOException
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
public File tempFile() throws IOException
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
public String getConfigFile()
Returns the configuration file.
-
getDate
public Date getDate()
Returns the engine date (the date at which this instance was created).
-
getEncoding
public String getEncoding()
Returns the output encoding.
-
getHandler
public OutputHandler getHandler(String name)
Returns a handler by name.
-
getHandlerMap
public Map<String,OutputHandler> getHandlerMap()
Returns map of handler names to handlers.
-
getHandlerList
public List<OutputHandler> getHandlerList()
Returns the list of handlers.
-
getJhoveHome
public String getJhoveHome()
Returns the JHOVE home directory.
-
getName
public String getName()
Returns the engine name.
-
getOuputFile
public String getOuputFile()
Returns the output file.
-
getRelease
public String getRelease()
Returns the engine release.
-
getRights
public String getRights()
Returns the engine rights statement.
-
getSaxClass
public String getSaxClass()
Returns the SAX class.
-
getTempDirectory
public String 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
public File 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
public String 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
public void setEncoding(String encoding)
Sets the output encoding.
-
setTempDirectory
public void setTempDirectory(String tempDir)
Sets the temporary directory path.
-
setLogLevel
public void setLogLevel(String level)
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
public void setSaveDirectory(File dir)
Sets the default directory for subsequent save operations.
-
setCurrentThread
public void setCurrentThread(Thread t)
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
public static String 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
public static String 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
public static String getFromProperties(String name)
Returns a named value from the properties file.
-
makeWriter
protected static PrintWriter makeWriter(String outputFile, String encoding) throws JhoveException
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
public File newTempFile() throws IOException
Creates a temporary file with a unique name. The file will be deleted when the application exits.- Throws:
IOException
-
-