This class wraps another SerializationHandler. The wrapped object will either
handler XML or HTML, which is not known until a little later when the first XML
tag is seen. If the first tag is then the wrapped object is an HTML
handler, otherwise it is an XML handler.
This class effectively caches the first few calls to it then passes them
on to the wrapped handler (once it exists). After that subsequent calls a
simply passed directly to the wrapped handler.
The user of this class doesn't know if the output is ultimatley XML or HTML.
This class is not a public API, it is public because it is used within Xalan.
| Method from com.sun.org.apache.xml.internal.serializer.ToUnknownStream Detail: |
public void addAttribute(String rawName,
String value) {
if (m_firstTagNotEmitted)
{
flush();
}
m_handler.addAttribute(rawName, value);
}
Adds an attribute to the currenly open tag |
public void addAttribute(String uri,
String localName,
String rawName,
String type,
String value) throws SAXException {
addAttribute(uri, localName, rawName, type, value, false);
}
Adds an attribute to the currenly open tag |
public void addAttribute(String uri,
String localName,
String rawName,
String type,
String value,
boolean XSLAttribute) throws SAXException {
if (m_firstTagNotEmitted)
{
flush();
}
m_handler.addAttribute(uri, localName, rawName, type, value, XSLAttribute);
}
Adds an attribute to the currenly open tag |
public void addAttributes(Attributes atts) throws SAXException {
m_handler.addAttributes(atts);
}
|
public void addUniqueAttribute(String rawName,
String value,
int flags) throws SAXException {
if (m_firstTagNotEmitted)
{
flush();
}
m_handler.addUniqueAttribute(rawName, value, flags);
}
Adds a unique attribute to the currenly open tag |
public ContentHandler asContentHandler() throws IOException {
/* don't return the real handler ( m_handler ) because
* that would expose the real handler to the outside.
* Keep m_handler private so it can be internally swapped
* to an HTML handler.
*/
return this;
}
|
public DOMSerializer asDOMSerializer() throws IOException {
return m_handler.asDOMSerializer();
}
|
public void attributeDecl(String arg0,
String arg1,
String arg2,
String arg3,
String arg4) throws SAXException {
m_handler.attributeDecl(arg0, arg1, arg2, arg3, arg4);
}
Pass the call on to the underlying handler |
public void characters(String chars) throws SAXException {
final int length = chars.length();
if (length > m_charsBuff.length)
{
m_charsBuff = new char[length*2 + 1];
}
chars.getChars(0, length, m_charsBuff, 0);
this.characters(m_charsBuff, 0, length);
}
Converts the String to a character array and calls the SAX method
characters(char[],int,int); |
public void characters(char[] characters,
int offset,
int length) throws SAXException {
if (m_firstTagNotEmitted)
{
flush();
}
m_handler.characters(characters, offset, length);
}
Pass the call on to the underlying handler |
public void close() {
m_handler.close();
}
|
public void comment(String comment) throws SAXException {
if (m_firstTagNotEmitted && m_firstElementName != null)
{
emitFirstTag();
}
else if (m_needToCallStartDocument)
{
m_handler.startDocument();
m_needToCallStartDocument = false;
}
m_handler.comment(comment);
}
Pass the call on to the underlying handler |
public void comment(char[] ch,
int start,
int length) throws SAXException {
if (m_firstTagNotEmitted)
{
flush();
}
m_handler.comment(ch, start, length);
}
Pass the call on to the underlying handler |
public void elementDecl(String arg0,
String arg1) throws SAXException {
if (m_firstTagNotEmitted)
{
emitFirstTag();
}
m_handler.elementDecl(arg0, arg1);
}
Pass the call on to the underlying handler |
public void endCDATA() throws SAXException {
m_handler.endCDATA();
}
Pass the call on to the underlying handler |
public void endDTD() throws SAXException {
m_handler.endDTD();
}
Pass the call on to the underlying handler |
public void endDocument() throws SAXException {
if (m_firstTagNotEmitted)
{
flush();
}
m_handler.endDocument();
}
Pass the call on to the underlying handler |
public void endElement(String elementName) throws SAXException {
if (m_firstTagNotEmitted)
{
flush();
}
m_handler.endElement(elementName);
}
Pass the call on to the underlying handler |
public void endElement(String namespaceURI,
String localName,
String qName) throws SAXException {
if (m_firstTagNotEmitted)
{
flush();
if (namespaceURI == null && m_firstElementURI != null)
namespaceURI = m_firstElementURI;
if (localName == null && m_firstElementLocalName != null)
localName = m_firstElementLocalName;
}
m_handler.endElement(namespaceURI, localName, qName);
}
Pass the call on to the underlying handler |
public void endEntity(String name) throws SAXException {
if (m_firstTagNotEmitted)
{
emitFirstTag();
}
m_handler.endEntity(name);
}
Pass the call on to the underlying handler |
public void endPrefixMapping(String prefix) throws SAXException {
m_handler.endPrefixMapping(prefix);
}
Pass the call on to the underlying handler |
public void entityReference(String entityName) throws SAXException {
m_handler.entityReference(entityName);
}
|
public void externalEntityDecl(String name,
String publicId,
String systemId) throws SAXException {
if (m_firstTagNotEmitted)
{
flush();
}
m_handler.externalEntityDecl(name, publicId, systemId);
}
Pass the call on to the underlying handler |
protected void firePseudoElement(String elementName) {
if (m_tracer != null) {
StringBuffer sb = new StringBuffer();
sb.append('< ");
sb.append(elementName);
// convert the StringBuffer to a char array and
// emit the trace event that these characters "might"
// be written
char ch[] = sb.toString().toCharArray();
m_tracer.fireGenerateEvent(
SerializerTrace.EVENTTYPE_OUTPUT_PSEUDO_CHARACTERS,
ch,
0,
ch.length);
}
}
|
public void flushPending() throws SAXException {
flush();
m_handler.flushPending();
}
|
public String getDoctypePublic() {
return m_handler.getDoctypePublic();
}
Pass the call on to the underlying handler |
public String getDoctypeSystem() {
return m_handler.getDoctypeSystem();
}
Pass the call on to the underlying handler |
public String getEncoding() {
return m_handler.getEncoding();
}
Pass the call on to the underlying handler |
public boolean getIndent() {
return m_handler.getIndent();
}
Pass the call on to the underlying handler |
public int getIndentAmount() {
return m_handler.getIndentAmount();
}
Pass the call on to the underlying handler |
public String getMediaType() {
return m_handler.getMediaType();
}
Pass the call on to the underlying handler |
public NamespaceMappings getNamespaceMappings() {
NamespaceMappings mappings = null;
if (m_handler != null)
{
mappings = m_handler.getNamespaceMappings();
}
return mappings;
}
Get the current namespace mappings.
Simply returns the mappings of the wrapped handler. |
public String getNamespaceURI(String qname,
boolean isElement) {
return m_handler.getNamespaceURI(qname, isElement);
}
|
public String getNamespaceURIFromPrefix(String prefix) {
return m_handler.getNamespaceURIFromPrefix(prefix);
}
|
public boolean getOmitXMLDeclaration() {
return m_handler.getOmitXMLDeclaration();
}
Pass the call on to the underlying handler |
public Properties getOutputFormat() {
return m_handler.getOutputFormat();
}
|
public OutputStream getOutputStream() {
return m_handler.getOutputStream();
}
|
public String getPrefix(String namespaceURI) {
return m_handler.getPrefix(namespaceURI);
}
|
public String getStandalone() {
return m_handler.getStandalone();
}
Pass the call on to the underlying handler |
public Transformer getTransformer() {
return m_handler.getTransformer();
}
|
public String getVersion() {
return m_handler.getVersion();
}
Pass the call on to the underlying handler |
public Writer getWriter() {
return m_handler.getWriter();
}
|
public void ignorableWhitespace(char[] ch,
int start,
int length) throws SAXException {
if (m_firstTagNotEmitted)
{
flush();
}
m_handler.ignorableWhitespace(ch, start, length);
}
Pass the call on to the underlying handler |
public void internalEntityDecl(String arg0,
String arg1) throws SAXException {
if (m_firstTagNotEmitted)
{
flush();
}
m_handler.internalEntityDecl(arg0, arg1);
}
Pass the call on to the underlying handler |
public void namespaceAfterStartElement(String prefix,
String uri) throws SAXException {
// hack for XSLTC with finding URI for default namespace
if (m_firstTagNotEmitted && m_firstElementURI == null && m_firstElementName != null)
{
String prefix1 = getPrefixPart(m_firstElementName);
if (prefix1 == null && EMPTYSTRING.equals(prefix))
{
// the elements URI is not known yet, and it
// doesn't have a prefix, and we are currently
// setting the uri for prefix "", so we have
// the uri for the element... lets remember it
m_firstElementURI = uri;
}
}
startPrefixMapping(prefix,uri, false);
}
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. |
public void processingInstruction(String target,
String data) throws SAXException {
if (m_firstTagNotEmitted)
{
flush();
}
m_handler.processingInstruction(target, data);
}
Pass the call on to the underlying handler |
public boolean reset() {
return m_handler.reset();
}
passes the call on to the underlying HTML or XML handler |
public void serialize(Node node) throws IOException {
if (m_firstTagNotEmitted)
{
flush();
}
m_handler.serialize(node);
}
Converts the DOM node to output |
public void setCdataSectionElements(Vector URI_and_localNames) {
m_handler.setCdataSectionElements(URI_and_localNames);
}
|
public void setContentHandler(ContentHandler ch) {
m_handler.setContentHandler(ch);
}
|
public void setDoctype(String system,
String pub) {
m_handler.setDoctypePublic(pub);
m_handler.setDoctypeSystem(system);
}
|
public void setDoctypePublic(String doctype) {
m_handler.setDoctypePublic(doctype);
m_setDoctypePublic_called = true;
}
Set the doctype in the underlying XML handler. Remember that this method
was called, just in case we need to transfer this doctype to an HTML handler |
public void setDoctypeSystem(String doctype) {
m_handler.setDoctypeSystem(doctype);
m_setDoctypeSystem_called = true;
}
Set the doctype in the underlying XML handler. Remember that this method
was called, just in case we need to transfer this doctype to an HTML handler |
public void setDocumentLocator(Locator locator) {
super.setDocumentLocator(locator);
m_handler.setDocumentLocator(locator);
}
Pass the call on to the underlying handler |
public void setEncoding(String encoding) {
m_handler.setEncoding(encoding);
}
Pass the call on to the underlying handler |
public boolean setEscaping(boolean escape) throws SAXException {
return m_handler.setEscaping(escape);
}
|
public void setIndent(boolean indent) {
m_handler.setIndent(indent);
}
Pass the call on to the underlying handler |
public void setIndentAmount(int value) {
m_handler.setIndentAmount(value);
}
Pass the call on to the underlying handler |
public void setMediaType(String mediaType) {
m_handler.setMediaType(mediaType);
m_setMediaType_called = true;
}
|
public void setOmitXMLDeclaration(boolean b) {
m_handler.setOmitXMLDeclaration(b);
}
Pass the call on to the underlying handler |
public void setOutputFormat(Properties format) {
m_handler.setOutputFormat(format);
}
Set the properties of the handler |
public void setOutputStream(OutputStream output) {
m_handler.setOutputStream(output);
}
Sets the output stream to write to |
public void setSourceLocator(SourceLocator locator) {
m_handler.setSourceLocator(locator);
}
This method is used to set the source locator, which might be used to
generated an error message. |
public void setStandalone(String standalone) {
m_handler.setStandalone(standalone);
}
Pass the call on to the underlying handler |
public void setTransformer(Transformer t) {
m_handler.setTransformer(t);
if ((t instanceof SerializerTrace) &&
(((SerializerTrace) t).hasTraceListeners())) {
m_tracer = (SerializerTrace) t;
} else {
m_tracer = null;
}
}
|
public void setVersion(String version) {
m_handler.setVersion(version);
// Cache call to setVersion()
// super.setVersion(version);
m_setVersion_called = true;
}
This method cannot be cached because default is different in
HTML and XML (we need more than a boolean). |
public void setWriter(Writer writer) {
m_handler.setWriter(writer);
}
Sets the writer to write to |
public void skippedEntity(String name) throws SAXException {
m_handler.skippedEntity(name);
}
Pass the call on to the underlying handler |
public void startCDATA() throws SAXException {
m_handler.startCDATA();
}
Pass the call on to the underlying handler |
public void startDTD(String name,
String publicId,
String systemId) throws SAXException {
m_handler.startDTD(name, publicId, systemId);
}
Pass the call on to the underlying handler |
public void startDocument() throws SAXException {
m_needToCallStartDocument = true;
}
|
public void startElement(String qName) throws SAXException {
this.startElement(null, null, qName, null);
}
|
public void startElement(String namespaceURI,
String localName,
String qName) throws SAXException {
this.startElement(namespaceURI, localName, qName, null);
}
|
public void startElement(String namespaceURI,
String localName,
String elementName,
Attributes atts) throws SAXException {
if (m_needToCallSetDocumentInfo){
super.setDocumentInfo();
m_needToCallSetDocumentInfo = false;
}
/* we are notified of the start of an element */
if (m_firstTagNotEmitted)
{
/* we have not yet sent the first element on its way */
if (m_firstElementName != null)
{
/* this is not the first element, but a later one.
* But we have the old element pending, so flush it out,
* then send this one on its way.
*/
flush();
m_handler.startElement(namespaceURI, localName, elementName, atts);
}
else
{
/* this is the very first element that we have seen,
* so save it for flushing later. We may yet get to know its
* URI due to added attributes.
*/
m_wrapped_handler_not_initialized = true;
m_firstElementName = elementName;
// null if not known
m_firstElementPrefix = getPrefixPartUnknown(elementName);
// null if not known
m_firstElementURI = namespaceURI;
// null if not known
m_firstElementLocalName = localName;
if (m_tracer != null)
firePseudoElement(elementName);
/* we don't want to call our own addAttributes, which
* merely delegates to the wrapped handler, but we want to
* add these attributes to m_attributes. So me must call super.
* addAttributes() In this case m_attributes is only used for the
* first element, after that this class totally delegates to the
* wrapped handler which is either XML or HTML.
*/
if (atts != null)
super.addAttributes(atts);
// if there are attributes, then lets make the flush()
// call the startElement on the handler and send the
// attributes on their way.
if (atts != null)
flush();
}
}
else
{
// this is not the first element, but a later one, so just
// send it on its way.
m_handler.startElement(namespaceURI, localName, elementName, atts);
}
}
|
public void startEntity(String name) throws SAXException {
m_handler.startEntity(name);
}
Pass the call on to the underlying handler |
public void startPrefixMapping(String prefix,
String uri) throws SAXException {
this.startPrefixMapping(prefix,uri, true);
}
|
public boolean startPrefixMapping(String prefix,
String uri,
boolean shouldFlush) throws SAXException {
boolean pushed = false;
if (m_firstTagNotEmitted)
{
if (m_firstElementName != null && shouldFlush)
{
/* we've already seen a startElement, and this is a prefix mapping
* for the up coming element, so flush the old element
* then send this event on its way.
*/
flush();
pushed = m_handler.startPrefixMapping(prefix, uri, shouldFlush);
}
else
{
if (m_namespacePrefix == null)
{
m_namespacePrefix = new Vector();
m_namespaceURI = new Vector();
}
m_namespacePrefix.addElement(prefix);
m_namespaceURI.addElement(uri);
if (m_firstElementURI == null)
{
if (prefix.equals(m_firstElementPrefix))
m_firstElementURI = uri;
}
}
}
else
{
pushed = m_handler.startPrefixMapping(prefix, uri, shouldFlush);
}
return pushed;
}
|