Class 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 Detail

      • _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.
      • _moduleList

        protected List<Module> _moduleList
        Ordered list of modules.
      • _moduleMap

        protected Map<String,​Module> _moduleMap
        Map of modules (for fast access by name).
      • _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
      • _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 JhoveException
        Class constructor. Instantiates a JhoveBase object.
        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 pathname
        saxClass - 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 is null.
      • 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. If dirFileOrUri is null, Does one of the following:
        • If module is non-null, provides information about the module.
        • Otherwise if aboutHandler is non-null, provides information about that handler.
        • If they're both null, provides information about the application.
        Parameters:
        app - The App object for the application
        module - The module to be used
        aboutHandler - If specified, the handler about which info is requested
        handler - The handler for processing the output
        outputFile - Name of the file to which output should go
        dirFileOrUri - 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
        Returns false if 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 calling abort, in which case it will delete the temporary file and return null.
        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. Returns false if 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.
      • 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.
      • getModule

        public Module getModule​(String name)
        Returns a module by name.
      • getModuleMap

        public Map<String,​Module> getModuleMap()
        Returns the map of module names to modules.
      • getModuleList

        public List<Module> getModuleList()
        Returns the list of modules.
      • 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 by setSaveDirectory.
      • getChecksumFlag

        public boolean getChecksumFlag()
        Returns true if checksums are requested.
      • getShowRawFlag

        public boolean getShowRawFlag()
        Returns true if 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 by doChecksum.
      • setShowRawFlag

        public void setShowRawFlag​(boolean raw)
        Sets the value to be returned by getShowRawFlag, 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 named jhove.conf. Returns null if no such file is found.
      • getSaxClassFromProperties

        public static String getSaxClassFromProperties()
        Returns the value of the property edu.harvard.hul.ois.jhove.saxClass, which should be the name of the main SAX class. Returns null if 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