edu.harvard.hul.ois.jhove
Class HandlerBase

java.lang.Object
  extended by edu.harvard.hul.ois.jhove.HandlerBase
All Implemented Interfaces:
OutputHandler
Direct Known Subclasses:
TextHandler, ViewHandler, XmlHandler

public abstract class HandlerBase
extends java.lang.Object
implements OutputHandler

Abstract base class for Jhove output handlers. Output handlers should normally subclass HandlerBase.


Nested Class Summary
static class HandlerBase.SynchronizedDateFormat
          A DateFormat class to address an issue of thread safety.
 
Field Summary
protected  App _app
          The application object
protected  JhoveBase _base
          The Jhove engine
protected  java.util.Date _date
          Handler last modification date
protected  java.util.List<java.lang.String> _defaultParams
          List of default parameters.
protected  java.lang.String _encoding
          Character encoding for writer
protected  java.lang.String _init
          Initialization value.
protected  JhoveBase _je
          JHOVE engine.
protected  int _level
          Indentation level
protected  java.util.logging.Logger _logger
          Logger for a handler class.
protected  java.lang.String _name
          Handler name
protected  java.lang.String _note
          Handler note
protected  java.lang.String _param
          Handler-specific parameter.
protected  java.lang.String _release
          Handler release description.
protected  java.lang.String _rights
          Copyright notice
protected  java.util.List<Document> _specification
          Handler specification document list
protected  Agent _vendor
          Handler vendor
protected  java.io.PrintWriter _writer
          Writer for doing output
static HandlerBase.SynchronizedDateFormat date
          A DateFormat for representing a Date in yyyy-MM-dd (e.g., 2003-07-31) format.
static HandlerBase.SynchronizedDateFormat dateTime
          A DateFormat for representing a Date in yyyy-MM-dd HH:mm:ss z (e.g., 2003-07-31 15:31:12 EDT) format.
static HandlerBase.SynchronizedDateFormat iso8601
          A DateFormat for representing a Date in ISO 8601 (e.g., 2003-07-31T15:31:12-0400) format.
 
Constructor Summary
protected HandlerBase(java.lang.String name, java.lang.String release, int[] date, java.lang.String note, java.lang.String rights)
          Constructors of all subclasses of HandlerBase should call this as a super constructor.
 
Method Summary
 void analyze(RepInfo info)
          Callback allowing post-parse, pre-show analysis of object representation information.
 void applyDefaultParams()
          Applies the default parameters.
 void close()
          Close the writer after all output has been done.
protected static java.lang.String doctype(java.lang.String root, java.lang.String uri)
          Return the XML DOCTYPE instruction.
protected static java.lang.String doctype(java.lang.String root, java.lang.String name, java.lang.String uri)
          Return the XML DOCTYPE instruction.
protected static java.lang.String doubleArray(double[] darray)
          Return String representation of an array of double.
protected static java.lang.String element(java.lang.String tag)
          Returns, as a String, an empty XML.
protected static java.lang.String element(java.lang.String tag, java.lang.String content)
          Returns, as a String, an XML element with a given tag and content
protected static java.lang.String element(java.lang.String tag, java.lang.String[][] attrs)
          Returns, as a String, an XML element with a given tag and attributes
protected static java.lang.String element(java.lang.String tag, java.lang.String[][] attrs, java.lang.String content)
          Returns, as a String, an XML element with a given tag, content and attributes
protected static java.lang.String elementEnd(java.lang.String tag)
          Returns, as a String, the closing tag of an element.
protected static java.lang.String elementStart(java.lang.String tag)
          Returns, as a String, the opening tag of an element.
protected static java.lang.String elementStart(java.lang.String tag, java.lang.String[][] attrs)
          Returns, as a String, the opening tag of an element with specified attributes.
 void endDirectory()
          Callback indicating a directory is finished being processed.
 java.util.Date getDate()
          Return the last modification date of this OutputHandler, as a Java Date object
 java.lang.String getEncoding()
          Returns this handler's encoding.
protected static java.lang.String getIndent(int level)
          Returns a String containing a number of spaces equal to the current indent level.
 java.lang.String getName()
          Return the OutputHandler name
 java.lang.String getNote()
          Return the OutputHandler note
 java.lang.String getRelease()
          Return the release identifier
 java.lang.String getRights()
          Return the copyright information string
 java.util.List<Document> getSpecification()
          Returns a list of Document objects (one for each specification document).
 Agent getVendor()
          Return the vendor information
 void init(java.lang.String init)
          Per-instantiation initialization.
