Class AbstractTraxSerializerFactory.NamespaceAsAttributes
- java.lang.Object
-
- org.apache.sling.rewriter.impl.components.AbstractTraxSerializerFactory.NamespaceAsAttributes
-
- All Implemented Interfaces:
ContentHandler
,LexicalHandler
- Enclosing class:
- AbstractTraxSerializerFactory
public static class AbstractTraxSerializerFactory.NamespaceAsAttributes extends Object implements ContentHandler, LexicalHandler
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.
-
-
Field Summary
Fields Modifier and Type Field Description protected ContentHandler
contentHandler
protected LexicalHandler
lexicalHandler
protected org.slf4j.Logger
logger
-
Constructor Summary
Constructors Constructor Description NamespaceAsAttributes(ContentHandler handler, org.slf4j.Logger logger)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
characters(char[] c, int start, int len)
Receive notification of character data.void
comment(char[] ch, int start, int len)
Report an XML comment anywhere in the document.void
endCDATA()
Report the end of a CDATA section.void
endDocument()
void
endDTD()
Report the end of DTD declarations.void
endElement(String eltUri, String eltLocalName, String eltQName)
Receive notification of the end of an element.void
endEntity(String name)
Report the end of an entity.void
endPrefixMapping(String prefix)
End the scope of a prefix-URI mapping: remove entry from mapping tables.void
ignorableWhitespace(char[] c, int start, int len)
Receive notification of ignorable whitespace in element content.void
processingInstruction(String target, String data)
Receive notification of a processing instruction.void
setDocumentLocator(Locator locator)
void
skippedEntity(String name)
Receive notification of a skipped entity.void
startCDATA()
Report the start of a CDATA section.void
startDocument()
void
startDTD(String name, String publicId, String systemId)
Report the start of DTD declarations, if any.void
startElement(String eltUri, String eltLocalName, String eltQName, Attributes attrs)
Ensure all namespace declarations are present asxmlns:
attributes and add those needed before calling superclass.void
startEntity(String name)
Report the beginning of an entity.void
startPrefixMapping(String prefix, String uri)
Track mappings to be able to addxmlns:
attributes instartElement()
.
-
-
-
Field Detail
-
contentHandler
protected final ContentHandler contentHandler
-
lexicalHandler
protected final LexicalHandler lexicalHandler
-
logger
protected final org.slf4j.Logger logger
-
-
Constructor Detail
-
NamespaceAsAttributes
public NamespaceAsAttributes(ContentHandler handler, org.slf4j.Logger logger)
-
-
Method Detail
-
setDocumentLocator
public void setDocumentLocator(Locator locator)
- Specified by:
setDocumentLocator
in interfaceContentHandler
- See Also:
ContentHandler.setDocumentLocator(org.xml.sax.Locator)
-
characters
public void characters(char[] c, int start, int len) throws SAXException
Receive notification of character data.- Specified by:
characters
in interfaceContentHandler
- Parameters:
c
- The characters from the XML document.start
- The start position in the array.len
- The number of characters to read from the array.- Throws:
SAXException
-
ignorableWhitespace
public void ignorableWhitespace(char[] c, int start, int len) throws SAXException
Receive notification of ignorable whitespace in element content.- Specified by:
ignorableWhitespace
in interfaceContentHandler
- Parameters:
c
- The characters from the XML document.start
- The start position in the array.len
- The number of characters to read from the array.- Throws:
SAXException
-
processingInstruction
public void processingInstruction(String target, String data) throws SAXException
Receive notification of a processing instruction.- Specified by:
processingInstruction
in interfaceContentHandler
- Parameters:
target
- The processing instruction target.data
- The processing instruction data, or null if none was supplied.- Throws:
SAXException
-
skippedEntity
public void skippedEntity(String name) throws SAXException
Receive notification of a skipped entity.- Specified by:
skippedEntity
in interfaceContentHandler
- Parameters:
name
- The name of the skipped entity. If it is a parameter entity, the name will begin with '%'.- Throws:
SAXException
-
startDTD
public void startDTD(String name, String publicId, String systemId) throws SAXException
Report the start of DTD declarations, if any.- Specified by:
startDTD
in interfaceLexicalHandler
- Parameters:
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.- Throws:
SAXException
-
endDTD
public void endDTD() throws SAXException
Report the end of DTD declarations.- Specified by:
endDTD
in interfaceLexicalHandler
- Throws:
SAXException
-
startEntity
public void startEntity(String name) throws SAXException
Report the beginning of an entity.- Specified by:
startEntity
in interfaceLexicalHandler
- Parameters:
name
- The name of the entity. If it is a parameter entity, the name will begin with '%'.- Throws:
SAXException
-
endEntity
public void endEntity(String name) throws SAXException
Report the end of an entity.- Specified by:
endEntity
in interfaceLexicalHandler
- Parameters:
name
- The name of the entity that is ending.- Throws:
SAXException
-
startCDATA
public void startCDATA() throws SAXException
Report the start of a CDATA section.- Specified by:
startCDATA
in interfaceLexicalHandler
- Throws:
SAXException
-
endCDATA
public void endCDATA() throws SAXException
Report the end of a CDATA section.- Specified by:
endCDATA
in interfaceLexicalHandler
- Throws:
SAXException
-
comment
public void comment(char[] ch, int start, int len) throws SAXException
Report an XML comment anywhere in the document.- Specified by:
comment
in interfaceLexicalHandler
- Parameters:
ch
- An array holding the characters in the comment.start
- The starting position in the array.len
- The number of characters to use from the array.- Throws:
SAXException
-
startDocument
public void startDocument() throws SAXException
- Specified by:
startDocument
in interfaceContentHandler
- Throws:
SAXException
-
startPrefixMapping
public void startPrefixMapping(String prefix, String uri) throws SAXException
Track mappings to be able to addxmlns:
attributes instartElement()
.- Specified by:
startPrefixMapping
in interfaceContentHandler
- Throws:
SAXException
-
startElement
public void startElement(String eltUri, String eltLocalName, String eltQName, Attributes attrs) throws SAXException
Ensure all namespace declarations are present asxmlns:
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
ignoresstart/endPrefixMapping()
.- Specified by:
startElement
in interfaceContentHandler
- Throws:
SAXException
-
endElement
public void endElement(String eltUri, String eltLocalName, String eltQName) throws SAXException
Receive notification of the end of an element. Try to restore the element qName.- Specified by:
endElement
in interfaceContentHandler
- Throws:
SAXException
-
endPrefixMapping
public void endPrefixMapping(String prefix) throws SAXException
End the scope of a prefix-URI mapping: remove entry from mapping tables.- Specified by:
endPrefixMapping
in interfaceContentHandler
- Throws:
SAXException
-
endDocument
public void endDocument() throws SAXException
- Specified by:
endDocument
in interfaceContentHandler
- Throws:
SAXException
-
-