org.apache.xalan.transformer

Class TransformerIdentityImpl

Implemented Interfaces:
ContentHandler, DeclHandler, DTDHandler, LexicalHandler, TransformerHandler

public class TransformerIdentityImpl
extends Transformer
implements TransformerHandler, DeclHandler

This class implements an identity transformer for SAXTransformerFactory.newTransformerHandler() and TransformerFactory.newTransformer(). It simply feeds SAX events directly to a serializer ContentHandler, if the result is a stream. If the result is a DOM, it will send the events to DOMBuilder. If the result is another content handler, it will simply pass the events on.

Nested Class Summary

Constructor Summary

TransformerIdentityImpl()
Constructor TransformerIdentityImpl creates an identity transform.

Method Summary

void
attributeDecl(String eName, String aName, String type, String valueDefault, String value)
Report an attribute type declaration.
void
characters(ch[] , int start, int length)
Receive notification of character data inside an element.
void
clearParameters()
Clear all parameters set with setParameter.
void
comment(ch[] , int start, int length)
Report an XML comment anywhere in the document.
void
elementDecl(String name, String model)
Report an element type declaration.
void
endCDATA()
Report the end of a CDATA section.
void
endDTD()
Report the end of DTD declarations.
void
endDocument()
Receive notification of the end of the document.
void
endElement(String uri, String localName, String qName)
Receive notification of the end of an element.
void
endEntity(String name)
Report the end of an entity.
void
endPrefixMapping(String prefix)
Receive notification of the end of a Namespace mapping.
void
externalEntityDecl(String name, String publicId, String systemId)
Report a parsed external entity declaration.
ErrorListener
getErrorListener()
Get the error event handler in effect for the transformation.
Properties
getOutputProperties()
Get a copy of the output properties for the transformation.
String
getOutputProperty(String name)
Get an output property that is in effect for the transformation.
Object
getParameter(String name)
Get a parameter that was explicitly set with setParameter or setParameters.
String
getSystemId()
Get the base ID (URI or system ID) from where relative URLs will be resolved.
Transformer
getTransformer()
Get the Transformer associated with this handler, which is needed in order to set parameters and output properties.
URIResolver
getURIResolver()
Get an object that will be used to resolve URIs used in document(), etc.
void
ignorableWhitespace(ch[] , int start, int length)
Receive notification of ignorable whitespace in element content.
void
internalEntityDecl(String name, String value)
Report an internal entity declaration.
void
notationDecl(String name, String publicId, String systemId)
Receive notification of a notation declaration.
void
processingInstruction(String target, String data)
Receive notification of a processing instruction.
void
setDocumentLocator(Locator locator)
Receive a Locator object for document events.
void
setErrorListener(ErrorListener listener)
Set the error event listener in effect for the transformation.
void
setOutputProperties(Properties oformat)
Set the output properties for the transformation.
void
setOutputProperty(String name, String value)
Set an output property that will be in effect for the transformation.
void
setParameter(String name, Object value)
Add a parameter for the transformation.
void
setResult(Result result)
Enables the user of the TransformerHandler to set the to set the Result for the transformation.
void
setSystemId(String systemID)
Set the base ID (URI or system ID) from where relative URLs will be resolved.
void
setURIResolver(URIResolver resolver)
Set an object that will be used to resolve URIs used in document().
void
skippedEntity(String name)
Receive notification of a skipped entity.
void
startCDATA()
Report the start of a CDATA section.
void
startDTD(String name, String publicId, String systemId)
Report the start of DTD declarations, if any.
void
startDocument()
Receive notification of the beginning of the document.
void
startElement(String uri, String localName, String qName, Attributes attributes)
Receive notification of the start of an element.
void
startEntity(String name)
Report the beginning of an entity in content.
void
startPrefixMapping(String prefix, String uri)
Receive notification of the start of a Namespace mapping.
void
transform(Source source, Result outputTarget)
Process the source tree to the output result.
void
unparsedEntityDecl(String name, String publicId, String systemId, String notationName)
Receive notification of an unparsed entity declaration.

Methods inherited from class javax.xml.transform.Transformer

clearParameters, getErrorListener, getOutputProperties, getOutputProperty, getParameter, getURIResolver, setErrorListener, setOutputProperties, setOutputProperty, setParameter, setURIResolver, transform

Constructor Details

TransformerIdentityImpl

public TransformerIdentityImpl()
Constructor TransformerIdentityImpl creates an identity transform.

Method Details

attributeDecl

public void attributeDecl(String eName,
                          String aName,
                          String type,
                          String valueDefault,
                          String value)
            throws SAXException
Report an attribute type declaration.

Only the effective (first) declaration for an attribute will be reported. The type will be one of the strings "CDATA", "ID", "IDREF", "IDREFS", "NMTOKEN", "NMTOKENS", "ENTITY", "ENTITIES", or "NOTATION", or a parenthesized token group with the separator "|" and all whitespace removed.

Specified by:
attributeDecl in interface DeclHandler

Parameters:
eName - The name of the associated element.
aName - The name of the attribute.
type - A string representing the attribute type.
valueDefault - A string representing the attribute default ("#IMPLIED", "#REQUIRED", or "#FIXED") or null if none of these applies.
value - A string representing the attribute's default value, or null if there is none.

Throws:
SAXException - The application may raise an exception.


characters

public void characters(ch[] ,
                       int start,
                       int length)
            throws SAXException
Receive notification of character data inside an element.

By default, do nothing. Application writers may override this method to take specific actions for each chunk of character data (such as adding the data to a node or buffer, or printing it to a file).

Specified by:
characters in interface ContentHandler

Parameters:
start - The start position in the character array.
length - The number of characters to use from the character array.

Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
SAXException -

See Also:
ContentHandler.characters(ch[],int,int)


clearParameters

public void clearParameters()
Clear all parameters set with setParameter.
Overrides:
clearParameters in interface Transformer


comment

public void comment(ch[] ,
                    int start,
                    int length)
            throws SAXException
Report an XML comment anywhere in the document.

This callback will be used for comments inside or outside the document element, including comments in the external DTD subset (if read).

Specified by:
comment in interface LexicalHandler

Parameters:
start - The starting position in the array.
length - The number of characters to use from the array.

Throws:
SAXException - The application may raise an exception.


elementDecl

public void elementDecl(String name,
                        String model)
            throws SAXException
Report an element type declaration.

The content model will consist of the string "EMPTY", the string "ANY", or a parenthesised group, optionally followed by an occurrence indicator. The model will be normalized so that all whitespace is removed,and will include the enclosing parentheses.

Specified by:
elementDecl in interface DeclHandler

Parameters:
name - The element type name.
model - The content model as a normalized string.

Throws:
SAXException - The application may raise an exception.


endCDATA

public void endCDATA()
            throws SAXException
Report the end of a CDATA section.
Specified by:
endCDATA in interface LexicalHandler

Throws:
SAXException - The application may raise an exception.

See Also:
startCDATA()


endDTD

public void endDTD()
            throws SAXException
Report the end of DTD declarations.
Specified by:
endDTD in interface LexicalHandler

Throws:
SAXException - The application may raise an exception.

See Also:
startDTD(String,String,String)


endDocument

public void endDocument()
            throws SAXException
Receive notification of the end of the document.

By default, do nothing. Application writers may override this method in a subclass to take specific actions at the end of a document (such as finalising a tree or closing an output file).

Specified by:
endDocument in interface ContentHandler

Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
SAXException -

See Also:
ContentHandler.endDocument()


endElement

public void endElement(String uri,
                       String localName,
                       String qName)
            throws SAXException
Receive notification of the end of an element.

By default, do nothing. Application writers may override this method in a subclass to take specific actions at the end of each element (such as finalising a tree node or writing output to a file).

Specified by:
endElement in interface ContentHandler

Parameters:
uri - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
localName - The local name (without prefix), or the empty string if Namespace processing is not being performed.
qName - The qualified name (with prefix), or the empty string if qualified names are not available.

Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
SAXException -

See Also:
ContentHandler.endElement(String,String,String)


endEntity

public void endEntity(String name)
            throws SAXException
Report the end of an entity.
Specified by:
endEntity in interface LexicalHandler

Parameters:
name - The name of the entity that is ending.

Throws:
SAXException - The application may raise an exception.

See Also:
startEntity(String)


endPrefixMapping

public void endPrefixMapping(String prefix)
            throws SAXException
Receive notification of the end of a Namespace mapping.

By default, do nothing. Application writers may override this method in a subclass to take specific actions at the end of each prefix mapping.

Specified by:
endPrefixMapping in interface ContentHandler

Parameters:
prefix - The Namespace prefix being declared.

Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
SAXException -

See Also:
ContentHandler.endPrefixMapping(String)


externalEntityDecl

public void externalEntityDecl(String name,
                               String publicId,
                               String systemId)
            throws SAXException
