KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ofbiz > webapp > taglib > PrintTag


1 /*
2  * $Id: PrintTag.java 5462 2005-08-05 18:35:48Z jonesde $
3  *
4  * Copyright (c) 2001-2003 The Open For Business Project - www.ofbiz.org
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  *
24  */

25 package org.ofbiz.webapp.taglib;
26
27 import java.io.IOException JavaDoc;
28 import javax.servlet.jsp.JspException JavaDoc;
29 import javax.servlet.jsp.JspWriter JavaDoc;
30 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
31
32 import org.ofbiz.base.util.Debug;
33 import org.ofbiz.base.util.UtilJ2eeCompat;
34
35 /**
36  * <p><b>Title:</b> PrintTag - Prints an attribute from the PageContext.
37  *
38  * @author <a HREF="mailto:jonesde@ofbiz.org">David E. Jones</a>
39  * @version $Rev: 5462 $
40  * @since 2.0
41  */

42 public class PrintTag extends TagSupport JavaDoc {
43     
44     public static final String JavaDoc module = PrintTag.class.getName();
45
46     private String JavaDoc attribute = null;
47     private String JavaDoc defaultStr = "";
48
49     public String JavaDoc getAttribute() {
50         return attribute;
51     }
52
53     public void setAttribute(String JavaDoc attribute) {
54         this.attribute = attribute;
55     }
56
57     public String JavaDoc getDefault() {
58         return defaultStr;
59     }
60
61     public void setDefault(String JavaDoc defaultStr) {
62         this.defaultStr = defaultStr;
63     }
64
65     public int doStartTag() throws JspException JavaDoc {
66         if (attribute == null)
67             return SKIP_BODY;
68         Object JavaDoc obj = pageContext.findAttribute(attribute);
69
70         if (obj == null)
71             obj = defaultStr;
72
73         try {
74             JspWriter JavaDoc out = pageContext.getOut();
75
76             out.print(obj.toString());
77         } catch (IOException JavaDoc e) {
78             if (UtilJ2eeCompat.useNestedJspException(pageContext.getServletContext())) {
79                 throw new JspException JavaDoc(e.getMessage(), e);
80             } else {
81                 Debug.logError(e, "Server does not support nested exceptions, here is the exception", module);
82                 throw new JspException JavaDoc(e.toString());
83             }
84         }
85
86         return SKIP_BODY;
87     }
88 }
89
90
Popular Tags