KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > patterns > scrollabletable > www > ScrollableTableHeaderSettingsTag


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: ScrollableTableHeaderSettingsTag.java,v 1.4 2007/01/07 06:14:16 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.scrollabletable.www;
23
24 import javax.servlet.jsp.JspException JavaDoc;
25 import javax.servlet.jsp.tagext.BodyContent JavaDoc;
26
27 import org.opensubsystems.core.www.BlockElementTag;
28
29 /**
30  * Custom tag to generate all HTML required to configure scrollable table headers.
31  *
32  * @version $Id: ScrollableTableHeaderSettingsTag.java,v 1.4 2007/01/07 06:14:16 bastafidli Exp $
33  * @author Miro Halas
34  * @code.reviewer Miroslav Halas
35  * @code.reviewed 1.2 2006/02/18 05:29:32 bastafidli
36  */

37 public class ScrollableTableHeaderSettingsTag extends BlockElementTag
38 {
39    // Constants ////////////////////////////////////////////////////////////////
40

41    /**
42     * Identifier used to store scrollable table header settings until it is ready
43     * to be retrieved.
44     */

45    public static final String JavaDoc SCROLLABLE_TABLE_HEADER_SETTINGS_CACHE
46                                  = "scrollabletableheadersettings";
47    
48    // Attributes ///////////////////////////////////////////////////////////////
49

50    /**
51     * Generated serial version id for this class.
52     */

53    private static final long serialVersionUID = -5244079289468850958L;
54
55    // Constructors /////////////////////////////////////////////////////////////
56

57    /**
58     * Constructor for custom tag.
59     */

60    public ScrollableTableHeaderSettingsTag(
61    )
62    {
63       super(null, BlockElementTag.DIV_BLOCK_ELEMENT);
64    }
65    
66    // Business logic ///////////////////////////////////////////////////////////
67

68    /**
69     * {@inheritDoc}
70     */

71    public int doStartTag(
72    ) throws JspException JavaDoc
73    {
74       // Buffer the header settings since we will neeed to display inside of
75
// the body and not in the header since the header is just a fake header
76
return (EVAL_BODY_BUFFERED);
77    }
78
79    /**
80     * {@inheritDoc}
81     */

82    public int doEndTag(
83    ) throws JspException JavaDoc
84    {
85       StringBuffer JavaDoc sbHtml = new StringBuffer JavaDoc();
86       String JavaDoc strHeaderSettings;
87       int iHeadingCount = 0;
88       int iIndex = 0;
89       
90       // Insert the buffered body
91
BodyContent JavaDoc content = getBodyContent();
92       
93       if (content != null)
94       {
95          strHeaderSettings = content.getString();
96       }
97       else
98       {
99          StringBuffer JavaDoc sbBuffer = new StringBuffer JavaDoc();
100          
101          sbBuffer.append("<!-- Missing header settings for ");
102          sbBuffer.append(getCurrentId());
103          sbBuffer.append("-->\n");
104          strHeaderSettings = sbBuffer.toString();
105       }
106       
107       // Now count number of headers in the table
108
while ((iIndex = strHeaderSettings.indexOf("<col ", iIndex)) != -1)
109       {
110          // We have found another heading to count it
111
iHeadingCount++;
112          // And now move forward
113
iIndex++;
114       }
115       
116       /*
117       <colgroup id="scrollabletablebodycolumns" span="2">
118          <col width="50%">
119          <col width="50%">
120       </colgroup>
121       */

122       sbHtml.append("<colgroup id=\"");
123       sbHtml.append(getCurrentId());
124       sbHtml.append("bodycolumns\" span=\"");
125       sbHtml.append(iHeadingCount);
126       sbHtml.append("\">");
127       if (iHeadingCount == 0)
128       {
129          sbHtml.append("\n<!-- No col tags found in header settings for ");
130          sbHtml.append(getCurrentId());
131          sbHtml.append("-->\n");
132       }
133       sbHtml.append(strHeaderSettings);
134       sbHtml.append("</colgroup>");
135
136       // Cache the content since it should be inserted at a row
137
// boundary and not at a field boundary
138
cache(SCROLLABLE_TABLE_HEADER_SETTINGS_CACHE, sbHtml.toString());
139       
140       return (EVAL_PAGE);
141    }
142 }
143
Popular Tags