Skip to content

Commit

Permalink
Improved source documentation.
Browse files Browse the repository at this point in the history
Some PMD optimization.
  • Loading branch information
ethauvin committed Dec 7, 2015
1 parent 1b59f8e commit f5f9d5c
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 25 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Optional attributes are:
Attribute | Description
----------- | -------------------------------------------------------------------------------------------
`default` | The fallback value to output, if no cause is available.
`escapeXml` | Converts <,>,&,'," to their corresponding [entity codes](http://dev.w3.org/html5/html-author/charref). Value is `true` by default.
`escapeXml` | Converts <, >, &, ', " to their corresponding [entity codes](http://dev.w3.org/html5/html-author/charref). Value is `true` by default.

## hs:code
The `<hs:code/>` tag displays the current HTTP status code, if any. A shorthand for:
Expand All @@ -60,7 +60,7 @@ Attribute | Description
----------- | -------------------------------------------------------------------------------------------
`code` | The HTTP status error code. If not specified the current status code is used.
`default` | The fallback value to output, if no reason 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.

The reasons are defined in a [ResourceBundle](http://docs.oracle.com/javase/8/docs/api/java/util/ResourceBundle.html) properties as follows:

Expand Down
9 changes: 5 additions & 4 deletions src/main/java/net/thauvin/erik/httpstatus/Reasons.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
import java.util.TreeMap;

/**
* The <code>Reasons</code> class.
* Populates the {@link #REASON_PHRASES reason phrases} map from {@link #BUNDLE_BASENAME bundle properties}, and
* implements accessor methods.
*
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
* @created 2015-12-02
Expand All @@ -57,7 +58,7 @@ public class Reasons
private static final Map<String, String> REASON_PHRASES = new TreeMap<String, String>();

/**
* Gets the reason phrase for the specified status code.
* Returns the reason phrase for the specified status code.
*
* @param statusCode The status code.
*
Expand All @@ -69,7 +70,7 @@ public static String getReasonPhrase(final int statusCode)
}

/**
* Gets the reason phrase for the specified status code.
* Returns the reason phrase for the specified status code.
*
* @param statusCode The status code.
*
Expand All @@ -81,7 +82,7 @@ public static String getReasonPhrase(final String statusCode)
}

/**
* Outputs the status codes and reason phrases.
* Prints the status codes and reason phrases.
*
* @param args The command line arguments.
*/
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/net/thauvin/erik/httpstatus/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public final class Utils
/**
* Disables the default constructor.
*
* @throws UnsupportedOperationException if an error occurred. if the constructor is called.
* @throws UnsupportedOperationException If the constructor is called.
*/
private Utils()
throws UnsupportedOperationException
Expand All @@ -58,14 +58,14 @@ private Utils()
}

/**
* Writes a string value.
* Writes a string value to the specified writer. The default value is used when the actual value is null.
*
* @param out The writer to output the value to.
* @param value The string value.
* @param defaultValue The default value.
* @param xml The xml flag.
* @param xml The {@link #escapeXml(String) xml} flag.
*/
public static void outWrite(Writer out, String value, String defaultValue, boolean xml)
public static void outWrite(final Writer out, final String value, final String defaultValue, final boolean xml)
throws IOException
{
if (xml)
Expand Down Expand Up @@ -93,13 +93,14 @@ else if (defaultValue != null)
}

/**
* Escapes a string value.
* Converts <code>&lt;</code>, <code>&gt;</code>, <code>&amp;</code>, <code>'</code>, <code>"</code>
* to their corresponding entity codes.
*
* @param value The string value to escape.
* @param value The string value to convert.
*
* @return The escaped string value.
* @return The converted string value.
*/
public static String escapeXml(String value)
public static String escapeXml(final String value)
{
final StringBuilder escaped = new StringBuilder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import java.io.IOException;

/**
* The <code>CauseTag</code> class.
* The <code>&lt;hs:cause&gt;</code> tag returns the cause (if any) for the current HTTP Status Error Code.
*
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
* @created 2015-12-03
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import java.io.IOException;

/**
* The <code>CodeTag</code> class.
* The <code>&lt;hs:code&gt;</code> tag returns the HTTP Status Error Code.
*
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
* @created 2015-12-03
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
import java.io.IOException;

/**
* The <code>ReasonTag</code> class.
* The <code>&lt;hs:reason&gt;</code> tag returns the Reason Phrase for the current (or specified) HTTP Status Error
* Code.
*
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
* @created 2015-12-02
Expand Down Expand Up @@ -85,7 +86,7 @@ public void doTag()
* @param statusCode The status code.
*/
@SuppressWarnings("unused")
public void setCode(int statusCode)
public void setCode(final int statusCode)
{
this.statusCode = statusCode;
}
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/net/thauvin/erik/httpstatus/taglibs/XmlSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,22 @@
import javax.servlet.jsp.tagext.SimpleTagSupport;

/**
* The <code>XmlSupport</code> class.
* Adds support for the <code>default</code> and <code>escapeXml</code> tag attributes.
*
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
* @created 2015-12-03
* @since 1.0
*/
public abstract class XmlSupport extends SimpleTagSupport
{
/**
* Default value string.
*/
protected String defaultValue;

/**
* Escape XML flag.
*/
protected boolean escapeXml = true;

/**
Expand All @@ -54,18 +60,18 @@ public abstract class XmlSupport extends SimpleTagSupport
* @param defaultValue The default value.
*/
@SuppressWarnings("unused")
public void setDefault(String defaultValue)
public void setDefault(final String defaultValue)
{
this.defaultValue = defaultValue;
}

/**
* Sets the escapeXMl flag.
* Sets the {@link net.thauvin.erik.httpstatus.Utils#escapeXml(String) xml} flag.
*
* @param escapeXml <code>true</code> or <code>false</code>
*/
@SuppressWarnings("unused")
public void setEscapeXml(boolean escapeXml)
public void setEscapeXml(final boolean escapeXml)
{
this.escapeXml = escapeXml;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/META-INF/httpstatus.tld
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
</attribute>
<attribute>
<description>
Converts &lt;,&gt;,&amp;,'," to their corresponding entity codes. Value is true by default.
Converts &lt;, &gt; ,&amp; ,' ," to their corresponding entity codes. Value is true by default.
</description>
<name>escapeXml</name>
<required>false</required>
Expand All @@ -70,7 +70,7 @@

<tag>
<description>
Outputs the HTTP Status Error Code.
Returns the HTTP Status Error Code.
</description>
<name>code</name>
<tag-class>net.thauvin.erik.httpstatus.taglibs.CodeTag</tag-class>
Expand Down Expand Up @@ -102,7 +102,7 @@
</attribute>
<attribute>
<description>
Converts &lt;,&gt;,&amp;,'," to their corresponding entity codes. Value is true by default.
Converts &lt;, &gt;, &amp;, ', " to their corresponding entity codes. Value is true by default.
</description>
<name>escapeXml</name>
<required>false</required>
Expand Down

0 comments on commit f5f9d5c

Please sign in to comment.