001: /*
002: * $Id: NestedPropertyTag.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: * NestedPropertyTag.
031: *
032: * The one of only two additions in this nested suite of tags. This is so that
033: * you can specify extra levels of nesting in one elegant tag rather than
034: * having to propagate and manage an extra dot notated property in nested
035: * child tags.
036: *
037: * It's simply recognised by the helper class and it's property is added to
038: * the nesting list.
039: *
040: * @version $Rev: 471754 $ $Date: 2004-10-16 12:38:42 -0400 (Sat, 16 Oct 2004)
041: * $
042: * @since Struts 1.1
043: */
044: public class NestedPropertyTag extends BodyTagSupport implements
045: NestedNameSupport {
046: /* the usual private member variable */
047: private String property = null;
048: private String originalNest = null;
049: private String originalName = null;
050: private String originalProperty = null;
051:
052: public String getName() {
053: return null;
054: }
055:
056: public void setName(String newNamed) {
057: }
058:
059: /**
060: * Getter method for the <i>property</i> property
061: *
062: * @return String value of the property property
063: */
064: public String getProperty() {
065: return this .property;
066: }
067:
068: /**
069: * Setter method for the <i>property</i> property Also, only setting the
070: * original property value to those values not set by the nested logic.
071: *
072: * @param newProperty new value for the property property
073: */
074: public void setProperty(String newProperty) {
075: property = newProperty;
076: }
077:
078: /**
079: * Overriding method of the heart of the tag. Gets the relative property
080: * and tells the JSP engine to evaluate its body content.
081: *
082: * @return int JSP continuation directive.
083: */
084: public int doStartTag() throws JspException {
085: originalProperty = property;
086:
087: HttpServletRequest request = (HttpServletRequest) pageContext
088: .getRequest();
089:
090: originalNest = NestedPropertyHelper.getCurrentProperty(request);
091: originalName = NestedPropertyHelper.getCurrentName(request,
092: this );
093:
094: String nested = NestedPropertyHelper.getAdjustedProperty(
095: request, originalProperty);
096:
097: NestedPropertyHelper.setProperty(request, nested);
098: NestedPropertyHelper.setName(request, originalName);
099:
100: // run the body part
101: return (EVAL_BODY_TAG);
102: }
103:
104: /**
105: * Render the resulting content evaluation.
106: *
107: * @return int JSP continuation directive.
108: */
109: public int doAfterBody() throws JspException {
110: /* Render the output */
111: if (bodyContent != null) {
112: TagUtils.getInstance().writePrevious(pageContext,
113: bodyContent.getString());
114: bodyContent.clearBody();
115: }
116:
117: return (SKIP_BODY);
118: }
119:
120: /**
121: * Evaluate the rest of the page
122: *
123: * @return int JSP continuation directive.
124: */
125: public int doEndTag() throws JspException {
126: /* set the reference back */
127: HttpServletRequest request = (HttpServletRequest) pageContext
128: .getRequest();
129:
130: if ((originalNest == null) && (originalName == null)) {
131: NestedPropertyHelper.deleteReference(request);
132: } else {
133: NestedPropertyHelper.setName(request, originalName);
134: NestedPropertyHelper.setProperty(request, originalNest);
135: }
136:
137: property = originalProperty;
138:
139: return (EVAL_PAGE);
140: }
141:
142: /**
143: * JSP method to release all resources held by the tag.
144: */
145: public void release() {
146: super.release();
147: this.property = null;
148: this.originalNest = null;
149: this.originalName = null;
150: this.originalProperty = null;
151: }
152: }
|