Class HtmlUtils


  • public class HtmlUtils
    extends Object
    Utility functions regarding HTML.
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    • Constructor Detail

      • HtmlUtils

        public HtmlUtils()
    • 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 HTML
        nbsp - 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 URLs
        toHtml - 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 URLs
        replacement - 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 HTML
        classCrossRefLinks - whether to generate class cross-reference links interpreted by the ADAMS help interface
        Returns:
        the HTML string