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
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final char[]
private final XMLSerializer.CharacterValidatingContentHandler
private static String
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 final char[]
-
Constructor Summary
ConstructorsConstructorDescription -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
findMatchingSubElement
(String elementName) Scan from last output node the child nodes, looking for a matching element.private Node
getFirstPrevCoIw
(Node original) Scan backwards from argument node, continuing until get something other than comment or ignorable whitespace.private static boolean
private boolean
hasNewline
(Node n) private static boolean
Dom parsers if not operating in validating mode can't distinguish between ignorable white space and non-ignorable white space.private static boolean
private void
maybeOutputCoIwAfterEnd
(Node node) private void
private void
maybeOutputCoIwBeforeEnd
(Node node) private void
CoIw = Comment or IgnorableWhitespaceprivate void
outputCoIw
(Node p) private void
outputCoIwAfterElement
(Node startNode) Output comments and ignorable whitespace after an element.void
outputEndElement
(Node node, String aNamespace, String localname, String qname) private void
outputIndent
(int indent) private void
outputNL()
void
outputStartElement
(Node node, String aNamespace, String localname, String qname, Attributes attributes) void
outputStartElementForArrayElement
(Node node, String nameSpace, String localName, String qName, Attributes attributes) void
saveAndAddNodeStore
(Node infoset) private Node
Skip nodes going forwards until find one with a nl, then return the one followingMethods inherited from class org.apache.uima.resource.metadata.impl.MetaDataObjectSerializer_plain
indentChildElements, insertNl, isArrayHasIndentableElements, maybeEndArraySymbol, maybeStartArraySymbol, outputEndElementForArrayElement, shouldBeSkipped, shouldEncloseInArrayElement, startElementProperty, writeDelayedStart, writeSimpleValue, writeSimpleValueWithTag
-
Field Details
-
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
-
-
Constructor Details
-
MetaDataObjectSerializer_indent
-
-
Method Details
-
hasElementChildNode
-
isWhitespaceText
-
isCoIw
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
- 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(Node node, String aNamespace, String localname, String qname, Attributes attributes) throws SAXException - Specified by:
outputStartElement
in interfaceMetaDataObject_impl.Serializer
- Overrides:
outputStartElement
in classMetaDataObjectSerializer_plain
- Throws:
SAXException
-
outputEndElement
public void outputEndElement(Node node, String aNamespace, String localname, String qname) throws SAXException - Specified by:
outputEndElement
in interfaceMetaDataObject_impl.Serializer
- Overrides:
outputEndElement
in classMetaDataObjectSerializer_plain
- Throws:
SAXException
-
outputStartElementForArrayElement
public void outputStartElementForArrayElement(Node node, String nameSpace, String localName, String qName, Attributes attributes) throws SAXException - Specified by:
outputStartElementForArrayElement
in interfaceMetaDataObject_impl.Serializer
- Overrides:
outputStartElementForArrayElement
in classMetaDataObjectSerializer_plain
- Throws:
SAXException
-
maybeOutputCoIwBeforeStart
CoIw = Comment or IgnorableWhitespace- Throws:
SAXException
-
maybeOutputCoIwAfterStart
- Throws:
SAXException
-
maybeOutputCoIwBeforeEnd
- Throws:
SAXException
-
maybeOutputCoIwAfterEnd
- Throws:
SAXException
-
outputCoIwAfterElement
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:
DOMException
- passthruSAXException
- passthru
-
getFirstPrevCoIw
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
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
-
findMatchingSubElement
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
- Throws:
DOMException
SAXException
-
outputIndent
- Throws:
SAXException
-
outputNL
- Throws:
SAXException
-