KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: NestedWriteNestingTag.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  * NestedWriteNestingTag.
28  *
29  * Created so developers could have a more elegant way of getting to the
30  * underlying nested property their tag properties are referencing.
31  *
32  * @since Struts 1.1
33  * @version $Rev: 54929 $
34  */

35 public class NestedWriteNestingTag extends BodyTagSupport JavaDoc {
36
37   /** Getter method for the <i>property</i> property
38    * @return String value of the property property
39    */

40   public String JavaDoc getProperty() {
41     return this.property;
42   }
43
44   /** Setter method for the <i>property</i> property
45    * @param newProperty new value for the property property
46    */

47   public void setProperty(String JavaDoc newProperty) {
48     this.property = newProperty;
49   }
50
51
52   /** Getter method for the <i>id</i> property
53    * @return String value for the id property
54    */

55   public String JavaDoc getId() {
56         return id;
57   }
58
59   /** Setter method for the <i>id</i> property
60    * @param id new value for the id property
61    */

62   public void setId(String JavaDoc id) {
63     this.id = id;
64   }
65
66
67   /** Getter method for the <i>filter</i> property
68    * @return String value of the filter property
69    */

70   public boolean getFilter() {
71     return this.filter;
72   }
73
74   /** Setter method for the <i>filter</i> property
75    * @param newFilter new value for the filter property
76    */

77   public void setFilter(boolean newFilter) {
78     this.filter = newFilter;
79   }
80
81
82   /**
83    * Overriding method of the heart of the tag. Gets the relative property
84    * and tells the JSP engine to evaluate its body content.
85    *
86    * @return int JSP continuation directive.
87    */

88   public int doStartTag() throws JspException JavaDoc {
89     // set the original property
90
originalProperty = property;
91
92     HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc)pageContext.getRequest();
93     String JavaDoc nesting = NestedPropertyHelper.getAdjustedProperty(request, property);
94
95     if (id != null) {
96       // use it as a scripting variable instead
97
pageContext.setAttribute(id, nesting);
98
99     } else {
100       /* write output, filtering if required */
101       if (this.filter) {
102         TagUtils.getInstance().write(pageContext, TagUtils.getInstance().filter(nesting));
103       } else {
104         TagUtils.getInstance().write(pageContext, nesting);
105       }
106     }
107
108     /* continue with page processing */
109     return (SKIP_BODY);
110   }
111
112   public int doEndTag() throws JspException JavaDoc {
113     // do the super thing
114
int i = super.doEndTag();
115     // reset the property
116
property = originalProperty;
117     // complete
118
return i;
119   }
120
121
122   /**
123    * JSP method to release all resources held by the tag.
124    */

125   public void release() {
126     super.release();
127     this.filter = false;
128     this.property = null;
129     this.originalProperty = null;
130   }
131
132   /* the usual private member variables */
133   private boolean filter = false;
134   private String JavaDoc property = null;
135   private String JavaDoc id = null;
136   private String JavaDoc originalProperty = null;
137 }
138
Popular Tags