protected static java.lang.String integerArray(int[] iarray)
          Return String representation of an integer array.
protected static java.lang.String integerArray(int[] iarray, char separator)
          Return String representation of an integer array with specified separator.
protected static java.lang.String longArray(long[] larray)
          Return String representation of an array of long with space separator.
 boolean okToProcess(java.lang.String filepath)
          Callback to give the handler the opportunity to decide whether or not to process a file.
 void param(java.lang.String param)
          Per-action initialization.
protected static java.lang.String rationalArray(Rational[] rarray)
          Return String representation of an array of Rational, each evaluated as a double, with space separator.
protected static java.lang.String rationalArray10(Rational[] rarray)
          Return String representation of an array of Rational, each as two integers, with space separator.
 void reset()
          Reset the handler.
 void resetParams()
          Reset parameter settings.
 void setApp(App app)
          Pass the associated App object to this Module.
 void setBase(JhoveBase je)
          Assigns the JHOVE engine object to provide services to this handler
 void setDefaultParams(java.util.List<java.lang.String> params)
          Set a a List of default parameters for the module.
 void setEncoding(java.lang.String encoding)
          Assigns the encoding to be used by this OutputHandler
 void setWriter(java.io.PrintWriter writer)
          Assigns a PrintWriter to do output for this OutputHandler
abstract  void show()
          Outputs minimal information about the application
abstract  void show(App app)
          Outputs detailed information about the application, including configuration, available modules and handlers, etc.
abstract  void show(Module module)
          Outputs information about a Module
abstract  void show(OutputHandler handler)
          Outputs information about the OutputHandler specified in the parameter
abstract  void show(RepInfo info)
          Outputs the information contained in a RepInfo object
abstract  void showFooter()
          Do the final output.
abstract  void showHeader()
          Do the initial output.
 void startDirectory(java.lang.String directory)
          Callback indicating a new directory is being processed.
protected  java.lang.String toDateTime(java.util.Date date)
           
protected static java.lang.String xmlDecl()
          Return a canonical XML declaration with default encoding.
protected static java.lang.String xmlDecl(java.lang.String encoding)
          Return a canonical XML declaration with specified encoding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

date

public static HandlerBase.SynchronizedDateFormat date
A DateFormat for representing a Date in yyyy-MM-dd (e.g., 2003-07-31) format.


dateTime

public static HandlerBase.SynchronizedDateFormat dateTime
A DateFormat for representing a Date in yyyy-MM-dd HH:mm:ss z (e.g., 2003-07-31 15:31:12 EDT) format.


iso8601

public static HandlerBase.SynchronizedDateFormat iso8601
A DateFormat for representing a Date in ISO 8601 (e.g., 2003-07-31T15:31:12-0400) format. We subclass SimpleDateFormat to make it thread-safe.


_app

protected App _app
The application object


_base

protected JhoveBase _base
The Jhove engine


_date

protected java.util.Date _date
Handler last modification date


_encoding

protected java.lang.String _encoding
Character encoding for writer


_init

protected java.lang.String _init
Initialization value.


_defaultParams

protected java.util.List<java.lang.String> _defaultParams
List of default parameters.


_je

protected JhoveBase _je
JHOVE engine.


_level

protected int _level
Indentation level


_name

protected java.lang.String _name
Handler name


_note

protected java.lang.String _note
Handler note


_release

protected java.lang.String _release
Handler release description.


_param

protected java.lang.String _param
Handler-specific parameter.


_rights

protected java.lang.String _rights
Copyright notice


_specification

protected java.util.List<Document> _specification
Handler specification document list


_vendor

protected Agent _vendor
Handler vendor


_writer

protected java.io.PrintWriter _writer
Writer for doing output


_logger

protected java.util.logging.Logger _logger
Logger for a handler class.

Constructor Detail

HandlerBase

protected HandlerBase(java.lang.String name,
                      java.lang.String release,
                      int[] date,
                      java.lang.String note,
                      java.lang.String rights)
Constructors of all subclasses of HandlerBase should call this as a super constructor.

