Class CompareTemplateOutputHandler

java.lang.Object
org.spdx.utility.compare.CompareTemplateOutputHandler
All Implemented Interfaces:
org.spdx.licenseTemplate.ILicenseTemplateOutputHandler

public class CompareTemplateOutputHandler extends Object implements org.spdx.licenseTemplate.ILicenseTemplateOutputHandler
Compares the output of a parsed license template to text. The method matches is called after the document is parsed to determine if the text matches.
Author:
Gary O'Neall
  • Constructor Details

    • CompareTemplateOutputHandler

      public CompareTemplateOutputHandler(String compareText) throws IOException
      Construct a new CompareTemplateOutputHandler with the specified text to compare

      This handler is used to compare the output of a parsed SPDX license template to the provided text. It tokenizes the input text and prepares it for comparison against the parsed license template.

      Parameters:
      compareText - The text to compare the parsed SPDX license template to.
      Throws:
      IOException - This is not to be expected since we are using StringReaders
  • Method Details

    • 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
    • matches

      public boolean matches() throws org.spdx.licenseTemplate.LicenseParserException
      Performs the actual parsing if it has not been completed

      NOTE: This should only be called after all text has been added.

      Returns:
      true if no differences were found
      Throws:
      org.spdx.licenseTemplate.LicenseParserException - on license parsing error
    • getDifferences

      Retrieve the details of the differences found during the comparison process
      Returns:
      details on the differences found
    • completeParsing

      public void completeParsing() throws org.spdx.licenseTemplate.LicenseParserException
      Specified by:
      completeParsing in interface org.spdx.licenseTemplate.ILicenseTemplateOutputHandler
      Throws:
      org.spdx.licenseTemplate.LicenseParserException
    • textEquivalent

      public int textEquivalent(String text, int startToken)
      Compares the text against the compareText
      Parameters:
      text - text to compare
      startToken - token of the compareText to being the comparison
      Returns:
      next token index (positive) if there is a match, negative first token where this is a miss-match if no match