Class MetaDataObjectSerializer_indent

    • 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
    • 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)
      • 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 - passthru
        org.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)
      • 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