Report a parsed external entity declaration.

Only the effective (first) declaration for each entity will be reported.

Specified by:
externalEntityDecl in interface DeclHandler

Parameters:
name - The name of the entity. If it is a parameter entity, the name will begin with '%'.
publicId - The declared public identifier of the entity, or null if none was declared.
systemId - The declared system identifier of the entity.

Throws:
SAXException - The application may raise an exception.

See Also:
internalEntityDecl(String,String), DTDHandler.unparsedEntityDecl(String,String,String,String)


getErrorListener

public ErrorListener getErrorListener()
Get the error event handler in effect for the transformation.
Overrides:
getErrorListener in interface Transformer

Returns:
The current error handler, which should never be null.


getOutputProperties

public Properties getOutputProperties()
Get a copy of the output properties for the transformation.

The properties returned should contain properties set by the user, and properties set by the stylesheet, and these properties are "defaulted" by default properties specified by section 16 of the XSL Transformations (XSLT) W3C Recommendation. The properties that were specifically set by the user or the stylesheet should be in the base Properties list, while the XSLT default properties that were not specifically set should be the default Properties list. Thus, getOutputProperties().getProperty(String key) will obtain any property in that was set by setOutputProperty(String,String), setOutputProperties(Properties), in the stylesheet, or the default properties, while getOutputProperties().get(String key) will only retrieve properties that were explicitly set by setOutputProperty(String,String), setOutputProperties(Properties), or in the stylesheet.

Note that mutation of the Properties object returned will not effect the properties that the transformation contains.

If any of the argument keys are not recognized and are not namespace qualified, the property will be ignored. In other words the behaviour is not orthogonal with setOutputProperties.

Overrides:
getOutputProperties in interface Transformer

Returns:
A copy of the set of output properties in effect for the next transformation.

See Also:
OutputKeys, java.util.Properties


getOutputProperty

public String getOutputProperty(String name)
            throws IllegalArgumentException
Get an output property that is in effect for the transformation. The property specified may be a property that was set with setOutputProperty, or it may be a property specified in the stylesheet.
Overrides:
getOutputProperty in interface Transformer

Parameters:
name - A non-null String that specifies an output property name, which may be namespace qualified.

Returns:
The string value of the output property, or null if no property was found.

See Also:
OutputKeys


getParameter

public Object getParameter(String name)
Get a parameter that was explicitly set with setParameter or setParameters.

This method does not return a default parameter value, which cannot be determined until the node context is evaluated during the transformation process.

Overrides:
getParameter in interface Transformer

Parameters:
name - Name of the parameter.

Returns:
A parameter that has been set with setParameter.


getSystemId

public String getSystemId()
Get the base ID (URI or system ID) from where relative URLs will be resolved.
Specified by:
getSystemId in interface TransformerHandler

Returns:
The systemID that was set with setSystemId(String).


getTransformer

public Transformer getTransformer()
Get the Transformer associated with this handler, which is needed in order to set parameters and output properties.
Specified by:
getTransformer in interface TransformerHandler

Returns:
non-null reference to the transformer.


getURIResolver

public URIResolver getURIResolver()
Get an object that will be used to resolve URIs used in document(), etc.
Overrides:
getURIResolver in interface Transformer

Returns:
An object that implements the URIResolver interface, or null.


ignorableWhitespace

public void ignorableWhitespace(ch[] ,
                                int start,
                                int length)
            throws SAXException
Receive notification of ignorable whitespace in element content.

By default, do nothing. Application writers may override this method to take specific actions for each chunk of ignorable whitespace (such as adding data to a node or buffer, or printing it to a file).

Specified by:
ignorableWhitespace in interface ContentHandler

Parameters:
start - The start position in the character array.
length - The number of characters to use from the character array.

Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
SAXException -

See Also:
ContentHandler.ignorableWhitespace(ch[],int,int)


internalEntityDecl

public void internalEntityDecl(String name,
                               String value)
            throws SAXException
Report an internal entity declaration.

Only the effective (first) declaration for each entity will be reported.

Specified by:
internalEntityDecl in interface DeclHandler

Parameters:
name - The name of the entity. If it is a parameter entity, the name will begin with '%'.
value - The replacement text of the entity.

Throws:
SAXException - The application may raise an exception.

See Also:
externalEntityDecl(String,String,String), DTDHandler.unparsedEntityDecl(String,String,String,String)


notationDecl

public void notationDecl(String name,
                         String publicId,
                         String systemId)
            throws SAXException
