Class MetaDataObjectSerializer_indent
- java.lang.Object
-
- org.apache.uima.resource.metadata.impl.MetaDataObjectSerializer_plain
-
- org.apache.uima.resource.metadata.impl.MetaDataObjectSerializer_indent
-
- All Implemented Interfaces:
MetaDataObject_impl.Serializer
class MetaDataObjectSerializer_indent extends MetaDataObjectSerializer_plain
-
-
Field Summary
Fields Modifier and Type Field Description private static char[]
blanks
private XMLSerializer.CharacterValidatingContentHandler
cc
private static java.lang.String
lineEnd
Heuristics for comment and whitespace processing Example:Each element has 2 calls: startElement, endElement Surround these with: maybeOutputCommentsBefore maybeOutputCommentsAfter Detect top level (by fact that parent is null), and for top level: collect all above -%gt; output before startelement BUT, note that the sax parser doesn't do callbacks for text (blank lines) before the start element, so all we can collect are the comment lines. private static char[]
nlca
-
Constructor Summary
Constructors Constructor Description MetaDataObjectSerializer_indent(XMLSerializer.CharacterValidatingContentHandler cc)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addNodeStore()
void
deleteNodeStore()
org.w3c.dom.Node
findMatchingSubElement(java.lang.String elementName)
Scan from last output node the child nodes, looking for a matching element.private org.w3c.dom.Node
getFirstPrevCoIw(org.w3c.dom.Node original)
Scan backwards from argument node, continuing until get something other than comment or ignorable whitespace.private static boolean
hasElementChildNode(org.w3c.dom.Node n)
private boolean
hasNewline(org.w3c.dom.Node n)
private static boolean
isCoIw(org.w3c.dom.Node n)
Dom parsers if not operating in validating mode can't distinguish between ignorable white space and non-ignorable white space.private static boolean
isWhitespaceText(org.w3c.dom.Node n)
private void
maybeOutputCoIwAfterEnd(org.w3c.dom.Node node)
private void
maybeOutputCoIwAfterStart(org.w3c.dom.Node node)
private void
maybeOutputCoIwBeforeEnd(org.w3c.dom.Node node)
private void
maybeOutputCoIwBeforeStart(org.w3c.dom.Node node)
CoIw = Comment or IgnorableWhitespaceprivate void
outputCoIw(org.w3c.dom.Node p)
private void
outputCoIwAfterElement(org.w3c.dom.Node startNode)
Output comments and ignorable whitespace after an element.void
outputEndElement(org.w3c.dom.Node node, java.lang.String aNamespace, java.lang.String localname, java.lang.String qname)
private void
outputIndent(int indent)
private void
outputNL()
void
outputStartElement(org.w3c.dom.Node node, java.lang.String aNamespace, java.lang.String localname, java.lang.String qname, org.xml.sax.Attributes attributes)
void
outputStartElementForArrayElement(org.w3c.dom.Node node, java.lang.String nameSpace, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes)
void
saveAndAddNodeStore(org.w3c.dom.Node infoset)
private org.w3c.dom.Node
skipUpToFirstAfterNL(org.w3c.dom.Node n)
Skip nodes going forwards until find one with a nl, then return the one following-
Methods inherited from class org.apache.uima.resource.metadata.impl.MetaDataObjectSerializer_plain
indentChildElements, insertNl, isArrayHasIndentableElements, maybeEndArraySymbol, maybeStartArraySymbol, outputEndElementForArrayElement, shouldBeSkipped, shouldEncloseInArrayElement, startElementProperty, startPrefixMapping, writeDelayedStart, writeSimpleValue, writeSimpleValueWithTag
-
-
-
-
Field Detail
-
lineEnd
private static java.lang.String lineEnd
Heuristics for comment and whitespace processing Example:Each element has 2 calls: startElement, endElement Surround these with: maybeOutputCommentsBefore maybeOutputCommentsAfter Detect top level (by fact that parent is null), and for top level: collect all above -%gt; output before startelement BUT, note that the sax parser doesn't do callbacks for text (blank lines) before the start element, so all we can collect are the comment lines. collect all below -%gt; output after endelement For normal element node, "start": --> output before element collect all prev white space siblings up to the one that contains the first newline because the prev white space siblings before and including that one will have been outputted as part of the previous start or end tag's "after element" processing if no nl assume comments go with previous element, and skip here (stop looking if get null for getPreviousSibling()) (stop looking if get other than comment or ignorable whitespace) (ignorable whitespace not always distinguishable from text that is whitespace?) --> output after element: if children: eg: collect all up to and including first nl before first Element child (stop at first Element node; if no nl, then the source had multiple elements on one line: associate the comments and whitespace with previous (and output them). if no children: - means it's written or Note: something not possible, because then it would have some text children output nothing - after comments will be done following endElement call For normal element node, "end": --> output before element collect all after last child Element; skip all up to first nl (assume before that, the comment goes with last child node) if no nl (e.g. ) assume comments go with previous element, and skip here (stop looking if get null for getNextSibling()) (stop looking if get Element) if no element children - output nothing --> output after element if this element has no successor sibling elements collect all up to the null else collect all up to and including first nl from getNextSibling(). (stop at first Element) For implied element nodes (no Java model object corresponding) We have only the "parent" node, and the element name. Try to do matching on the element name In this case, we always are working with the children in the Dom infoset; we have a last-outputted reference Scan from last-outputted, to find element match, and then use that element as the "root".
-
blanks
private static final char[] blanks
-
nlca
private static final char[] nlca
-
cc
private final XMLSerializer.CharacterValidatingContentHandler cc
-
-
Constructor Detail
-
MetaDataObjectSerializer_indent
public MetaDataObjectSerializer_indent(XMLSerializer.CharacterValidatingContentHandler cc)
-
-
Method Detail
-
hasElementChildNode
private static boolean hasElementChildNode(org.w3c.dom.Node n)
-
isWhitespaceText
private static boolean isWhitespaceText(org.w3c.dom.Node n)
-
isCoIw
private static boolean isCoIw(org.w3c.dom.Node n)
Dom parsers if not operating in validating mode can't distinguish between ignorable white space and non-ignorable white space. So we use a heuristic instead - we see if the text is whitespace only, and if so, we consider it to be ignorable white space.- Parameters:
n
-- Returns:
- true if node is a comment or is ignorable whitespace (approximately)
-
saveAndAddNodeStore
public void saveAndAddNodeStore(org.w3c.dom.Node infoset)
- Specified by:
saveAndAddNodeStore
in interfaceMetaDataObject_impl.Serializer
- Overrides:
saveAndAddNodeStore
in classMetaDataObjectSerializer_plain
-
deleteNodeStore
public void deleteNodeStore()
- Specified by:
deleteNodeStore
in interfaceMetaDataObject_impl.Serializer
- Overrides:
deleteNodeStore
in classMetaDataObjectSerializer_plain
-
addNodeStore
public void addNodeStore()
- Specified by:
addNodeStore
in interfaceMetaDataObject_impl.Serializer
- Overrides:
addNodeStore
in classMetaDataObjectSerializer_plain
-
outputStartElement
public void outputStartElement(org.w3c.dom.Node node, java.lang.String aNamespace, java.lang.String localname, java.lang.String qname, org.xml.sax.Attributes attributes) throws org.xml.sax.SAXException
- Specified by:
outputStartElement
in interfaceMetaDataObject_impl.Serializer
- Overrides:
outputStartElement
in classMetaDataObjectSerializer_plain
- Throws:
org.xml.sax.SAXException
-
outputEndElement
public void outputEndElement(org.w3c.dom.Node node, java.lang.String aNamespace, java.lang.String localname, java.lang.String qname) throws org.xml.sax.SAXException
- Specified by:
outputEndElement
in interfaceMetaDataObject_impl.Serializer
- Overrides:
outputEndElement
in classMetaDataObjectSerializer_plain
- Throws:
org.xml.sax.SAXException
-
outputStartElementForArrayElement
public void outputStartElementForArrayElement(org.w3c.dom.Node node, java.lang.String nameSpace, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes attributes) throws org.xml.sax.SAXException
- Specified by:
outputStartElementForArrayElement
in interfaceMetaDataObject_impl.Serializer
- Overrides:
outputStartElementForArrayElement
in classMetaDataObjectSerializer_plain
- Throws:
org.xml.sax.SAXException
-
maybeOutputCoIwBeforeStart
private void maybeOutputCoIwBeforeStart(org.w3c.dom.Node node) throws org.xml.sax.SAXException
CoIw = Comment or IgnorableWhitespace- Throws:
org.xml.sax.SAXException
-
maybeOutputCoIwAfterStart
private void maybeOutputCoIwAfterStart(org.w3c.dom.Node node) throws org.xml.sax.SAXException
- Throws:
org.xml.sax.SAXException
-
maybeOutputCoIwBeforeEnd
private void maybeOutputCoIwBeforeEnd(org.w3c.dom.Node node) throws org.xml.sax.SAXException
- Throws:
org.xml.sax.SAXException
-
maybeOutputCoIwAfterEnd
private void maybeOutputCoIwAfterEnd(org.w3c.dom.Node node) throws org.xml.sax.SAXException
- Throws:
org.xml.sax.SAXException
-
outputCoIwAfterElement
private void outputCoIwAfterElement(org.w3c.dom.Node startNode) throws org.w3c.dom.DOMException, org.xml.sax.SAXException
Output comments and ignorable whitespace after an element. Comments following an element can either be grouped with the preceeding element or with the following one. e.g.We arbitrarily group comment 1 with the element, and comment 2 and 3 with the subelement. This is for purposes of when they get processed and put out. This also affects what happens when new elements are "inserted" by an editor. This routine outputs only the whitespace and comment on the same line (e.g., it stops after outputting the ignorable whitespace that contains a nl.) If find text which is not whitespace, don't output anything. Use case: some text - Parameters:
startNode
- - the node corresponding to the start or end element just outputted- Throws:
org.w3c.dom.DOMException
- passthruorg.xml.sax.SAXException
- passthru
-
getFirstPrevCoIw
private org.w3c.dom.Node getFirstPrevCoIw(org.w3c.dom.Node original)
Scan backwards from argument node, continuing until get something other than comment or ignorable whitespace. Return the first node after a nl If no nl found, return original node NOTE: never called with original == the top node- Parameters:
r
- - guaranteed non-null- Returns:
- first node after a new line
-
skipUpToFirstAfterNL
private org.w3c.dom.Node skipUpToFirstAfterNL(org.w3c.dom.Node n)
Skip nodes going forwards until find one with a nl, then return the one following- Parameters:
n
- must not be null, and there must be a NL in the siblings- Returns:
- node following the one with a new line
-
hasNewline
private boolean hasNewline(org.w3c.dom.Node n)
-
findMatchingSubElement
public org.w3c.dom.Node findMatchingSubElement(java.lang.String elementName)
Scan from last output node the child nodes, looking for a matching element. Side effect if found - set lastoutput node to the found one.- Specified by:
findMatchingSubElement
in interfaceMetaDataObject_impl.Serializer
- Overrides:
findMatchingSubElement
in classMetaDataObjectSerializer_plain
- Parameters:
elementName
-- Returns:
- null (if no match) or matching node
-
outputCoIw
private void outputCoIw(org.w3c.dom.Node p) throws org.w3c.dom.DOMException, org.xml.sax.SAXException
- Throws:
org.w3c.dom.DOMException
org.xml.sax.SAXException
-
outputIndent
private void outputIndent(int indent) throws org.xml.sax.SAXException
- Throws:
org.xml.sax.SAXException
-
outputNL
private void outputNL() throws org.xml.sax.SAXException
- Throws:
org.xml.sax.SAXException
-
-