Parameters:
name - Name of the handler
release - Release identifier
date - Last modification date of the handler code, in the form of an array of three numbers. date[0] is the year, date[1] the month, and date[2] the day.
note - Additional information about the handler (may be null)
rights - Copyright notice for the handler
Method Detail

reset

public void reset()
Reset the handler. This needs to be called before each invocation.

Specified by:
reset in interface OutputHandler

setDefaultParams

public void setDefaultParams(java.util.List<java.lang.String> params)
Set a a List of default parameters for the module.

Specified by:
setDefaultParams in interface OutputHandler
Parameters:
params - A List whose elements are Strings. May be empty.

applyDefaultParams

public void applyDefaultParams()
                        throws java.lang.Exception
Applies the default parameters. Calling this clears any prior parameters.

Specified by:
applyDefaultParams in interface OutputHandler
Throws:
java.lang.Exception

resetParams

public void resetParams()
                 throws java.lang.Exception
Reset parameter settings. Returns to a default state without any parameters. The default method clears the saved parameter.

Specified by:
resetParams in interface OutputHandler
Throws:
java.lang.Exception

init

public void init(java.lang.String init)
          throws java.lang.Exception
Per-instantiation initialization. The default method does nothing.

Specified by:
init in interface OutputHandler
Parameters:
init - Initialization parameter. This is typically obtained from the configuration file.
Throws:
java.lang.Exception

param

public void param(java.lang.String param)
           throws java.lang.Exception
Per-action initialization. The default method does nothing.

Specified by:
param in interface OutputHandler
Parameters:
param - Initialization parameter.
Throws:
java.lang.Exception

getDate

public final java.util.Date getDate()
Return the last modification date of this OutputHandler, as a Java Date object

Specified by:
getDate in interface OutputHandler

getName

public final java.lang.String getName()
Return the OutputHandler name

Specified by:
getName in interface OutputHandler

getNote

public final java.lang.String getNote()
Return the OutputHandler note

Specified by:
getNote in interface OutputHandler

getRelease

public final java.lang.String getRelease()
Return the release identifier

Specified by:
getRelease in interface OutputHandler

getRights

public final java.lang.String getRights()
Return the copyright information string

Specified by:
getRights in interface OutputHandler

getSpecification

public final java.util.List<Document> getSpecification()
Returns a list of Document objects (one for each specification document). The specification list is generated by the OutputHandler, and specifications cannot be added by callers.

Specified by:
getSpecification in interface OutputHandler
See Also:
Document

getVendor

public final Agent getVendor()
Return the vendor information

Specified by:
getVendor in interface OutputHandler

getEncoding

public java.lang.String getEncoding()
Returns this handler's encoding.

Specified by:
getEncoding in interface OutputHandler

setApp

public final void setApp(App app)
Pass the associated App object to this Module. The App makes various services available.

Specified by:
setApp in interface OutputHandler

setBase

public final void setBase(JhoveBase je)
Assigns the JHOVE engine object to provide services to this handler

Specified by:
setBase in interface OutputHandler

setEncoding

public void setEncoding(java.lang.String encoding)
Assigns the encoding to be used by this OutputHandler

Specified by:
setEncoding in interface OutputHandler

setWriter

public final void setWriter(java.io.PrintWriter writer)
Assigns a PrintWriter to do output for this OutputHandler

Specified by:
setWriter in interface OutputHandler

analyze

public void analyze(RepInfo info)
Callback allowing post-parse, pre-show analysis of object representation information.

Specified by:
analyze in interface OutputHandler
Parameters:
info - Object representation information

endDirectory

public void endDirectory()
Callback indicating a directory is finished being processed.

Specified by:
endDirectory in interface OutputHandler

okToProcess

public boolean okToProcess(java.lang.String filepath)
Callback to give the handler the opportunity to decide whether or not to process a file. Most handlers will always return true.

Specified by:
okToProcess in interface OutputHandler
Parameters:
filepath - File pathname

show

public abstract void show(Module module)
Outputs information about a Module

Specified by:
show in interface OutputHandler

show

public abstract void show(RepInfo info)
Outputs the information contained in a RepInfo object

Specified by:
show in interface OutputHandler

show

public abstract void show(OutputHandler handler)
Outputs information about the OutputHandler specified in the parameter

Specified by:
show in interface OutputHandler

show

public abstract void show()
Outputs minimal information about the application

