KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > killingar > webwork > view > taglib > FocusTag


1 /* Copyright 2000-2005 Anders Hovmöller
2  *
3  * The person or persons who have associated their work with
4  * this document (the "Dedicator") hereby dedicate the entire
5  * copyright in the work of authorship identified below (the
6  * "Work") to the public domain.
7  *
8  * Dedicator makes this dedication for the benefit of the
9  * public at large and to the detriment of Dedicator's heirs
10  * and successors. Dedicator intends this dedication to be an
11  * overt act of relinquishment in perpetuity of all present
12  * and future rights under copyright law, whether vested or
13  * contingent, in the Work. Dedicator understands that such
14  * relinquishment of all rights includes the relinquishment of
15  * all rights to enforce (by lawsuit or otherwise) those
16  * copyrights in the Work.
17  *
18  * Dedicator recognizes that, once placed in the public
19  * domain, the Work may be freely reproduced, distributed,
20  * transmitted, used, modified, built upon, or otherwise
21  * exploited by anyone for any purpose, commercial or non-
22  * commercial, and in any way, including by methods that have
23  * not yet been invented or conceived.
24  */

25
26 /**
27  * Push a value from the ValueStack on top of the ValueStack, pop at end tag.
28  */

29 package net.killingar.webwork.view.taglib;
30
31 import webwork.util.TextUtil;
32
33 import javax.servlet.jsp.JspException JavaDoc;
34 import javax.servlet.jsp.JspTagException JavaDoc;
35
36 public class FocusTag extends webwork.view.taglib.WebWorkBodyTagSupport
37 {
38    // Attributes ----------------------------------------------------
39
protected String JavaDoc valueAttr;
40    protected Boolean JavaDoc escape = new Boolean JavaDoc(false);
41
42    // Public --------------------------------------------------------
43
public void setValue(String JavaDoc inName)
44    {
45       valueAttr = inName;
46    }
47
48    public void setEscape(boolean inEscape)
49    {
50       escape = new Boolean JavaDoc(inEscape);
51    }
52
53    // BodyTag implementation ----------------------------------------
54
public int doStartTag() throws JspException JavaDoc
55    {
56       Object JavaDoc value = findValue(valueAttr);
57       getStack().pushValue(value);
58
59       return EVAL_BODY_TAG;
60    }
61
62    public int doAfterBody() throws JspException JavaDoc
63    {
64       return SKIP_BODY;
65    }
66
67    public int doEndTag() throws JspException JavaDoc
68    {
69       Object JavaDoc value = getStack().popValue();
70
71             String JavaDoc body = null;
72             try
73             {
74                  body = getBodyContent().getString();
75             }
76             catch (Exception JavaDoc e)
77             {
78                  body = new String JavaDoc("");
79             }
80
81             try
82             {
83                 if (escape.booleanValue())
84                      body = TextUtil.escapeHTML(body);
85
86                 bodyContent.getEnclosingWriter().write(body);
87             }
88             catch (java.io.IOException JavaDoc e)
89             {
90                     throw new JspTagException JavaDoc("Could not show attribute " + valueAttr + ":" + e);
91             }
92
93             // Bruce Ritchie
94
// don't reset escape since some container implementations won't handle correctly
95
// since escape property might not get set if it's the same value as the previous
96
// call to the tag
97
// see the jsp spec (1.2) section 10.1
98
//
99
//Once properly set, all properties are expected to be persistent, so that if the
100
//JSP container ascertains that a property has already been set on a given tag
101
//handler instance, it needs not set it again. User code can access property
102
//information and access and modify tag handler internal state starting with the first
103
//action method (doStartTag) up until the last action method (doEndTag or
104
//doFinally for tag handlers implementing TryCatchFinally).
105
//escape=null;
106

107       return EVAL_PAGE;
108    }
109 }
Popular Tags