eu.clarin.cmdi.mdservice.action
Class MDTransformer

java.lang.Object
  extended by eu.clarin.cmdi.mdservice.action.MDTransformer

public class MDTransformer
extends java.lang.Object

Helper class, encapsulating the xsl-transformations handling the contract is, that the requester passes a key, which can be resolved to a xsl-script (momentary mapped in properties: Admin.getConfig()) Bad things happen, if the key or the appropriate xsl-file do not exist

Author:
vronk

Field Summary
private static MDTransformer singleton
           
private  java.net.URL srcFile
           
(package private)  javax.xml.transform.TransformerFactory tfactory
           
 
Constructor Summary
MDTransformer()
           
 
Method Summary
static MDTransformer getMDTransformer()
           
private  java.lang.String getXSLPath(java.lang.String key)
          get the path to the transform-xsl file from properties, based on the key
private  javax.xml.transform.stream.StreamSource getXSLStreamSource(java.lang.String key)
           
 java.io.InputStream transformXML(java.io.InputStream xmlStream, java.lang.String transkey)
          just a wrapper for the main method translating the output-stream into a input-stream (expected by the Controller-Actions to return as response)
 void transformXML(java.io.InputStream in, java.lang.String transkey, java.io.OutputStream out)
          The main method for transforming, applies the appropriate (based on the transkey) stylesheet on the xml-stream and writes the result into the output stream.
 java.lang.String transformXML(java.lang.String xml, java.lang.String transkey)
          this is for xml present as string.
 java.io.InputStream transformXML(java.net.URL xmlFile, java.lang.String transkey)
          another wrapper for the main method allowing to directly pass a URL to the source-xml
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

srcFile

private java.net.URL srcFile

singleton

private static MDTransformer singleton

tfactory

javax.xml.transform.TransformerFactory tfactory
Constructor Detail

MDTransformer

public MDTransformer()
Method Detail

getMDTransformer

public static MDTransformer getMDTransformer()

getXSLPath

private java.lang.String getXSLPath(java.lang.String key)
get the path to the transform-xsl file from properties, based on the key

Parameters:
key -
Returns:

getXSLStreamSource

private javax.xml.transform.stream.StreamSource getXSLStreamSource(java.lang.String key)

transformXML

public void transformXML(java.io.InputStream in,
                         java.lang.String transkey,
                         java.io.OutputStream out)
                  throws javax.xml.transform.TransformerException,
                         java.io.IOException
The main method for transforming, applies the appropriate (based on the transkey) stylesheet on the xml-stream and writes the result into the output stream.

Parameters:
in - InpuStream with xml
transkey - this defines the stylesheet to use and is also passed to the stylesheet as "format"-parameter
out - the stream to write the output to
Throws:
javax.xml.transform.TransformerException
java.io.IOException

transformXML

public java.io.InputStream transformXML(java.io.InputStream xmlStream,
                                        java.lang.String transkey)
                                 throws java.io.IOException,
                                        java.lang.InterruptedException,
                                        javax.xml.transform.TransformerException
just a wrapper for the main method translating the output-stream into a input-stream (expected by the Controller-Actions to return as response)

Parameters:
xmlStream - the source xml stream
transkey -
Returns:
result-stream (converted to InputStream)
Throws:
java.io.IOException
java.lang.InterruptedException
javax.xml.transform.TransformerException

transformXML

public java.io.InputStream transformXML(java.net.URL xmlFile,
                                        java.lang.String transkey)
                                 throws java.io.IOException,
                                        java.lang.InterruptedException,
                                        javax.xml.transform.TransformerException
another wrapper for the main method allowing to directly pass a URL to the source-xml

Parameters:
xmlFile - URL of the source-file
transkey -
Returns:
the result-stream (already converted to an InputStream)
Throws:
javax.xml.transform.TransformerException
java.io.IOException
java.lang.InterruptedException

transformXML

public java.lang.String transformXML(java.lang.String xml,
                                     java.lang.String transkey)
this is for xml present as string. if xml in a file or a stream, use the other methods

Parameters:
xml - xml as string
transkey -
Returns: