Skip to content

Commit

Permalink
Make HTTP response codes explicit for documentation
Browse files Browse the repository at this point in the history
This requires a higher Java language level for the source,
while keeping Java 8 compatibility for the target.
  • Loading branch information
ascheman committed Aug 10, 2024
1 parent fff8811 commit 8092977
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 22 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,10 @@ configure(subprojects) {

java {
toolchain {
languageVersion = JavaLanguageVersion.of(8)
languageVersion = JavaLanguageVersion.of(11)
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
withSourcesJar()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public SuggestingChecker(Configuration pConfig) {
/**
* let the instance determine the list of possible values
* Examples:
* - MissingImageFilesChecker -> collect the names of images files
* - BrokenCrossReferencesChecker -> collect all (internal) link targets
* - MissingImageFilesChecker collect the names of images files
* - BrokenCrossReferencesChecker collect all (internal) link targets
**/
protected abstract void setValidPossibilities();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public final List<String> getAllMapNames() {
}

/**
* @return list of all usemap-references y with <img src="x" usemap="y"
* @return list of all usemap-references y with &lt;img src="x" usemap="y" ...
*/
public List<String> getAllUsemapRefs() {
return getImagesWithUsemapDeclaration().stream()
Expand Down Expand Up @@ -133,7 +133,7 @@ public final List<HtmlElement> getAllImageTagsWithNonEmptyAltAttribute() {
}

/**
* builds an immutable list of <img...> tags, where
* Builds an immutable list of &lt;img...&gt; tags, where
* the alt-tag is missing or empty ("").
*/
public final List<HtmlElement> getAllImageTagsWithMissingAltAttribute() {
Expand Down Expand Up @@ -169,11 +169,11 @@ public final List<HtmlElement> getAllIds() {
}

/**
* @return List < String > of all href-attributes
* @return List<String> of all href-attributes
* <p>
* common pitfalls with hrefs:
* - local hrefs start with # (like "#appendix")
* - remote hrefs should be valid URLs (like "<a href="https://google.com">https://google.com</a>")
* - remote hrefs should be valid URLs (like "&lt;a href="https://google.com"&gt;https://google.com&lt;/a&gt;")
* - remote hrefs might start with other than http (e.g. https, mailto, telnet, ssh)
* - hrefs might start with file://
* - href might be empty string (nobody knows wtf this is good for, but html parsers usually accept it)
Expand Down Expand Up @@ -206,8 +206,15 @@ public List<HtmlElement> getImagesWithUsemapDeclaration() {
}

/**
* html-map has the following form:
* <map name="mapName"><area...><area...></map>
* An HTML map has the following form:
*
* <code>
* &lt;map name="mapName"&gt;
* &lt;area...&gt;
* &lt;area...&gt;
* &lt;/map&gt;
* </code>
*
* <p>
* collect all area elements for a given map.
* If more than one map exists with this name, areas
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

public class SummarizerUtil {
/**
* returns the percentage of successful checks.
* Returns the percentage of successful checks.
* <p>
* Edge case:
* 0 checks -> 100% successful
* 0 checks 100% successful
*/
public static int percentSuccessful(int totalChecks, int totalNrOfFindings) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,45 @@ private Web() {

// these are regarded as "Success" when checking
// http(s) links
public static final Set<Integer> HTTP_SUCCESS_CODES = initHttpReturnCodes(200, 208, 226, 226);
public static final Set<Integer> HTTP_SUCCESS_CODES = Set.of(
// tag::HTTP_SUCCESS_CODES[]
200, 201, 202, 203, 204,
205, 206, 207, 208, 226
// end::HTTP_SUCCESS_CODES[]
);

public static final Set<Integer> HTTP_REDIRECT_CODES = Set.of(
// tag::HTTP_REDIRECT_CODES[]
300, 301, 302, 303, 304,
305, 306, 307, 308
// end::HTTP_REDIRECT_CODES[]
);

private static Set<Integer> join (Set<Integer> first, Set<Integer> second) {
Set<Integer> result = new HashSet<>(first);
result.addAll(second);

public static final Set<Integer> HTTP_WARNING_CODES = initHttpReturnCodes(100, 102, 300, 308);

public static final Set<Integer> HTTP_ERROR_CODES = initHttpReturnCodes(400, 451, 500, 511);
return Collections.unmodifiableSet(result);
}

public static final Set<Integer> HTTP_REDIRECT_CODES = initHttpReturnCodes(301, 303, 307, 308);
public static final Set<Integer> HTTP_WARNING_CODES = join (Set.of(
// tag::HTTP_WARNING_CODES[]
100, 101, 102
// end::HTTP_WARNING_CODES[]
), HTTP_REDIRECT_CODES);

public static final Set<Integer> HTTP_ERROR_CODES = Set.of(
// tag::HTTP_ERROR_CODES[]
400, 401, 402, 403, 404,
405, 406, 407, 408, 409,
410, 411, 412, 413, 414,
415, 416, 417, 418, 421,
422, 423, 424, 425, 426,
428, 429, 431, 451,
500, 501, 502, 503, 504,
505, 506, 507, 508, 510, 511
// end::HTTP_ERROR_CODES[]
);

public static final Set<String> POSSIBLE_EXTENSIONS = initExtensions();

Expand All @@ -45,12 +77,6 @@ private Web() {

private static final Pattern linkPattern = Pattern.compile("^//.*$");

private static Set<Integer> initHttpReturnCodes(int aLow, int aHigh, int bLow, int bHigh) {
Set<Integer> result = IntStream.rangeClosed(aLow, aHigh).collect(HashSet::new, Set::add, Set::addAll);
result.addAll(IntStream.rangeClosed(bLow, bHigh).collect(HashSet::new, Set::add, Set::addAll));
return Collections.unmodifiableSet(result);
}

private static Set<String> initExtensions() {
Set<String> result = new HashSet<>(8);
result.add("html");
Expand Down Expand Up @@ -79,6 +105,7 @@ public static boolean isInternetConnectionAvailable() {
protected static boolean isInternetConnectionAvailable(String host) {
try {
// if we can get google's address, there is the Internet...
//noinspection ResultOfMethodCallIgnored
InetAddress.getByName(host);
return true;
} catch (UnknownHostException e) {
Expand Down

0 comments on commit 8092977

Please sign in to comment.