KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > patterns > listdata > www > ListDataInitTag


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: ListDataInitTag.java,v 1.2 2007/02/20 04:17:45 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21  
22 package org.opensubsystems.patterns.listdata.www;
23
24 import javax.servlet.ServletRequest JavaDoc;
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26 import javax.servlet.jsp.JspException JavaDoc;
27
28 import org.opensubsystems.core.www.PageElementCacheTag;
29
30 /**
31  * Custom tag to initialize the page using the list data pattern. This needs to
32  * be the first tag of all list data tags and should be placed in the page
33  * before the html tag. The <core:pagecache id="xyz"/> in emptypage.jsp layout
34  * will take the elements put into cache by this tag and place them at correct
35  * location.
36  *
37  * @version $Id: ListDataInitTag.java,v 1.2 2007/02/20 04:17:45 bastafidli Exp $
38  * @author Miro Halas
39  * @code.reviewer Miro Halas
40  * @code.reviewed Initial revision
41  */

42 public class ListDataInitTag extends PageElementCacheTag
43 {
44    // Attributes ///////////////////////////////////////////////////////////////
45

46    /**
47     * Generated serial version id for this class.
48     */

49    private static final long serialVersionUID = -6615631964966361736L;
50
51    /**
52     * Name of the attribute under which the page is expecting the data published
53     * from the ListBrowserServlet. ListBrowserServlet always publishes its data
54     * using PARAMETER_DATA_OBJECT_LIST_NAME name. By specifying this alias
55     * this tag will automatically create attribute with the desirect name
56     * and the value of the attribute will be the data published under
57     * PARAMETER_DATA_OBJECT_LIST_NAME or it will create attribute with the name
58     * PARAMETER_DATA_OBJECT_LIST_NAME and the value of the attribute will be the
59     * data published under the specified alias.
60     */

61    protected String JavaDoc m_strDataAlias;
62    
63    // Constructors /////////////////////////////////////////////////////////////
64

65    /**
66     * Constructor for custom tag.
67     */

68    public ListDataInitTag()
69    {
70       super();
71    }
72    
73    // Business logic ///////////////////////////////////////////////////////////
74

75    /**
76     * {@inheritDoc}
77     */

78    public int doStartTag(
79    ) throws JspException JavaDoc
80    {
81       String JavaDoc contextpath;
82       StringBuffer JavaDoc sbBuffer = new StringBuffer JavaDoc();
83       ServletRequest JavaDoc request = pageContext.getRequest();
84
85       contextpath = ((HttpServletRequest JavaDoc)request).getContextPath();
86       if ((m_strDataAlias != null) && (m_strDataAlias.length() > 0))
87       {
88          Object JavaDoc data = request.getAttribute(
89                           ListBrowserServlet.PARAMETER_DATA_OBJECT_LIST_NAME);
90          if (data != null)
91          {
92             request.setAttribute(m_strDataAlias, data);
93          }
94          else
95          {
96             data = request.getAttribute(m_strDataAlias);
97             if (data != null)
98             {
99                request.setAttribute(
100                   ListBrowserServlet.PARAMETER_DATA_OBJECT_LIST_NAME, data);
101             }
102          }
103       }
104       
105       /*
106       <script type="text/javascript" language="JavaScript"
107               src="<%=contextpath%>/patterns/js/listdata.js"></script>
108       */

109       sbBuffer.append("<script type=\"text/javascript\" language=\"JavaScript\" SRC=\"");
110       sbBuffer.append(contextpath);
111       sbBuffer.append("/patterns/js/listdata.js\"></script>");
112       cache(PageElementCacheTag.JS_ELEMENT, sbBuffer.toString());
113                
114       return (SKIP_BODY);
115    }
116
117    /**
118     * {@inheritDoc}
119     */

120    public int doEndTag(
121    ) throws JspException JavaDoc
122    {
123       return (EVAL_PAGE);
124    }
125    
126    /**
127     * Get the name of the attribute under which the page is expecting the data
128     * published from the ListBrowserServlet. ListBrowserServlet always publishes
129     * its data using PARAMETER_DATA_OBJECT_LIST_NAME name. By specifying this
130     * alias this tag will automatically create attribute with the desirect name
131     * and the value of the attribute will be the data published under
132     * PARAMETER_DATA_OBJECT_LIST_NAME.
133     *
134     * @return String - name of the attribute under which the page is expecting
135     * the data published from the ListBrowserServlet.
136     */

137    public String JavaDoc getDataAlias()
138    {
139       return m_strDataAlias;
140    }
141
142    /**
143     * Set the name of the attribute under which the page is expecting the data
144     * published from the ListBrowserServlet. ListBrowserServlet always publishes
145     * its data using PARAMETER_DATA_OBJECT_LIST_NAME name. By specifying this
146     * alias this tag will automatically create attribute with the desirect name
147     * and the value of the attribute will be the data published under
148     * PARAMETER_DATA_OBJECT_LIST_NAME.
149     *
150     * @param strDataAlias - name of the attribute under which the page is
151     * expecting the data published from the
152     * ListBrowserServlet.
153     */

154    public void setDataAlias(
155       String JavaDoc strDataAlias
156    )
157    {
158       m_strDataAlias = strDataAlias;
159    }
160 }
161
Popular Tags