org.outerj.daisy.xmlutil
Class XmlSerializer.NamespaceAsAttributes

java.lang.Object
  extended by org.outerj.daisy.xmlutil.XmlSerializer.NamespaceAsAttributes
All Implemented Interfaces:
org.xml.sax.ContentHandler
Enclosing class:
XmlSerializer

public class XmlSerializer.NamespaceAsAttributes
extends java.lang.Object
implements org.xml.sax.ContentHandler

A pipe that ensures that all namespace prefixes are also present as 'xmlns:' attributes. This used to circumvent Xalan's serialization behaviour which is to ignore namespaces if they're not present as 'xmlns:xxx' attributes.

THIS CLASS IS COPIED FROM COCOON'S AbstractTextSerializer with some modifications


Constructor Summary
XmlSerializer.NamespaceAsAttributes(org.xml.sax.ContentHandler nextHandler)
           
 
Method Summary
 void characters(char[] ch, int start, int length)
           
 void endDocument()
           
 void endElement(java.lang.String eltUri, java.lang.String eltLocalName, java.lang.String eltQName)
          Receive notification of the end of an element.
 void endPrefixMapping(java.lang.String prefix)
          End the scope of a prefix-URI mapping: remove entry from mapping tables.
 void ignorableWhitespace(char[] ch, int start, int length)
           
 void processingInstruction(java.lang.String target, java.lang.String data)
           
 void setDocumentLocator(org.xml.sax.Locator locator)
           
 void skippedEntity(java.lang.String name)
           
 void startDocument()
           
 void startElement(java.lang.String eltUri, java.lang.String eltLocalName, java.lang.String eltQName, org.xml.sax.Attributes attrs)
          Ensure all namespace declarations are present as xmlns: attributes and add those needed before calling superclass.
 void startPrefixMapping(java.lang.String prefix, java.lang.String uri)
          Track mappings to be able to add xmlns: attributes in startElement().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlSerializer.NamespaceAsAttributes

public XmlSerializer.NamespaceAsAttributes(org.xml.sax.ContentHandler nextHandler)
Method Detail

startDocument

public void startDocument()
                   throws org.xml.sax.SAXException
Specified by:
startDocument in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

startPrefixMapping

public void startPrefixMapping(java.lang.String prefix,
                               java.lang.String uri)
                        throws org.xml.sax.SAXException
Track mappings to be able to add xmlns: attributes in startElement().

Specified by:
startPrefixMapping in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

startElement

public void startElement(java.lang.String eltUri,
                         java.lang.String eltLocalName,
                         java.lang.String eltQName,
                         org.xml.sax.Attributes attrs)
                  throws org.xml.sax.SAXException
Ensure all namespace declarations are present as xmlns: attributes and add those needed before calling superclass. This is a workaround for a Xalan bug (at least in version 2.0.1) : org.apache.xalan.serialize.SerializerToXML ignores start/endPrefixMapping().

Specified by:
startElement in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

endElement

public void endElement(java.lang.String eltUri,
                       java.lang.String eltLocalName,
                       java.lang.String eltQName)
                throws org.xml.sax.SAXException
Receive notification of the end of an element. Try to restore the element qName.

Specified by:
endElement in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

endPrefixMapping

public void endPrefixMapping(java.lang.String prefix)
                      throws org.xml.sax.SAXException
End the scope of a prefix-URI mapping: remove entry from mapping tables.

Specified by:
endPrefixMapping in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

endDocument

public void endDocument()
                 throws org.xml.sax.SAXException
Specified by:
endDocument in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws org.xml.sax.SAXException
Specified by:
characters in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws org.xml.sax.SAXException
Specified by:
ignorableWhitespace in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

skippedEntity

public void skippedEntity(java.lang.String name)
                   throws org.xml.sax.SAXException
Specified by:
skippedEntity in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException

setDocumentLocator

public void setDocumentLocator(org.xml.sax.Locator locator)
Specified by:
setDocumentLocator in interface org.xml.sax.ContentHandler

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
                           throws org.xml.sax.SAXException
Specified by:
processingInstruction in interface org.xml.sax.ContentHandler
Throws:
org.xml.sax.SAXException


Copyright © -2012 . All Rights Reserved.