org.activemath.xsl
Class JaxpProcessor

java.lang.Object
  extended by org.activemath.xsl.Processor
      extended by org.activemath.xsl.JaxpProcessor
All Implemented Interfaces:
Stylesheets
Direct Known Subclasses:
SaxonProcessor

public class JaxpProcessor
extends Processor

Class JaxpProcessor

A class for centrally processing the stylesheet transformations. This class uses the jaxp transformation standard, including the URI resolving facilities.

These allow imports of stylesheets to be all relative to a single base URI.

For the reason that JAXP is an API standard but not a real processor for processing stylesheets it has to be told which one to use. For this you have to set the system property "javax.xml.transform.TransformerFactory" to the name of a class of a specific stylesheetprocessor which has an implentation of the JAXP API. For example SAXON is one of these processors. In this example you have to set javax.xml.transform.TransformerFactory=com.icl.saxon.TransformerFactoryImpl in your system properties.

Version:
1.0

Field Summary
protected  Hashtable importedStylesheets
          Hashtable with all stylesheets imported (as Set) by a stylesheet
protected static Category log
           
protected  Hashtable preparedTemplates
          Hashtable with prepared transformers for a given Stylesheet
protected  Hashtable timestamps
          Hashtable with the timestamps long of the last modification of the stylesheet
 
Fields inherited from class org.activemath.xsl.Processor
baseURI, hasGeneratedSymbolImports, thisLogCat
 
Constructor Summary
JaxpProcessor()
          Constructor * set baseURI to the Manager's one
JaxpProcessor(String baseURI)
          Constructor
JaxpProcessor(URL base)
          Constructor
 
Method Summary
protected  void calcImports0(String stylesheet, Set imports)
           
protected  TransformerFactory getTransformerFactory()
          get a instance of TransformerFactory
 Templates loadTemplate(String stylesheet)
          get a templates object for the given stylesheet If the wanted one already exists then return this one else create a new one an return it If the wanted one already exists but has been modified then a new Templates will be created for the new stylesheet an replace the old one.
 void loadTemplateAsync(String stylesheet)
          Loads a template asynchronously.
static void main(String[] args)
          method for testing parameters: first: URI of the stylesheet to use second:URI of the document to transform [third]:base URI for the Stylesheet (optional) If the third parameter is not set use the Manager's URI
 void transform(org.jdom.Document document, OutputStream outStream, String stylesheet, Hashtable params)
          transform a JDOM document by the given Stylesheet
 void transform(org.jdom.Document document, Result result, String stylesheet, Hashtable params)
          transform a JDOM document by the given Stylesheet
 void transform(org.jdom.Document document, Writer writer, String stylesheet, Hashtable params)
          transform a JDOM document by the given Stylesheet
 void transform(InputStream inStream, OutputStream outStream, String stylesheet, Hashtable params)
          transform a xml document by the given Stylesheet
 void transform(Source inputSource, Result outputResult, String stylesheet, Hashtable params)
          transform a xml document by the given Stylesheet
 org.jdom.Document transform2Jdom(org.jdom.Document document, String stylesheet, Hashtable params)
          transform a jdom document by the given Stylesheet Be aware that the resulting document has to be XML code to output a JDOOM document
 
Methods inherited from class org.activemath.xsl.Processor
getBaseURI, setBaseURI, setBaseURI
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static Category log

preparedTemplates

protected Hashtable preparedTemplates
Hashtable with prepared transformers for a given Stylesheet


timestamps

protected Hashtable timestamps
Hashtable with the timestamps long of the last modification of the stylesheet


importedStylesheets

protected Hashtable importedStylesheets
Hashtable with all stylesheets imported (as Set) by a stylesheet

Constructor Detail

JaxpProcessor

public JaxpProcessor()
              throws MalformedURLException
Constructor

* set baseURI to the Manager's one

Throws:
MalformedURLException - Description of Exception

JaxpProcessor

public JaxpProcessor(String baseURI)
              throws MalformedURLException
Constructor

Parameters:
base - the base URI of the stylesheets to use
Throws:
MalformedURLException - In case the URI is malformed

JaxpProcessor

public JaxpProcessor(URL base)
Constructor

Parameters:
base - the base URI of the stylesheets to use
Throws:
MalformedURLException - In case the URI is malformed
Method Detail

main

public static void main(String[] args)
                 throws Exception
method for testing

parameters:

If the third parameter is not set use the Manager's URI

Parameters:
args - The command line arguments
Throws:
Exception

loadTemplate

public Templates loadTemplate(String stylesheet)
get a templates object for the given stylesheet

If the wanted one already exists then return this one else create a new one an return it

If the wanted one already exists but has been modified then a new Templates will be created for the new stylesheet an replace the old one.

Specified by:
loadTemplate in interface Stylesheets
Specified by:
loadTemplate in class Processor
Parameters:
stylesheet - the URI of the stylesheet to use for loading (may be absolute or relative to the baseURI)
Returns:
the loaded appropriate Templates object (null if the template couldn't be loaded)
Throws:
TransformerException - If anything happened during the transformation

transform2Jdom

public org.jdom.Document transform2Jdom(org.jdom.Document document,
                                        String stylesheet,
                                        Hashtable params)
                                 throws TransformerException
transform a jdom document by the given Stylesheet

Be aware that the resulting document has to be XML code to output a JDOOM document

Specified by:
transform2Jdom in class Processor
Parameters:
document - the jdom document to transform
stylesheet - the URI of the stylesheet used for transformation
params - the parameters used during transformation (as Hashtable) - may be null
Returns:
transformed jdom document
Throws:
TransformerException - Description of Exception

transform

public void transform(org.jdom.Document document,
                      Result result,
                      String stylesheet,
                      Hashtable params)
               throws TransformerException
transform a JDOM document by the given Stylesheet

Specified by:
transform in interface Stylesheets
Specified by:
transform in class Processor
Parameters:
document - the JDOM document to transform
result - the Result of the transformation (that means: the transformed document)
stylesheet - the URI of the stylesheet used for transformation
params - the parameters used during transformation (as Hashtable) - may be null
Throws:
TransformerException - Description of Exception

transform

public void transform(org.jdom.Document document,
                      OutputStream outStream,
                      String stylesheet,
                      Hashtable params)
               throws TransformerException
transform a JDOM document by the given Stylesheet

Specified by:
transform in interface Stylesheets
Specified by:
transform in class Processor
Parameters:
document - the JDOM document to transform
outStream - the resultingOutputStream of the transformation
stylesheet - the URI of the stylesheet used for transformation
params - the parameters used during transformation (as Hashtable) - may be null
Throws:
TransformerException - Description of Exception

transform

public void transform(org.jdom.Document document,
                      Writer writer,
                      String stylesheet,
                      Hashtable params)
               throws TransformerException
transform a JDOM document by the given Stylesheet

Specified by:
transform in interface Stylesheets
Specified by:
transform in class Processor
Parameters:
document - the JDOM document to transform
stylesheet - the URI of the stylesheet used for transformation
params - the parameters used during transformation (as Hashtable) - may be null
writer - Description of Parameter
Throws:
TransformerException - Description of Exception

transform

public void transform(Source inputSource,
                      Result outputResult,
                      String stylesheet,
                      Hashtable params)
               throws TransformerException
transform a xml document by the given Stylesheet

Specified by:
transform in interface Stylesheets
Specified by:
transform in class Processor
Parameters:
inputSource - the Source of the xml document to transform
outputResult - the Result of the transformation (that means: the transformed document)
stylesheet - the URI of the stylesheet used for transformation
params - the parameters used during transformation (as Hashtable) - may be null
Throws:
TransformerException - Description of Exception

transform

public void transform(InputStream inStream,
                      OutputStream outStream,
                      String stylesheet,
                      Hashtable params)
               throws TransformerException
transform a xml document by the given Stylesheet

Specified by:
transform in interface Stylesheets
Specified by:
transform in class Processor
Parameters:
inStream - the InputStream of the xml document to transform
outStream - the resultingOutputStream of the transformation
stylesheet - the URI of the stylesheet used for transformation
params - the parameters used during transformation (as Hashtable) - may be null
Throws:
TransformerException - Description of Exception

getTransformerFactory

protected TransformerFactory getTransformerFactory()
get a instance of TransformerFactory

Returns:
an instance of TransformerFactory

calcImports0

protected void calcImports0(String stylesheet,
                            Set imports)

loadTemplateAsync

public void loadTemplateAsync(String stylesheet)
Description copied from interface: Stylesheets
Loads a template asynchronously. The processor object (the Stylesheets object) has to wait for the load to be complete before applying the transformation to the named stylesheet.

Specified by:
loadTemplateAsync in interface Stylesheets
Specified by:
loadTemplateAsync in class Processor