Class TemplateRegexMatcher

  • All Implemented Interfaces:
    org.spdx.licenseTemplate.ILicenseTemplateOutputHandler

    public class TemplateRegexMatcher
    extends Object
    implements org.spdx.licenseTemplate.ILicenseTemplateOutputHandler
    Constructs a regular expression from a license or exception template and provide a matching method to see if code matching the template exists within the text provided

    Note that the regular expression assumes a fully normalized text string to match

    isTemplateMatchWithinText(String text) will return true if the text matches the template

    getQuickMatchRegex() will return a regular expression with limited backtracking which can be used for a quick search getCompleteRegex() will return a regular expression for the entire license where getStartRegex(int wordLimit) will return a regular expression to match the beginning of a license and getEndRegex(int wordLimit) will return a regular expression to match the end of a license

    Author:
    Gary O'Neall
    • Method Detail

      • getCompleteRegex

        public String getCompleteRegex()
        Returns:
        the complete regular expression for the template
      • getQuickMatchRegex

        public String getQuickMatchRegex​(int wordLimit)
        Parameters:
        wordLimit - maximum number of contiguous words to match
        Returns:
        a regular expression to match the template with minimum backtracking - avoiding optional and var tags
      • getStartRegex

        public String getStartRegex​(int wordLimit)
        Parameters:
        wordLimit - number of non-optional words to include in the pattern
        Returns:
        a regex to match the start of the license per the template
      • getEndRegex

        public String getEndRegex​(int wordLimit)
        Parameters:
        wordLimit - number of non-optional words to include in the pattern
        Returns:
        a regex to match the end of the license per the template
      • isTemplateMatchWithinText

        public boolean isTemplateMatchWithinText​(String text)
                                          throws SpdxCompareException,
                                                 org.spdx.core.InvalidSPDXAnalysisException
        Parameters:
        text - text to search for a match
        Returns:
        true if a match is found, otherwise false
        Throws:
        SpdxCompareException
        org.spdx.core.InvalidSPDXAnalysisException
      • text

        public void text​(String text)
        Specified by:
        text in interface org.spdx.licenseTemplate.ILicenseTemplateOutputHandler
      • variableRule

        public void variableRule​(org.spdx.licenseTemplate.LicenseTemplateRule rule)
        Specified by:
        variableRule in interface org.spdx.licenseTemplate.ILicenseTemplateOutputHandler
      • beginOptional

        public void beginOptional​(org.spdx.licenseTemplate.LicenseTemplateRule rule)
        Specified by:
        beginOptional in interface org.spdx.licenseTemplate.ILicenseTemplateOutputHandler
      • endOptional

        public void endOptional​(org.spdx.licenseTemplate.LicenseTemplateRule rule)
        Specified by:
        endOptional in interface org.spdx.licenseTemplate.ILicenseTemplateOutputHandler
      • completeParsing

        public void completeParsing()
        Specified by:
        completeParsing in interface org.spdx.licenseTemplate.ILicenseTemplateOutputHandler