KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > taglibs > io > URLParameterTag


1 /*
2  * Copyright 1999,2004 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 package org.apache.taglibs.io;
18
19 import javax.servlet.ServletContext JavaDoc;
20 import javax.servlet.jsp.JspException JavaDoc;
21 import javax.servlet.jsp.tagext.BodyContent JavaDoc;
22
23 /** Adds a query paramter to the current HTTP request URL
24   *
25   * @author <a HREF="mailto:james.strachan@metastuff.com">James Strachan</a>
26   * @version $Revision: 1.2 $
27   */

28 public class URLParameterTag extends AbstractBodyTag {
29
30     /** Stores the name of the request */
31     private String JavaDoc name;
32     
33     /** Stores the value of the request */
34     private String JavaDoc value;
35     
36     
37     // BodyTag interface
38
//-------------------------------------------------------------------------
39
public int doStartTag() throws JspException JavaDoc {
40         if ( value != null ) {
41             fireParameter();
42             return SKIP_BODY;
43         }
44         return EVAL_BODY_TAG;
45     }
46     
47     public int doAfterBody() throws JspException JavaDoc {
48         BodyContent JavaDoc body = getBodyContent();
49         value = body.getString();
50         body.clearBody();
51         fireParameter();
52         return EVAL_PAGE;
53     }
54     
55     public void release() {
56         name = null;
57         value = null;
58     }
59     
60     // Properties
61
//-------------------------------------------------------------------------
62
/** Sets the name of the HTTP header
63       */

64     public void setName(String JavaDoc name) {
65         this.name = name;
66     }
67     
68     /** Sets the value of the HTTP header.
69       * If no value is set then the body of the tag is used
70       */

71     public void setValue(String JavaDoc value) {
72         this.value = value;
73     }
74     
75     // Implementation methods
76
//-------------------------------------------------------------------------
77
protected void fireParameter() throws JspException JavaDoc {
78         URLTag tag = (URLTag) findAncestorWithClass( this, URLTag.class );
79         if ( tag == null ) {
80             throw new JspException JavaDoc("<io:param> tag must be within a <io:url> tag");
81         }
82         tag.addParameter( name, value );
83     }
84     
85 }
86
Popular Tags