KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > roller > ui > core > tags > LinkParamTag


1 /*
2  * $Header: /cvs/roller/roller/src/org/roller/presentation/tags/LinkParamTag.java,v 1.2 2004/08/18 03:19:34 lavandowska Exp $
3  * $Revision: 1.2 $
4  * $Date: 2004/08/18 03:19:34 $
5  *
6  * ====================================================================
7  */

8
9
10 package org.apache.roller.ui.core.tags;
11
12 import org.apache.log4j.Category;
13 import org.apache.struts.util.RequestUtils;
14
15 import javax.servlet.jsp.JspException JavaDoc;
16 import javax.servlet.jsp.tagext.BodyContent JavaDoc;
17 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
18
19 /**
20  * Implements a custom tag to add parameter to a href request.<br/>
21  * This tag is intended to be nested in a <code>hm:link</code> tag.
22  *
23  * Title: BSquare
24  * Description: Bsquare Projects
25  * Copyright: Copyright (c) 2001
26  * Company: HubMethods
27  * @author Eric Fesler
28  * @version 1.0
29  */

30
31 public class LinkParamTag extends BodyTagSupport JavaDoc {
32     // ----------------------------------------------------- Logging
33
static Category cat = Category.getInstance(LinkParamTag.class);
34
35     // ----------------------------------------------------- Instance variables
36
/**
37      * The name of the request parameter
38      */

39     private String JavaDoc id = null;
40
41     /**
42      * The value of the request parameter
43      */

44     private String JavaDoc value = null;
45
46     /**
47      * The source bean
48      */

49     private String JavaDoc name = null;
50
51     /**
52      * The source bean property
53      */

54     private String JavaDoc property = null;
55
56     /**
57      * The scope of the source bean
58      */

59     private String JavaDoc scope = null;
60
61
62     // ----------------------------------------------------- Properties
63

64     /**
65      * Sets the request parameter tag name
66      *
67      * @param name the request parameter tag name
68      */

69     public void setId(String JavaDoc id) {
70         this.id = id;
71     }
72
73     /**
74      * Returns the request parameter name
75      *
76      * @return the request parameter name
77      */

78     public String JavaDoc getId() {
79         return id;
80     }
81
82     /**
83      * Sets the request parameter value
84      *
85      * @param value the request parameter value
86      */

87     public void setValue(String JavaDoc value) {
88         this.value = value;
89     }
90
91     /**
92      * Returns the request parameter value
93      *
94      * @return the request parameter value
95      */

96     public String JavaDoc getValue() {
97         return value;
98     }
99
100     /**
101      * Sets the source bean name
102      * @param sourceBean the source bean name
103      */

104     public void setName ( String JavaDoc sourceBean) {
105         this.name = sourceBean;
106     }
107
108     /**
109      * Returns the source bean name
110      * @return the source bean name
111      */

112     public String JavaDoc getName () {
113         return this.name;
114     }
115
116     /**
117      * Sets the source bean property
118      * @param sourceProperty the source property
119      */

120     public void setProperty(String JavaDoc sourceProperty) {
121         this.property = sourceProperty;
122     }
123
124     /**
125      * Returns the source bean property
126      * @return the source property
127      */

128     public String JavaDoc getProperty() {
129         return property;
130     }
131
132     /**
133      * Set the source bean scope.
134      * @param sourceScope the source bean scope
135      */

136     public void setScope(String JavaDoc sourceScope) {
137         this.scope = sourceScope;
138     }
139
140     /**
141      * Returns the source bean scope
142      * @return the source bean scope
143      */

144     public String JavaDoc getScope() {
145         return this.scope;
146     }
147
148
149     // ------------------------------------------------------ Public Methods
150
/**
151      * Add the parameter and its value to the link tag
152      */

153     public int doEndTag() throws JspException JavaDoc {
154         // parent tag must be a LinkTag, gives access to methods in parent
155
LinkTag myparent = (LinkTag)javax.servlet.jsp.tagext.TagSupport.findAncestorWithClass(this, LinkTag.class);
156
157     if (myparent == null)
158         throw new JspException JavaDoc("linkparam tag not nested within link tag");
159         else {
160             BodyContent JavaDoc bodyContent = getBodyContent();
161             if (bodyContent != null && !bodyContent.getString().equals("")) {
162                 setValue(bodyContent.getString());
163             }
164             else if (getValue() == null) setValue("null");
165 // throw new JspException("Unable to assign a value to the parameter: '" + getId() + "'");
166
myparent.addRequestParameter(getId(), getValue());
167     }
168     return SKIP_BODY;
169     }
170
171     /**
172      * Process the start tag
173      */

174     public int doStartTag() throws javax.servlet.jsp.JspException JavaDoc {
175
176         // Look up the requested property value
177
if (name != null) {
178             Object JavaDoc beanValue =
179                 RequestUtils.lookup(pageContext, name, property, scope);
180             if (cat.isDebugEnabled()) cat.debug("Value is : '" + beanValue + "'");
181             if (beanValue == null)
182                 return (EVAL_BODY_TAG);
183
184         // set the property as value
185
setValue(beanValue.toString());
186         }
187
188     // Continue processing this page
189
return (EVAL_BODY_TAG);
190
191     }
192 }
193
Popular Tags