Package adams.core.net
Class HtmlUtils
- java.lang.Object
-
- adams.core.net.HtmlUtils
-
public class HtmlUtils extends Object
Utility functions regarding HTML.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
-
-
Field Summary
Fields Modifier and Type Field Description static String
CROSSREF_PREFIX
the prefix to use in URLs.static String
DEFAULT_MARKUP
the default replacement for URL markup.static String
JAVA_API_URL
the URL prefix for the Java Javadoc.
-
Constructor Summary
Constructors Constructor Description HtmlUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
convertLines(String s, boolean nbsp)
Line feeds are converted into <br>.static String
extractClassFromCrossRefURL(String url)
Returns the classname from the cross reference URL.static String
fromHTML(String s)
Converts some HTML entities with the corresponding characters.static String
hyperlinkClassnames(String s, boolean classCrossRefLinks)
Hyperlinks class names in the string.static boolean
isClassCrossRefURL(String url)
Checks whether the URL is a fake class cross reference link.static String
markUpURLs(String raw, boolean toHtml)
Replaces URLs in the string with the HTML URL tags.static String
markUpURLs(String raw, String replacement, boolean toHtml)
Replaces URLs in the string with the URL replaced by the replacement string.static String
toClassCrossRefURL(String classname)
Generates a classname cross reference fake link used in the help.static String
toHTML(String s)
Converts the given String into HTML, i.e., replacing some char entities with HTML entities.static String
toJavaApiURL(Class cls)
Generates an API URL from the Java class.static String
toJavaApiURL(String classname)
Generates an API URL from the Java classname.
-
-
-
Field Detail
-
DEFAULT_MARKUP
public static final String DEFAULT_MARKUP
the default replacement for URL markup.- See Also:
- Constant Field Values
-
CROSSREF_PREFIX
public static final String CROSSREF_PREFIX
the prefix to use in URLs.- See Also:
- Constant Field Values
-
JAVA_API_URL
public static final String JAVA_API_URL
the URL prefix for the Java Javadoc.- See Also:
- Constant Field Values
-
-
Method Detail
-
toHTML
public static String toHTML(String s)
Converts the given String into HTML, i.e., replacing some char entities with HTML entities.- Parameters:
s
- the string to convert- Returns:
- the HTML conform string, empty string if input was null
-
convertLines
public static String convertLines(String s, boolean nbsp)
Line feeds are converted into <br>.- Parameters:
s
- the string to convert the line breaks into HTMLnbsp
- whether to convert leading blanks to non-breaking spaces- Returns:
- the converted string
-
fromHTML
public static String fromHTML(String s)
Converts some HTML entities with the corresponding characters.- Parameters:
s
- the HTML string to convert- Returns:
- the converted string
-
markUpURLs
public static String markUpURLs(String raw, boolean toHtml)
Replaces URLs in the string with the HTML URL tags.- Parameters:
raw
- the raw text with URLstoHtml
- whether to transform < and > into their HTML counterparts- Returns:
- the marked up text
- See Also:
DEFAULT_MARKUP
-
markUpURLs
public static String markUpURLs(String raw, String replacement, boolean toHtml)
Replaces URLs in the string with the URL replaced by the replacement string. Use "$0" to reference the URL in the replacement string. For example, for turning a URL in to a link, use the following replacement string:"$0"
- Parameters:
raw
- the raw text with URLsreplacement
- the replacement string (use $0 as placeholder for the URL)toHtml
- whether to transform < and > into their HTML counterparts- Returns:
- the marked up text
- See Also:
DEFAULT_MARKUP
-
toClassCrossRefURL
public static String toClassCrossRefURL(String classname)
Generates a classname cross reference fake link used in the help.- Parameters:
classname
- the class to generate the link for- Returns:
- the fake url
-
isClassCrossRefURL
public static boolean isClassCrossRefURL(String url)
Checks whether the URL is a fake class cross reference link.- Parameters:
url
- the url to check- Returns:
- true if a class cross reference
-
extractClassFromCrossRefURL
public static String extractClassFromCrossRefURL(String url)
Returns the classname from the cross reference URL.- Parameters:
url
- the cross reference url- Returns:
- the classname, null if failed to extract
-
toJavaApiURL
public static String toJavaApiURL(Class cls)
Generates an API URL from the Java class.- Parameters:
cls
- the class to generate the URL for- Returns:
- the URL
-
toJavaApiURL
public static String toJavaApiURL(String classname)
Generates an API URL from the Java classname.- Parameters:
classname
- the classname to generate the URL for- Returns:
- the URL
-
hyperlinkClassnames
public static String hyperlinkClassnames(String s, boolean classCrossRefLinks)
Hyperlinks class names in the string.- Parameters:
s
- the string to convert to HTMLclassCrossRefLinks
- whether to generate class cross-reference links interpreted by the ADAMS help interface- Returns:
- the HTML string
-
-