001: /*
002: * $Id: NestedRootTag.java 471754 2006-11-06 14:55:09Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts.taglib.nested;
022:
023: import org.apache.struts.taglib.TagUtils;
024:
025: import javax.servlet.http.HttpServletRequest;
026: import javax.servlet.jsp.JspException;
027: import javax.servlet.jsp.tagext.BodyTagSupport;
028:
029: /**
030: * NestedRootTag.
031: *
032: * The only other addition in this nested suite of tags. This tag allows for a
033: * nested structure to start without relying on the bean and workings of the
034: * FormTag. Useful for view pages that don't update when returning to the
035: * server, or use hyperlinks rather than form submits.
036: *
037: * The Bean that it uses can come out of a jsp:useBean tag or define another
038: * bean that's already in scope. As long as the other Struts tags can find the
039: * bean by name, it'll work.
040: *
041: * It's simply recognised by the helper class and it's property is added to
042: * the nesting list.
043: *
044: * @version $Rev: 471754 $ $Date: 2004-10-16 12:38:42 -0400 (Sat, 16 Oct 2004)
045: * $
046: * @since Struts 1.1
047: */
048: public class NestedRootTag extends BodyTagSupport implements
049: NestedNameSupport {
050: /* usual member variables */
051: private String name = null;
052: private String originalName = "";
053: private String originalNesting = "";
054: private String originalNestingName = "";
055:
056: /**
057: * Getter method for the <i>property</i> property
058: *
059: * @return String value of the property property
060: */
061: public String getProperty() {
062: return "";
063: }
064:
065: /**
066: * Setter method for the <i>property</i> property
067: *
068: * @param property new value for the property property
069: */
070: public void setProperty(String property) {
071: }
072:
073: /**
074: * Getter method for the <i>name</i> property
075: *
076: * @return String value of the name property
077: */
078: public String getName() {
079: return this .name;
080: }
081:
082: /**
083: * Setter method for the <i>name</i> property
084: *
085: * @param name new value for the name property
086: */
087: public void setName(String name) {
088: this .name = name;
089: }
090:
091: /**
092: * Overriding method of the heart of the tag. Gets the relative property
093: * and tells the JSP engine to evaluate its body content.
094: *
095: * @return int JSP continuation directive.
096: */
097: public int doStartTag() throws JspException {
098: /* set the nested reference for possible inclusions etc */
099: HttpServletRequest request = (HttpServletRequest) pageContext
100: .getRequest();
101:
102: // get al the originals
103: originalName = name;
104: originalNesting = NestedPropertyHelper
105: .getCurrentProperty(request);
106: originalNestingName = NestedPropertyHelper.getCurrentName(
107: request, this );
108:
109: // set what we have to
110: if (name != null) {
111: NestedPropertyHelper.setProperty(request, "");
112: NestedPropertyHelper.setName(request, this .name);
113: }
114:
115: // do the JSP thing
116: return (EVAL_BODY_TAG);
117: }
118:
119: /**
120: * Render the resulting content evaluation.
121: *
122: * @return int JSP continuation directive.
123: */
124: public int doAfterBody() throws JspException {
125: /* Render the output */
126: if (bodyContent != null) {
127: TagUtils.getInstance().writePrevious(pageContext,
128: bodyContent.getString());
129: bodyContent.clearBody();
130: }
131:
132: return (SKIP_BODY);
133: }
134:
135: /**
136: * Evaluate the rest of the page
137: *
138: * @return int JSP continuation directive.
139: */
140: public int doEndTag() throws JspException {
141: /* reset the reference */
142: HttpServletRequest request = (HttpServletRequest) pageContext
143: .getRequest();
144:
145: if (originalNesting == null) {
146: NestedPropertyHelper.deleteReference(request);
147: } else {
148: NestedPropertyHelper.setName(request, originalNestingName);
149: NestedPropertyHelper.setProperty(request, originalNesting);
150: }
151:
152: this .name = originalName;
153:
154: return (EVAL_PAGE);
155: }
156:
157: /**
158: * JSP method to release all resources held by the tag.
159: */
160: public void release() {
161: super.release();
162: this.name = null;
163: this.originalName = null;
164: this.originalNesting = null;
165: this.originalNestingName = null;
166: }
167: }
|