Devsphere.com


com.devsphere.examples.xml.saxdomix
Class SmartTransformer

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

public class SmartTransformer
extends SDXTransformer

This example is similar to MixedTransformer, but it "knows" when to request the DOM sub-trees for transformation. SmartTransformer parses the XSL file and analyzes the match attribute of the template and key tags. This process is done before the mixed SAX-DOM parsing and is useful to find out the names of the elements for which there are template rules. The wantDOM() method returns true for these elements.

See Also:
SDXTransformer, TransformerRunner

Field Summary
protected  java.util.Vector elements
          The names of the elements that will be the roots of the DOM sub-trees
protected static javax.xml.parsers.SAXParserFactory jaxpFactory
          JAXP factory for SAX parsers used to analyze the XSL files
 
Fields inherited from class com.devsphere.xml.saxdomix.SDXTransformer
builder, fragmentTransformer, resultFilter, serializer, traxFactory
 
Constructor Summary
SmartTransformer(java.lang.String xslSystemID)
          Does the initialization
 
Method Summary
protected  void buildElementsVector(java.lang.String xslSystemID)
          Parses the XSL file end analyzes the match attributes of the template and key tags.
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.
protected  void processPath(java.lang.String path)
          Adds the last element of an XPath to the elements vector.
protected  void processPattern(java.lang.String pattern)
          Processes the value of the match attribute of a template or key tag.
 boolean wantDOM(java.lang.String namespaceURI, java.lang.String localName, java.lang.String qualifiedName, org.xml.sax.Attributes attributes)
          Returns true when the application wants to receive a DOM sub-tree for handling, that is the elements vector contains the qualified name of the current element
 
Methods inherited from class com.devsphere.xml.saxdomix.SDXTransformer
clearParameters, createBuilder, createResultFilter, createSerializer, getErrorListener, getOutputProperties, getOutputProperty, getParameter, getURIResolver, handleDOM, setErrorListener, setOutputProperties, setOutputProperty, setParameter, setURIResolver, transform
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

jaxpFactory

protected static javax.xml.parsers.SAXParserFactory jaxpFactory
JAXP factory for SAX parsers used to analyze the XSL files


elements

protected java.util.Vector elements
The names of the elements that will be the roots of the DOM sub-trees

Constructor Detail

SmartTransformer

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

Method Detail

wantDOM

public boolean wantDOM(java.lang.String namespaceURI,
                       java.lang.String localName,
                       java.lang.String qualifiedName,
                       org.xml.sax.Attributes attributes)
                throws org.xml.sax.SAXException
Returns true when the application wants to receive a DOM sub-tree for handling, that is the elements vector contains the qualified name of the current element

Specified by:
wantDOM in interface SDXController
Specified by:
wantDOM in class SDXTransformer
Parameters:
namespaceURI - The element's namespace URI
localName - The element's local name
qualifiedName - The element's qualified name
attributes - The element's attributes
Returns:
A boolean value indicating whether the builder must enter in DOM parsing mode or must remain in SAX parsing mode
Throws:
org.xml.sax.SAXException - If an error must be signaled

buildElementsVector

protected void buildElementsVector(java.lang.String xslSystemID)
                            throws javax.xml.parsers.ParserConfigurationException,
                                   org.xml.sax.SAXException,
                                   java.io.IOException
Parses the XSL file end analyzes the match attributes of the template and key tags. This process is done before the mixed SAX-DOM parsing and is useful to find out the names of the elements for which there are template rules. The wantDOM() method returns true for these elements.

javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
java.io.IOException

processPattern

protected void processPattern(java.lang.String pattern)
Processes the value of the match attribute of a template or key tag. It removes all predicates and passes each XPath to processPath().


processPath

protected void processPath(java.lang.String path)
Adds the last element of an XPath to the elements vector.


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