gnu.xml
Class XMLFilter
public
class
XMLFilter
extends Object
implements DocumentHandler, ContentHandler, SourceLocator, XConsumer, PositionConsumer
Fixup XML input events.
Handles namespace resolution, and adds "namespace nodes" if needed.
Does various error checking.
This wrapper should be used when creating a NodeTree,
as is done for XQuery node constructor expressions.
Can also be called directly from XMLParser, in which case we use a slightly
lower-level interface where we array char array segments rather than
Strings. This is to avoid duplicate String allocation and interning.
The combination XMLParser+XMLFilter+NodeTree makes for a fast and
compact way to read an XML file into a DOM.
Method Summary |
void | beginEntity(Object baseUri) |
void | characters(char[] ch, int start, int length) |
protected void | checkValidComment(char[] chars, int offset, int length) |
protected boolean | checkWriteAtomic() |
void | commentFromParser(char[] chars, int start, int length) Process a comment, when called from an XML parser.
|
void | consume(SeqPosition position) |
static String | duplicateAttributeMessage(Symbol attrSymbol, Object elementName) |
void | emitCharacterReference(int value, char[] name, int start, int length) Process a character entity reference.
|
void | emitDoctypeDecl(char[] buffer, int target, int tlength, int data, int dlength) Process a DOCTYPE declaration. |
void | emitEndAttributes() Process the end of a start tag.
|
void | emitEndElement(char[] data, int start, int length) Process an end tag.
|
void | emitEntityReference(char[] name, int start, int length) Process an entity reference.
|
void | emitStartAttribute(char[] data, int start, int count) Process an attribute, with the given attribute name.
|
void | emitStartElement(char[] data, int start, int count) Process a start tag, with the given element name. |
void | endAttribute() |
void | endDocument() |
void | endElement() |
void | endElement(String namespaceURI, String localName, String qName) |
void | endElement(String name) |
void | endEntity() |
void | endPrefixMapping(String prefix) |
void | error(char severity, String message) |
NamespaceBinding | findNamespaceBinding(String prefix, String uri, NamespaceBinding oldBindings) Functionally equivalent to
{@code new NamespaceBinding(prefix, uri, oldBindings},
but uses "hash consing". |
int | getColumnNumber() |
String | getFileName() |
int | getLineNumber() |
String | getPublicId() |
String | getSystemId() |
void | ignorableWhitespace(char[] ch, int start, int length) |
boolean | ignoring() |
boolean | isStableSourceLocation() |
void | linefeedFromParser() |
MappingInfo | lookupNamespaceBinding(String prefix, char[] uriChars, int uriStart, int uriLength, int uriHash, NamespaceBinding oldBindings) Return a MappingInfo containing a match namespaces.
|
void | processingInstruction(String target, String data) |
void | processingInstructionFromParser(char[] buffer, int tstart, int tlength, int dstart, int dlength) Process a processing instruction. |
void | setDocumentLocator(Locator locator) |
void | setMessages(SourceMessages messages) |
void | setSourceLocator(LineBufferedReader in) |
void | setSourceLocator(SourceLocator locator) |
void | skippedEntity(String name) |
void | startAttribute(Object attrType) |
void | startDocument() |
void | startElement(Object type) |
void | startElement(String namespaceURI, String localName, String qName, Attributes atts) |
void | startElement(String name, AttributeList atts) |
protected void | startElementCommon() |
void | startPrefixMapping(String prefix, String uri) |
void | textFromParser(char[] data, int start, int length) |
void | write(int v) |
void | write(char[] data, int start, int length) Process raw text. |
void | write(String str) |
void | write(CharSequence str, int start, int length) |
void | writeBoolean(boolean v) |
void | writeCDATA(char[] data, int start, int length) Process a CDATA section.
|
void | writeComment(char[] chars, int start, int length) Process a comment.
|
void | writeDocumentUri(Object uri) |
void | writeDouble(double v) |
void | writeFloat(float v) |
void | writeInt(int v) |
protected void | writeJoiner() |
void | writeLong(long v) |
void | writeObject(Object v) If v is a node, make a copy of it. |
void | writePosition(AbstractSequence seq, int ipos) |
void | writeProcessingInstruction(String target, char[] content, int offset, int length) |
public transient int copyNamespacesMode
public static final int COPY_NAMESPACES_INHERIT
public static final int COPY_NAMESPACES_PRESERVE
protected int ignoringLevel
Postive if all output should be ignored.
This happens if we're inside an attribute value inside an element which
is stringized because it is in turm inside an outer attribute. Phew.
If gets increment by nested attributes so we can tell when to stop.
public boolean namespacePrefixes
True if namespace declarations should be passed through as attributes.
Like SAX2's http://xml.org/features/namespace-prefixes.
protected int nesting
Twice the number of active startElement and startDocument calls.
The specified target Consumer that accepts the output.
In contrast, base may be either {@code ==out} or {@code ==tlist}.
protected int stringizingElementNesting
Value of {@code nesting} just before outermost startElement
while {@code stringizingLevel > 0}.
I.e. if we're nested inside a element nested inside an attribute
then {@code stringizingElementNesting >= 0},
otherwise {@code stringizingElementNesting == -1}.
protected int stringizingLevel
If {@code stringizingLevel > 0} then stringize rather than copy nodes.
It counts the number of nested startAttributes that are active.
(In the future it should also count begun comment and
processing-instruction constructors, when those support nesting.)
public void beginEntity(Object baseUri)
public void characters(char[] ch, int start, int length)
protected void checkValidComment(char[] chars, int offset, int length)
protected boolean checkWriteAtomic()
public void commentFromParser(char[] chars, int start, int length)
Process a comment, when called from an XML parser.
The data (starting at start for length chars).
Does not include the delimiters (i.e. "" are excluded).
public static String duplicateAttributeMessage(
Symbol attrSymbol, Object elementName)
public void emitCharacterReference(int value, char[] name, int start, int length)
Process a character entity reference.
The string encoding of the character (e.g. "xFF" or "255") is given,
as well as the character value.
public void emitDoctypeDecl(char[] buffer, int target, int tlength, int data, int dlength)
Process a DOCTYPE declaration.
public void emitEndAttributes()
Process the end of a start tag.
There are no more attributes.
public void emitEndElement(char[] data, int start, int length)
Process an end tag.
An abbreviated tag (such as {@code '
'}) has a name==null.
public void emitEntityReference(char[] name, int start, int length)
Process an entity reference.
The entity name is given.
This handles the predefined entities, such as "<" and """.
public void emitStartAttribute(char[] data, int start, int count)
Process an attribute, with the given attribute name.
The attribute value is given using {@code write}.
The value is terminated by either another emitStartAttribute
or an emitEndAttributes.
public void emitStartElement(char[] data, int start, int count)
Process a start tag, with the given element name.
public void endAttribute()
public void endDocument()
public void endElement()
public void endElement(String namespaceURI, String localName, String qName)
public void endElement(String name)
public void endEntity()
public void endPrefixMapping(String prefix)
public void error(char severity, String message)
Functionally equivalent to
{@code new NamespaceBinding(prefix, uri, oldBindings},
but uses "hash consing".
public int getColumnNumber()
public String getFileName()
public int getLineNumber()
public String getPublicId()
public String getSystemId()
public void ignorableWhitespace(char[] ch, int start, int length)
public boolean ignoring()
public boolean isStableSourceLocation()
public void linefeedFromParser()
public MappingInfo lookupNamespaceBinding(String prefix, char[] uriChars, int uriStart, int uriLength, int uriHash,
NamespaceBinding oldBindings)
Return a MappingInfo containing a match namespaces.
Specifically, return a {@code MappingInfo info} is such that
{@code info.namespaces} is equal to
{@code new NamespaceBinding(prefix, uri, oldBindings)}, where {@code uri}
is {@code new String(uriChars, uriStart, uriLength).intern())}.
public void processingInstruction(String target, String data)
public void processingInstructionFromParser(char[] buffer, int tstart, int tlength, int dstart, int dlength)
Process a processing instruction.
public void setDocumentLocator(Locator locator)
public void skippedEntity(String name)
public void startAttribute(Object attrType)
public void startDocument()
public void startElement(Object type)
public void startElement(String namespaceURI, String localName, String qName, Attributes atts)
public void startElement(String name, AttributeList atts)
protected void startElementCommon()
public void startPrefixMapping(String prefix, String uri)
public void textFromParser(char[] data, int start, int length)
public void write(int v)
public void write(char[] data, int start, int length)
Process raw text.
public void write(String str)
public void write(CharSequence str, int start, int length)
public void writeBoolean(boolean v)
public void writeCDATA(char[] data, int start, int length)
Process a CDATA section.
The data (starting at start for length char).
Does not include the delimiters (i.e. {@code ""} are excluded).
public void writeComment(char[] chars, int start, int length)
Process a comment.
The data (starting at start for length chars).
Does not include the delimiters (i.e. "" are excluded).
public void writeDocumentUri(Object uri)
public void writeDouble(double v)
public void writeFloat(float v)
public void writeInt(int v)
protected void writeJoiner()
public void writeLong(long v)
public void writeObject(Object v)
If v is a node, make a copy of it.
public void writeProcessingInstruction(String target, char[] content, int offset, int length)