Class HtmlReviewer

java.lang.Object
org.machanism.machai.gw.reviewer.HtmlReviewer
All Implemented Interfaces:
Reviewer

public class HtmlReviewer extends Object implements Reviewer
A Reviewer implementation for HTML and XML files with the .html, .htm, or .xml extension. It identifies guidance comments and turns matching files into localized review prompts.

The reviewer reads the complete file as UTF-8 text and looks for the configured guidance tag inside an HTML/XML comment. When guidance is found, it creates a localized prompt containing the file name, its path relative to the project directory, and the complete file content.

Guidance is expected to appear in an HTML/XML comment block, for example <!-- @guidance ... -->. Files without such a comment are not reviewable by this implementation. The source is decoded as UTF-8 and is passed to the prompt template without altering its content.

  • Field Details

    • promptBundle

      private final ResourceBundle promptBundle
      The resource bundle used to obtain localized prompt templates for HTML and XML files.

      The html_file resource is expected to accept the file name, project-relative path, and complete file content, in that order. The bundle is resolved using the default locale when this reviewer is initialized.

      This field is initialized when an HtmlReviewer instance is created and remains unchanged for the lifetime of that instance.

  • Constructor Details

    • HtmlReviewer

      public HtmlReviewer()
  • Method Details

    • getSupportedFileExtensions

      public String[] getSupportedFileExtensions()
      Returns the file extensions supported by this reviewer. The returned extensions do not include a leading period.
      Specified by:
      getSupportedFileExtensions in interface Reviewer
      Returns:
      an array containing "html", "htm", and "xml"
    • perform

      public String perform(File projectDir, File guidancesFile) throws IOException
      Reviews the given file and returns a formatted prompt fragment when the file contains the configured guidance tag in an HTML/XML comment. The complete file is read as UTF-8 so that the prompt preserves its source content exactly. The first matching guidance comment determines whether the file is reviewable; the extracted comment text is used only for that determination because the prompt contains the complete source file.
      Specified by:
      perform in interface Reviewer
      Parameters:
      projectDir - the project root directory used to compute a project-relative path for context
      guidancesFile - the HTML/XML file to analyze
      Returns:
      a formatted prompt fragment, or null when the file does not contain guidance
      Throws:
      IOException - if an error occurs while reading the file