Class HTMLShortener


  • public final class HTMLShortener
    extends Object
    Author:
    cybercon <bndly@cybercon.de>
    • Method Detail

      • shorten

        public static String shorten​(String inputHtml,
                                     int maxCharacters)
                              throws HTMLParsingException
        Shortens the input string and strips all markup elements. <p>bla</p> will be shortened to bl when a maxCharacters of 2 is used.
        Parameters:
        inputHtml - valid html string
        maxCharacters - maximum number of visible text characters
        Returns:
        a string with a max length of maxCharacters and no markup
        Throws:
        HTMLParsingException
      • shortenAndKeepMarkup

        public static String shortenAndKeepMarkup​(String inputHtml,
                                                  int maxCharacters)
                                           throws HTMLParsingException
        Shortens the input string and keeps all markup elements. <p>bla</p> will be shortened to <p>bl</p> when a maxCharacters of 2 is used.
        Parameters:
        inputHtml - valid html string
        maxCharacters - maximum number of visible text characters
        Returns:
        a string with markup
        Throws:
        HTMLParsingException
      • shortenAndKeepMarkup

        public static String shortenAndKeepMarkup​(String inputHtml,
                                                  int maxCharacters,
                                                  String appendAtEnd)
                                           throws HTMLParsingException
        Shortens the input string and keeps all markup elements. The value of appendAtEnd will be appended at the end inside the last element with textual content, if the result is shorter than the original input. <p>bla</p> will be shortened to <p>bl</p> when a maxCharacters of 2 is used.
        Parameters:
        inputHtml - valid html string
        maxCharacters - maximum number of visible text characters
        appendAtEnd - a String that will be appended after the last textual content, if the result is cut off.
        Returns:
        a string with markup
        Throws:
        HTMLParsingException