Class HtmlLineSplitter


  • public class HtmlLineSplitter
    extends java.lang.Object
    Splits into lines a given String that is meant to be rendered as HTML.

    Really, this class exists simply to remove hundreds of lines of code from HTMLUtilities, which is what this code supports. The methods in here could easily be in StringUtils, but to keep dependencies low on code that has such a specific use, it lives here, with a name that implies you shouldn't use it unless you are working with HTML.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int MAX_WORD_LENGTH
      Used when trying to split on word boundaries; the value past which to give up
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.List<java.lang.String> split​(java.lang.String text, int maxLineLength)
      Splits the given line into multiple lines based upon the given max length.
      static java.util.List<java.lang.String> split​(java.lang.String text, int maxLineLength, boolean retainSpacing)
      Splits the given line into multiple lines based upon the given max length.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • MAX_WORD_LENGTH

        public static final int MAX_WORD_LENGTH
        Used when trying to split on word boundaries; the value past which to give up
        See Also:
        Constant Field Values
    • Constructor Detail

      • HtmlLineSplitter

        public HtmlLineSplitter()
    • Method Detail

      • split

        public static java.util.List<java.lang.String> split​(java.lang.String text,
                                                             int maxLineLength)
        Splits the given line into multiple lines based upon the given max length. This method will first split on each newline and then wrap each of the lines returned from that split.

        The wrapping routine will attempt to wrap at word boundaries.

        This method does not retain leading whitespace.

        Parameters:
        text - the text to wrap
        maxLineLength - the max desired length of each output line; 0 or less signals not to wrap the line based upon length
        Returns:
        the new lines
        See Also:
        wrap(String, int, WhitespaceHandler), split(String, int, boolean)
      • split

        public static java.util.List<java.lang.String> split​(java.lang.String text,
                                                             int maxLineLength,
                                                             boolean retainSpacing)
        Splits the given line into multiple lines based upon the given max length. This method will first split on each newline and then wrap each of the lines returned from that split.

        The wrapping routine will attempt to wrap at word boundaries.

        Parameters:
        text - the text to wrap
        maxLineLength - the max desired length of each output line; 0 or less signals not to wrap the line based upon length
        retainSpacing - true signals to keep whitespace on line breaks; false discards leading whitespace
        Returns:
        the new lines
        See Also:
        wrap(String, int, WhitespaceHandler)