KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > taglib > nested > html > NestedLinkTag


1 /*
2  * $Id: NestedLinkTag.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.html;
19
20 import javax.servlet.http.HttpServletRequest JavaDoc;
21 import javax.servlet.jsp.JspException JavaDoc;
22
23 import org.apache.struts.taglib.html.LinkTag;
24 import org.apache.struts.taglib.nested.NestedNameSupport;
25 import org.apache.struts.taglib.nested.NestedPropertyHelper;
26
27 /**
28  * NestedLinkTag.
29  * @since Struts 1.1
30  * @version $Rev: 54929 $ $Date: 2004-10-16 17:38:42 +0100 (Sat, 16 Oct 2004) $
31  */

32 public class NestedLinkTag extends LinkTag implements NestedNameSupport {
33
34   /**
35    * Overriding method of the heart of the matter. Gets the relative property
36    * and leaves the rest up to the original tag implementation. Sweet.
37    * @return int JSP continuation directive.
38    * This is in the hands of the super class.
39    */

40   public int doStartTag() throws JspException JavaDoc {
41     origName = super.getName();
42     origProperty = super.getProperty();
43     origParamProperty = super.getParamProperty();
44
45     /* decide the incoming options. Always two there are */
46     boolean doProperty = (origProperty != null && origProperty.length() > 0);
47     boolean doParam = (origParamProperty != null && origParamProperty.length() > 0);
48
49     // request
50
HttpServletRequest JavaDoc request = (HttpServletRequest JavaDoc)pageContext.getRequest();
51
52     boolean hasName = (getName() != null && getName().trim().length() > 0);
53     String JavaDoc currentName;
54     if (hasName) {
55       currentName = getName();
56     } else {
57       currentName = NestedPropertyHelper.getCurrentName(request, this);
58     }
59     // set the bean name
60
super.setName(currentName);
61
62     // set property details
63
if (doProperty && !hasName) {
64       super.setProperty(NestedPropertyHelper.getAdjustedProperty(request, origProperty));
65     }
66     // do the param property details
67
if (doParam) {
68       super.setName(null);
69       super.setParamName(currentName);
70       super.setParamProperty(NestedPropertyHelper.getAdjustedProperty(request, origParamProperty));
71     }
72     
73     /* do the tag */
74     return super.doStartTag();
75   }
76
77   /**
78    * Complete the processing of the tag. The nested tags here will restore
79    * all the original value for the tag itself and the nesting context.
80    * @return int to describe the next step for the JSP processor
81    * @throws JspException for the bad things JSP's do
82    */

83   public int doEndTag() throws JspException JavaDoc {
84     // do the super's ending part
85
int i = super.doEndTag();
86
87     // reset the properties
88
setName(origName);
89     setProperty(origProperty);
90     setParamProperty(origParamProperty);
91
92     // continue
93
return i;
94   }
95
96   /**
97    * Release the tag's resources and reset the values.
98    */

99   public void release() {
100     super.release();
101     // reset the originals
102
origName = null;
103     origProperty = null;
104     origParamProperty = null;
105   }
106
107
108   /* hold original property */
109   private String JavaDoc origName = null;
110   private String JavaDoc origProperty = null;
111   private String JavaDoc origParamProperty = null;
112 }
113
Popular Tags