Devsphere.com


com.devsphere.examples.xml.saxdomix
Class WrapperTransformer

java.lang.Object
  |
  +--javax.xml.transform.Transformer
        |
        +--com.devsphere.xml.saxdomix.SDXTransformer
              |
              +--com.devsphere.examples.xml.saxdomix.SmartTransformer
                    |
                    +--com.devsphere.examples.xml.saxdomix.WrapperTransformer
All Implemented Interfaces:
SDXController

public class WrapperTransformer
extends SmartTransformer

This example is based on SmartTransformer, but it creates an HTML file as output. The SAX events are ignored during the mixed parsing. The markup that results from the transformation of the DOM sub-trees is outputted between a header and a footer, which are taken from an HTML wrapper.

See Also:
SDXTransformer, SmartTransformer, TransformerRunner

Field Summary
protected  int footerLength
          The length of the HTML footer
protected  int footerOffset
          The offset of the HTML footer
protected  int headerLength
          The length of the HTML header
protected  int headerOffset
          The offset of the HTML header
protected  java.io.OutputStream stream
          The stream used for output
protected  byte[] variable
          The name of the wariable from the HTML wrapper
protected  byte[] wrapper
          The content of the HTML wrapper
protected  java.io.Writer writer
          The writer used for output
 
Fields inherited from class com.devsphere.examples.xml.saxdomix.SmartTransformer
elements, jaxpFactory
 
Fields inherited from class com.devsphere.xml.saxdomix.SDXTransformer
builder, fragmentTransformer, resultFilter, serializer, traxFactory
 
Constructor Summary
WrapperTransformer(java.lang.String xslSystemID, java.lang.String wrapperSystemID, java.lang.String variableName)
          Does the initialization.
 
Method Summary
protected  org.xml.sax.ContentHandler createBuilder(javax.xml.transform.sax.TransformerHandler serializer)
          Creates the SDXBuilderT object.
protected  void initHeaderAndFooter(java.lang.String wrapperSystemID, java.lang.String variableName)
          Initializes the fields that maintain the offsets and the lengths of the HTML header and footer.
protected  byte[] loadWrapper(java.lang.String wrapperSystemID)
          Loads the wrapper and returns its content as a byte array.
static void main(java.lang.String[] args)
          Uses TransformerRunner in order to create an instance of this class, configure it and call its transform() method.
 void transform(javax.xml.transform.Source xmlSource, javax.xml.transform.Result outputTarget)
          Does the transformation.
 
Methods inherited from class com.devsphere.examples.xml.saxdomix.SmartTransformer
buildElementsVector, processPath, processPattern, wantDOM
 
Methods inherited from class com.devsphere.xml.saxdomix.SDXTransformer
clearParameters, createResultFilter, createSerializer, getErrorListener, getOutputProperties, getOutputProperty, getParameter, getURIResolver, handleDOM, setErrorListener, setOutputProperties, setOutputProperty, setParameter, setURIResolver
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

wrapper

protected byte[] wrapper
The content of the HTML wrapper


variable

protected byte[] variable
The name of the wariable from the HTML wrapper


headerOffset

protected int headerOffset
The offset of the HTML header


headerLength

protected int headerLength
The length of the HTML header


footerOffset

protected int footerOffset
The offset of the HTML footer


footerLength

protected int footerLength
The length of the HTML footer


stream

protected java.io.OutputStream stream
The stream used for output


writer

protected java.io.Writer writer
The writer used for output

Constructor Detail

WrapperTransformer

public WrapperTransformer(java.lang.String xslSystemID,
                          java.lang.String wrapperSystemID,
                          java.lang.String variableName)
                   throws javax.xml.transform.TransformerException,
                          javax.xml.parsers.ParserConfigurationException,
                          org.xml.sax.SAXException,
                          java.io.IOException
Does the initialization.

Method Detail

transform

public void transform(javax.xml.transform.Source xmlSource,
                      javax.xml.transform.Result outputTarget)
               throws javax.xml.transform.TransformerException
Does the transformation.

This method can work only with a StreamResult. It saves its stream or writer within an instance variable for later usage. Then it calls the method with the same name inherited from SDXTransformer.

Overrides:
transform in class SDXTransformer
Parameters:
xmlSource - The input source for the transformation
outputTarget - The output target for the transformation
Throws:
javax.xml.transform.TransformerException - If an error must be signaled

createBuilder

protected org.xml.sax.ContentHandler createBuilder(javax.xml.transform.sax.TransformerHandler serializer)
                                            throws javax.xml.transform.TransformerException
Creates the SDXBuilderT object. This customization of SDXTransformer in necessary in order to save the header and the footer of the HTML output.

Instead of using the serializer object, the application provides its own handler for the SAX events that don't participate to the construction of the DOM sub-trees. The startDocument() and endDocument() events are still forwarded to the serializer object.

Overrides:
createBuilder in class SDXTransformer
Parameters:
serializer - The current serializer object
Returns:
The created builder
Throws:
javax.xml.transform.TransformerException - If an error must be signaled

initHeaderAndFooter

protected void initHeaderAndFooter(java.lang.String wrapperSystemID,
                                   java.lang.String variableName)
                            throws java.io.IOException
Initializes the fields that maintain the offsets and the lengths of the HTML header and footer.

java.io.IOException

loadWrapper

protected byte[] loadWrapper(java.lang.String wrapperSystemID)
                      throws java.io.IOException
Loads the wrapper and returns its content as a byte array.

java.io.IOException

main

public static void main(java.lang.String[] args)
Uses TransformerRunner in order to create an instance of this class, configure it and call its transform() method.


 Devsphere.com