de.dfki.lt.hog
Class TransformationService

java.lang.Object
  extended by de.dfki.lt.hog.TransformationService
All Implemented Interfaces:
javax.xml.transform.URIResolver

public class TransformationService
extends java.lang.Object
implements javax.xml.transform.URIResolver

Service class mainly for module implementations that make use of XSLT transformations. This class also implements a URI resolver that allows to access HoG annotations from within stylesheets using the document() function of XSLT. The URI syntax for HoG annotations is hog://sessionID/collectionID/annotationID.


Constructor Summary
TransformationService()
          Alternative constructor (not recommended).
TransformationService(MoCoMan mocoman)
          The TransformationService class supports XSL transformations plus a special handling for access to HoG-internal annotations for the XSLT document() function.
 
Method Summary
 javax.xml.transform.Transformer createTransformer()
          Create an empty Transformer object (e.g.
 javax.xml.transform.Transformer createTransformer(java.io.File stylesheetfile)
          Create a Transformer object from a stylesheet specified as File.
 javax.xml.transform.Transformer createTransformer(javax.xml.transform.Source sheet)
          Create a Transformer object from a stylesheet specified as Source.
 javax.xml.transform.Transformer createTransformer(java.lang.String stylesheetfilename)
          Create a Transformer object from a stylesheet specified as filename String.
 javax.xml.transform.Transformer createTransformerFromString(java.lang.String stylesheet)
          Create a Transformer object from a stylesheet specified as filename String.
 javax.xml.transform.TransformerFactory getTransformerFactory()
          Return the TransformerFactory of this instance
 javax.xml.transform.Source resolve(java.lang.String href, java.lang.String base)
           
 void setMoCoMan(MoCoMan mcm)
          Set MoCoMan object.
 org.w3c.dom.Node transform(javax.xml.transform.Transformer transformer, org.w3c.dom.Node node)
          Transform the DOM node using the specified Transformer.
 java.lang.String transform(javax.xml.transform.Transformer transformer, javax.xml.transform.Source source)
          Transform the XML Source using the specified Transformer.
 java.lang.String transform(javax.xml.transform.Transformer transformer, java.lang.String sourceString)
          Transform the XML String using the specified Transformer.
 org.w3c.dom.Node transformToDom(javax.xml.transform.Transformer transformer, java.lang.String sourceString)
          Transform the XML Source using the specified Transformer.
 java.lang.String transformToString(javax.xml.transform.Transformer transformer, org.w3c.dom.Node node)
          Transform the XML Source using the specified Transformer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransformationService

public TransformationService(MoCoMan mocoman)
The TransformationService class supports XSL transformations plus a special handling for access to HoG-internal annotations for the XSLT document() function. The syntax in XPath expressions is:
document('hog://sid/acid/aid')
where sid is a sessionID, acid is a collection ID and aid is an annotation identifier such as Chunkie or JTok.
To use the TransformationService in a Module subclass, create a field variable for a TransformationService object, say transformationService:

private TransformationService transformationService = null;
...
in process():

if (this.transformationService==null) {
this.transformationService = new TransformationService(getMoCoMan());
myTransformer = this.transformationService.createTransformer(xslfile);
}

myTransformer.setParameter("sessionID", sid);
myTransformer.setParameter("collectionID", acid);
myTransformer.setParameter("annotationID", aid);
String result = transformationService.transform(myTransformer, xmlinput);

Access to multiple input annotations can be obtained by adding further parameters with unique names for annotationIDs (e.g., annotationID2 etc.).
There are also DOM-based variants of createTransformer() and transform().
The method getTransformerFactory() gives access to the underlying TransformerFactory.


TransformationService

public TransformationService()
Alternative constructor (not recommended). setMoCoMan() must be used afterwards!

Method Detail

setMoCoMan

public void setMoCoMan(MoCoMan mcm)
Set MoCoMan object.


resolve

public javax.xml.transform.Source resolve(java.lang.String href,
                                          java.lang.String base)
                                   throws javax.xml.transform.TransformerException
Specified by:
resolve in interface javax.xml.transform.URIResolver
Throws:
javax.xml.transform.TransformerException

getTransformerFactory

public javax.xml.transform.TransformerFactory getTransformerFactory()
Return the TransformerFactory of this instance

Returns:
the TransformerFactory

createTransformer

public javax.xml.transform.Transformer createTransformer(javax.xml.transform.Source sheet)
                                                  throws javax.xml.transform.TransformerConfigurationException
Create a Transformer object from a stylesheet specified as Source.

Parameters:
sheet - a stylesheet specified as Source object
Returns:
a new Transformer object
Throws:
javax.xml.transform.TransformerConfigurationException

createTransformer

public javax.xml.transform.Transformer createTransformer()
                                                  throws javax.xml.transform.TransformerConfigurationException
Create an empty Transformer object (e.g. for ID transformation DOM to String etc.)

Returns:
a new Transformer object
Throws:
javax.xml.transform.TransformerConfigurationException

createTransformer

public javax.xml.transform.Transformer createTransformer(java.lang.String stylesheetfilename)
                                                  throws javax.xml.transform.TransformerConfigurationException
Create a Transformer object from a stylesheet specified as filename String.

Parameters:
stylesheetfilename - a stylesheet specified as filename String
Returns:
a new Transformer object
Throws:
javax.xml.transform.TransformerConfigurationException

createTransformerFromString

public javax.xml.transform.Transformer createTransformerFromString(java.lang.String stylesheet)
                                                            throws javax.xml.transform.TransformerConfigurationException
Create a Transformer object from a stylesheet specified as filename String.

Parameters:
stylesheet - a stylesheet specified as XML String
Returns:
a new Transformer object
Throws:
javax.xml.transform.TransformerConfigurationException

createTransformer

public javax.xml.transform.Transformer createTransformer(java.io.File stylesheetfile)
                                                  throws javax.xml.transform.TransformerConfigurationException
Create a Transformer object from a stylesheet specified as File.

Parameters:
stylesheetfile - a stylesheet specified as File
Returns:
a new Transformer object
Throws:
javax.xml.transform.TransformerConfigurationException

transform

public java.lang.String transform(javax.xml.transform.Transformer transformer,
                                  javax.xml.transform.Source source)
                           throws javax.xml.transform.TransformerException
Transform the XML Source using the specified Transformer.

Parameters:
transformer - the Transformer object
source - the XML Source object to be transformed
Returns:
the transformation result as String
Throws:
javax.xml.transform.TransformerException

transform

public java.lang.String transform(javax.xml.transform.Transformer transformer,
                                  java.lang.String sourceString)
                           throws javax.xml.transform.TransformerException
Transform the XML String using the specified Transformer.

Parameters:
transformer - the Transformer object
sourceString - the XML Source as String
Returns:
the transformation result as String
Throws:
javax.xml.transform.TransformerException

transform

public org.w3c.dom.Node transform(javax.xml.transform.Transformer transformer,
                                  org.w3c.dom.Node node)
                           throws javax.xml.transform.TransformerException
Transform the DOM node using the specified Transformer.

Parameters:
transformer - the Transformer object
node - the XML document to be transformed
Returns:
the transformation result as DOM node
Throws:
javax.xml.transform.TransformerException

transformToString

public java.lang.String transformToString(javax.xml.transform.Transformer transformer,
                                          org.w3c.dom.Node node)
                                   throws javax.xml.transform.TransformerException
Transform the XML Source using the specified Transformer.

Parameters:
transformer - the Transformer object
source - the XML Source object to be transformed
Returns:
the transformation result as String
Throws:
javax.xml.transform.TransformerException

transformToDom

public org.w3c.dom.Node transformToDom(javax.xml.transform.Transformer transformer,
                                       java.lang.String sourceString)
                                throws javax.xml.transform.TransformerException
Transform the XML Source using the specified Transformer.

Parameters:
transformer - the Transformer object
source - the XML Source object to be transformed
Returns:
the transformation result as DOM node
Throws:
javax.xml.transform.TransformerException