-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added <hs:cause/> and <hs:code/> tags and associated parameters.
- Loading branch information
Showing
9 changed files
with
485 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
* Utils.java | ||
* | ||
* Copyright (c) 2015, Erik C. Thauvin (erik@thauvin.net) | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are | ||
* met: | ||
* | ||
* Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* Neither the name of the author nor the names of its contributors may be | ||
* used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package net.thauvin.erik.httpstatus; | ||
|
||
import java.io.IOException; | ||
import java.io.Writer; | ||
|
||
/** | ||
* The <code>Utils</code> class. | ||
* | ||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a> | ||
* @created 2015-12-03 | ||
* @since 1.0 | ||
*/ | ||
public class Utils | ||
{ | ||
|
||
/** | ||
* Disables the default constructor. | ||
* | ||
* @throws UnsupportedOperationException if an error occurred. if the constructor is called. | ||
*/ | ||
private Utils() | ||
throws UnsupportedOperationException | ||
{ | ||
throw new UnsupportedOperationException("Illegal constructor call."); | ||
} | ||
|
||
/** | ||
* Writes a string value. | ||
* | ||
* @param out The writer to output the value to. | ||
* @param value The string value. | ||
* @param defaultValue The default value. | ||
* @param xml The xml flag. | ||
*/ | ||
public static void outWrite(Writer out, String value, String defaultValue, boolean xml) | ||
throws IOException | ||
{ | ||
if (xml) | ||
{ | ||
if (value != null) | ||
{ | ||
out.write(escapeXml(value)); | ||
} | ||
else if (defaultValue != null) | ||
{ | ||
out.write(escapeXml(defaultValue)); | ||
} | ||
} | ||
else | ||
{ | ||
if (value != null) | ||
{ | ||
out.write(value); | ||
} | ||
else if (defaultValue != null) | ||
{ | ||
out.write(defaultValue); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Escapes a string value. | ||
* | ||
* @param value The string value to escape. | ||
* | ||
* @return The escaped string value. | ||
*/ | ||
public static String escapeXml(String value) | ||
{ | ||
final StringBuilder escaped = new StringBuilder(); | ||
|
||
for (int i = 0; i < value.length(); i++) | ||
{ | ||
final char c = value.charAt(i); | ||
switch (c) | ||
{ | ||
case '<': | ||
escaped.append("<"); | ||
break; | ||
case '>': | ||
escaped.append(">"); | ||
break; | ||
case '&': | ||
escaped.append("&"); | ||
break; | ||
case '\'': | ||
escaped.append("'"); | ||
break; | ||
case '"': | ||
escaped.append("""); | ||
break; | ||
default: | ||
escaped.append(c); | ||
break; | ||
} | ||
} | ||
|
||
return escaped.toString(); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
src/main/java/net/thauvin/erik/httpstatus/taglibs/CauseTag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* CauseTag.java | ||
* | ||
* Copyright (c) 2015, Erik C. Thauvin (erik@thauvin.net) | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are | ||
* met: | ||
* | ||
* Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* Neither the name of the author nor the names of its contributors may be | ||
* used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package net.thauvin.erik.httpstatus.taglibs; | ||
|
||
import net.thauvin.erik.httpstatus.Utils; | ||
|
||
import javax.servlet.jsp.JspException; | ||
import javax.servlet.jsp.JspWriter; | ||
import javax.servlet.jsp.PageContext; | ||
import java.io.IOException; | ||
|
||
/** | ||
* The <code>CauseTag</code> class. | ||
* | ||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a> | ||
* @created 2015-12-03 | ||
* @since 1.0 | ||
*/ | ||
public class CauseTag extends XmlSupport | ||
{ | ||
@Override | ||
public void doTag() | ||
throws JspException, IOException | ||
{ | ||
final PageContext pageContext = (PageContext) getJspContext(); | ||
final JspWriter out = pageContext.getOut(); | ||
|
||
String cause; | ||
|
||
try | ||
{ | ||
cause = pageContext.getErrorData().getThrowable().getCause().getLocalizedMessage(); | ||
} | ||
catch (NullPointerException ignore) | ||
{ | ||
cause = defaultValue; | ||
} | ||
|
||
Utils.outWrite(out, cause, defaultValue, escapeXml); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/net/thauvin/erik/httpstatus/taglibs/CodeTag.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* CodeTag.java | ||
* | ||
* Copyright (c) 2015, Erik C. Thauvin (erik@thauvin.net) | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are | ||
* met: | ||
* | ||
* Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* | ||
* Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* Neither the name of the author nor the names of its contributors may be | ||
* used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package net.thauvin.erik.httpstatus.taglibs; | ||
|
||
import javax.servlet.jsp.JspException; | ||
import javax.servlet.jsp.JspWriter; | ||
import javax.servlet.jsp.PageContext; | ||
import javax.servlet.jsp.tagext.SimpleTagSupport; | ||
import java.io.IOException; | ||
|
||
/** | ||
* The <code>CodeTag</code> class. | ||
* | ||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a> | ||
* @created 2015-12-03 | ||
* @since 1.0 | ||
*/ | ||
public class CodeTag extends SimpleTagSupport | ||
{ | ||
@Override | ||
public void doTag() | ||
throws JspException, IOException | ||
{ | ||
final PageContext pageContext = (PageContext) getJspContext(); | ||
final JspWriter out = pageContext.getOut(); | ||
|
||
out.write(String.valueOf(pageContext.getErrorData().getStatusCode())); | ||
} | ||
} |
Oops, something went wrong.