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 void
beginOptional(org.spdx.licenseTemplate.LicenseTemplateRule rule)
void
completeParsing()
void
endOptional(org.spdx.licenseTemplate.LicenseTemplateRule rule)
String
getCompleteRegex()
String
getEndRegex(int wordLimit)
String
getQuickMatchRegex(int wordLimit)
String
getStartRegex(int wordLimit)
boolean
isTemplateMatchWithinText(String text)
String
normalizeText(String text)
Normalizes text for use in the template matchervoid
text(String text)
void
variableRule(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:
SpdxCompareException
org.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:
text
in interfaceorg.spdx.licenseTemplate.ILicenseTemplateOutputHandler
-
variableRule
public void variableRule(org.spdx.licenseTemplate.LicenseTemplateRule rule)
- Specified by:
variableRule
in interfaceorg.spdx.licenseTemplate.ILicenseTemplateOutputHandler
-
beginOptional
public void beginOptional(org.spdx.licenseTemplate.LicenseTemplateRule rule)
- Specified by:
beginOptional
in interfaceorg.spdx.licenseTemplate.ILicenseTemplateOutputHandler
-
endOptional
public void endOptional(org.spdx.licenseTemplate.LicenseTemplateRule rule)
- Specified by:
endOptional
in interfaceorg.spdx.licenseTemplate.ILicenseTemplateOutputHandler
-
completeParsing
public void completeParsing()
- Specified by:
completeParsing
in interfaceorg.spdx.licenseTemplate.ILicenseTemplateOutputHandler
-
-