<commit_before>[[checking-concept]]
=== Flexible Checking Algorithms
kbd:[HtmlSC] uses the {template-method-pattern} to enable flexible checking algorithms:

[quote, http://sourcemaking.com/design_patterns/template_method]
The Template Method defines a skeleton of an algorithm in an operation, and defers some steps to subclasses.

We achieve that by defining the skeleton of the checking algorithm in one operation, deferring the specific checking algorithm steps to subclasses.

The invariant steps are implemented in the abstract base class, while the variant checking algorithms have to be provided by the subclasses.

[source, groovy]
    /**
    ** template method for performing a single type of checks
     * on the given @see HtmlPage.
     *
     * Prerequisite: pageToCheck has been successfully parsed,
     * prior to constructing this Checker instance.
    **/
    public CheckingResultsCollector performCheck() {
        // assert prerequisite
        assert pageToCheck != null
        initResults()
        return check() // execute the actual checking algorithm
    }



image::template-method.png["Template Method", title="Template-Method Overview"]

[options="header", cols="1,4"]
.Template Method
|===
| Component | Description
| Checker                           | _abstract_ base class, containing the template method +check()+
                                        plus the public method +performCheck()+
| <<ImageFileExistChecker>>         | checks if referenced local image files exist
| <<BrokenCrossReferencesChecker>>  | checks if cross references (links referenced within the page) exist
| <<DuplicateIdChecker>>            | checks if any id has multiple definitions
| MissingAltTagsForImagesChecker    | (planned) checks if there are image tags without alt-attributes.
|===


==== MissingImageFilesChecker

[small]#Adresses requirement <<Types of Sanity Checks, R1>>.#

The (little) problem with checking images is their path: Consider the following
HTML fragment (from the file +testme.html+:


[source, html]
<img src="./images/one-image.jpg">


This image file ("one-image.jpg") has to be located relative to the directory
containing the corresponding HTML file.

Therefore the expected absolute path of the "one-image.jpg" has to be determined
from the absolute path of the html file under test.

We check for existing files using the usual Java api, but have to do some
_directory arithmetic_ to get the +absolutePathToImageFile+:

[source, java]
  File f = new File( absolutePathToImageFile );
  if(f.exists() && !f.isDirectory())



==== BrokenCrossReferencesChecker

[small]#Adresses requirement <<Types of Sanity Checks, R-2>>.#

Cross references are document-internal links where the +href="link-target" from the html anchor<commit_msg>MissingImgAltAttributeChecker gets own link target (header)<commit_after>[[checking-concept]]
=== Flexible Checking Algorithms
kbd:[HtmlSC] uses the {template-method-pattern} to enable flexible checking algorithms:

[quote, http://sourcemaking.com/design_patterns/template_method]
The Template Method defines a skeleton of an algorithm in an operation, and defers some steps to subclasses.

We achieve that by defining the skeleton of the checking algorithm in one operation, deferring the specific checking algorithm steps to subclasses.

The invariant steps are implemented in the abstract base class, while the variant checking algorithms have to be provided by the subclasses.

[source, groovy]
    /**
    ** template method for performing a single type of checks
     * on the given @see HtmlPage.
     *
     * Prerequisite: pageToCheck has been successfully parsed,
     * prior to constructing this Checker instance.
    **/
    public CheckingResultsCollector performCheck() {
        // assert prerequisite
        assert pageToCheck != null
        initResults()
        return check() // execute the actual checking algorithm
    }



image::template-method.png["Template Method", title="Template-Method Overview"]

[options="header", cols="1,4"]
.Template Method
|===
| Component | Description
| Checker                           | _abstract_ base class, containing the template method +check()+
                                        plus the public method +performCheck()+
| <<ImageFileExistChecker>>         | checks if referenced local image files exist
| <<BrokenCrossReferencesChecker>>  | checks if cross references (links referenced within the page) exist
| <<DuplicateIdChecker>>            | checks if any id has multiple definitions
| MissingAltTagsForImagesChecker    | (planned) checks if there are image tags without alt-attributes.
|===


==== MissingImageFilesChecker

[small]#Adresses requirement <<Types of Sanity Checks, R1>>.#

The (little) problem with checking images is their path: Consider the following
HTML fragment (from the file +testme.html+:


[source, html]
<img src="./images/one-image.jpg">


This image file ("one-image.jpg") has to be located relative to the directory
containing the corresponding HTML file.

Therefore the expected absolute path of the "one-image.jpg" has to be determined
from the absolute path of the html file under test.

We check for existing files using the usual Java api, but have to do some
_directory arithmetic_ to get the +absolutePathToImageFile+:

[source, java]
  File f = new File( absolutePathToImageFile );
  if(f.exists() && !f.isDirectory())


==== MissingImgAltAttributeChecker
[small]#Adresses requirement <<Types of Sanity Checks, R-6>>.#

Simple syntactic check: iterates over all <img> tags to check
if the image has an alt-tag.

==== BrokenCrossReferencesChecker

[small]#Adresses requirement <<Types of Sanity Checks, R-2>>.#

Cross references are document-internal links where the +href="link-target" from the html anchor
{'fraction_non_alphanumeric': 0.08278716798896171, 'fraction_numerical': 0.001552259399793032, 'mean_word_length': 3.9734133790737562, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '824786', 'n_tokens_mistral': 1498, 'n_tokens_neox': 1439, 'n_words': 630}