Receive notification of a notation declaration.

By default, do nothing. Application writers may override this method in a subclass if they wish to keep track of the notations declared in a document.

Specified by:
notationDecl in interface DTDHandler

Parameters:
name - The notation name.
publicId - The notation public identifier, or null if not available.
systemId - The notation system identifier.

Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
SAXException -

See Also:
DTDHandler.notationDecl(String,String,String)


processingInstruction

public void processingInstruction(String target,
                                  String data)
            throws SAXException
Receive notification of a processing instruction.

By default, do nothing. Application writers may override this method in a subclass to take specific actions for each processing instruction, such as setting status variables or invoking other methods.

Specified by:
processingInstruction in interface ContentHandler

Parameters:
target - The processing instruction target.
data - The processing instruction data, or null if none is supplied.

Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
SAXException -

See Also:
ContentHandler.processingInstruction(String,String)


setDocumentLocator

public void setDocumentLocator(Locator locator)
Receive a Locator object for document events.

By default, do nothing. Application writers may override this method in a subclass if they wish to store the locator for use with other document events.

Specified by:
setDocumentLocator in interface ContentHandler

Parameters:
locator - A locator for all SAX document events.

See Also:
ContentHandler.setDocumentLocator(Locator), Locator


setErrorListener

public void setErrorListener(ErrorListener listener)
            throws IllegalArgumentException
Set the error event listener in effect for the transformation.
Overrides:
setErrorListener in interface Transformer

Parameters:
listener - The new error listener.


setOutputProperties

public void setOutputProperties(Properties oformat)
            throws IllegalArgumentException
Set the output properties for the transformation. These properties will override properties set in the Templates with xsl:output.

If argument to this function is null, any properties previously set are removed, and the value will revert to the value defined in the templates object.

Pass a qualified property key name as a two-part string, the namespace URI enclosed in curly braces ({}), followed by the local name. If the name has a null URL, the String only contain the local name. An application can safely check for a non-null URI by testing to see if the first character of the name is a '{' character.

For example, if a URI and local name were obtained from an element defined with <xyz:foo xmlns:xyz="http://xyz.foo.com/yada/baz.html"/>, then the qualified name would be "{http://xyz.foo.com/yada/baz.html}foo". Note that no prefix is used.

Overrides:
setOutputProperties in interface Transformer

Parameters:
oformat - A set of output properties that will be used to override any of the same properties in affect for the transformation.

See Also:
OutputKeys, java.util.Properties


setOutputProperty

public void setOutputProperty(String name,
                              String value)
            throws IllegalArgumentException
Overrides:
setOutputProperty in interface Transformer

Parameters:
name - A non-null String that specifies an output property name, which may be namespace qualified.
value - The non-null string value of the output property.

See Also:
OutputKeys


setParameter

public void setParameter(String name,
                         Object value)
Add a parameter for the transformation.

Pass a qualified name as a two-part string, the namespace URI enclosed in curly braces ({}), followed by the local name. If the name has a null URL, the String only contain the local name. An application can safely check for a non-null URI by testing to see if the first character of the name is a '{' character.

For example, if a URI and local name were obtained from an element defined with <xyz:foo xmlns:xyz="http://xyz.foo.com/yada/baz.html"/>, then the qualified name would be "{http://xyz.foo.com/yada/baz.html}foo". Note that no prefix is used.

Overrides:
setParameter in interface Transformer

Parameters:
name - The name of the parameter, which may begin with a namespace URI in curly braces ({}).
value - The value object. This can be any valid Java object. It is up to the processor to provide the proper object coersion or to simply pass the object on for use in an extension.


setResult

public void setResult(Result result)
            throws IllegalArgumentException
Enables the user of the TransformerHandler to set the to set the Result for the transformation.
Specified by:
setResult in interface TransformerHandler

Parameters:
result - A Result instance, should not be null.


setSystemId

public void setSystemId(String systemID)
Set the base ID (URI or system ID) from where relative URLs will be resolved.
Specified by:
setSystemId in interface TransformerHandler

Parameters:
systemID - Base URI for the source tree.


setURIResolver

public void setURIResolver(URIResolver resolver)
Set an object that will be used to resolve URIs used in document().

If the resolver argument is null, the URIResolver value will be cleared, and the default behavior will be used.

Overrides:
setURIResolver in interface Transformer

Parameters:
resolver - An object that implements the URIResolver interface, or null.


skippedEntity

public void skippedEntity(String name)
            throws SAXException
