|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.xml.transform.Transformer org.apache.xalan.transformer.TransformerIdentityImpl
This class implements an identity transformer for javax.xml.transform.sax.SAXTransformerFactory#newTransformerHandler() and {@link javax.xml.transform.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 {@link 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 OutputProperties |
m_outputFormat
The output properties. |
private FileOutputStream |
m_outputStream
This is null unless we own the stream. |
private 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 Serializer |
m_serializer
The Serializer, which may or may not be null. |
private 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(String eName,
String aName,
String type,
String valueDefault,
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(String name,
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(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. |
protected void |
flushStartDoc()
|
javax.xml.transform.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. |
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(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(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(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(javax.xml.transform.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(javax.xml.transform.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 |
startDocument()
Receive notification of the beginning of the document. |
void |
startDTD(String name,
String publicId,
String systemId)
Report the start of DTD declarations, if any. |
void |
startElement(String uri,
String localName,
String qName,
org.xml.sax.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(javax.xml.transform.Source source,
javax.xml.transform.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 java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
boolean m_flushedStartDoc
private FileOutputStream m_outputStream
private org.xml.sax.ContentHandler m_resultContentHandler
private org.xml.sax.ext.LexicalHandler m_resultLexicalHandler
private org.xml.sax.DTDHandler m_resultDTDHandler
private org.xml.sax.ext.DeclHandler m_resultDeclHandler
private Serializer m_serializer
private javax.xml.transform.Result m_result
private String m_systemID
private Hashtable m_params
private javax.xml.transform.ErrorListener m_errorListener
javax.xml.transform.URIResolver m_URIResolver
private OutputProperties m_outputFormat
boolean m_foundFirstElement
Constructor Detail |
public TransformerIdentityImpl()
Method Detail |
public void setResult(javax.xml.transform.Result result) throws IllegalArgumentException
setResult
in interface javax.xml.transform.sax.TransformerHandler
result
- A Result instance, should not be null.
IllegalArgumentException
- if result is invalid for some reason.public void setSystemId(String systemID)
setSystemId
in interface javax.xml.transform.sax.TransformerHandler
systemID
- Base URI for the source tree.public String getSystemId()
getSystemId
in interface javax.xml.transform.sax.TransformerHandler
setSystemId(java.lang.String)
.public javax.xml.transform.Transformer getTransformer()
getTransformer
in interface javax.xml.transform.sax.TransformerHandler
private void createResultContentHandler(javax.xml.transform.Result outputTarget) throws javax.xml.transform.TransformerException
outputTarget
- Where the transform result should go,
should not be null.
javax.xml.transform.TransformerException
public void transform(javax.xml.transform.Source source, javax.xml.transform.Result outputTarget) throws javax.xml.transform.TransformerException
source
- The input for the source tree.outputTarget
- The output target.
javax.xml.transform.TransformerException
- If an unrecoverable error occurs
during the course of the transformation.public void setParameter(String name, Object value)
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.
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.public Object getParameter(String name)
This method does not return a default parameter value, which cannot be determined until the node context is evaluated during the transformation process.
name
- Name of the parameter.
public void clearParameters()
public void setURIResolver(javax.xml.transform.URIResolver resolver)
If the resolver argument is null, the URIResolver value will be cleared, and the default behavior will be used.
resolver
- An object that implements the URIResolver interface,
or null.public javax.xml.transform.URIResolver getURIResolver()
public void setOutputProperties(Properties oformat) throws IllegalArgumentException
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.
oformat
- A set of output properties that will be
used to override any of the same properties in affect
for the transformation.
IllegalArgumentException
- if any of the argument keys are not
recognized and are not namespace qualified.OutputKeys
,
Properties
public Properties getOutputProperties()
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)
,
setOutputProperties(java.util.Properties)
, 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)
,
setOutputProperties(java.util.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.
OutputKeys
,
Properties
public void setOutputProperty(String name, String value) throws IllegalArgumentException
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)
won't
be effected by calling this method.
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.
IllegalArgumentException
- If the property is not supported, and is
not qualified with a namespace.OutputKeys
public String getOutputProperty(String name) throws IllegalArgumentException
name
- A non-null String that specifies an output
property name, which may be namespace qualified.
IllegalArgumentException
- If the property is not supported.OutputKeys
public void setErrorListener(javax.xml.transform.ErrorListener listener) throws IllegalArgumentException
listener
- The new error listener.
IllegalArgumentException
- if listener is null.public javax.xml.transform.ErrorListener getErrorListener()
public void notationDecl(String name, String publicId, String systemId) throws org.xml.sax.SAXException
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.
notationDecl
in interface org.xml.sax.DTDHandler
name
- The notation name.publicId
- The notation public identifier, or null if not
available.systemId
- The notation system identifier.
org.xml.sax.SAXException
- Any SAX exception, possibly
wrapping another exception.
org.xml.sax.SAXException
DTDHandler.notationDecl(java.lang.String, java.lang.String, java.lang.String)
public void unparsedEntityDecl(String name, String publicId, String systemId, String notationName) throws org.xml.sax.SAXException
By default, do nothing. Application writers may override this method in a subclass to keep track of the unparsed entities declared in a document.
unparsedEntityDecl
in interface org.xml.sax.DTDHandler
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.
org.xml.sax.SAXException
- Any SAX exception, possibly
wrapping another exception.
org.xml.sax.SAXException
DTDHandler.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
public void setDocumentLocator(org.xml.sax.Locator locator)
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.
setDocumentLocator
in interface org.xml.sax.ContentHandler
locator
- A locator for all SAX document events.ContentHandler.setDocumentLocator(org.xml.sax.Locator)
,
Locator
public void startDocument() throws org.xml.sax.SAXException
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).
startDocument
in interface org.xml.sax.ContentHandler
org.xml.sax.SAXException
- Any SAX exception, possibly
wrapping another exception.
org.xml.sax.SAXException
ContentHandler.startDocument()
protected final void flushStartDoc() throws org.xml.sax.SAXException
org.xml.sax.SAXException
public void endDocument() throws org.xml.sax.SAXException
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).
endDocument
in interface org.xml.sax.ContentHandler
org.xml.sax.SAXException
- Any SAX exception, possibly
wrapping another exception.
org.xml.sax.SAXException
ContentHandler.endDocument()
public void startPrefixMapping(String prefix, String uri) throws org.xml.sax.SAXException
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).
startPrefixMapping
in interface org.xml.sax.ContentHandler
prefix
- The Namespace prefix being declared.uri
- The Namespace URI mapped to the prefix.
org.xml.sax.SAXException
- Any SAX exception, possibly
wrapping another exception.
org.xml.sax.SAXException
ContentHandler.startPrefixMapping(java.lang.String, java.lang.String)
public void endPrefixMapping(String prefix) throws org.xml.sax.SAXException
By default, do nothing. Application writers may override this method in a subclass to take specific actions at the end of each prefix mapping.
endPrefixMapping
in interface org.xml.sax.ContentHandler
prefix
- The Namespace prefix being declared.
org.xml.sax.SAXException
- Any SAX exception, possibly
wrapping another exception.
org.xml.sax.SAXException
ContentHandler.endPrefixMapping(java.lang.String)
public void startElement(String uri, String localName, String qName, org.xml.sax.Attributes attributes) throws org.xml.sax.SAXException
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).
startElement
in interface org.xml.sax.ContentHandler
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.
org.xml.sax.SAXException
- Any SAX exception, possibly
wrapping another exception.
org.xml.sax.SAXException
ContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
public void endElement(String uri, String localName, String qName) throws org.xml.sax.SAXException
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).
endElement
in interface org.xml.sax.ContentHandler
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.
org.xml.sax.SAXException
- Any SAX exception, possibly
wrapping another exception.
org.xml.sax.SAXException
ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)
public void characters(char[] ch, int start, int length) throws org.xml.sax.SAXException
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).
characters
in interface org.xml.sax.ContentHandler
ch
- The characters.start
- The start position in the character array.length
- The number of characters to use from the
character array.
org.xml.sax.SAXException
- Any SAX exception, possibly
wrapping another exception.
org.xml.sax.SAXException
ContentHandler.characters(char[], int, int)
public void ignorableWhitespace(char[] ch, int start, int length) throws org.xml.sax.SAXException
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).
ignorableWhitespace
in interface org.xml.sax.ContentHandler
ch
- The whitespace characters.start
- The start position in the character array.length
- The number of characters to use from the
character array.
org.xml.sax.SAXException
- Any SAX exception, possibly
wrapping another exception.
org.xml.sax.SAXException
ContentHandler.ignorableWhitespace(char[], int, int)
public void processingInstruction(String target, String data) throws org.xml.sax.SAXException
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.
processingInstruction
in interface org.xml.sax.ContentHandler
target
- The processing instruction target.data
- The processing instruction data, or null if
none is supplied.
org.xml.sax.SAXException
- Any SAX exception, possibly
wrapping another exception.
org.xml.sax.SAXException
ContentHandler.processingInstruction(java.lang.String, java.lang.String)
public void skippedEntity(String name) throws org.xml.sax.SAXException
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.
skippedEntity
in interface org.xml.sax.ContentHandler
name
- The name of the skipped entity.
org.xml.sax.SAXException
- Any SAX exception, possibly
wrapping another exception.
org.xml.sax.SAXException
ContentHandler.processingInstruction(java.lang.String, java.lang.String)
public void startDTD(String name, String publicId, String systemId) throws org.xml.sax.SAXException
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.
startDTD
in interface org.xml.sax.ext.LexicalHandler
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.
org.xml.sax.SAXException
- The application may raise an
exception.endDTD()
,
startEntity(java.lang.String)
public void endDTD() throws org.xml.sax.SAXException
endDTD
in interface org.xml.sax.ext.LexicalHandler
org.xml.sax.SAXException
- The application may raise an exception.startDTD(java.lang.String, java.lang.String, java.lang.String)
public void startEntity(String name) throws org.xml.sax.SAXException
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.
startEntity
in interface org.xml.sax.ext.LexicalHandler
name
- The name of the entity. If it is a parameter
entity, the name will begin with '%'.
org.xml.sax.SAXException
- The application may raise an exception.endEntity(java.lang.String)
,
DeclHandler.internalEntityDecl(java.lang.String, java.lang.String)
,
DeclHandler.externalEntityDecl(java.lang.String, java.lang.String, java.lang.String)
public void endEntity(String name) throws org.xml.sax.SAXException
endEntity
in interface org.xml.sax.ext.LexicalHandler
name
- The name of the entity that is ending.
org.xml.sax.SAXException
- The application may raise an exception.startEntity(java.lang.String)
public void startCDATA() throws org.xml.sax.SAXException
The contents of the CDATA section will be reported through
the regular characters
event.
startCDATA
in interface org.xml.sax.ext.LexicalHandler
org.xml.sax.SAXException
- The application may raise an exception.endCDATA()
public void endCDATA() throws org.xml.sax.SAXException
endCDATA
in interface org.xml.sax.ext.LexicalHandler
org.xml.sax.SAXException
- The application may raise an exception.startCDATA()
public void comment(char[] ch, int start, int length) throws org.xml.sax.SAXException
This callback will be used for comments inside or outside the document element, including comments in the external DTD subset (if read).
comment
in interface org.xml.sax.ext.LexicalHandler
ch
- An array holding the characters in the comment.start
- The starting position in the array.length
- The number of characters to use from the array.
org.xml.sax.SAXException
- The application may raise an exception.public void elementDecl(String name, String model) throws org.xml.sax.SAXException
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.
elementDecl
in interface org.xml.sax.ext.DeclHandler
name
- The element type name.model
- The content model as a normalized string.
org.xml.sax.SAXException
- The application may raise an exception.public void attributeDecl(String eName, String aName, String type, String valueDefault, String value) throws org.xml.sax.SAXException
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.
attributeDecl
in interface org.xml.sax.ext.DeclHandler
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.
org.xml.sax.SAXException
- The application may raise an exception.public void internalEntityDecl(String name, String value) throws org.xml.sax.SAXException
Only the effective (first) declaration for each entity will be reported.
internalEntityDecl
in interface org.xml.sax.ext.DeclHandler
name
- The name of the entity. If it is a parameter
entity, the name will begin with '%'.value
- The replacement text of the entity.
org.xml.sax.SAXException
- The application may raise an exception.externalEntityDecl(java.lang.String, java.lang.String, java.lang.String)
,
DTDHandler.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
public void externalEntityDecl(String name, String publicId, String systemId) throws org.xml.sax.SAXException
Only the effective (first) declaration for each entity will be reported.
externalEntityDecl
in interface org.xml.sax.ext.DeclHandler
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.
org.xml.sax.SAXException
- The application may raise an exception.internalEntityDecl(java.lang.String, java.lang.String)
,
DTDHandler.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |