DLESE Tools
v1.2

org.dlese.dpc.xml
Class XMLConversionService

java.lang.Object
  extended byorg.dlese.dpc.xml.XMLConversionService

public final class XMLConversionService
extends Object

Manages the conversion of XML files from one format to another using XSL or Java classes. Caches the converted XML to disc and provides rapid access to the converted format. Conversions may be accomplished using XSL stylesheets or Java classes that implement one of either the XMLFormatConverter or XMLDocumentFormatConverter interfaces.

Author:
John Weatherley
See Also:
XMLFormatConverter, XMLDocumentFormatConverter

Constructor Summary
XMLConversionService(File cacheDir, boolean filter)
          Constructor for the XMLConversionService.
 
Method Summary
 void addJavaConverterClass(String fromFormat, String toFormat, String className, ServletContext context)
          Adds a concrete implementation of the XMLFormatConverter interface that can convert XML from one format to another.
 void addXslStylesheet(String fromFormat, String toFormat, String xslFilePath)
          Adds a XSL stylesheet that can convert from one XML format to another.
 boolean canConvert(String fromFormat, String toFormat)
          Determines whether this XMLConversionService can perform the given converstion.
 ArrayList getAvailableFormats(String fromFormat)
          Gets the metadata format conversions that are available for the given format, including the given format.
static String getContentFromXML(String input)
          Gets the content from XML by stripping all XML tags.
 StringBuffer getConvertedXml(String fromFormat, String toFormat, File originalXMLFile)
          Converts XML from one format to another, saving and retrieving the converted content to and from a file cache.
 StringBuffer getConvertedXml(String fromFormat, String toFormat, File originalXMLFile, XMLDocReader luceneDoc)
          Converts XML from one format to another, saving and retrieving the converted content to and from a file cache.
static String getDateStamp()
          Gets a datestamp of the current time formatted for display with logs and output.
static void setDebug(boolean db)
          Sets the debug attribute of the SimpleLuceneIndex object
static StringBuffer stripXmlDeclaration(BufferedReader rdr)
          Strips the XML declaration and DTD declaration from the given XML.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLConversionService

public XMLConversionService(File cacheDir,
                            boolean filter)
                     throws IOException
Constructor for the XMLConversionService.

Parameters:
cacheDir - The directory where converted files will be cached and stored for later retrieval by ID.
filter - Set to true to filter out the XML and DTD declarations in the converted XML.
Throws:
IOException - If the directory is not valid or does not have read/write access.
Method Detail

getConvertedXml

public StringBuffer getConvertedXml(String fromFormat,
                                    String toFormat,
                                    File originalXMLFile)
Converts XML from one format to another, saving and retrieving the converted content to and from a file cache. Returns null if there are no known conversions available for the requested conversion, or if a processing error occurs. The cache file is automatically updated if the modification time of the input XML file is newer than the cache.

Parameters:
fromFormat - The XML format to convert from. Example: 'dlese_ims.'
toFormat - The format to convert to. Example: 'adn.'
originalXMLFile - The original XML file, in the 'from' format.
Returns:
Content converted to the 'to' format, or null if unable to process.

getConvertedXml

public StringBuffer getConvertedXml(String fromFormat,
                                    String toFormat,
                                    File originalXMLFile,
                                    XMLDocReader luceneDoc)
Converts XML from one format to another, saving and retrieving the converted content to and from a file cache. Returns null if there are no known conversions available for the requested conversion, or if a processing error occurs. The cache file is automatically updated if the modification time of the input XML file is newer than the cache.

Parameters:
fromFormat - The XML format to convert from. Example: 'dlese_ims.'
toFormat - The format to convert to. Example: 'adn.'
originalXMLFile - The original XML file, in the 'from' format. Should not be null.
luceneDoc - A Lucene Document that holds content that may be used by the conversion class, or null.
Returns:
Content converted to the 'to' format, or null if unable to process.

canConvert

public boolean canConvert(String fromFormat,
                          String toFormat)
Determines whether this XMLConversionService can perform the given converstion. Returns true of the toFormat is the same as the fromFormat.

Parameters:
fromFormat - The format to convert from.
toFormat - The format to convert to.
Returns:
True if this XMLConversionService can perform the conversion.

getAvailableFormats

public ArrayList getAvailableFormats(String fromFormat)
Gets the metadata format conversions that are available for the given format, including the given format.

Parameters:
fromFormat - The format to convert from.
Returns:
The availableFormats.

addXslStylesheet

public void addXslStylesheet(String fromFormat,
                             String toFormat,
                             String xslFilePath)
Adds a XSL stylesheet that can convert from one XML format to another.

Parameters:
fromFormat - The XML format from which the stylesheet will convert.
toFormat - The XML format to which the stylesheet will convert.
xslFilePath - The absolute path to the stylesheet.

addJavaConverterClass

public void addJavaConverterClass(String fromFormat,
                                  String toFormat,
                                  String className,
                                  ServletContext context)
Adds a concrete implementation of the XMLFormatConverter interface that can convert XML from one format to another. The class must be available in the classpath for Tomcat or the running JVM that is using this broker.

Parameters:
fromFormat - The XML format from which the class will convert.
toFormat - The XML format to which the class will convert.
className - The fully-qualified class that will perform the conversion.

stripXmlDeclaration

public static StringBuffer stripXmlDeclaration(BufferedReader rdr)
                                        throws IOException
Strips the XML declaration and DTD declaration from the given XML. The resulting content is sutable for export in an OAI container.

Parameters:
rdr - A BufferedReader containing XML.
Returns:
Content witht the XML and DTD declarations stipped out.
Throws:
IOException - If error.

getContentFromXML

public static final String getContentFromXML(String input)
Gets the content from XML by stripping all XML tags. The input XML should be valid prior to calling this method.

Parameters:
input - A valid XML string.
Returns:
The contentFromXML.

getDateStamp

public static final String getDateStamp()
Gets a datestamp of the current time formatted for display with logs and output.

Returns:
A datestamp for display purposes.

setDebug

public static final void setDebug(boolean db)
Sets the debug attribute of the SimpleLuceneIndex object

Parameters:
db - The new debug value

DLESE Tools
v1.2