Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.xalan.transformer
Class TransformerIdentityImpl  view TransformerIdentityImpl download TransformerIdentityImpl.java

java.lang.Object
  extended byjavax.xml.transform.Transformer
      extended byorg.apache.xalan.transformer.TransformerIdentityImpl
All Implemented Interfaces:
org.xml.sax.ContentHandler, org.xml.sax.ext.DeclHandler, org.xml.sax.DTDHandler, org.xml.sax.ext.LexicalHandler, javax.xml.transform.sax.TransformerHandler

public class TransformerIdentityImpl
extends javax.xml.transform.Transformer
implements javax.xml.transform.sax.TransformerHandler, org.xml.sax.ext.DeclHandler

This class implements an identity transformer for SAXTransformerFactory.newTransformerHandler()>SAXTransformerFactory.newTransformerHandler() 55 and TransformerFactory.newTransformer()>TransformerFactory.newTransformer() 55 . 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 org.apache.xml.utils.DOMBuilder. If the result is another content handler, it will simply pass the events on.


Field Summary
private  javax.xml.transform.ErrorListener m_errorListener
          The error listener for TrAX errors and warnings.
(package private)  boolean m_flushedStartDoc
           
(package private)  boolean m_foundFirstElement
          Flag to set if we've found the first element, so we can tell if we have to check to see if we should create an HTML serializer.
private  org.apache.xalan.templates.OutputProperties m_outputFormat
          The output properties.
private  java.io.FileOutputStream m_outputStream
          This is null unless we own the stream.
private  java.util.Hashtable m_params
          The parameters, which is unused, but must be returned to fullfill the Transformer interface.
private  javax.xml.transform.Result m_result
          The Result object.
private  org.xml.sax.ContentHandler m_resultContentHandler
          The content handler where result events will be sent.
private  org.xml.sax.ext.DeclHandler m_resultDeclHandler
          The Decl handler where result events will be sent.
private  org.xml.sax.DTDHandler m_resultDTDHandler
          The DTD handler where result events will be sent.
private  org.xml.sax.ext.LexicalHandler m_resultLexicalHandler
          The lexical handler where result events will be sent.
private  org.apache.xml.serializer.Serializer m_serializer
          The Serializer, which may or may not be null.
private  java.lang.String m_systemID
          The system ID, which is unused, but must be returned to fullfill the TransformerHandler interface.
(package private)  javax.xml.transform.URIResolver m_URIResolver
          The URIResolver, which is unused, but must be returned to fullfill the TransformerHandler interface.
 
Constructor Summary
TransformerIdentityImpl()
          Constructor TransformerIdentityImpl creates an identity transform.
 
Method Summary
 void attributeDecl(java.lang.String eName, java.lang.String aName, java.lang.String type, java.lang.String valueDefault, java.lang.String value)
          Report an attribute type declaration.
 void characters(char[] ch, int start, int length)
          Receive notification of character data inside an element.
 void clearParameters()
          Clear all parameters set with setParameter.
 void comment(char[] ch, int start, int length)
          Report an XML comment anywhere in the document.
private  void createResultContentHandler(javax.xml.transform.Result outputTarget)
          Create a result ContentHandler from a Result object, based on the current OutputProperties.
 void elementDecl(java.lang.String name, java.lang.String model)
          Report an element type declaration.
 void endCDATA()
          Report the end of a CDATA section.
 void endDocument()
          Receive notification of the end of the document.
 void endDTD()
          Report the end of DTD declarations.
 void endElement(java.lang.String uri, java.lang.String localName, java.lang.String qName)
          Receive notification of the end of an element.
 void endEntity(java.lang.String name)
          Report the end of an entity.
 void endPrefixMapping(java.lang.String prefix)
          Receive notification of the end of a Namespace mapping.
 void externalEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
          Report a parsed external entity declaration.
