Package org.bndly.common.html
Class HTMLShortener
- java.lang.Object
-
- org.bndly.common.html.HTMLShortener
-
public final class HTMLShortener extends Object
- Author:
- cybercon <bndly@cybercon.de>
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Stringshorten(String inputHtml, int maxCharacters)Shortens the input string and strips all markup elements.static StringshortenAndKeepMarkup(String inputHtml, int maxCharacters)Shortens the input string and keeps all markup elements.static StringshortenAndKeepMarkup(String inputHtml, int maxCharacters, String appendAtEnd)Shortens the input string and keeps all markup elements.static voidshortenAndKeepMarkupOnHTML(HTML html, int maxCharacters, String appendAtEnd)
-
-
-
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 toblwhen a maxCharacters of 2 is used.- Parameters:
inputHtml- valid html stringmaxCharacters- 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 stringmaxCharacters- maximum number of visible text characters- Returns:
- a string with markup
- Throws:
HTMLParsingException
-
shortenAndKeepMarkupOnHTML
public static void shortenAndKeepMarkupOnHTML(HTML html, int maxCharacters, String appendAtEnd) throws HTMLParsingException
- 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 stringmaxCharacters- maximum number of visible text charactersappendAtEnd- a String that will be appended after the last textual content, if the result is cut off.- Returns:
- a string with markup
- Throws:
HTMLParsingException
-
-