ParamTag xref

View Javadoc

    1   /*
    2    * $Id: ParamTag.java 482912 2006-12-06 05:48:32Z pbenedict $
    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.html;
    22
    23  import org.apache.struts.util.MessageResources;
    24
    25  import javax.servlet.jsp.JspException;
    26  import javax.servlet.jsp.tagext.BodyTagSupport;
    27  import javax.servlet.jsp.tagext.Tag;
    28
    29  /**
    30   * Adds a new request parameter to its parent {@link LinkTag}.
    31   *
    32   * @version $Rev: 482912 $ $Date: 2006-12-05 23:48:32 -0600 (Tue, 05 Dec 2006) $
    33   * @since Struts 1.3.6
    34   */
    35  public class ParamTag extends BodyTagSupport {
    36
    37      /**
    38       * The message resources for this package.
    39       */
    40      protected static MessageResources messages =
    41          MessageResources.getMessageResources(Constants.Package
    42              + ".LocalStrings");
    43
    44      /**
    45       * The name of the query parameter.
    46       */
    47      protected String name = null;
    48
    49      /**
    50       * The value of the query parameter or body content of this tag (if any).
    51       */
    52      protected String value = null;
    53
    54      // ----------------------------------------------------- Constructor
    55
    56      public ParamTag() {
    57          super();
    58      }
    59
    60      public String getName() {
    61          return (this.name);
    62      }
    63
    64      public void setName(String name) {
    65          this.name = name;
    66      }
    67
    68      public String getValue() {
    69          return (this.value);
    70      }
    71
    72      public void setValue(String value) {
    73          this.value = value;
    74      }
    75
    76      // --------------------------------------------------------- Public Methods
    77
    78      /**
    79       * @throws JspException if a JSP exception has occurred
    80       */
    81      public int doStartTag() throws JspException {
    82          return (EVAL_BODY_TAG);
    83      }
    84
    85      /**
    86       * Save the associated from the body content.
    87       *
    88       * @throws JspException if a JSP exception has occurred
    89       */
    90      public int doAfterBody() throws JspException {
    91          if (this.bodyContent != null) {
    92              String value = this.bodyContent.getString().trim();
    93              if (value.length() > 0) {
    94                  this.value = value;
    95              }
    96          }
    97          return (SKIP_BODY);
    98      }
    99
    100     /**
    101      * Render the end of the hyperlink.
    102      *
    103      * @throws JspException if a JSP exception has occurred
    104      */
    105     public int doEndTag() throws JspException {
    106         Tag tag = findAncestorWithClass(this, LinkTag.class);
    107         if (tag != null) {
    108             ((LinkTag)tag).addParameter(this.name, this.value);
    109         } else {
    110             throw new JspException(messages.getMessage("linkParamTag.linkParam"));
    111         }
    112         return (EVAL_PAGE);
    113     }
    114
    115     /**
    116      * Release any acquired resources.
    117      */
    118     public void release() {
    119         super.release();
    120         this.name = null;
    121         this.value = null;
    122     }
    123 }