protected  void flushStartDoc()
           
 javax.xml.transform.ErrorListener getErrorListener()
          Get the error event handler in effect for the transformation.
 java.util.Properties getOutputProperties()
          Get a copy of the output properties for the transformation.
 java.lang.String getOutputProperty(java.lang.String name)
          Get an output property that is in effect for the transformation.
 java.lang.Object getParameter(java.lang.String name)
          Get a parameter that was explicitly set with setParameter or setParameters.
 java.lang.String getSystemId()
          Get the base ID (URI or system ID) from where relative URLs will be resolved.
 javax.xml.transform.Transformer getTransformer()
          Get the Transformer associated with this handler, which is needed in order to set parameters and output properties.
 javax.xml.transform.URIResolver getURIResolver()
          Get an object that will be used to resolve URIs used in document(), etc.
 void ignorableWhitespace(char[] ch, int start, int length)
          Receive notification of ignorable whitespace in element content.
 void internalEntityDecl(java.lang.String name, java.lang.String value)
          Report an internal entity declaration.
 void notationDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
          Receive notification of a notation declaration.
 void processingInstruction(java.lang.String target, java.lang.String data)
          Receive notification of a processing instruction.
 void setDocumentLocator(org.xml.sax.Locator locator)
          Receive a Locator object for document events.
 void setErrorListener(javax.xml.transform.ErrorListener listener)
          Set the error event listener in effect for the transformation.
 void setOutputProperties(java.util.Properties oformat)
          Set the output properties for the transformation.
 void setOutputProperty(java.lang.String name, java.lang.String value)
          Set an output property that will be in effect for the transformation.
 void setParameter(java.lang.String name, java.lang.Object value)
          Add a parameter for the transformation.
 void setResult(javax.xml.transform.Result result)
          Enables the user of the TransformerHandler to set the to set the Result for the transformation.
 void setSystemId(java.lang.String systemID)
          Set the base ID (URI or system ID) from where relative URLs will be resolved.
 void setURIResolver(javax.xml.transform.URIResolver resolver)
          Set an object that will be used to resolve URIs used in document().
 void skippedEntity(java.lang.String name)
          Receive notification of a skipped entity.
 void startCDATA()
          Report the start of a CDATA section.
 void startDocument()
          Receive notification of the beginning of the document.
 void startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId)
          Report the start of DTD declarations, if any.
 void startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes)
          Receive notification of the start of an element.
 void startEntity(java.lang.String name)
          Report the beginning of an entity in content.
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
          Receive notification of the start of a Namespace mapping.
 void transform(javax.xml.transform.Source source, javax.xml.transform.Result outputTarget)
          Process the source tree to the output result.
 void unparsedEntityDecl(java.lang.String name, java.lang.String publicId, java.lang.String systemId, java.lang.String notationName)
          Receive notification of an unparsed entity declaration.
 
Methods inherited from class javax.xml.transform.Transformer
reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_flushedStartDoc

boolean m_flushedStartDoc

m_outputStream

private java.io.FileOutputStream m_outputStream
This is null unless we own the stream.


m_resultContentHandler

private org.xml.sax.ContentHandler m_resultContentHandler
The content handler where result events will be sent.


m_resultLexicalHandler

private org.xml.sax.ext.LexicalHandler m_resultLexicalHandler
The lexical handler where result events will be sent.


m_resultDTDHandler

private org.xml.sax.DTDHandler m_resultDTDHandler
The DTD handler where result events will be sent.


m_resultDeclHandler

private org.xml.sax.ext.DeclHandler m_resultDeclHandler
The Decl handler where result events will be sent.


m_serializer

private org.apache.xml.serializer.Serializer m_serializer
The Serializer, which may or may not be null.


m_result

private javax.xml.transform.Result m_result
The Result object.


m_systemID

private java.lang.String m_systemID
The system ID, which is unused, but must be returned to fullfill the TransformerHandler interface.


m_params

private java.util.Hashtable m_params
The parameters, which is unused, but must be returned to fullfill the Transformer interface.


