View Javadoc

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