View Javadoc

1   /*
2    * $Id: AttributeToScopeTag.java 421151 2006-07-12 06:07:14Z wsmoak $
3    *
4    * Copyright 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  
19  package org.apache.struts.tiles.taglib;
20  
21  import javax.servlet.jsp.JspException;
22  import javax.servlet.jsp.PageContext;
23  import javax.servlet.jsp.tagext.TagSupport;
24  
25  import org.apache.struts.tiles.taglib.util.TagUtils;
26  import org.apache.struts.tiles.ComponentContext;
27  
28  
29  /***
30    *  Custom  tag  that  puts  component's  attributes  in  a  scope  (request,  page,  ...).
31    *  @deprecated  Is  it  still  in  use  ?
32    */
33  public  final  class  AttributeToScopeTag  extends  TagSupport  {
34  
35  
36          //  ----------------------------------------------------- Instance Variables
37  
38  
39      /***
40       * The scope name.
41       */
42      private String scopeName = null;
43  
44      /***
45       * The scope value.
46       */
47      private int scope = PageContext.PAGE_SCOPE;
48  
49  
50  
51      /***
52       * The property name to be exposed.
53       */
54      private String property = null;
55  
56  
57      // ------------------------------------------------------------- Properties
58  
59  
60  
61      /***
62       * Return the property name.
63       */
64      public String getProperty()
65      {
66      return  (this.property);
67      }
68  
69  
70       /***
71         *  Set  the  property  name.
72         *
73         *  @param  property  The  property  name
74         */
75      public  void  setProperty(String  property)
76      {
77      this.property  =  property;
78      }
79  
80      /***
81        *  Set  the  scope.
82        *
83        *  @param  scope  The  new  scope
84        */
85      public  void  setScope(String  scope)
86      {
87      this.scopeName  =  scope;
88      }
89  
90          //  ---------------------------------------------------------  Public  Methods
91  
92  
93          /***
94            *  Expose  the  requested  property  from  component  context.
95            *
96            *  @exception  JspException  if  a  JSP  exception  has  occurred
97            */
98      public  int  doStartTag()  throws  JspException
99          {
100         if(  id==null  )
101             id=property;
102 
103         ComponentContext  compContext  =  (ComponentContext)pageContext.getAttribute(  ComponentConstants.COMPONENT_CONTEXT,  PageContext.REQUEST_SCOPE);
104 
105         if(  compContext  ==  null  )
106             throw  new  JspException  (  "Error  -  tag.useProperty  :  component  context  is  not  defined.  Check  tag  syntax"  );
107 
108         Object  value  =  compContext.getAttribute(property);
109         if(  value  ==  null  )
110             throw  new  JspException  (  "Error  -  tag.useProperty  :  property  '"+  property  +  "'  not  found  in  context.  Check  tag  syntax"  );
111 
112         if(  scopeName  !=  null  )
113             {
114             scope  =  TagUtils.getScope(  scopeName,  PageContext.PAGE_SCOPE  );
115             pageContext.setAttribute(id,  value,  scope);
116             }
117           else
118             pageContext.setAttribute(id,  value);
119 
120           //  Continue  processing  this  page
121         return  SKIP_BODY;
122         }
123 
124 
125 
126 
127         /***
128           *  Clean  up  after  processing  this  enumeration.
129           *
130           *  @exception  JspException  if  a  JSP  exception  has  occurred
131           */
132     public  int  doEndTag()  throws  JspException
133         {
134         return  (EVAL_PAGE);
135         }
136 
137         /***
138           *  Release  all  allocated  resources.
139           */
140         public  void  release()  {
141 
142                 super.release();
143                 property  =  null;
144                 scopeName  =  null;
145                 scope  =  PageContext.PAGE_SCOPE;
146         }
147 
148 }