Methods Summary |
---|
public void | addAttribute(java.lang.String uri, java.lang.String localName, java.lang.String rawName, java.lang.String type, java.lang.String value, boolean XSLAttribute)Adds the given attribute to the set of collected attributes , but only if
there is a currently open element.
An element is currently open if a startElement() notification has
occured but the start of the element has not yet been written to the
output. In the stream case this means that we have not yet been forced
to close the elements opening tag by another notification, such as a
character notification.
if (m_elemContext.m_startTagOpen)
{
addAttributeAlways(uri, localName, rawName, type, value, XSLAttribute);
}
|
public void | addAttribute(java.lang.String uri, java.lang.String localName, java.lang.String rawName, java.lang.String type, java.lang.String value)This method adds an attribute the the current element,
but should not be used for an xsl:attribute child.
if (m_elemContext.m_startTagOpen)
{
addAttributeAlways(uri, localName, rawName, type, value, false);
}
|
public void | addAttribute(java.lang.String name, java.lang.String value)Adds the given attribute to the set of collected attributes,
but only if there is a currently open element.
if (m_elemContext.m_startTagOpen)
{
final String patchedName = patchName(name);
final String localName = getLocalName(patchedName);
final String uri = getNamespaceURI(patchedName, false);
addAttributeAlways(uri,localName, patchedName, "CDATA", value, false);
}
|
public boolean | addAttributeAlways(java.lang.String uri, java.lang.String localName, java.lang.String rawName, java.lang.String type, java.lang.String value, boolean XSLAttribute)Adds the given attribute to the set of attributes, even if there is
no currently open element. This is useful if a SAX startPrefixMapping()
should need to add an attribute before the element name is seen.
boolean was_added;
// final int index =
// (localName == null || uri == null) ?
// m_attributes.getIndex(rawName):m_attributes.getIndex(uri, localName);
int index;
// if (localName == null || uri == null){
// index = m_attributes.getIndex(rawName);
// }
// else {
// index = m_attributes.getIndex(uri, localName);
// }
if (localName == null || uri == null || uri.length() == 0)
index = m_attributes.getIndex(rawName);
else {
index = m_attributes.getIndex(uri,localName);
}
if (index >= 0)
{
/* We've seen the attribute before.
* We may have a null uri or localName, but all
* we really want to re-set is the value anyway.
*/
m_attributes.setValue(index,value);
was_added = false;
}
else
{
// the attribute doesn't exist yet, create it
m_attributes.addAttribute(uri, localName, rawName, type, value);
was_added = true;
}
return was_added;
|
public void | addAttributes(org.xml.sax.Attributes atts)Add the given attributes to the currently collected ones. These
attributes are always added, regardless of whether on not an element
is currently open.
int nAtts = atts.getLength();
for (int i = 0; i < nAtts; i++)
{
String uri = atts.getURI(i);
if (null == uri)
uri = "";
addAttributeAlways(
uri,
atts.getLocalName(i),
atts.getQName(i),
atts.getType(i),
atts.getValue(i),
false);
}
|
public void | addXSLAttribute(java.lang.String name, java.lang.String value, java.lang.String uri)Adds the given xsl:attribute to the set of collected attributes,
but only if there is a currently open element.
if (m_elemContext.m_startTagOpen)
{
final String patchedName = patchName(name);
final String localName = getLocalName(patchedName);
addAttributeAlways(uri,localName, patchedName, "CDATA", value, true);
}
|
public org.xml.sax.ContentHandler | asContentHandler()Return a {@link ContentHandler} interface into this serializer.
If the serializer does not support the {@link ContentHandler}
interface, it should return null.
return this;
|
public com.sun.org.apache.xml.internal.serializer.DOMSerializer | asDOMSerializer()Return a {@link DOMSerializer} interface into this serializer. If the
serializer does not support the {@link DOMSerializer} interface, it should
return null.
return this;
|
public void | characters(org.w3c.dom.Node node)This method gets the nodes value as a String and uses that String as if
it were an input character notification.
flushPending();
String data = node.getNodeValue();
if (data != null)
{
final int length = data.length();
if (length > m_charsBuff.length)
{
m_charsBuff = new char[length * 2 + 1];
}
data.getChars(0, length, m_charsBuff, 0);
characters(m_charsBuff, 0, length);
}
|
public void | close()Flush and close the underlying java.io.Writer. This method applies to
ToStream serializers, not ToSAXHandler serializers.
// do nothing (base behavior)
|
public void | comment(java.lang.String data)Receive notification of a comment.
final int length = data.length();
if (length > m_charsBuff.length)
{
m_charsBuff = new char[length * 2 + 1];
}
data.getChars(0, length, m_charsBuff, 0);
comment(m_charsBuff, 0, length);
|
public void | endEntity(java.lang.String name)Report the end of an entity.
if (name.equals("[dtd]"))
m_inExternalDTD = false;
m_inEntityRef = false;
if (m_tracer != null)
this.fireEndEntity(name);
|
public void | entityReference(java.lang.String name)Entity reference event.
flushPending();
startEntity(name);
endEntity(name);
if (m_tracer != null)
fireEntityReference(name);
|
public void | error(org.xml.sax.SAXParseException exc)
|
public void | fatalError(org.xml.sax.SAXParseException exc)
m_elemContext.m_startTagOpen = false;
|
protected void | fireCDATAEvent(char[] chars, int start, int length)Report the CDATA trace event
if (m_tracer != null)
{
flushMyWriter();
m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_CDATA, chars, start,length);
}
|
protected void | fireCharEvent(char[] chars, int start, int length)Report the characters trace event
if (m_tracer != null)
{
flushMyWriter();
m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_CHARACTERS, chars, start,length);
}
|
protected void | fireCommentEvent(char[] chars, int start, int length)Report the comment trace event
if (m_tracer != null)
{
flushMyWriter();
m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_COMMENT, new String(chars, start, length));
}
|
protected void | fireEndDoc()To fire off end document trace event
if (m_tracer != null)
{
flushMyWriter();
m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_ENDDOCUMENT);
}
|
protected void | fireEndElem(java.lang.String name)To fire off the end element trace event
if (m_tracer != null)
{
flushMyWriter();
m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_ENDELEMENT,name, (Attributes)null);
}
|
public void | fireEndEntity(java.lang.String name)To fire off end entity trace event
if (m_tracer != null)
flushMyWriter();
// we do not need to handle this.
|
protected void | fireEntityReference(java.lang.String name)To fire off the entity reference trace event
if (m_tracer != null)
{
flushMyWriter();
m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_ENTITYREF,name, (Attributes)null);
}
|
protected void | fireEscapingEvent(java.lang.String name, java.lang.String data)To fire off the PI trace event
if (m_tracer != null)
{
flushMyWriter();
m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_PI,name, data);
}
|
protected void | fireStartDoc()To fire off start document trace event
if (m_tracer != null)
{
flushMyWriter();
m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_STARTDOCUMENT);
}
|
protected void | fireStartElem(java.lang.String elemName)Report the start element trace event. This trace method needs to be
called just before the attributes are cleared.
if (m_tracer != null)
{
flushMyWriter();
m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_STARTELEMENT,
elemName, m_attributes);
}
|
protected void | fireStartEntity(java.lang.String name)To fire off start entity trace event
if (m_tracer != null)
{
flushMyWriter();
m_tracer.fireGenerateEvent(SerializerTrace.EVENTTYPE_ENTITYREF, name);
}
|
private void | flushMyWriter()This method is only used internally when flushing the writer from the
various fire...() trace events. Due to the writer being wrapped with
SerializerTraceWriter it may cause the flush of these trace events:
EVENTTYPE_OUTPUT_PSEUDO_CHARACTERS
EVENTTYPE_OUTPUT_CHARACTERS
which trace the output written to the output stream.
if (m_writer != null)
{
try
{
m_writer.flush();
}
catch(IOException ioe)
{
}
}
|
public java.lang.String | getDoctypePublic()Returns the previously set value of the value to be used as the public
identifier in the document type declaration (DTD).
return m_doctypePublic;
|
public java.lang.String | getDoctypeSystem()Returns the previously set value of the value to be used
as the system identifier in the document type declaration (DTD).
return m_doctypeSystem;
|
public java.lang.String | getEncoding()Returns the character encoding to be used in the output document.
return m_encoding;
|
public boolean | getIndent()
return m_doIndent;
|
public int | getIndentAmount()
return m_indentAmount;
|
protected static java.lang.String | getLocalName(java.lang.String qname)Returns the local name of a qualified name. If the name has no prefix,
then it works as the identity (SAX2).
final int col = qname.lastIndexOf(':");
return (col > 0) ? qname.substring(col + 1) : qname;
|
public java.lang.String | getMediaType()Gets the mediatype the media-type or MIME type associated with the output
document.
return m_mediatype;
|
public com.sun.org.apache.xml.internal.serializer.NamespaceMappings | getNamespaceMappings()Some users of the serializer may need the current namespace mappings
return m_prefixMap;
|
public java.lang.String | getNamespaceURI(java.lang.String qname, boolean isElement)Returns the URI of an element or attribute. Note that default namespaces
do not apply directly to attributes.
String uri = EMPTYSTRING;
int col = qname.lastIndexOf(':");
final String prefix = (col > 0) ? qname.substring(0, col) : EMPTYSTRING;
if (!EMPTYSTRING.equals(prefix) || isElement)
{
if (m_prefixMap != null)
{
uri = m_prefixMap.lookupNamespace(prefix);
if (uri == null && !prefix.equals(XMLNS_PREFIX))
{
throw new RuntimeException(
Utils.messages.createMessage(
MsgKey.ER_NAMESPACE_PREFIX,
new Object[] { qname.substring(0, col) } ));
}
}
}
return uri;
|
public java.lang.String | getNamespaceURIFromPrefix(java.lang.String prefix)Returns the URI of prefix (if any)
String uri = null;
if (m_prefixMap != null)
uri = m_prefixMap.lookupNamespace(prefix);
return uri;
|
public boolean | getOmitXMLDeclaration()
return m_shouldNotWriteXMLHeader;
|
public java.lang.String | getPrefix(java.lang.String namespaceURI)Returns the prefix currently pointing to the given URI (if any).
String prefix = m_prefixMap.lookupPrefix(namespaceURI);
return prefix;
|
protected static final java.lang.String | getPrefixPart(java.lang.String qname)Returns the local name of a qualified name.
If the name has no prefix,
then it works as the identity (SAX2).
final int col = qname.indexOf(':");
return (col > 0) ? qname.substring(0, col) : null;
//return (col > 0) ? qname.substring(0,col) : "";
|
public java.lang.String | getStandalone()Gets the XSL standalone attribute
return m_standalone;
|
public javax.xml.transform.Transformer | getTransformer()Gets the transformer associated with this serializer
return m_transformer;
|
public java.lang.String | getVersion()Gets the version of the output format.
return m_version;
|
final boolean | inTemporaryOutputState()Returns true if the serializer is used for temporary output rather than
final output.
This concept is made clear in the XSLT 2.0 draft.
/* This is a hack. We should really be letting the serializer know
* that it is in temporary output state with an explicit call, but
* from a pragmatic point of view (for now anyways) having no output
* encoding at all, not even the default UTF-8 indicates that the serializer
* is being used for temporary RTF.
*/
return (getEncoding() == null);
|
protected void | initCDATA()Initialize global variables
// CDATA stack
// _cdataStack = new Stack();
// _cdataStack.push(new Integer(-1)); // push dummy value
|
protected boolean | isCdataSection()Push a boolean state based on if the name of the current element
is found in the list of qnames. A state is only pushed if
there were some cdata-section-names were specified.
Hidden parameters are the vector of qualified elements specified in
cdata-section-names attribute, and the m_cdataSectionStates stack
onto which whether the current element is in the list is pushed (true or
false). Other hidden parameters are the current elements namespaceURI,
localName and qName
boolean b = false;
if (null != m_cdataSectionElements)
{
if (m_elemContext.m_elementLocalName == null)
m_elemContext.m_elementLocalName =
getLocalName(m_elemContext.m_elementName);
if (m_elemContext.m_elementURI == null)
{
String prefix = getPrefixPart(m_elemContext.m_elementName);
if (prefix != null)
m_elemContext.m_elementURI =
m_prefixMap.lookupNamespace(prefix);
}
if ((null != m_elemContext.m_elementURI)
&& m_elemContext.m_elementURI.length() == 0)
m_elemContext.m_elementURI = null;
int nElems = m_cdataSectionElements.size();
// loop through 2 at a time, as these are pairs of URI and localName
for (int i = 0; i < nElems; i += 2)
{
String uri = (String) m_cdataSectionElements.elementAt(i);
String loc = (String) m_cdataSectionElements.elementAt(i + 1);
if (loc.equals(m_elemContext.m_elementLocalName)
&& subPartMatch(m_elemContext.m_elementURI, uri))
{
b = true;
break;
}
}
}
return b;
|
public void | namespaceAfterStartElement(java.lang.String uri, java.lang.String prefix)This method is used when a prefix/uri namespace mapping
is indicated after the element was started with a
startElement() and before and endElement().
startPrefixMapping(prefix,uri) would be used before the
startElement() call.
// default behavior is to do nothing
|
public void | notationDecl(java.lang.String arg0, java.lang.String arg1, java.lang.String arg2)
// This method just provides a definition to satisfy the interface
// A particular sub-class of SerializerBase provides the implementation (if desired)
|
protected java.lang.String | patchName(java.lang.String qname)If at runtime, when the qname of the attribute is
known, another prefix is specified for the attribute, then we can
patch or hack the name with this method. For
a qname of the form "ns?:otherprefix:name", this function patches the
qname by simply ignoring "otherprefix".
TODO: This method is a HACK! We do not have access to the
XML file, it sometimes generates a NS prefix of the form "ns?" for
an attribute.
final int lastColon = qname.lastIndexOf(':");
if (lastColon > 0) {
final int firstColon = qname.indexOf(':");
final String prefix = qname.substring(0, firstColon);
final String localName = qname.substring(lastColon + 1);
// If uri is "" then ignore prefix
final String uri = m_prefixMap.lookupNamespace(prefix);
if (uri != null && uri.length() == 0) {
return localName;
}
else if (firstColon != lastColon) {
return prefix + ':" + localName;
}
}
return qname;
|
public boolean | reset()
resetSerializerBase();
return true;
|
private void | resetSerializerBase()Reset all of the fields owned by SerializerBase
this.m_attributes.clear();
this.m_cdataSectionElements = null;
this.m_elemContext = new ElemContext();
this.m_doctypePublic = null;
this.m_doctypeSystem = null;
this.m_doIndent = false;
this.m_encoding = null;
this.m_indentAmount = 0;
this.m_inEntityRef = false;
this.m_inExternalDTD = false;
this.m_mediatype = null;
this.m_needToCallStartDocument = true;
this.m_needToOutputDocTypeDecl = false;
if (this.m_prefixMap != null)
this.m_prefixMap.reset();
this.m_shouldNotWriteXMLHeader = false;
this.m_sourceLocator = null;
this.m_standalone = null;
this.m_standaloneWasSpecified = false;
this.m_tracer = null;
this.m_transformer = null;
this.m_version = null;
// don't set writer to null, so that it might be re-used
//this.m_writer = null;
|
public void | setDTDEntityExpansion(boolean expand)If set to false the serializer does not expand DTD entities,
but leaves them as is, the default value is true.
// This method just provides a definition to satisfy the interface
// A particular sub-class of SerializerBase provides the implementation (if desired)
|
public void | setDoctype(java.lang.String doctypeSystem, java.lang.String doctypePublic)Set the value coming from the xsl:output doctype-public and doctype-system stylesheet properties
this.m_doctypeSystem = doctypeSystem;
this.m_doctypePublic = doctypePublic;
|
public void | setDoctypePublic(java.lang.String doctypePublic)Set the value coming from the xsl:output doctype-public stylesheet attribute.
this.m_doctypePublic = doctypePublic;
|
public void | setDoctypeSystem(java.lang.String doctypeSystem)Set the value coming from the xsl:output doctype-system stylesheet attribute.
this.m_doctypeSystem = doctypeSystem;
|
protected void | setDocumentInfo()
if (m_locator == null)
return;
try{
String strVersion = ((Locator2)m_locator).getXMLVersion();
if (strVersion != null)
setVersion(strVersion);
/*String strEncoding = ((Locator2)m_locator).getEncoding();
if (strEncoding != null)
setEncoding(strEncoding); */
}catch(ClassCastException e){}
|
public void | setDocumentLocator(org.xml.sax.Locator locator)Receive an object for locating the origin of SAX document events.
m_locator = locator;
|
public void | setEncoding(java.lang.String m_encoding)Sets the character encoding coming from the xsl:output encoding stylesheet attribute.
this.m_encoding = m_encoding;
|
public void | setIndent(boolean doIndent)Sets the value coming from the xsl:output indent stylesheet
attribute.
m_doIndent = doIndent;
|
public void | setIndentAmount(int m_indentAmount)Sets the indentation amount.
this.m_indentAmount = m_indentAmount;
|
public void | setMediaType(java.lang.String mediaType)Sets the value coming from the xsl:output media-type stylesheet attribute.
m_mediatype = mediaType;
|
public void | setNamespaceMappings(com.sun.org.apache.xml.internal.serializer.NamespaceMappings mappings)Used only by TransformerSnapshotImpl to restore the serialization
to a previous state.
m_prefixMap = mappings;
|
public void | setOmitXMLDeclaration(boolean b)Sets the value coming from the xsl:output omit-xml-declaration stylesheet attribute
this.m_shouldNotWriteXMLHeader = b;
|
public void | setSourceLocator(javax.xml.transform.SourceLocator locator)This method is used to set the source locator, which might be used to
generated an error message.
m_sourceLocator = locator;
|
public void | setStandalone(java.lang.String standalone)Sets the value coming from the xsl:output standalone stylesheet attribute.
if (standalone != null)
{
m_standaloneWasSpecified = true;
setStandaloneInternal(standalone);
}
|
protected void | setStandaloneInternal(java.lang.String standalone)Sets the XSL standalone attribute, but does not remember if this is a
default or explicite setting.
if ("yes".equals(standalone))
m_standalone = "yes";
else
m_standalone = "no";
|
public void | setTransformer(javax.xml.transform.Transformer t)Sets the transformer associated with this serializer
m_transformer = t;
// If this transformer object implements the SerializerTrace interface
// then assign m_tracer to the transformer object so it can be used
// to fire trace events.
if ((m_transformer instanceof SerializerTrace) &&
(((SerializerTrace) m_transformer).hasTraceListeners())) {
m_tracer = (SerializerTrace) m_transformer;
} else {
m_tracer = null;
}
|
public void | setVersion(java.lang.String version)Sets the value coming from the xsl:output version attribute.
m_version = version;
|
public void | startDocument()Receive notification of the beginning of a document.
This method is never a self generated call,
but only called externally.
The SAX parser will invoke this method only once, before any
other methods in this interface or in DTDHandler (except for
setDocumentLocator).
// if we do get called with startDocument(), handle it right away
startDocumentInternal();
m_needToCallStartDocument = false;
return;
|
protected void | startDocumentInternal()This method handles what needs to be done at a startDocument() call,
whether from an external caller, or internally called in the
serializer. For historical reasons the serializer is flexible to
startDocument() not always being called.
Even if no external call is
made into startDocument() this method will always be called as a self
generated internal startDocument, it handles what needs to be done at a
startDocument() call.
This method exists just to make sure that startDocument() is only ever
called from an external caller, which in principle is just a matter of
style.
if (m_tracer != null)
this.fireStartDoc();
|
private static final boolean | subPartMatch(java.lang.String p, java.lang.String t)Tell if two strings are equal, without worry if the first string is null.
return (p == t) || ((null != p) && (p.equals(t)));
|
public void | unparsedEntityDecl(java.lang.String arg0, java.lang.String arg1, java.lang.String arg2, java.lang.String arg3)
// This method just provides a definition to satisfy the interface
// A particular sub-class of SerializerBase provides the implementation (if desired)
|
public void | warning(org.xml.sax.SAXParseException exc)
|