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 javax.servlet.jsp.JspTagException;
24  
25  import com.pow2.util.Util;
26  import com.pow2.webgui.WidgetFactory;
27  import com.pow2.webgui.contentprovider.BaseContentProvider;
28  import com.pow2.webgui.lister.Lister;
29  
30  
31  /***
32   *  ListerTag class.
33   *  <br>
34   *  This tag renderers a "lister".
35   *
36   * @author  Luca Fossato
37   */
38  public class ListerTag extends Lister
39  {
40    private WidgetFactory wf     = null;
41    private Lister        lister = null;
42  
43  
44    /***
45     * @return  Description of the Return Value
46     * @exception  JspTagException Description of the Exception
47     */
48    public int doStartTag() throws JspTagException
49    {
50      return EVAL_BODY_BUFFERED;
51    }
52  
53  
54    /***
55     * @return  Description of the Return Value
56     * @exception  JspTagException Description of the Exception
57     */
58    public int doEndTag() throws JspTagException
59    {
60      try
61      {
62        wf     = WidgetFactory.instance();
63        lister = (Lister)wf.getWidget(Lister.KEY);
64        lister.updateAttributes(this);
65        lister.setWidgetDrawer(drawer);
66  
67        // get (ad then retrieve) the contentProvider class instance;
68        if (!Util.isNull(contentProviderName))
69        {
70         lister.setContentProvider(contentProviderName);
71         BaseContentProvider cp = lister.getContentProvider();
72  
73         if (cp != null)
74          TagUtil.setContentProviderData(cp, pageContext);
75        }
76      }
77      catch (Exception e)
78      {
79        cat.error("::doStartTag - error:", e);
80        throw new JspTagException(e.getMessage());
81      }
82  
83      // ------------------------------------------------------------------
84  
85      if (bodyContent != null)
86      {
87        lister.setContent(new StringBuffer(bodyContent.getString()));
88  
89        try
90        {
91          bodyContent.getEnclosingWriter().print(lister.draw());
92        }
93        catch(Exception e)
94        {
95          cat.error("::doAfterBody - error:", e);
96          throw new JspTagException(e.getMessage());
97        }
98      }
99  
100     return EVAL_PAGE;
101   }
102 }