Package Torello.HTML

Class PrettyPrint

    • Method Detail

      • removeAllIndentation

        🡅  🡇     🗕  🗗  🗖
        public static int removeAllIndentation​(java.util.Vector<HTMLNode> html,
                                               int sPos,
                                               int ePos)
        Any White-Space which immediately follows a '\n' New-Line character is removed from all TextNode's, by this method.
        Parameters:
        html - This may be any Vectorized-HTML Web-Page (or sub-page).

        The Variable-Type Wild-Card Expression '? extends HTMLNode' means that a Vector<TagNode>, Vector<TextNode> or Vector<CommentNode> will all be accepted by this paramter without causing an exception throw.

        These 'sub-type' Vectors are often returned as search results from the classes in the 'NodeSearch'vpackage.
        sPos - This is the (integer) Vector-index that sets a limit for the left-most Vector-position to inspect/search inside the input Vector-parameter.

        This value is considered 'inclusive' meaning that the HTMLNode at this Vector-index will be visited by this method.

        NOTE: If this value is negative, or larger than the length of the input-Vector, an exception will be thrown.
        ePos - This is the (integer) Vector-index that sets a limit for the right-most Vector-position to inspect/search inside the input Vector-parameter.

        This value is considered 'exclusive' meaning that the 'HTMLNode' at this Vector-index will not be visited by this method.

        NOTE: If this value is larger than the size of input the Vector-parameter, an exception will throw.

        ALSO: Passing a negative value to this parameter, 'ePos', will cause its value to be reset to the size of the input Vector-parameter.
        Returns:
        The number of TextNode's that changed as a result of this method.
        Throws:
        java.lang.IndexOutOfBoundsException - This exception shall be thrown if any of the following are true:

        • If 'sPos' is negative, or if sPos is greater-than-or-equal-to the size of the Vector
        • If 'ePos' is zero, or greater than the size of the Vector
        • If the value of 'sPos' is a larger integer than 'ePos'. If 'ePos' was negative, it is first reset to Vector.size(), before this check is done.
        Code:
        Exact Method Body:
         return RemAllIndent.remove(html, sPos, ePos);
        
      • ensureBlockTagsOnNewlines

        🡅  🡇     🗕  🗗  🗖
        public static int ensureBlockTagsOnNewlines​
                    (java.util.Vector<HTMLNode> html,
                     int sPos,
                     int ePos)
        
        Any Block-Tag identified on the page, or page sub-section, may only be preceeded by:

        • Optional White-Space of any type
        • At least one, mandatory, new-line 'n' character

        If an HTML-5 Block-Tag ( TagNode ) is identified that is preceeded by other HTML-Tags or Text:

        1. If the preceeding node is a TextNode, a new-line 'n' is appended to the first non-white-space character at the end of that TextNode
        2. If the preceeding node is another TagNode, a single-character TextNode containing the character 'n' (a new-line) is inserted into the input HTML-Vector directly before that Block-TagNode.
        Parameters:
        html - This may be any Vectorized-HTML Web-Page (or sub-page).

        The Variable-Type Wild-Card Expression '? extends HTMLNode' means that a Vector<TagNode>, Vector<TextNode> or Vector<CommentNode> will all be accepted by this paramter without causing an exception throw.

        These 'sub-type' Vectors are often returned as search results from the classes in the 'NodeSearch'vpackage.
        sPos - This is the (integer) Vector-index that sets a limit for the left-most Vector-position to inspect/search inside the input Vector-parameter.

        This value is considered 'inclusive' meaning that the HTMLNode at this Vector-index will be visited by this method.

        NOTE: If this value is negative, or larger than the length of the input-Vector, an exception will be thrown.
        ePos - This is the (integer) Vector-index that sets a limit for the right-most Vector-position to inspect/search inside the input Vector-parameter.

        This value is considered 'exclusive' meaning that the 'HTMLNode' at this Vector-index will not be visited by this method.

        NOTE: If this value is larger than the size of input the Vector-parameter, an exception will throw.

        ALSO: Passing a negative value to this parameter, 'ePos', will cause its value to be reset to the size of the input Vector-parameter.
        Returns:
        The number of new-line characters that have been inserted onto this page.
        Throws:
        java.lang.IndexOutOfBoundsException - This exception shall be thrown if any of the following are true:

        • If 'sPos' is negative, or if sPos is greater-than-or-equal-to the size of the Vector
        • If 'ePos' is zero, or greater than the size of the Vector
        • If the value of 'sPos' is a larger integer than 'ePos'. If 'ePos' was negative, it is first reset to Vector.size(), before this check is done.
        Code:
        Exact Method Body:
         return AddNewLines.beforeAllBlockTags(html, sPos, ePos);
        
      • textChecker

        🡅  🡇     🗕  🗗  🗖
        public static java.lang.String textChecker​
                    (java.util.Vector<HTMLNode> html,
                     int sPos,
                     int ePos)
        

        This method may be used to verify your page changes

        This method does not actually perform any HTML-Modifications at all. The purpose of it is merely to facilitate checking that the results of your Pretty-Printing Desicions have done justice to the original, and intended, output.

        This method attempts to verify that the resulting Output-Text from a Prettify-Operation on an HTML-Vector was not changed during that clean-up. This method is intended for use with Testing-Suite Tools.
        This method ignores all instances of CommentNode and TagNode that are present within the input HTML-Vector. It iterates only the TextNode instances.

        During this iteration process, all identified White-Space is summarily removed from each TextNode. After this strip, the remaining characters (from each TextNode) are appended to a simple Java StringBuilder.

        Applicability:
        As a means of checking & testing your Pretty-Printed Output, this method can be used to facilitate a 'Before & After' comparison on your page when modifying a Web-Page for Pretty-Printing.

        If your goal was merely to add or remove White-Space, then checking to ensure that all non-white-space characters are identical will help validate the modifications you have made. Please see the example code below:

        Example:
        // Strip everything but HTML Text-Nodes.  Append all non-white-space characters to a String
        // This String can then be used to evaluate if any text was accidentally modified, removed or
        // added.  This method 'textChecker' is essentially a Test-Framework Helper-Method.
        
        String textOnlyOld = PrettyPrint.textChecker(html, 0, -1);
        
        cleanIt(myHTML, 0, -1);
        
        // Repeat the previous process using the "Pretty-Printed Text" instead.
        String textOnlyNew = PrettyPrint.textChecker(html, 0, -1);
        
        System.out.println(
            textOnlyOld.equals(textOnlyNew) 
                 ? "The original & prettified text are identical"
                 : "Houston, there may be a problem, you have modified your text"
        );
        
        Parameters:
        html - This may be any Vectorized-HTML Web-Page (or sub-page).

        The Variable-Type Wild-Card Expression '? extends HTMLNode' means that a Vector<TagNode>, Vector<TextNode> or Vector<CommentNode> will all be accepted by this paramter without causing an exception throw.

        These 'sub-type' Vectors are often returned as search results from the classes in the 'NodeSearch'vpackage.
        sPos - This is the (integer) Vector-index that sets a limit for the left-most Vector-position to inspect/search inside the input Vector-parameter.

        This value is considered 'inclusive' meaning that the HTMLNode at this Vector-index will be visited by this method.

        NOTE: If this value is negative, or larger than the length of the input-Vector, an exception will be thrown.
        ePos - This is the (integer) Vector-index that sets a limit for the right-most Vector-position to inspect/search inside the input Vector-parameter.

        This value is considered 'exclusive' meaning that the 'HTMLNode' at this Vector-index will not be visited by this method.

        NOTE: If this value is larger than the size of input the Vector-parameter, an exception will throw.

        ALSO: Passing a negative value to this parameter, 'ePos', will cause its value to be reset to the size of the input Vector-parameter.
        Returns:
        The number of new-line characters that have been inserted onto this page.
        Throws:
        java.lang.IndexOutOfBoundsException - This exception shall be thrown if any of the following are true:

        • If 'sPos' is negative, or if sPos is greater-than-or-equal-to the size of the Vector
        • If 'ePos' is zero, or greater than the size of the Vector
        • If the value of 'sPos' is a larger integer than 'ePos'. If 'ePos' was negative, it is first reset to Vector.size(), before this check is done.
        Code:
        Exact Method Body:
         LV              l   = new LV(html, sPos, ePos);
         StringBuilder   sb  = new StringBuilder();
         HTMLNode        n   = null;
        
         for (int i=l.start; i < l.end; i++)
             if ((n = html.elementAt(i)).isTextNode())
                 sb.append(n.str.replaceAll("\\s+",""));
        
         return sb.toString();
        
      • tagChecker

        🡅     🗕  🗗  🗖
        public static java.lang.String tagChecker​(java.util.Vector<HTMLNode> html,
                                                  int sPos,
                                                  int ePos)

        This method may be used to verify your page changes

        This method does not actually perform any HTML-Modifications at all. The purpose of it is merely to facilitate checking that the results of your Pretty-Printing Desicions have done justice to the original, and intended, output.

        This method attempts to verify that the resulting list of TagNode's in an HTML-Vector has not been changed as a result f a Prettify-Operation. This method is intended for use with Testing-Suite Tools.
        This method ignores all instances of CommentNode and TextNode that are present within the input HTML-Vector. It iterates only the TagtNode instances.

        During this iteration process, the TagNode-Field's tok and isClosing are checked, and appending to a StringBuilder. The Java-String produced by this StringBuilder-Operation are the results returned by this method.

        Applicability:
        As a means of checking & testing your Pretty-Printed Output, this method can be used to facilitate a 'Before & After' comparison on your page when modifying a Web-Page for Pretty-Printing.

        If your goal was merely to add or remove White-Space, then checking to ensure that all non-white-space characters are identical will help validate the modifications you have made. Please see the example code below:

        Example:
        // Strip everything but HTML Tag-Nodes.  Append "TagNode.tok" String's into a Master
        // StringBuilder instance.  This String can then be used to evaluate if any nodes were
        // accidentally modified, removed or added.  This method 'tagChecker' is essentially a 
        // Test-Framework Helper-Method.
        
        String tagListOld = PrettyPrint.textChecker(html, 0, -1);
        
        cleanIt(myHTML, 0, -1);
        
        // Repeat the previous process with the "Pretty-Printed Text"
        String tagListNew = PrettyPrint.textChecker(html, 0, -1);
        
        System.out.println(
            tagListOld.equals(tagListNew) 
                    ? "The original & prettified list of TagNode's are identical"
                    : "Houston, there may be a problem, you have added or removed TagNode's"
        );
        
        Parameters:
        html - This may be any Vectorized-HTML Web-Page (or sub-page).

        The Variable-Type Wild-Card Expression '? extends HTMLNode' means that a Vector<TagNode>, Vector<TextNode> or Vector<CommentNode> will all be accepted by this paramter without causing an exception throw.

        These 'sub-type' Vectors are often returned as search results from the classes in the 'NodeSearch'vpackage.
        sPos - This is the (integer) Vector-index that sets a limit for the left-most Vector-position to inspect/search inside the input Vector-parameter.

        This value is considered 'inclusive' meaning that the HTMLNode at this Vector-index will be visited by this method.

        NOTE: If this value is negative, or larger than the length of the input-Vector, an exception will be thrown.
        ePos - This is the (integer) Vector-index that sets a limit for the right-most Vector-position to inspect/search inside the input Vector-parameter.

        This value is considered 'exclusive' meaning that the 'HTMLNode' at this Vector-index will not be visited by this method.

        NOTE: If this value is larger than the size of input the Vector-parameter, an exception will throw.

        ALSO: Passing a negative value to this parameter, 'ePos', will cause its value to be reset to the size of the input Vector-parameter.
        Returns:
        The number of new-line characters that have been inserted onto this page.
        Throws:
        java.lang.IndexOutOfBoundsException - This exception shall be thrown if any of the following are true:

        • If 'sPos' is negative, or if sPos is greater-than-or-equal-to the size of the Vector
        • If 'ePos' is zero, or greater than the size of the Vector
        • If the value of 'sPos' is a larger integer than 'ePos'. If 'ePos' was negative, it is first reset to Vector.size(), before this check is done.
        Code:
        Exact Method Body:
         LV              l   = new LV(html, sPos, ePos);
         StringBuilder   sb  = new StringBuilder();
         TagNode         tn  = null;
        
         for (int i=l.start; i < l.end; i++)
             if ((tn = html.elementAt(i).ifTagNode()) != null)
                 sb.append((tn.isClosing ? " /" : " ") + tn.tok);
        
         return sb.toString();