|
BEA Systems, Inc. | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--weblogic.apache.xalan.serialize.SerializerToXML
SerializerToXML formats SAX-style events into XML.
This class is based on an implementation from the Apache XML Project. In future releases the XML parser, XSLT processor, and associated classes will likely be updated to be based on a later version of the Apache implementations. Since Apache does not guarantee backwards compatibility between versions of their software, we cannot guarantee backwards compatibility of any of the classes contained in the weblogic.apache package or sub-packages.
Field Summary | |
protected int |
level
Current level of indent. |
protected java.util.Vector |
m_cdataSectionNames
List of QNames obtained from the xsl:output properties. |
protected BoolStack |
m_cdataSectionStates
True will be pushed, if characters should be in CDATA section blocks. |
protected CharInfo |
m_charInfo
Map that tells which characters should have special treatment, and it provides character to entity name lookup. |
protected int |
m_currentIndent
Flag to keep track of the indent amount. |
protected BoolStack |
m_disableOutputEscapingStates
Stack to keep track of disabling output escaping. |
protected boolean |
m_doIndent
Flag to tell if indenting (pretty-printing) is on. |
protected BoolStack |
m_elemStack
A stack of Boolean objects that tell if the given element has children. |
protected java.lang.String |
m_encoding
The character encoding. |
protected java.util.Properties |
m_format
The xsl:output properties. |
protected boolean |
m_inCData
True if the current characters should be in CDATA blocks. |
int |
m_indentAmount
Amount to indent. |
protected boolean |
m_inEntityRef
Tells if we're in an EntityRef event. |
protected boolean |
m_ispreserve
State flag to tell if preservation of whitespace is important. |
protected boolean |
m_isprevtext
State flag that tells if the previous node processed was text, so we can tell if we should preserve whitespace. |
protected char[] |
m_lineSep
Use the system line seperator to write line breaks. |
protected int |
m_lineSepLen
The length of the line seperator, since the write is done one character at a time. |
protected int |
m_maxCharacter
The maximum character size before we have to resort to escaping. |
protected int |
m_pos
The current position in the m_charBuf or m_byteBuf. |
protected BoolStack |
m_preserves
Stack to keep track of whether or not we need to preserve whitespace. |
boolean |
m_shouldNotWriteXMLHeader
Tells if we should write the XML declaration. |
boolean |
m_spaceBeforeClose
Add space before '/>' for XHTML. |
java.lang.String |
m_version
Tells the XML version, for writing out to the XML decl. |
protected java.io.Writer |
m_writer
The writer where the XML will be written. |
protected static CharInfo |
m_xmlcharInfo
Map that tells which XML characters should have special treatment, and it provides character to entity name lookup. |
Constructor Summary | |
SerializerToXML()
Default constructor. |
Method Summary | |
protected void |
accum(char b)
Append a character to the buffer. |
protected void |
accum(char[] chars,
int start,
int length)
Append a character to the buffer. |
protected void |
accum(java.lang.String s)
Append a character to the buffer. |
protected int |
accumDefaultEntity(char ch,
int i,
char[] chars,
int len,
boolean escLF)
Handle one of the default entities, return false if it is not a default entity. |
protected int |
accumDefaultEscape(char ch,
int i,
char[] chars,
int len,
boolean escLF)
Escape and m_writer.write a character. |
org.xml.sax.ContentHandler |
asContentHandler()
Return a ContentHandler interface into this serializer. |
DOMSerializer |
asDOMSerializer()
Return a DOMSerializer interface into this serializer. |
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. |
boolean |
canConvert(char ch)
Tell if this character can be written without escaping. |
void |
cdata(char[] ch,
int start,
int length)
Receive notification of cdata. |
void |
characters(char[] chars,
int start,
int length)
Receive notification of character data. |
void |
charactersRaw(char[] ch,
int start,
int length)
If available, when the disable-output-escaping attribute is used, output raw text without escaping. |
protected boolean |
childNodesWereAdded()
Tell if child nodes have been added to the current element. |
void |
comment(char[] ch,
int start,
int length)
Report an XML comment anywhere in the document. |
void |
CopyFrom(SerializerToXML xmlListener)
Copy properties from another SerializerToXML. |
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 a document. |
void |
endDTD()
Report the end of DTD declarations. |
void |
endElement(java.lang.String namespaceURI,
java.lang.String localName,
java.lang.String name)
Receive notification of the end of an element. |
void |
endEntity(java.lang.String name)
Report the end of an entity. |
void |
endNonEscaping()
Ends an un-escaping section. |
void |
endPrefixMapping(java.lang.String prefix)
End the scope of a prefix-URI Namespace mapping. |
void |
endPreserving()
Ends a whitespace preserving section. |
void |
entityReference(java.lang.String name)
Receive notivication of a entityReference. |
void |
externalEntityDecl(java.lang.String name,
java.lang.String publicId,
java.lang.String systemId)
Report a parsed external entity declaration. |
void |
flushWriter()
Flush the formatter's result stream. |
java.util.Properties |
getOutputFormat()
Returns the output format for this serializer. |
java.io.OutputStream |
getOutputStream()
Get the output stream where the events will be serialized to. |
java.io.Writer |
getWriter()
Get the character stream where the events will be serialized to. |
void |
ignorableWhitespace(char[] ch,
int start,
int length)
Receive notification of ignorable whitespace in element content. |
void |
indent(int n)
Prints a newline character and n spaces. |
void |
init(java.io.OutputStream output,
java.util.Properties format)
Initialize the serializer with the specified output stream and output format. |
void |
init(java.io.Writer writer,
java.util.Properties format)
Initialize the serializer with the specified writer and output format. |
void |
internalEntityDecl(java.lang.String name,
java.lang.String value)
Report an internal entity declaration. |
protected boolean |
isCDataSection()
Tell if the characters in the current state should be put in cdata section blocks. |
protected boolean |
isEscapingDisabled()
Tell if the character escaping should be disabled for the current state. |
protected void |
openElementForChildren()
Flag the current element as not yet having any children. |
protected void |
outputLineSep()
Output a system-dependent line break. |
void |
printSpace(int n)
Prints n spaces. |
protected void |
processAttribute(java.lang.String name,
java.lang.String value)
Process an attribute. |
void |
processingInstruction(java.lang.String target,
java.lang.String data)
Receive notification of a processing instruction. |
protected void |
pushState(java.lang.String namespaceURI,
java.lang.String localName,
java.util.Vector qnames,
BoolStack state)
Push a boolean state based on if the name of the element is found in the list of qnames. |
boolean |
reset()
Resets the serializer. |
void |
serialize(org.w3c.dom.Node node)
Serializes the DOM node. |
void |
setDocumentLocator(org.xml.sax.Locator locator)
Receive an object for locating the origin of SAX document events. |
void |
setOutputFormat(java.util.Properties format)
Specifies an output format for this serializer. |
void |
setOutputStream(java.io.OutputStream output)
Specifies an output stream to which the document should be serialized. |
void |
setWriter(java.io.Writer writer)
Specifies a writer to which the document should be serialized. |
protected boolean |
shouldIndent()
Tell if, based on space preservation constraints and the doIndent property, if an indent should occur. |
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 a 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 namespaceURI,
java.lang.String localName,
java.lang.String name,
org.xml.sax.Attributes atts)
Receive notification of the beginning of an element. |
void |
startEntity(java.lang.String name)
Report the beginning of an entity. |
void |
startNonEscaping()
Starts an un-escaping section. |
void |
startPrefixMapping(java.lang.String prefix,
java.lang.String uri)
Begin the scope of a prefix-URI Namespace mapping. |
void |
startPreserving()
Starts a whitespace preserving section. |
protected static boolean |
subPartMatch(java.lang.String p,
java.lang.String t)
Tell if two strings are equal, without worry if the first string is null. |
void |
writeAttrString(java.lang.String string,
java.lang.String encoding)
Returns the specified string after substituting specials, and UTF-16 surrogates for chracter references &#xnn . |
protected void |
writeParentTagEnd()
Check to see if a parent's ">" has been written, and, if it has not, write it. |
protected int |
writeUTF16Surrogate(char c,
char[] ch,
int i,
int end)
Once a surrogate has been detected, write the pair as a single character reference. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
protected java.io.Writer m_writer
protected java.lang.String m_encoding
public boolean m_shouldNotWriteXMLHeader
public java.lang.String m_version
protected BoolStack m_elemStack
protected BoolStack m_disableOutputEscapingStates
protected BoolStack m_cdataSectionStates
protected java.util.Vector m_cdataSectionNames
protected boolean m_inCData
protected final char[] m_lineSep
protected final int m_lineSepLen
protected boolean m_ispreserve
protected BoolStack m_preserves
protected boolean m_isprevtext
protected boolean m_doIndent
protected int m_currentIndent
public int m_indentAmount
protected int level
protected boolean m_inEntityRef
protected static CharInfo m_xmlcharInfo
protected CharInfo m_charInfo
protected int m_maxCharacter
public boolean m_spaceBeforeClose
protected java.util.Properties m_format
protected int m_pos
Constructor Detail |
public SerializerToXML()
Method Detail |
protected boolean isEscapingDisabled()
protected boolean isCDataSection()
protected final void outputLineSep() throws org.xml.sax.SAXException
public void CopyFrom(SerializerToXML xmlListener)
xmlListener
- non-null reference to a SerializerToXML object.public void init(java.io.Writer writer, java.util.Properties format)
writer
- The writer to useformat
- The output formatpublic void init(java.io.OutputStream output, java.util.Properties format) throws java.io.UnsupportedEncodingException
output
- The output stream to useformat
- The output formatpublic void setDocumentLocator(org.xml.sax.Locator locator)
locator
- An object that can return the location of
any SAX document event.Locator
public void startDocument() throws org.xml.sax.SAXException
public void endDocument() throws org.xml.sax.SAXException
public void startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId) throws org.xml.sax.SAXException
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.endDTD()
,
startEntity(java.lang.String)
public void endDTD() throws org.xml.sax.SAXException
startDTD(java.lang.String, java.lang.String, java.lang.String)
public void startPrefixMapping(java.lang.String prefix, java.lang.String uri) throws org.xml.sax.SAXException
prefix
- The Namespace prefix being declared.uri
- The Namespace URI the prefix is mapped to.ContentHandler.startPrefixMapping(java.lang.String, java.lang.String)
public void endPrefixMapping(java.lang.String prefix) throws org.xml.sax.SAXException
prefix
- The prefix that was being mapping.ContentHandler.endPrefixMapping(java.lang.String)
protected static final boolean subPartMatch(java.lang.String p, java.lang.String t)
p
- String reference, which may be null.t
- String reference, which may be null.protected void pushState(java.lang.String namespaceURI, java.lang.String localName, java.util.Vector qnames, BoolStack state)
namespaceURI
- Should be a non-null reference to the namespace URL
of the element that owns the state, or empty string.localName
- Should be a non-null reference to the local name
of the element that owns the state.qnames
- Vector of qualified names of elements, or null.state
- The stack where the state should be pushed.public void startElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String name, org.xml.sax.Attributes atts) throws org.xml.sax.SAXException
namespaceURI
- 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.name
- The element type name.atts
- The attributes attached to the element, if any.ContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
,
ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)
,
AttributeList
protected void writeParentTagEnd() throws org.xml.sax.SAXException
protected void openElementForChildren()
protected boolean childNodesWereAdded()
public void endElement(java.lang.String namespaceURI, java.lang.String localName, java.lang.String name) throws org.xml.sax.SAXException
namespaceURI
- 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.name
- The element type nameprotected void processAttribute(java.lang.String name, java.lang.String value) throws org.xml.sax.SAXException
name
- The name of the attribute.value
- The value of the attribute.public void startNonEscaping() throws org.xml.sax.SAXException
The contents of the un-escaping section will be delivered through the regular characters event.
public void endNonEscaping() throws org.xml.sax.SAXException
startNonEscaping()
public void startPreserving() throws org.xml.sax.SAXException
The contents of the whitespace preserving section will be delivered through the regular characters event.
public void endPreserving() throws org.xml.sax.SAXException
startPreserving()
public void processingInstruction(java.lang.String target, java.lang.String data) throws org.xml.sax.SAXException
target
- The processing instruction target.data
- The processing instruction data, or null if
none was supplied.public void comment(char[] ch, int start, int length) throws org.xml.sax.SAXException
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.public void startCDATA() throws org.xml.sax.SAXException
endCDATA()
public void endCDATA() throws org.xml.sax.SAXException
startCDATA()
public void cdata(char[] ch, int start, int length) throws org.xml.sax.SAXException
The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information.
The application must not attempt to read from the array outside of the specified range.
Note that some parsers will report whitespace using the ignorableWhitespace() method rather than this one (validating parsers must do so).
ch
- The characters from the XML document.start
- The start position in the array.length
- The number of characters to read from the array.ignorableWhitespace(char[], int, int)
,
Locator
protected final void accum(char b) throws org.xml.sax.SAXException
b
- byte to be written to result stream.protected final void accum(char[] chars, int start, int length) throws org.xml.sax.SAXException
chars
- non-null reference to character array.start
- Start of characters to be written.length
- Number of characters to be written.protected final void accum(java.lang.String s) throws org.xml.sax.SAXException
s
- non-null reference to string to be written to the character buffer.public final void flushWriter() throws org.xml.sax.SAXException
public void characters(char[] chars, int start, int length) throws org.xml.sax.SAXException
The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks; however, all of the characters in any single event must come from the same external entity, so that the Locator provides useful information.
The application must not attempt to read from the array outside of the specified range.
Note that some parsers will report whitespace using the ignorableWhitespace() method rather than this one (validating parsers must do so).
chars
- The characters from the XML document.start
- The start position in the array.length
- The number of characters to read from the array.ignorableWhitespace(char[], int, int)
,
Locator
public void charactersRaw(char[] ch, int start, int length) throws org.xml.sax.SAXException
ch
- The characters from the XML document.start
- The start position in the array.length
- The number of characters to read from the array.protected int writeUTF16Surrogate(char c, char[] ch, int i, int end) throws java.io.IOException, org.xml.sax.SAXException
c
- the first part of the surrogate.ch
- Character array.i
- position Where the surrogate was detected.end
- The end index of the significant characters.public void ignorableWhitespace(char[] ch, int start, int length) throws org.xml.sax.SAXException
ch
- The characters from the XML document.start
- The start position in the array.length
- The number of characters to read from the array.characters(char[], int, int)
public void skippedEntity(java.lang.String name) throws org.xml.sax.SAXException
name
- The name of the skipped entity. If it is a
parameter entity, the name will begin with '%', and if
it is the external DTD subset, it will be the string
"[dtd]".ContentHandler.skippedEntity(java.lang.String)
public void startEntity(java.lang.String name) throws org.xml.sax.SAXException
name
- The name of the entity. If it is a parameter
entity, the name will begin with '%'.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(java.lang.String name) throws org.xml.sax.SAXException
name
- The name of the entity that is ending.startEntity(java.lang.String)
public void entityReference(java.lang.String name) throws org.xml.sax.SAXException
name
- The name of the entity.public void elementDecl(java.lang.String name, java.lang.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.
name
- The element type name.model
- The content model as a normalized string.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
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.
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.public void internalEntityDecl(java.lang.String name, java.lang.String value) throws org.xml.sax.SAXException
Only the effective (first) declaration for each entity will be reported.
name
- The name of the entity. If it is a parameter
entity, the name will begin with '%'.value
- The replacement text of the entity.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(java.lang.String name, java.lang.String publicId, java.lang.String systemId) throws org.xml.sax.SAXException
Only the effective (first) declaration for each entity will be reported.
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.internalEntityDecl(java.lang.String, java.lang.String)
,
DTDHandler.unparsedEntityDecl(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
protected int accumDefaultEntity(char ch, int i, char[] chars, int len, boolean escLF) throws org.xml.sax.SAXException
ch
- character to be escaped.i
- index into character array.chars
- non-null reference to character array.len
- length of chars.escLF
- true if the linefeed should be escaped.protected int accumDefaultEscape(char ch, int i, char[] chars, int len, boolean escLF) throws org.xml.sax.SAXException
ch
- character to be escaped.i
- index into character array.chars
- non-null reference to character array.len
- length of chars.escLF
- true if the linefeed should be escaped.public boolean canConvert(char ch)
public void writeAttrString(java.lang.String string, java.lang.String encoding) throws org.xml.sax.SAXException
&#xnn
.
string
- String to convert to XML format.encoding
- CURRENTLY NOT IMPLEMENTED.protected boolean shouldIndent()
public void printSpace(int n) throws org.xml.sax.SAXException
pw
- The character output stream to use.n
- Number of spaces to print.public void indent(int n) throws org.xml.sax.SAXException
pw
- The character output stream to use.n
- Number of spaces to print.public void setOutputStream(java.io.OutputStream output)
The encoding specified in the output properties is used, or if no encoding was specified, the default for the selected output method.
output
- The output streampublic java.io.OutputStream getOutputStream()
public void setWriter(java.io.Writer writer)
writer
- The output writer streampublic java.io.Writer getWriter()
public void setOutputFormat(java.util.Properties format)
format
- The output format to usepublic java.util.Properties getOutputFormat()
public org.xml.sax.ContentHandler asContentHandler() throws java.io.IOException
ContentHandler
interface into this serializer.
If the serializer does not support the ContentHandler
interface, it should return null.
ContentHandler
interface into this serializer,
or null if the serializer is not SAX 2 capablepublic DOMSerializer asDOMSerializer() throws java.io.IOException
DOMSerializer
interface into this serializer.
If the serializer does not support the DOMSerializer
interface, it should return null.
DOMSerializer
interface into this serializer,
or null if the serializer is not DOM capablepublic boolean reset()
public void serialize(org.w3c.dom.Node node) throws java.io.IOException
elem
- The element to serializenode
- Node to serialize.
|
Documentation is available at http://download.oracle.com/docs/cd/E13222_01/wls/docs70 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |