KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > portlet > taglib > URLParameterTag


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.portlet.taglib;
10
11 import javax.servlet.jsp.JspException JavaDoc;
12 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
13
14 /**
15  * The additional parameters definitions for the
16  * actionURL and renderURL tags for the JSR 168 Portlet specification.
17  *
18  * @author <a HREF="mailto:sgwood@ix.netcom.com">Sherman Wood</a>
19  * @version $Revision: 1.1.1.1 $
20  *
21  * @jsp.tag name="param"
22  * body-content="empty"
23  */

24 public class URLParameterTag extends TagSupport JavaDoc
25 {
26    private String JavaDoc name;
27    private String JavaDoc value;
28
29    /**
30     * The name of the parameter to add to the URL.
31     *
32     * If null or empty, no action is performed.
33     *
34     * @return Returns the name.
35     *
36     * @jsp.attribute
37     * required="true"
38     * rtexprvalue="true"
39     */

40    public String JavaDoc getName()
41    {
42       return name;
43    }
44
45    /**
46     * @param name The name to set.
47     */

48    public void setName(String JavaDoc name)
49    {
50       this.name = name;
51    }
52
53    /**
54     * The value of the parameter to add to the URL.
55     *
56     * If null, it is processed as an empty value.
57     *
58     * @return Returns the value.
59     *
60     * @jsp.attribute
61     * required="true"
62     * rtexprvalue="true"
63     */

64    public String JavaDoc getValue()
65    {
66       return value;
67    }
68
69    /**
70     * @param value The value to set.
71     */

72    public void setValue(String JavaDoc value)
73    {
74       this.value = value;
75    }
76
77    /**
78     * No body to process
79     *
80     * @see javax.servlet.jsp.tagext.Tag#doStartTag()
81     */

82    public int doStartTag() throws JspException JavaDoc
83    {
84       return SKIP_BODY;
85    }
86
87    /**
88     * Include the parameter in the surround tag parameters
89     *
90     * @see javax.servlet.jsp.tagext.Tag#doEndTag()
91     */

92    public int doEndTag() throws JspException JavaDoc
93    {
94       try
95       {
96          GenerateURLTag ancestorTag =
97                (GenerateURLTag)findAncestorWithClass(this, GenerateURLTag.class);
98
99          Parameter p = new Parameter(getName(), getValue());
100
101          if (p.isValid())
102          {
103             ancestorTag.addParameter(p.getName(), p.getValue());
104          }
105          else
106          {
107             // Should throw a JspException?
108
// Not according to the JSR 168 spec. Ignore it
109
}
110
111       }
112       catch (Exception JavaDoc e)
113       {
114          e.printStackTrace();
115          throw new JspException JavaDoc(e);
116       }
117       return EVAL_PAGE;
118    }
119
120    public class Parameter
121    {
122       private String JavaDoc name;
123       private String JavaDoc value;
124
125       /**
126        * @return Returns the name.
127        */

128       public String JavaDoc getName()
129       {
130          return name;
131       }
132
133       /**
134        * Per JSR 168 spec, if null, return an empty value
135        *
136        * @return Returns the value.
137        */

138       public String JavaDoc getValue()
139       {
140          return value;
141       }
142
143       public Parameter(String JavaDoc name, String JavaDoc value)
144       {
145          this.name = name;
146          this.value = value;
147       }
148
149       public boolean isValid()
150       {
151          return name != null && name.length() > 0;
152       }
153    }
154 }
155
Popular Tags