NestedOptionsTag xref

View Javadoc

    1   /*
    2    * $Id: NestedOptionsTag.java 471754 2006-11-06 14:55:09Z husted $
    3    *
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
    10   * with the License.  You may obtain a copy of the License at
    11   *
    12   *  http://www.apache.org/licenses/LICENSE-2.0
    13   *
    14   * Unless required by applicable law or agreed to in writing,
    15   * software distributed under the License is distributed on an
    16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    17   * KIND, either express or implied.  See the License for the
    18   * specific language governing permissions and limitations
    19   * under the License.
    20   */
    21  package org.apache.struts.taglib.nested.html;
    22
    23  import org.apache.struts.taglib.html.Constants;
    24  import org.apache.struts.taglib.html.OptionsTag;
    25  import org.apache.struts.taglib.nested.NestedNameSupport;
    26  import org.apache.struts.taglib.nested.NestedPropertyHelper;
    27
    28  import javax.servlet.http.HttpServletRequest;
    29  import javax.servlet.jsp.JspException;
    30
    31  /**
    32   * NestedOptionsTag.
    33   *
    34   * @version $Rev: 471754 $ $Date: 2004-10-16 12:38:42 -0400 (Sat, 16 Oct 2004)
    35   *          $
    36   * @since Struts 1.1
    37   */
    38  public class NestedOptionsTag extends OptionsTag implements NestedNameSupport {
    39      /* the usual private member variables */
    40      private String originalName = null;
    41      private String originalProperty = null;
    42      private String originalLabelProperty = null;
    43
    44      /**
    45       * Overriding method of the heart of the matter. Gets the relative
    46       * property and leaves the rest up to the original tag implementation.
    47       * Sweet.
    48       *
    49       * @return int JSP continuation directive. This is in the hands of the
    50       *         super class.
    51       */
    52      public int doStartTag() throws JspException {
    53          // get the original properties
    54          originalName = getName();
    55          originalProperty = getProperty();
    56          originalLabelProperty = getLabelProperty();
    57
    58          // request
    59          HttpServletRequest request =
    60              (HttpServletRequest) pageContext.getRequest();
    61
    62          // if we have a label property
    63          if (originalLabelProperty != null) {
    64              // do the label property first
    65              if ((getName() == null) || Constants.BEAN_KEY.equals(getName())) {
    66                  super.setLabelProperty(NestedPropertyHelper.getAdjustedProperty(
    67                          request, originalLabelProperty));
    68              } else {
    69                  super.setLabelProperty(originalLabelProperty);
    70              }
    71          }
    72
    73          // set the other properties
    74          NestedPropertyHelper.setNestedProperties(request, this);
    75
    76          // let the super do it's thing
    77          return super.doStartTag();
    78      }
    79
    80      /**
    81       * Complete the processing of the tag. The nested tags here will restore
    82       * all the original value for the tag itself and the nesting context.
    83       *
    84       * @return int to describe the next step for the JSP processor
    85       * @throws JspException for the bad things JSP's do
    86       */
    87      public int doEndTag() throws JspException {
    88          // do the super's ending part
    89          int i = super.doEndTag();
    90
    91          // reset the properties
    92          setName(originalName);
    93          setProperty(originalProperty);
    94          setLabelProperty(originalLabelProperty);
    95
    96          // continue
    97          return i;
    98      }
    99
    100     /**
    101      * Release the tag's resources and reset the values.
    102      */
    103     public void release() {
    104         super.release();
    105
    106         // reset the originals
    107         originalName = null;
    108         originalProperty = null;
    109         originalLabelProperty = null;
    110     }
    111 }