View Javadoc

1   /***
2    *  The contents of this file are subject to the Mozilla Public
3    *  License Version 1.1 (the "License"); you may not use this file
4    *  except in compliance with the License. You may obtain a copy of
5    *  the License at http://www.mozilla.org/MPL/
6    *
7    *  Software distributed under the License is distributed on an "AS
8    *  IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9    *  implied. See the License for the specific language governing
10   *  rights and limitations under the License.
11   *
12   *  The Original Code is pow2WebGui library.
13   *
14   *  The Initial Owner of the Original Code is Power Of Two S.R.L.
15   *  Portions created by Power Of Two S.R.L. are Copyright (C) Power Of Two S.R.L.
16   *  All Rights Reserved.
17   *
18   * Contributor(s):
19   */
20  
21  package com.pow2.webgui.taglib;
22  
23  import java.util.Collection;
24  import java.util.HashMap;
25  
26  import javax.servlet.jsp.JspException;
27  import javax.servlet.jsp.JspTagException;
28  import javax.servlet.jsp.tagext.TagSupport;
29  
30  import org.apache.log4j.Category;
31  
32  import com.pow2.webgui.Widget;
33  
34  /***
35   *  ContentProviderTag class.
36   *  <br>
37   *
38   *  <code>
39   *    <gui:lister drawer="amazon" titleType="image" title= "pics/listerTitle-category.gif">
40   *      <gui:contentProvider name="lister" collection=<%=myCollection %>" />
41   *    </gui:lister>
42   *  </code>
43   *
44   * @author  Luca Fossato
45   * @created  22 September 2001
46   */
47  public class ContentProviderTag extends TagSupport
48  {
49    protected final static String KEY_TEMPLATE      = "com.pow2.webgui.contentprovider.template";
50    protected final static String KEY_COLLECTION    = "com.pow2.webgui.contentprovider.collection";
51    protected final static String KEY_PROPERTIESMAP = "com.pow2.webgui.contentprovider.propertiesMap";
52  
53    /*** Log4j category */
54    private static Category cat = Category.getInstance(ContentProviderTag.class);
55  
56    private  String      name        = null;
57    private  Collection  collection  = null;
58    private  String      template    = null;
59    private  HashMap     propertiesMap = null;
60    private  Widget      parent      = null;
61  
62  
63    /***
64     *  Constructor
65     */
66    public ContentProviderTag()
67    {
68      super();
69    }
70  
71  
72    /***
73     *  Gets the collection attribute of the CollectionContentProvider object
74     *
75     * @return  The collection value
76     */
77    public Collection getCollection()
78    {
79      return collection;
80    }
81  
82  
83    /***
84     *  Sets the collection attribute of the CollectionContentProvider object
85     *
86     * @param  collection The new collection value
87     */
88    public void setCollection(Collection collection)
89    {
90      this.collection = collection;
91    }
92  
93  
94    /***
95     *  Gets the name attribute of the CollectionContentProviderTag object
96     *
97     * @return  The name value
98     */
99    public String getName()
100   {
101     return name;
102   }
103 
104 
105   /***
106    *  Gets the propertiesMap attribute of the BaseContentProvider object
107    *
108    * @return  The propertiesMap value
109    */
110   public HashMap getPropertiesMap()
111   {
112     return propertiesMap;
113   }
114 
115 
116   /***
117    *  Sets the name attribute of the CollectionContentProviderTag object
118    *
119    * @param  name The new name value
120    */
121   public void setName(String name)
122   {
123     this.name = name;
124   }
125 
126 
127   /***
128    *  Gets the template attribute of the CollectionContentProviderTag object
129    *
130    * @return  The template value
131    */
132   public String getTemplate()
133   {
134     return template;
135   }
136 
137 
138   /***
139    *  Sets the template attribute of the CollectionContentProviderTag object
140    *
141    * @param  template The new template value
142    */
143   public void setTemplate(String template)
144   {
145     this.template = template;
146   }
147 
148 
149   /***
150    *  Sets the propertiesMap attribute of the BaseContentProvider object
151    *
152    * @param  propertiesMap The new propertiesMap value
153    */
154   public void setPropertiesMap(HashMap propertiesMap)
155   {
156     this.propertiesMap = propertiesMap;
157   }
158 
159 
160   /***
161    * @return  Description of the Returned Value
162    * @exception  JspException Description of Exception
163    */
164   public int doEndTag() throws JspException
165   {
166     if ((parent = (Widget)findAncestorWithClass(this, Widget.class)) == null)
167     {
168       String err = "cannot retrieve the parent tag class (must be a Widget subclass)";
169       cat.error("::doEndTag - " + err);
170       throw new JspTagException(err);
171     }
172 
173     parent.setContentProviderName(name);
174     if (template      != null) pageContext.setAttribute(KEY_TEMPLATE,      template);
175     if (collection    != null) pageContext.setAttribute(KEY_COLLECTION,    collection);
176     if (propertiesMap != null) pageContext.setAttribute(KEY_PROPERTIESMAP, propertiesMap);
177 
178     return EVAL_PAGE;
179   }
180 }