Package org.spdx.utility.compare
Class TemplateRegexMatcher
- java.lang.Object
-
- org.spdx.utility.compare.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 providedNote that the regular expression assumes a fully normalized text string to match
isTemplateMatchWithinText(String text)will return true if the text matches the templategetQuickMatchRegex()will return a regular expression with limited backtracking which can be used for a quick searchgetCompleteRegex()will return a regular expression for the entire license wheregetStartRegex(int wordLimit)will return a regular expression to match the beginning of a license andgetEndRegex(int wordLimit)will return a regular expression to match the end of a license- Author:
- Gary O'Neall
-
-
Constructor Summary
Constructors Constructor Description TemplateRegexMatcher(String template)Generates regular expressions from a license or exception template
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbeginOptional(org.spdx.licenseTemplate.LicenseTemplateRule rule)voidcompleteParsing()voidendOptional(org.spdx.licenseTemplate.LicenseTemplateRule rule)StringgetCompleteRegex()StringgetEndRegex(int wordLimit)StringgetQuickMatchRegex(int wordLimit)StringgetStartRegex(int wordLimit)booleanisTemplateMatchWithinText(String text)StringnormalizeText(String text)Normalizes text for use in the template matchervoidtext(String text)voidvariableRule(org.spdx.licenseTemplate.LicenseTemplateRule rule)
-
-
-
Constructor Detail
-
TemplateRegexMatcher
public TemplateRegexMatcher(String template) throws SpdxCompareException
Generates regular expressions from a license or exception template- Throws:
SpdxCompareException- on compare errors
-
-
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:
SpdxCompareExceptionorg.spdx.core.InvalidSPDXAnalysisException
-
normalizeText
public String normalizeText(String text)
Normalizes text for use in the template matcher- Parameters:
text- text to normalize- Returns:
- text that is normalized for license comparison
-
text
public void text(String text)
- Specified by:
textin interfaceorg.spdx.licenseTemplate.ILicenseTemplateOutputHandler
-
variableRule
public void variableRule(org.spdx.licenseTemplate.LicenseTemplateRule rule)
- Specified by:
variableRulein interfaceorg.spdx.licenseTemplate.ILicenseTemplateOutputHandler
-
beginOptional
public void beginOptional(org.spdx.licenseTemplate.LicenseTemplateRule rule)
- Specified by:
beginOptionalin interfaceorg.spdx.licenseTemplate.ILicenseTemplateOutputHandler
-
endOptional
public void endOptional(org.spdx.licenseTemplate.LicenseTemplateRule rule)
- Specified by:
endOptionalin interfaceorg.spdx.licenseTemplate.ILicenseTemplateOutputHandler
-
completeParsing
public void completeParsing()
- Specified by:
completeParsingin interfaceorg.spdx.licenseTemplate.ILicenseTemplateOutputHandler
-
-