Sort command line output. Closes #10

Updated copyright

Code cleanup
This commit is contained in:
Erik C. Thauvin 2024-06-07 14:12:11 -07:00
parent 8c79c0e17a
commit 053dcba26b
Signed by: erik
GPG key ID: 776702A6A2DA330E
17 changed files with 100 additions and 85 deletions

2
.idea/misc.xml generated
View file

@ -1,9 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="EntryPointsManager"> <component name="EntryPointsManager">
<pattern value="net.thauvin.erik.httpstatus.HttpStatusBuild" /> <pattern value="net.thauvin.erik.httpstatus.HttpStatusBuild" />
<pattern value="net.thauvin.erik.httpstatus.HttpStatusBuild" method="pmd" /> <pattern value="net.thauvin.erik.httpstatus.HttpStatusBuild" method="pmd" />
<pattern value="net.thauvin.erik.httpstatus.HttpStatusBuild" method="jacoco" /> <pattern value="net.thauvin.erik.httpstatus.HttpStatusBuild" method="jacoco" />
<pattern value="net.thauvin.erik.httpstatus.taglibs.ReasonTag" method="setCode" /> <pattern value="net.thauvin.erik.httpstatus.taglibs.ReasonTag" method="setCode" />
<pattern value="net.thauvin.erik.httpstatus.HttpStatusBuild" method="pmdCli" />
</component> </component>
<component name="PDMPlugin"> <component name="PDMPlugin">
<option name="customRuleSets"> <option name="customRuleSets">

View file

