001: /*
002: * $Id: NestedLinkTag.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.html;
022:
023: import org.apache.struts.taglib.html.LinkTag;
024: import org.apache.struts.taglib.nested.NestedNameSupport;
025: import org.apache.struts.taglib.nested.NestedPropertyHelper;
026:
027: import javax.servlet.http.HttpServletRequest;
028: import javax.servlet.jsp.JspException;
029:
030: /**
031: * NestedLinkTag.
032: *
033: * @version $Rev: 471754 $ $Date: 2004-10-16 12:38:42 -0400 (Sat, 16 Oct 2004)
034: * $
035: * @since Struts 1.1
036: */
037: public class NestedLinkTag extends LinkTag implements NestedNameSupport {
038: /* hold original property */
039: private String origName = null;
040: private String origProperty = null;
041: private String origParamProperty = null;
042:
043: /**
044: * Overriding method of the heart of the matter. Gets the relative
045: * property and leaves the rest up to the original tag implementation.
046: * Sweet.
047: *
048: * @return int JSP continuation directive. This is in the hands of the
049: * super class.
050: */
051: public int doStartTag() throws JspException {
052: origName = super .getName();
053: origProperty = super .getProperty();
054: origParamProperty = super .getParamProperty();
055:
056: /* decide the incoming options. Always two there are */
057: boolean doProperty = ((origProperty != null) && (origProperty
058: .length() > 0));
059: boolean doParam = ((origParamProperty != null) && (origParamProperty
060: .length() > 0));
061:
062: // request
063: HttpServletRequest request = (HttpServletRequest) pageContext
064: .getRequest();
065:
066: boolean hasName = ((getName() != null) && (getName().trim()
067: .length() > 0));
068: String currentName;
069:
070: if (hasName) {
071: currentName = getName();
072: } else {
073: currentName = NestedPropertyHelper.getCurrentName(request,
074: this );
075: }
076:
077: // set the bean name
078: super .setName(currentName);
079:
080: // set property details
081: if (doProperty && !hasName) {
082: super .setProperty(NestedPropertyHelper.getAdjustedProperty(
083: request, origProperty));
084: }
085:
086: // do the param property details
087: if (doParam) {
088: super .setName(null);
089: super .setParamName(currentName);
090: super .setParamProperty(NestedPropertyHelper
091: .getAdjustedProperty(request, origParamProperty));
092: }
093:
094: /* do the tag */
095: return super .doStartTag();
096: }
097:
098: /**
099: * Complete the processing of the tag. The nested tags here will restore
100: * all the original value for the tag itself and the nesting context.
101: *
102: * @return int to describe the next step for the JSP processor
103: * @throws JspException for the bad things JSP's do
104: */
105: public int doEndTag() throws JspException {
106: // do the super's ending part
107: int i = super .doEndTag();
108:
109: // reset the properties
110: setName(origName);
111: setProperty(origProperty);
112: setParamProperty(origParamProperty);
113:
114: // continue
115: return i;
116: }
117:
118: /**
119: * Release the tag's resources and reset the values.
120: */
121: public void release() {
122: super .release();
123:
124: // reset the originals
125: origName = null;
126: origProperty = null;
127: origParamProperty = null;
128: }
129: }
|