Receive notification of a skipped entity.

By default, do nothing. Application writers may override this method in a subclass to take specific actions for each processing instruction, such as setting status variables or invoking other methods.

Specified by:
skippedEntity in interface ContentHandler

Parameters:
name - The name of the skipped entity.

Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
SAXException -

See Also:
ContentHandler.processingInstruction(String,String)


startCDATA

public void startCDATA()
            throws SAXException
Report the start of a CDATA section.

The contents of the CDATA section will be reported through the regular characters event.

Specified by:
startCDATA in interface LexicalHandler

Throws:
SAXException - The application may raise an exception.

See Also:
endCDATA()


startDTD

public void startDTD(String name,
                     String publicId,
                     String systemId)
            throws SAXException
Report the start of DTD declarations, if any.

Any declarations are assumed to be in the internal subset unless otherwise indicated by a startEntity event.

Note that the start/endDTD events will appear within the start/endDocument events from ContentHandler and before the first startElement event.

Specified by:
startDTD in interface LexicalHandler

Parameters:
name - The document type name.
publicId - The declared public identifier for the external DTD subset, or null if none was declared.
systemId - The declared system identifier for the external DTD subset, or null if none was declared.

Throws:
SAXException - The application may raise an exception.

See Also:
endDTD(), startEntity(String)


startDocument

public void startDocument()
            throws SAXException
Receive notification of the beginning of the document.

By default, do nothing. Application writers may override this method in a subclass to take specific actions at the beginning of a document (such as allocating the root node of a tree or creating an output file).

Specified by:
startDocument in interface ContentHandler

Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
SAXException -

See Also:
ContentHandler.startDocument()


startElement

public void startElement(String uri,
                         String localName,
                         String qName,
                         Attributes attributes)
            throws SAXException
Receive notification of the start of an element.

By default, do nothing. Application writers may override this method in a subclass to take specific actions at the start of each element (such as allocating a new tree node or writing output to a file).

Specified by:
startElement in interface ContentHandler

Parameters:
uri - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
localName - The local name (without prefix), or the empty string if Namespace processing is not being performed.
qName - The qualified name (with prefix), or the empty string if qualified names are not available.
attributes - The specified or defaulted attributes.

Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
SAXException -

See Also:
ContentHandler.startElement(String,String,String,Attributes)


startEntity

public void startEntity(String name)
            throws SAXException
Report the beginning of an entity in content.

NOTE: entity references in attribute values -- and the start and end of the document entity -- are never reported.

The start and end of the external DTD subset are reported using the pseudo-name "[dtd]". All other events must be properly nested within start/end entity events.

Note that skipped entities will be reported through the skippedEntity event, which is part of the ContentHandler interface.

Specified by:
startEntity in interface LexicalHandler

Parameters:
name - The name of the entity. If it is a parameter entity, the name will begin with '%'.

Throws:
SAXException - The application may raise an exception.

See Also:
endEntity(String), DeclHandler.internalEntityDecl(String,String), DeclHandler.externalEntityDecl(String,String,String)


startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
            throws SAXException
Receive notification of the start of a Namespace mapping.

By default, do nothing. Application writers may override this method in a subclass to take specific actions at the start of each Namespace prefix scope (such as storing the prefix mapping).

Specified by:
startPrefixMapping in interface ContentHandler

Parameters:
prefix - The Namespace prefix being declared.
uri - The Namespace URI mapped to the prefix.

Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
SAXException -

See Also:
ContentHandler.startPrefixMapping(String,String)


transform

public void transform(Source source,
                      Result outputTarget)
            throws TransformerException
Process the source tree to the output result.
Overrides:
transform in interface Transformer

Parameters:
source - The input for the source tree.
outputTarget - The output target.

Throws:
TransformerException - If an unrecoverable error occurs during the course of the transformation.


unparsedEntityDecl

public void unparsedEntityDecl(String name,
                               String publicId,
                               String systemId,
                               String notationName)
            throws SAXException
Receive notification of an unparsed entity declaration.

By default, do nothing. Application writers may override this method in a subclass to keep track of the unparsed entities declared in a document.

Specified by:
unparsedEntityDecl in interface DTDHandler

Parameters:
name - The entity name.
publicId - The entity public identifier, or null if not available.
systemId - The entity system identifier.
notationName - The name of the associated notation.

Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
SAXException -

See Also:
DTDHandler.unparsedEntityDecl(String,String,String,String)


Copyright B) 2004 Apache XML Project. All Rights Reserved.