1 /**
2 * Copyright (c) 2009-2010, Elias Gomes. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
5 * following conditions are met:
6 *
7 * - Redistributions of source code must retain the above copyright notice, this list of conditions and the following
8 * disclaimer.
9 *
10 * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
14 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
16 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
17 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
18 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
19 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
20 */
21 package net.sourceforge.mystique.infrastructure.xhtml;
22
23 import java.io.IOException;
24 import java.io.PrintWriter;
25 import java.io.StringWriter;
26
27 import javax.servlet.jsp.JspException;
28 import javax.servlet.jsp.tagext.SimpleTagSupport;
29
30 /**
31 * @author Elias Gomes [eliasgomes@users.sourceforge.net]
32 */
33 public class ExceptionTag extends SimpleTagSupport {
34
35 private Exception attr;
36
37 private String cssClass;
38
39 private String cssStyle;
40
41 @Override
42 public void doTag() throws JspException, IOException {
43
44 StringWriter exceptionOut = new StringWriter();
45 attr.printStackTrace(new PrintWriter(exceptionOut));
46 exceptionOut.close();
47
48 StringBuilder builder = new StringBuilder();
49 builder.append("<pre");
50 if (cssClass != null) {
51 builder.append(" class=\"").append(cssClass).append("\"");
52 }
53 if (cssStyle != null) {
54 builder.append(" style=\"").append(cssStyle).append("\"");
55 }
56 builder.append(">\n");
57 builder.append(exceptionOut);
58 builder.append("</pre>\n");
59
60 getJspContext().getOut().print(builder.toString());
61
62 }
63
64 public void setAttr(Exception attr) {
65 this.attr = attr;
66 }
67
68 public void setCssClass(String cssClass) {
69 this.cssClass = cssClass;
70 }
71
72 public void setCssStyle(String cssStyle) {
73 this.cssStyle = cssStyle;
74 }
75
76 }