View Javadoc

1   /*
2    * Copyright 2003-2005 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  /* 
17  
18   */
19  
20  package org.apache.pluto.tags;
21  
22  import java.io.IOException;
23  
24  import javax.portlet.PortletURL;
25  import javax.servlet.jsp.JspException;
26  import javax.servlet.jsp.JspWriter;
27  import javax.servlet.jsp.PageContext;
28  import javax.servlet.jsp.tagext.TagData;
29  import javax.servlet.jsp.tagext.TagExtraInfo;
30  import javax.servlet.jsp.tagext.TagSupport;
31  import javax.servlet.jsp.tagext.VariableInfo;
32  
33  /***
34   * Supporting class for the <CODE>actionURL</CODE> and <CODE>renderURL</CODE> tag.
35   * Creates a url that points to the current Portlet and triggers an action request
36   * with the supplied parameters.
37   *
38   */
39  public abstract class BasicURLTag extends TagSupport
40  {
41  
42      public static class TEI extends TagExtraInfo
43      {
44          public VariableInfo[] getVariableInfo(TagData tagData)
45          {
46              VariableInfo vi[] = null;
47              String var = tagData.getAttributeString("var");
48              if (var != null)
49              {
50                  vi = new VariableInfo[1];
51                  vi[0] = new VariableInfo(var, "java.lang.String", true, VariableInfo.AT_END);
52              }
53              return vi;
54          }
55      }
56  
57      protected String portletMode;
58      protected String secure;
59      protected Boolean secureBoolean;
60      protected String windowState;
61      protected PortletURL url;
62      protected String var;
63  
64      /***
65       * Processes the <CODE>actionURL</CODE> or <CODE>renderURL</CODE> tag.
66       * @return int
67       */
68      public abstract int doStartTag() throws JspException;
69  
70      /***
71       *
72       * @return int
73       */
74      public int doEndTag() throws JspException {
75          if (var == null)
76          {
77              try
78              {
79                  JspWriter writer = pageContext.getOut();
80                  writer.print(url); 
81                  writer.flush();
82              }
83              catch (IOException ioe)
84              {
85                  throw new JspException("actionURL/renderURL Tag Exception: cannot write to the output writer.");
86              }
87          } else {
88                  pageContext.setAttribute (var, url.toString(), PageContext.PAGE_SCOPE);
89          }
90          return EVAL_PAGE;
91      }
92  
93      /***
94       * Returns the portletMode.
95       * @return String
96       */
97      public String getPortletMode()
98      {
99          return portletMode;
100     }
101 
102     /***
103      * @return secure as String
104      */
105     public String getSecure()
106     {
107         return secure;
108     }
109 
110     /***
111      * @return secure as Boolean
112      */
113     public boolean getSecureBoolean()
114     {
115         return this.secureBoolean.booleanValue();
116     }
117 
118     /***
119      * Returns the windowState.
120      * @return String
121      */
122     public String getWindowState()
123     {
124         return windowState;
125     }
126 
127     /***
128      * @return PortletURL
129      */
130     public PortletURL getUrl()
131     {
132         return url;
133     }
134 
135     /***
136      * Returns the var.
137      * @return String
138      */
139     public String getVar()
140     {
141         return var;
142     }
143 
144     /***
145      * Sets the portletMode.
146      * @param portletMode The portletMode to set
147      */
148     public void setPortletMode(String portletMode)
149     {
150         this.portletMode = portletMode;
151     }
152 
153     /***
154      * Sets secure to boolean value of the string
155      * @param secure
156      */
157     public void setSecure(String secure)
158     {
159         this.secure = secure;
160         this.secureBoolean = new Boolean(secure);
161     }
162 
163     /***
164      * Sets the windowState.
165      * @param windowState The windowState to set
166      */
167     public void setWindowState(String windowState)
168     {
169         this.windowState = windowState;
170     }
171 
172     /***
173      * Sets the url.
174      * @param url The url to set
175      */
176     public void setUrl(PortletURL url)
177     {
178         this.url = url;
179     }
180 
181     /***
182      * Sets the var.
183      * @param var The var to set
184      */
185     public void setVar(String var)
186     {
187         this.var = var;
188     }
189 }