m_errorListener

private javax.xml.transform.ErrorListener m_errorListener
The error listener for TrAX errors and warnings.


m_URIResolver

javax.xml.transform.URIResolver m_URIResolver
The URIResolver, which is unused, but must be returned to fullfill the TransformerHandler interface.


m_outputFormat

private org.apache.xalan.templates.OutputProperties m_outputFormat
The output properties.


m_foundFirstElement

boolean m_foundFirstElement
Flag to set if we've found the first element, so we can tell if we have to check to see if we should create an HTML serializer.

Constructor Detail

TransformerIdentityImpl

public TransformerIdentityImpl()
Constructor TransformerIdentityImpl creates an identity transform.

Method Detail

setResult

public void setResult(javax.xml.transform.Result result)
               throws java.lang.IllegalArgumentException
Enables the user of the TransformerHandler to set the to set the Result for the transformation.

Specified by:
setResult in interface javax.xml.transform.sax.TransformerHandler

setSystemId

public void setSystemId(java.lang.String systemID)
Set the base ID (URI or system ID) from where relative URLs will be resolved.

Specified by:
setSystemId in interface javax.xml.transform.sax.TransformerHandler

getSystemId

public java.lang.String getSystemId()
Get the base ID (URI or system ID) from where relative URLs will be resolved.

Specified by:
getSystemId in interface javax.xml.transform.sax.TransformerHandler

getTransformer

public javax.xml.transform.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 javax.xml.transform.sax.TransformerHandler

createResultContentHandler

private void createResultContentHandler(javax.xml.transform.Result outputTarget)
                                 throws javax.xml.transform.TransformerException
Create a result ContentHandler from a Result object, based on the current OutputProperties.


transform

public void transform(javax.xml.transform.Source source,
                      javax.xml.transform.Result outputTarget)
               throws javax.xml.transform.TransformerException
Process the source tree to the output result.


setParameter

public void setParameter(java.lang.String name,
                         java.lang.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.


getParameter

public java.lang.Object getParameter(java.lang.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.


clearParameters

public void clearParameters()
Clear all parameters set with setParameter.


setURIResolver

public void setURIResolver(javax.xml.transform.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.


getURIResolver

public javax.xml.transform.URIResolver getURIResolver()
Get an object that will be used to resolve URIs used in document(), etc.


setOutputProperties

public void setOutputProperties(java.util.Properties oformat)
                         throws java.lang.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.


getOutputProperties

public java.util.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(java.lang.String, java.lang.String) 55 , setOutputProperties(java.util.Properties) 55 , in the stylesheet, or the default properties, while getOutputProperties().get(String key) will only retrieve properties that were explicitly set by setOutputProperty(java.lang.String, java.lang.String) 55 , setOutputProperties(java.util.Properties) 55 , 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.


setOutputProperty

public void setOutputProperty(java.lang.String name,
                              java.lang.String value)
                       throws java.lang.IllegalArgumentException
Set an output property that will be in effect for the transformation.

Pass a qualified property 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.

The Properties object that was passed to setOutputProperties(java.util.Properties) 55 won't be effected by calling this method.


getOutputProperty

public java.lang.String getOutputProperty(java.lang.String name)
                                   throws java.lang.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.


setErrorListener

public void setErrorListener(javax.xml.transform.ErrorListener listener)
                      throws java.lang.IllegalArgumentException
Set the error event listener in effect for the transformation.


getErrorListener

public javax.xml.transform.ErrorListener getErrorListener()
Get the error event handler in effect for the transformation.


notationDecl

public void notationDecl(java.lang.String name,
                         java.lang.String publicId,
                         java.lang.String systemId)
                  throws org.xml.sax.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 org.xml.sax.DTDHandler

unparsedEntityDecl

public void unparsedEntityDecl(java.lang.String name,
                               java.lang.String publicId,
                               java.lang.String systemId,
                               java.lang.String notationName)
                        throws org.xml.sax.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 org.xml.sax.DTDHandler

setDocumentLocator

public void setDocumentLocator(org.xml.sax.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 org.xml.sax.ContentHandler

startDocument

public void startDocument()
                   throws org.xml.sax.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 org.xml.sax.ContentHandler

flushStartDoc

protected final void flushStartDoc()
                            throws org.xml.sax.SAXException

endDocument

public void endDocument()
                 throws org.xml.sax.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 org.xml.sax.ContentHandler

startPrefixMapping

public void startPrefixMapping(java.lang.String prefix,
                               java.lang.String uri)
                        throws org.xml.sax.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 org.xml.sax.ContentHandler

endPrefixMapping

public void endPrefixMapping(java.lang.String prefix)
                      throws org.xml.sax.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 org.xml.sax.ContentHandler

startElement

public void startElement(java.lang.String uri,
                         java.lang.String localName,
                         java.lang.String qName,
                         org.xml.sax.Attributes attributes)
                  throws org.xml.sax.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 org.xml.sax.ContentHandler

endElement

public void endElement(java.lang.String uri,
                       java.lang.String localName,
                       java.lang.String qName)
                throws org.xml.sax.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 org.xml.sax.ContentHandler

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.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 org.xml.sax.ContentHandler

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws org.xml.sax.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 org.xml.sax.ContentHandler

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
                           throws org.xml.sax.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 org.xml.sax.ContentHandler

skippedEntity

public void skippedEntity(java.lang.String name)
                   throws org.xml.sax.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 org.xml.sax.ContentHandler

startDTD

public void startDTD(java.lang.String name,
                     java.lang.String publicId,
                     java.lang.String systemId)
              throws org.xml.sax.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 55 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 org.xml.sax.ext.LexicalHandler

endDTD

public void endDTD()
            throws org.xml.sax.SAXException
Report the end of DTD declarations.

Specified by:
endDTD in interface org.xml.sax.ext.LexicalHandler

startEntity

public void startEntity(java.lang.String name)
                 throws org.xml.sax.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 55 event, which is part of the ContentHandler interface.

Specified by:
startEntity in interface org.xml.sax.ext.LexicalHandler

endEntity

public void endEntity(java.lang.String name)
               throws org.xml.sax.SAXException
Report the end of an entity.

Specified by:
endEntity in interface org.xml.sax.ext.LexicalHandler

startCDATA

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

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

Specified by:
startCDATA in interface org.xml.sax.ext.LexicalHandler

endCDATA

public void endCDATA()
              throws org.xml.sax.SAXException
Report the end of a CDATA section.

Specified by:
endCDATA in interface org.xml.sax.ext.LexicalHandler

comment

public void comment(char[] ch,
                    int start,
                    int length)
             throws org.xml.sax.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 org.xml.sax.ext.LexicalHandler

elementDecl

public void elementDecl(java.lang.String name,
                        java.lang.String model)
                 throws org.xml.sax.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 org.xml.sax.ext.DeclHandler

attributeDecl

public void attributeDecl(java.lang.String eName,
                          java.lang.String aName,
                          java.lang.String type,
                          java.lang.String valueDefault,
                          java.lang.String value)
                   throws org.xml.sax.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 org.xml.sax.ext.DeclHandler

internalEntityDecl

public void internalEntityDecl(java.lang.String name,
                               java.lang.String value)
                        throws org.xml.sax.SAXException
Report an internal entity declaration.

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

Specified by:
internalEntityDecl in interface org.xml.sax.ext.DeclHandler

externalEntityDecl

public void externalEntityDecl(java.lang.String name,
                               java.lang.String publicId,
                               java.lang.String systemId)
                        throws org.xml.sax.SAXException
Report a parsed external entity declaration.

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

Specified by:
externalEntityDecl in interface org.xml.sax.ext.DeclHandler