Specified by:
show in interface OutputHandler

show

public abstract void show(App app)
Outputs detailed information about the application, including configuration, available modules and handlers, etc.

Specified by:
show in interface OutputHandler

showHeader

public abstract void showHeader()
Do the initial output. This should be in a suitable format for including multiple files between the header and the footer.

Specified by:
showHeader in interface OutputHandler

showFooter

public abstract void showFooter()
Do the final output. This should be in a suitable format for including multiple files between the header and the footer.

Specified by:
showFooter in interface OutputHandler

close

public void close()
Close the writer after all output has been done.

Specified by:
close in interface OutputHandler

startDirectory

public void startDirectory(java.lang.String directory)
Callback indicating a new directory is being processed.

Specified by:
startDirectory in interface OutputHandler
Parameters:
directory - Directory path

doctype

protected static java.lang.String doctype(java.lang.String root,
                                          java.lang.String uri)
Return the XML DOCTYPE instruction.

Parameters:
root - Root element of the DTD
uri - URI of the DTD

doctype

protected static java.lang.String doctype(java.lang.String root,
                                          java.lang.String name,
                                          java.lang.String uri)
Return the XML DOCTYPE instruction.

Parameters:
root - Root element of the DTD
name - Public name of the DTD
uri - URI of the DTD

element

protected static java.lang.String element(java.lang.String tag)
Returns, as a String, an empty XML.

Parameters:
tag - XML tag

element

protected static java.lang.String element(java.lang.String tag,
                                          java.lang.String content)
Returns, as a String, an XML element with a given tag and content

Parameters:
tag - An XML tag
content - Content string. Characters requiring conversion to entitites will be converted.

element

protected static java.lang.String element(java.lang.String tag,
                                          java.lang.String[][] attrs)
Returns, as a String, an XML element with a given tag and attributes

Parameters:
tag - An XML tag
attrs - An array of String[2] elements, where for each element, attrs[i][0] is the attribute key and attrs[i][1] is the attribute value. Null values are skipped.

element

protected static java.lang.String element(java.lang.String tag,
                                          java.lang.String[][] attrs,
                                          java.lang.String content)
Returns, as a String, an XML element with a given tag, content and attributes

Parameters:
tag - An XML tag
content - Content string. Characters requiring conversion to entitites will be converted.
attrs - An array of String[2] elements, where for each element, attrs[i][0] is the attribute key and attrs[i][1] is the attribute value. Null values are skipped.

elementEnd

protected static java.lang.String elementEnd(java.lang.String tag)
Returns, as a String, the closing tag of an element. No checking is done that opening and closing tags match.

Parameters:
tag - An XML tag

elementStart

protected static java.lang.String elementStart(java.lang.String tag)
Returns, as a String, the opening tag of an element.

Parameters:
tag - An XML tag

elementStart

protected static java.lang.String elementStart(java.lang.String tag,
                                               java.lang.String[][] attrs)
Returns, as a String, the opening tag of an element with specified attributes.

Parameters:
tag - An XML tag
attrs - An array of String[2] elements, where for each element, attrs[i][0] is the attribute key and attrs[i][1] is the attribute value.

xmlDecl

protected static java.lang.String xmlDecl()
Return a canonical XML declaration with default encoding.


xmlDecl

protected static java.lang.String xmlDecl(java.lang.String encoding)
Return a canonical XML declaration with specified encoding.


getIndent

protected static java.lang.String getIndent(int level)
Returns a String containing a number of spaces equal to the current indent level.


integerArray

protected static java.lang.String integerArray(int[] iarray)
Return String representation of an integer array.


integerArray

protected static java.lang.String integerArray(int[] iarray,
                                               char separator)
Return String representation of an integer array with specified separator.


longArray

protected static java.lang.String longArray(long[] larray)
Return String representation of an array of long with space separator.


rationalArray

protected static java.lang.String rationalArray(Rational[] rarray)
Return String representation of an array of Rational, each evaluated as a double, with space separator.


rationalArray10

protected static java.lang.String rationalArray10(Rational[] rarray)
Return String representation of an array of Rational, each as two integers, with space separator.


doubleArray

protected static java.lang.String doubleArray(double[] darray)
Return String representation of an array of double.


toDateTime

protected java.lang.String toDateTime(java.util.Date date)