@ -2,7 +2,7 @@
[![License (3-Clause BSD)](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg?style=flat-square)](http://opensource.org/licenses/BSD-3-Clause) [![License (3-Clause BSD)](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg?style=flat-square)](http://opensource.org/licenses/BSD-3-Clause)
[![Java](https://img.shields.io/badge/java-17%2B-blue)](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html) [![Java](https://img.shields.io/badge/java-17%2B-blue)](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html)
[![bld](https://img.shields.io/badge/1.8.0-FA9052?label=bld&labelColor=2392FF)](https://rife2.com/bld) [![bld](https://img.shields.io/badge/1.9.1-FA9052?label=bld&labelColor=2392FF)](https://rife2.com/bld)
[![Release](https://img.shields.io/github/release/ethauvin/httpstatus.svg)](https://github.com/ethauvin/httpstatus/releases/latest) [![Release](https://img.shields.io/github/release/ethauvin/httpstatus.svg)](https://github.com/ethauvin/httpstatus/releases/latest)
[![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/net.thauvin.erik.httpstatus/httpstatus?label=sanpshot&server=https%3A%2F%2Foss.sonatype.org)](https://oss.sonatype.org/content/repositories/snapshots/net/thauvin/erik/httpstatus/httpstatus/) [![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/net.thauvin.erik.httpstatus/httpstatus?label=sanpshot&server=https%3A%2F%2Foss.sonatype.org)](https://oss.sonatype.org/content/repositories/snapshots/net/thauvin/erik/httpstatus/httpstatus/)
[![Maven Central](https://img.shields.io/maven-central/v/net.thauvin.erik.httpstatus/httpstatus.svg?color=blue)](https://central.sonatype.com/artifact/net.thauvin.erik.httpstatus/httpstatus) [![Maven Central](https://img.shields.io/maven-central/v/net.thauvin.erik.httpstatus/httpstatus.svg?color=blue)](https://central.sonatype.com/artifact/net.thauvin.erik.httpstatus/httpstatus)
@ -17,11 +17,11 @@ A simple [JSP](http://www.oracle.com/technetwork/java/javaee/jsp/index.html) Tag
## Table of Contents ## Table of Contents
- [Examples](#examples) - [Examples](#examples)
- Usage - [Usage](#usage)
- [Gradle](#gradle) - [Gradle](#gradle)
- [bld](#bld) - [bld](#bld)
- [Maven](#maven) - [Maven](#maven)
- JSP Tags - [JSP Tags](#jsp-tags)
- [hs:cause](#hscause) - [hs:cause](#hscause)
- [hs:code](#hscode) - [hs:code](#hscode)
- [hs:message](#hsmessage) - [hs:message](#hsmessage)
@ -111,7 +111,7 @@ The `<hs:cause/>` tag displays the cause of current HTTP status code, if any. A
Optional attributes are: Optional attributes are:
| Attribute | Description | | Attribute | Description |
|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------| | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `default` | The fallback value to output, if no cause is | | `default` | The fallback value to output, if no cause is |
| `escapeXml` | Converts &lt;, &gt;, &amp;, ', " to their corresponding [entity codes](http://dev.w3.org/html5/html-author/charref). Value is `true` by default. | | `escapeXml` | Converts &lt;, &gt;, &amp;, ', " to their corresponding [entity codes](http://dev.w3.org/html5/html-author/charref). Value is `true` by default. |
@ -134,7 +134,7 @@ The `<hs:message/>` tag displays the current error message, if any. A shorthand
Optional attributes are: Optional attributes are:
| Attribute | Description | | Attribute | Description |
|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------| | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `default` | The fallback value to output, if no error message is available. | | `default` | The fallback value to output, if no error message is available. |
| `escapeXml` | Converts &lt;, &gt;, &amp;, ', " to their corresponding [entity codes](http://dev.w3.org/html5/html-author/charref). Value is `true` by default. | | `escapeXml` | Converts &lt;, &gt;, &amp;, ', " to their corresponding [entity codes](http://dev.w3.org/html5/html-author/charref). Value is `true` by default. |
@ -143,7 +143,7 @@ Optional attributes are:
The `<hs:reason/>` tag displays the reason for an HTTP status code, if any. Optional attributes are: The `<hs:reason/>` tag displays the reason for an HTTP status code, if any. Optional attributes are:
| Attribute | Description | | Attribute | Description |
|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------| | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `default` | The fallback value to output, if no reason is available. | | `default` | The fallback value to output, if no reason is available. |
| `code` | The HTTP status error code. If not specified the current status code is used. | | `code` | The HTTP status error code. If not specified the current status code is used. |
| `escapeXml` | Converts &lt;, &gt;, &amp;, ', " to their corresponding [entity codes](http://dev.w3.org/html5/html-author/charref). Value is `true` by default. | | `escapeXml` | Converts &lt;, &gt;, &amp;, ', " to their corresponding [entity codes](http://dev.w3.org/html5/html-author/charref). Value is `true` by default. |
@ -191,7 +191,7 @@ public class ExampleServlet extends HttpServlet {
The `StatusCode` bean methods are: The `StatusCode` bean methods are:
| Method | Description | | Method | Description |
|-----------------|----------------------------------------------------------------------| | --------------- | -------------------------------------------------------------------- |
| `getReason` | Returns the reason for the status code (eg: `Internal Server Error`) | | `getReason` | Returns the reason for the status code (eg: `Internal Server Error`) |
| `isClientError` | Checks if the status code is a client error. | | `isClientError` | Checks if the status code is a client error. |
| `isError` | Checks if the status code is a server or client error. | | `isError` | Checks if the status code is a server or client error. |
@ -206,11 +206,16 @@ The `StatusCode` bean methods are:
The reasons are defined in a [ResourceBundle](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/ResourceBundle.html) properties as follows: The reasons are defined in a [ResourceBundle](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/ResourceBundle.html) properties as follows:
| Status Code | Reason | | Status Code | Reason |
|-------------|------------------------------------------------------------| | ----------- | ---------------------------------------------------------- |
| `100` | Continue | | `100` | Continue |
| `101` | Switching Protocols | | `101` | Switching Protocols |
| `102` | Processing | | `102` | Processing |
| `103` | Early Hints | | `103` | Early Hints |
| `110` | Response is Stale |
| `111` | Revalidation Failed |
| `112` | Disconnected Operation |
| `113` | Heuristic Expiration |
| `199` | Miscellaneous Warning |
| `200` | OK | | `200` | OK |
| `201` | Created | | `201` | Created |
| `202` | Accepted | | `202` | Accepted |
@ -220,15 +225,17 @@ The reasons are defined in a [ResourceBundle](https://docs.oracle.com/en/java/ja
| `206` | Partial Content | | `206` | Partial Content |
| `207` | Multi-Status | | `207` | Multi-Status |
| `208` | Already Reported | | `208` | Already Reported |
| `214` | Transformation Applied |
| `218` | This is fine | | `218` | This is fine |
| `226` | IM Used | | `226` | IM Used |
| `299` | Miscellaneous Persistent Warning |
| `300` | Multiple Choices | | `300` | Multiple Choices |
| `301` | Moved Permanently | | `301` | Moved Permanently |
| `302` | Found/Moved Temporarily | | `302` | Found/Moved Temporarily |
| `303` | See Other | | `303` | See Other |
| `304` | Not Modified | | `304` | Not Modified |
| `305` | Use Proxy | | `305` | Use Proxy |
| `306` | Switch Proxy | | `306` | Unused |
| `307` | Temporary Redirect | | `307` | Temporary Redirect |
| `308` | Permanent Redirect | | `308` | Permanent Redirect |
| `400` | Bad Request | | `400` | Bad Request |
@ -244,18 +251,19 @@ The reasons are defined in a [ResourceBundle](https://docs.oracle.com/en/java/ja
| `410` | Gone | | `410` | Gone |
| `411` | Length Required | | `411` | Length Required |
| `412` | Precondition Failed | | `412` | Precondition Failed |
| `413` | Request Entity/Payload Too Large | | `413` | Payload Too Large |
| `414` | Request-URI Too Long | | `414` | URI Too Long |
| `415` | Unsupported Media Type | | `415` | Unsupported Media Type |
| `416` | Requested Range Not Satisfiable | | `416` | Range Not Satisfiable |
| `417` | Expectation Failed | | `417` | Expectation Failed |
| `418` | I'm A Teapot | | `418` | I'm A Teapot |
| `419` | Insufficient Space on Resource | | `419` | Insufficient Space on Resource |
| `420` | Method Failure | | `420` | Method Failure |
| `421` | Misdirected Request | | `421` | Misdirected Request |
| `422` | Unprocessable Entity | | `422` | Unprocessable Content |
| `423` | Locked | | `423` | Locked |
| `424` | Failed Dependency | | `424` | Failed Dependency |
| `425` | Too Early |
| `426` | Upgrade Required | | `426` | Upgrade Required |
| `428` | Precondition Required | | `428` | Precondition Required |
| `429` | Too Many Requests | | `429` | Too Many Requests |
@ -270,7 +278,7 @@ The reasons are defined in a [ResourceBundle](https://docs.oracle.com/en/java/ja
| `463` | X-Forwarded-For Header with More than 30 IP Addresses | | `463` | X-Forwarded-For Header with More than 30 IP Addresses |
| `494` | Request Header Too Large | | `494` | Request Header Too Large |
| `495` | SSL Certificate Error | | `495` | SSL Certificate Error |
| `496` | No SSL Certificate | | `496` | SSL Certificate Required |
| `497` | HTTP Request Sent to HTTPS Port | | `497` | HTTP Request Sent to HTTPS Port |
| `498` | Token Expired/Invalid | | `498` | Token Expired/Invalid |
| `499` | Client Closed Request | | `499` | Client Closed Request |
@ -288,7 +296,7 @@ The reasons are defined in a [ResourceBundle](https://docs.oracle.com/en/java/ja
| `511` | Network Authentication Required | | `511` | Network Authentication Required |
| `520` | Unknown Error | | `520` | Unknown Error |
| `521` | Web Server Is Down | | `521` | Web Server Is Down |
| `522` | Origin Connection Time-out | | `522` | Connection Timed Out |
| `523` | Origin Is Unreachable | | `523` | Origin Is Unreachable |
| `524` | A Timeout Occurred | | `524` | A Timeout Occurred |
| `525` | SSL Handshake Failed | | `525` | SSL Handshake Failed |
@ -296,8 +304,11 @@ The reasons are defined in a [ResourceBundle](https://docs.oracle.com/en/java/ja
| `527` | Railgun Error | | `527` | Railgun Error |
| `529` | Site is overloaded | | `529` | Site is overloaded |
| `530` | Site is frozen | | `530` | Site is frozen |
| `540` | Temporarily Disabled |
| `561` | Unauthorized |
| `598` | Network Read Timeout Error | | `598` | Network Read Timeout Error |
| `599` | Network Connect Timeout Error | | `599` | Network Connect Timeout Error |
| `783` | Unexpected Token |
## Command Line Usage ## Command Line Usage
@ -317,6 +328,11 @@ $ java -jar httpstatus-1.1.0.jar
101: Switching Protocols 101: Switching Protocols
102: Processing 102: Processing
103: Early Hints 103: Early Hints
110: Response is Stale
111: Revalidation Failed
112: Disconnected Operation
113: Heuristic Expiration
199: Miscellaneous Warning
200: OK 200: OK
201: Created 201: Created
202: Accepted 202: Accepted
@ -332,7 +348,7 @@ $ java -jar httpstatus-1.1.0.jar 2xx
201: Created 201: Created
202: Accepted 202: Accepted
203: Non-Authoritative Information 203: Non-Authoritative Information
...
``` ```
## Contributing ## Contributing

View file

@ -1,7 +1,7 @@
/* /*
* HttpStatusBuild.java * HttpStatusBuild.java
* *
* Copyright 2015-2023 Erik C. Thauvin (erik@thauvin.net) * Copyright 2015-2024 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -140,6 +140,11 @@ public class HttpStatusBuild extends Project {
pmdOp.includeLineNumber(false).execute(); pmdOp.includeLineNumber(false).execute();
} }
private void pomRoot() throws FileUtilsErrorException {
PomBuilder.generateInto(publishOperation().info(), dependencies(),
Path.of(workDirectory.getPath(), "pom.xml").toFile());
}
@Override @Override
public void publish() throws Exception { public void publish() throws Exception {
super.publish(); super.publish();
@ -151,9 +156,4 @@ public class HttpStatusBuild extends Project {
super.publishLocal(); super.publishLocal();
pomRoot(); pomRoot();
} }
private void pomRoot() throws FileUtilsErrorException {
PomBuilder.generateInto(publishOperation().info(), dependencies(),
Path.of(workDirectory.getPath(), "pom.xml").toFile());
}
} }

View file

@ -1,7 +1,7 @@
/* /*
* Reasons.java * Reasons.java
* *
* Copyright 2015-2023 Erik C. Thauvin (erik@thauvin.net) * Copyright 2015-2024 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -34,6 +34,7 @@ package net.thauvin.erik.httpstatus;
import java.util.Map; import java.util.Map;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
/** /**
@ -56,8 +57,8 @@ public final class Reasons {
// Initializes the reason phrases map. // Initializes the reason phrases map.
static { static {
final ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_BASENAME); var bundle = ResourceBundle.getBundle(BUNDLE_BASENAME);
for (final String key : bundle.keySet()) { for (var key : bundle.keySet()) {
REASON_PHRASES.put(key, bundle.getString(key)); REASON_PHRASES.put(key, bundle.getString(key));
} }
} }
@ -75,7 +76,7 @@ public final class Reasons {
* @param statusCode The status code. * @param statusCode The status code.
* @return The reason phrase, or <code>null</code>. * @return The reason phrase, or <code>null</code>.
*/ */
public static String getReasonPhrase(final int statusCode) { public static String getReasonPhrase(int statusCode) {
return getReasonPhrase(Integer.toString(statusCode)); return getReasonPhrase(Integer.toString(statusCode));
} }
@ -85,7 +86,7 @@ public final class Reasons {
* @param statusCode The status code. * @param statusCode The status code.
* @return The reason phrase, or <code>null</code>. * @return The reason phrase, or <code>null</code>.
*/ */
public static String getReasonPhrase(final String statusCode) { public static String getReasonPhrase(String statusCode) {
return REASON_PHRASES.get(statusCode); return REASON_PHRASES.get(statusCode);
} }
@ -95,29 +96,26 @@ public final class Reasons {
* @param args The status code(s) or response class(es), prints all if none. * @param args The status code(s) or response class(es), prints all if none.
*/ */
@SuppressWarnings("PMD.SystemPrintln") @SuppressWarnings("PMD.SystemPrintln")
public static void main(final String... args) { public static void main(String... args) {
var keys = new TreeSet<>(REASON_PHRASES.keySet());
if (args.length >= 1) { if (args.length >= 1) {
for (final String key : args) { for (var key : args) {
if (key.endsWith("xx")) { if (key.endsWith("xx")) {
var responseClass = key.charAt(0); var responseClass = key.charAt(0);
REASON_PHRASES.forEach((k, v) -> { keys.forEach((k) -> {
if (k.charAt(0) == responseClass) { if (k.charAt(0) == responseClass) {
System.out.println(k + ": " + v); System.out.println(k + ": " + REASON_PHRASES.get(k));
} }
}); });
} else { } else {
final String value = REASON_PHRASES.get(key); var value = REASON_PHRASES.get(key);
if (value != null) { if (value != null) {
System.out.println(key + ": " + value); System.out.println(key + ": " + value);
} }
} }
} }
} else { } else {
REASON_PHRASES.forEach((k, v) -> { keys.forEach((k) -> System.out.println(k + ": " + REASON_PHRASES.get(k)));
if (v != null) {
System.out.println(k + ": " + v);
}
});
System.out.println("Total: " + REASON_PHRASES.size()); System.out.println("Total: " + REASON_PHRASES.size());
} }
} }

View file

@ -1,7 +1,7 @@
/* /*
* StatusCode.java * StatusCode.java
* *
* Copyright 2015-2023 Erik C. Thauvin (erik@thauvin.net) * Copyright 2015-2024 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -58,7 +58,7 @@ public class StatusCode implements Serializable {
* *
* @param code The status code. * @param code The status code.
*/ */
public StatusCode(final int code) { public StatusCode(int code) {
this.code = code; this.code = code;
} }
@ -147,7 +147,7 @@ public class StatusCode implements Serializable {
* *
* @param code The HTTP status code. * @param code The HTTP status code.
*/ */
public void setCode(final int code) { public void setCode(int code) {
this.code = code; this.code = code;
} }
} }

View file

@ -1,7 +1,7 @@
/* /*
* Utils.java * Utils.java
* *
* Copyright 2015-2023 Erik C. Thauvin (erik@thauvin.net) * Copyright 2015-2024 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -59,11 +59,11 @@ public final class Utils {
* @param value The string value to convert. * @param value The string value to convert.
* @return The converted string value. * @return The converted string value.
*/ */
public static String escapeXml(final String value) { public static String escapeXml(String value) {
final StringBuilder escaped = new StringBuilder(); var escaped = new StringBuilder();
for (int i = 0; i < value.length(); i++) { for (var i = 0; i < value.length(); i++) {
final char c = value.charAt(i); var c = value.charAt(i);
switch (c) { switch (c) {
case '<' -> escaped.append("&lt;"); case '<' -> escaped.append("&lt;");
case '>' -> escaped.append("&gt;"); case '>' -> escaped.append("&gt;");
@ -86,7 +86,7 @@ public final class Utils {
* @param xml The {@link #escapeXml(String) xml} flag. * @param xml The {@link #escapeXml(String) xml} flag.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public static void outWrite(final Writer out, final String value, final String defaultValue, final boolean xml) public static void outWrite(Writer out, String value, String defaultValue, boolean xml)
throws IOException { throws IOException {
if (value != null) { if (value != null) {
out.write(xml ? escapeXml(value) : value); out.write(xml ? escapeXml(value) : value);

View file

@ -1,7 +1,7 @@
/* /*
* CauseTag.java * CauseTag.java
* *
* Copyright 2015-2023 Erik C. Thauvin (erik@thauvin.net) * Copyright 2015-2024 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -32,10 +32,11 @@
package net.thauvin.erik.httpstatus.taglibs; package net.thauvin.erik.httpstatus.taglibs;
import jakarta.servlet.jsp.PageContext;
import java.io.IOException;
import net.thauvin.erik.httpstatus.Utils;
import jakarta.servlet.jsp.JspWriter; import jakarta.servlet.jsp.JspWriter;
import jakarta.servlet.jsp.PageContext;
import net.thauvin.erik.httpstatus.Utils;
import java.io.IOException;
/** /**
@ -51,12 +52,10 @@ public class CauseTag extends XmlSupport {
*/ */
@Override @Override
public void doTag() throws IOException { public void doTag() throws IOException {
final PageContext pageContext = (PageContext) getJspContext(); PageContext pageContext = (PageContext) getJspContext();
final JspWriter out = pageContext.getOut(); JspWriter out = pageContext.getOut();
Throwable cause = pageContext.getErrorData().getThrowable().getCause();
final Throwable cause = pageContext.getErrorData().getThrowable().getCause();
Utils.outWrite(out, getCause(cause), defaultValue, escapeXml); Utils.outWrite(out, getCause(cause), defaultValue, escapeXml);
} }

View file

@ -1,7 +1,7 @@
/* /*
* CodeTag.java * CodeTag.java
* *
* Copyright 2015-2023 Erik C. Thauvin (erik@thauvin.net) * Copyright 2015-2024 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -51,8 +51,8 @@ public class CodeTag extends SimpleTagSupport {
*/ */
@Override @Override
public void doTag() throws IOException { public void doTag() throws IOException {
final PageContext pageContext = (PageContext) getJspContext(); PageContext pageContext = (PageContext) getJspContext();
final JspWriter out = pageContext.getOut(); JspWriter out = pageContext.getOut();
out.write(String.valueOf(pageContext.getErrorData().getStatusCode())); out.write(String.valueOf(pageContext.getErrorData().getStatusCode()));
} }

View file

@ -1,7 +1,7 @@
/* /*
* MessageTag.java * MessageTag.java
* *
* Copyright 2015-2023 Erik C. Thauvin (erik@thauvin.net) * Copyright 2015-2024 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -51,10 +51,10 @@ public class MessageTag extends XmlSupport {
*/ */
@Override @Override
public void doTag() throws IOException { public void doTag() throws IOException {
final PageContext pageContext = (PageContext) getJspContext(); PageContext pageContext = (PageContext) getJspContext();
final JspWriter out = pageContext.getOut(); JspWriter out = pageContext.getOut();
final String message = (String) pageContext.getRequest().getAttribute( String message = (String) pageContext.getRequest().getAttribute(
jakarta.servlet.RequestDispatcher.ERROR_MESSAGE); jakarta.servlet.RequestDispatcher.ERROR_MESSAGE);
Utils.outWrite(out, message, defaultValue, escapeXml); Utils.outWrite(out, message, defaultValue, escapeXml);

View file

@ -1,7 +1,7 @@
/* /*
* ReasonTag.java * ReasonTag.java
* *
* Copyright 2015-2023 Erik C. Thauvin (erik@thauvin.net) * Copyright 2015-2024 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -55,8 +55,8 @@ public class ReasonTag extends XmlSupport {
*/ */
@Override @Override
public void doTag() { public void doTag() {
final PageContext pageContext = (PageContext) getJspContext(); PageContext pageContext = (PageContext) getJspContext();
final JspWriter out = pageContext.getOut(); JspWriter out = pageContext.getOut();
try { try {
if (statusCode > -1) { if (statusCode > -1) {
@ -75,7 +75,7 @@ public class ReasonTag extends XmlSupport {
* *
* @param statusCode The status code. * @param statusCode The status code.
*/ */
public void setCode(final int statusCode) { public void setCode(int statusCode) {
this.statusCode = statusCode; this.statusCode = statusCode;
} }
} }

View file

@ -1,7 +1,7 @@
/* /*
* XmlSupport.java * XmlSupport.java
* *
* Copyright 2015-2023 Erik C. Thauvin (erik@thauvin.net) * Copyright 2015-2024 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -58,7 +58,7 @@ public abstract class XmlSupport extends SimpleTagSupport {
* @param defaultValue The default value. * @param defaultValue The default value.
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
public void setDefault(final String defaultValue) { public void setDefault(String defaultValue) {
this.defaultValue = defaultValue; this.defaultValue = defaultValue;
} }
@ -68,7 +68,7 @@ public abstract class XmlSupport extends SimpleTagSupport {
* @param escapeXml <code>true</code> or <code>false</code> * @param escapeXml <code>true</code> or <code>false</code>
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
public void setEscapeXml(final boolean escapeXml) { public void setEscapeXml(boolean escapeXml) {
this.escapeXml = escapeXml; this.escapeXml = escapeXml;
} }
} }

View file

@ -2,7 +2,7 @@
<!-- <!--
~ httpstatus.tld ~ httpstatus.tld
~ ~
~ Copyright 2015-2023 Erik C. Thauvin (erik@thauvin.net) ~ Copyright 2015-2024 Erik C. Thauvin (erik@thauvin.net)
~ All rights reserved. ~ All rights reserved.
~ ~
~ Redistribution and use in source and binary forms, with or without ~ Redistribution and use in source and binary forms, with or without
@ -37,7 +37,7 @@
<description>HttpStatus JSP Tag Library</description> <description>HttpStatus JSP Tag Library</description>
<display-name>HttpStatus JSP Tags</display-name> <display-name>HttpStatus JSP Tags</display-name>
<tlib-version>1.1.0</tlib-version> <tlib-version>1.1.1</tlib-version>
<short-name>hs</short-name> <short-name>hs</short-name>
<uri>http://erik.thauvin.net/taglibs/httpstatus</uri> <uri>http://erik.thauvin.net/taglibs/httpstatus</uri>

View file

@ -1,7 +1,7 @@
/* /*
* CauseTagTest.java * CauseTagTest.java
* *
* Copyright 2015-2023 Erik C. Thauvin (erik@thauvin.net) * Copyright 2015-2024 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View file

@ -1,7 +1,7 @@
/* /*
* ReasonsMainTest.java * ReasonsMainTest.java
* *
* Copyright 2015-2023 Erik C. Thauvin (erik@thauvin.net) * Copyright 2015-2024 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without

View file

@ -1,7 +1,7 @@
/* /*
* ReasonsTest.java * ReasonsTest.java
* *
* Copyright 2015-2023 Erik C. Thauvin (erik@thauvin.net) * Copyright 2015-2024 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -48,8 +48,8 @@ import static org.assertj.core.api.Assertions.assertThat;
class ReasonsTest { class ReasonsTest {
@Test @Test
void testGetReasonPhrase() { void testGetReasonPhrase() {
final ResourceBundle bundle = ResourceBundle.getBundle(Reasons.BUNDLE_BASENAME); var bundle = ResourceBundle.getBundle(Reasons.BUNDLE_BASENAME);
for (final String key : bundle.keySet()) { for (var key : bundle.keySet()) {
assertThat(Reasons.getReasonPhrase(key)).as("getReasonPhrase(" + key + ')').isEqualTo(bundle.getString(key)); assertThat(Reasons.getReasonPhrase(key)).as("getReasonPhrase(" + key + ')').isEqualTo(bundle.getString(key));
assertThat(Reasons.getReasonPhrase(Integer.parseInt(key))) assertThat(Reasons.getReasonPhrase(Integer.parseInt(key)))
.as("getReasonPhrase(int: " + key + ')').isEqualTo(bundle.getString(key)); .as("getReasonPhrase(int: " + key + ')').isEqualTo(bundle.getString(key));

View file

@ -1,7 +1,7 @@
/* /*
* StatusCodeTest.java * StatusCodeTest.java
* *
* Copyright 2015-2023 Erik C. Thauvin (erik@thauvin.net) * Copyright 2015-2024 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -47,10 +47,10 @@ import static org.assertj.core.api.Assertions.assertThat;
class StatusCodeTest { class StatusCodeTest {
@Test @Test
void testStatusCode() { void testStatusCode() {
final ResourceBundle bundle = ResourceBundle.getBundle(Reasons.BUNDLE_BASENAME); var bundle = ResourceBundle.getBundle(Reasons.BUNDLE_BASENAME);
StatusCode statusCode = new StatusCode(); var statusCode = new StatusCode();
for (final String key : bundle.keySet()) { for (var key : bundle.keySet()) {
final int code = Integer.parseInt(key); int code = Integer.parseInt(key);
statusCode.setCode(code); statusCode.setCode(code);
assertThat(statusCode.getCode()).as("is not " + code).isEqualTo(code); assertThat(statusCode.getCode()).as("is not " + code).isEqualTo(code);
assertThat(statusCode.isInfo()).as(code + " is info").isEqualTo(code >= 100 && code < 200); assertThat(statusCode.isInfo()).as(code + " is info").isEqualTo(code >= 100 && code < 200);
@ -65,8 +65,8 @@ class StatusCodeTest {
.isEqualTo(Reasons.getReasonPhrase(code)); .isEqualTo(Reasons.getReasonPhrase(code));
} }
final int[] unknowns = {0, 99, 600}; int[] unknowns = {0, 99, 600};
for (final int code : unknowns) { for (var code : unknowns) {
statusCode.setCode(code); statusCode.setCode(code);
assertThat(statusCode.getCode()).as("is not " + code).isEqualTo(code); assertThat(statusCode.getCode()).as("is not " + code).isEqualTo(code);
assertThat(statusCode.isInfo()).as(code + " is info").isFalse(); assertThat(statusCode.isInfo()).as(code + " is info").isFalse();

View file

@ -1,7 +1,7 @@
/* /*
* UtilsTest.java * UtilsTest.java
* *
* Copyright 2015-2023 Erik C. Thauvin (erik@thauvin.net) * Copyright 2015-2024 Erik C. Thauvin (erik@thauvin.net)
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -59,7 +59,7 @@ class UtilsTest {
@SuppressWarnings("PMD.AvoidDuplicateLiterals") @SuppressWarnings("PMD.AvoidDuplicateLiterals")
@Test @Test
void testOutWrite() throws IOException { void testOutWrite() throws IOException {
try (StringWriter sw = new StringWriter()) { try (var sw = new StringWriter()) {
Utils.outWrite(sw, null, "default", false); Utils.outWrite(sw, null, "default", false);
assertThat(sw.toString()).isEqualTo("default").as("outWrite(default)"); assertThat(sw.toString()).isEqualTo("default").as("outWrite(default)");