Class SpdxLicenseTemplateHelper


  • public class SpdxLicenseTemplateHelper
    extends Object
    Implements common conversion methods for processing SPDX license templates
    Author:
    Gary O'Neall
    • Field Detail

      • RULE_PATTERN

        public static final Pattern RULE_PATTERN
      • END_RULE_PATTERN

        public static final Pattern END_RULE_PATTERN
    • Method Detail

      • templateTextToHtml

        public static String templateTextToHtml​(String licenseTemplate)
                                         throws LicenseTemplateRuleException
        Converts a license template string to formatted HTML which highlights any rules or tags
        Parameters:
        licenseTemplate - standard license template
        Returns:
        an HTML representation of the license template
        Throws:
        LicenseTemplateRuleException - on a rule parsing errors
      • templateToText

        public static String templateToText​(String template)
                                     throws LicenseTemplateRuleException
        Converts template text to standard default text using any default parameters in the rules
        Parameters:
        template - standard license template
        Returns:
        text representation of the license
        Throws:
        LicenseTemplateRuleException - on any rule parsing errors
      • formatEscapeHTML

        public static String formatEscapeHTML​(String text)
        Escapes and formats text
        Parameters:
        text - unformatted text
        Returns:
        text suitable for inclusion in HTML
      • formatEscapeHTML

        public static String formatEscapeHTML​(String text,
                                              boolean inParagraph)
        Escapes and formats text
        Parameters:
        text - unformatted text
        inParagraph - true if inside a paragraph tag
        Returns:
        text escaped and formatted for inclusion in HTML
      • addHtmlFormatting

        public static String addHtmlFormatting​(String text)
        Adds HTML formatting <br> and <p>
        Parameters:
        text - unformatted text
        Returns:
        HTML formatted text
      • addHtmlFormatting

        public static String addHtmlFormatting​(String text,
                                               boolean inParagraph)
        Adds HTML formatting <br> and <p>
        Parameters:
        text - unformatted text
        inParagraph - true if inside a paragraph tag
        Returns:
        HTML formatted text
      • htmlToText

        public static String htmlToText​(String html)
        Converts an HTML string to text preserving line breaks for <br/> tags
        Parameters:
        html - string of HTML formatted text
        Returns:
        text representation of the HTML