KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > taglib > nested > NestedPropertyTag


1 /*
2  * $Id: NestedPropertyTag.java 54929 2004-10-16 16:38:42Z germuska $
3  *
4  * Copyright 1999-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.struts.taglib.nested;
19
20 import javax.servlet.http.HttpServletRequest JavaDoc;
21 import javax.servlet.jsp.JspException JavaDoc;
22 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
23
24 import org.apache.struts.taglib.TagUtils;
25
26 /**
27  * NestedPropertyTag.
28  *
29  * The one of only two additions in this nested suite of tags. This is so that
30  * you can specify extra levels of nesting in one elegant tag rather than having
31  * to propagate and manage an extra dot notated property in nested child tags.
32  *
33  * It's simply recognised by the helper class and it's property is added to the
34  * nesting list.
35  *
36  * @since Struts 1.1
37  * @version $Rev: 54929 $ $Date: 2004-10-16 17:38:42 +0100 (Sat, 16 Oct 2004) $
38  */

39 public class NestedPropertyTag extends BodyTagSupport JavaDoc implements NestedNameSupport {
40
41   public String JavaDoc getName() { return null; }
42   public void setName(String JavaDoc newNamed) {}
43
44   /** Getter method for the <i>property</i> property
45    * @return String value of the property property
46    */

47   public String JavaDoc getProperty() {
48     return this.property;
49   }
50
51   /** Setter method for the <i>property</i> property
52    * Also, only setting the original property value to those values not
53    * set by the nested logic.
54    * @param newProperty new value for the property property
55    */

56   public void setProperty(String JavaDoc newProperty) {
57     property = newProperty;
58   }
59
60   /**
61    * Overriding method of the heart of the tag. Gets the relative property
62    * and tells the JSP engine to evaluate its body content.
63    *
64    * @return int JSP continuation directive.
65    */

66   public int doStartTag() throws JspException JavaDoc {
67     originalProperty = property;
68
69     HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc)pageContext.getRequest();
70     originalNest = NestedPropertyHelper.getCurrentProperty(request);
71     originalName = NestedPropertyHelper.getCurrentName(request, this);
72
73     String JavaDoc nested = NestedPropertyHelper.getAdjustedProperty(request, originalProperty);
74     NestedPropertyHelper.setProperty(request, nested);
75     NestedPropertyHelper.setName(request, originalName);
76
77     // run the body part
78
return (EVAL_BODY_TAG);
79   }
80
81
82   /**
83    * Render the resulting content evaluation.
84    *
85    * @return int JSP continuation directive.
86    */

87   public int doAfterBody() throws JspException JavaDoc {
88
89     /* Render the output */
90     if (bodyContent != null) {
91       TagUtils.getInstance().writePrevious(pageContext, bodyContent.getString());
92       bodyContent.clearBody();
93     }
94
95     return (SKIP_BODY);
96   }
97
98
99   /**
100    * Evaluate the rest of the page
101    *
102    * @return int JSP continuation directive.
103    */

104   public int doEndTag() throws JspException JavaDoc {
105     /* set the reference back */
106     HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc)pageContext.getRequest();
107     if (originalNest == null && originalName == null) {
108       NestedPropertyHelper.deleteReference(request);
109     } else {
110       NestedPropertyHelper.setName(request, originalName);
111       NestedPropertyHelper.setProperty(request, originalNest);
112     }
113     property = originalProperty;
114     return (EVAL_PAGE);
115   }
116
117
118   /**
119    * JSP method to release all resources held by the tag.
120    */

121   public void release() {
122     super.release();
123     this.property = null;
124     this.originalNest = null;
125     this.originalName = null;
126     this.originalProperty = null;
127   }
128
129   /* the usual private member variable */
130   private String JavaDoc property = null;
131   private String JavaDoc originalNest = null;
132   private String JavaDoc originalName = null;
133   private String JavaDoc originalProperty = null;
134 }
135
Popular Tags