KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > improve > struts > taglib > layout > util > BasicCollection2


1 package fr.improve.struts.taglib.layout.util;
2
3 import javax.servlet.jsp.JspException JavaDoc;
4 import javax.servlet.jsp.PageContext JavaDoc;
5 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
6
7 import fr.improve.struts.taglib.layout.collection.CollectionTag;
8 ;
9
10 /**
11  * Simple implementation of the CollectionInterface.
12  *
13  * @author: Jean-NoŽl Ribette
14  */

15 public class BasicCollection2 extends BasicPanel implements CollectionInterface {
16     CollectionTag collectionTag;
17     PageContext JavaDoc pageContext;
18     /**
19      * Display a special message if the collection is empty.
20      */

21     public void doPrintEmptyCollection(StringBuffer JavaDoc out_buffer, String JavaDoc in_message) {
22         out_buffer.append("<tr><td><span class=\"");
23         out_buffer.append(styleClass);
24         out_buffer.append("\">&nbsp;");
25         out_buffer.append(in_message);
26         out_buffer.append("</span></td></tr>");
27     }
28     /**
29      * Overrides the display ot the title.
30      */

31     public void doPrintTitle(StringBuffer JavaDoc buffer, String JavaDoc title) {
32         if (title!=null) {
33             if (isNested) {
34                 buffer.append("<td colspan=\"");
35                 buffer.append(LayoutUtils.getSkin(pageContext.getSession()).getFieldInterface().getColumnNumber());
36                 buffer.append("\">");
37             }
38             if (styleClass!=null) {
39                 buffer.append("<p class=\"");
40                 buffer.append(styleClass);
41                 buffer.append("\">");
42             }
43             buffer.append(title);
44             if (styleClass!=null) {
45                 buffer.append("</p>");
46             }
47             if (isNested) {
48                 buffer.append("</td></tr><tr align=\"center\">");
49             }
50         }
51     }
52     /**
53      *
54      */

55     private void doPrintSeparator(StringBuffer JavaDoc out_buffer) {
56         out_buffer.append("<tr>");
57         out_buffer.append("<td colspan=\"");
58         out_buffer.append(2 * collectionTag.getNbOfColumns() - 1);
59         out_buffer.append("\" class=\"tableborder\"><img SRC=\"");
60         out_buffer.append(LayoutUtils.getSkin(pageContext.getSession()).getImageDirectory(pageContext.getRequest()));
61         out_buffer.append("shim.gif\" width=\"1\" height=\"1\"></td>");
62         out_buffer.append("</tr>\n");
63     }
64     /**
65      * Start display.
66      */

67     public void doStartPanel(StringBuffer JavaDoc out_buffer, String JavaDoc in_align, String JavaDoc in_width) {
68         out_buffer.append("<td colspan=\"");
69         out_buffer.append(LayoutUtils.getSkin(pageContext.getSession()).getFieldInterface().getColumnNumber());
70         out_buffer.append("\">\n");
71         out_buffer.append("<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\"");
72         if (in_align!=null) {
73             out_buffer.append(" align=\"");
74             out_buffer.append(in_align);
75             out_buffer.append("\"");
76         }
77         if (in_width!=null) {
78             out_buffer.append(" width=\"");
79             out_buffer.append(in_width);
80             out_buffer.append("\"");
81         }
82         out_buffer.append(">");
83     }
84     /**
85      * End display
86      */

87     public void doEndPanel(StringBuffer JavaDoc out_buffer) {
88         doPrintSeparator(out_buffer);
89         out_buffer.append("</table>");
90         out_buffer.append("</td>\n");
91     }
92     /**
93      * Prepare to display the headers.
94      */

95     public void doStartHeaders(StringBuffer JavaDoc out_buffer) {
96         doPrintSeparator(out_buffer);
97         out_buffer.append("<tr>");
98     }
99     /**
100      * Display a header.
101      */

102     public void doPrintHeader(StringBuffer JavaDoc out_buffer, String JavaDoc in_header, String JavaDoc in_width, String JavaDoc in_sortUrl) {
103         if (collectionTag.getColumn()!=0) {
104             out_buffer.append("<td class=\"tableborder\" width=\"1\"><div class=\"SHIMARRAY\" width=\"1\" height=\"23\"></div></td>");
105         }
106         out_buffer.append("<th class=\"tableentete\">");
107         out_buffer.append(in_header);
108         out_buffer.append("</th>");
109     }
110     /**
111      * Finish to render the headers.
112      */

113     public void doEndHeaders(StringBuffer JavaDoc out_buffer) {
114         out_buffer.append("</tr>");
115     }
116     /**
117      * Prepare to render a line.
118      */

119     public void doStartItems(StringBuffer JavaDoc out_buffer) {
120         doPrintSeparator(out_buffer);
121         out_buffer.append("<tr>");
122     }
123     /**
124      * Render an element in the line.
125      */

126     public void doPrintItem(StringBuffer JavaDoc out_buffer, String JavaDoc in_item, String JavaDoc[] in_styleClass, String JavaDoc in_id) {
127         if (collectionTag.getColumn()!=0) {
128             out_buffer.append("<td class=\"tableborder\" width=\"1\"><div class=\"SHIMARRAY\" width=\"1\" height=\"23\"></div></td>");
129         }
130         out_buffer.append("<td");
131 // if (in_styleClass[0] != null) {
132
out_buffer.append(" class=\"");
133 // out_buffer.append(in_styleClass[0]);
134
out_buffer.append("tabletexte");
135             out_buffer.append("\"");
136 //}
137
if (in_id!=null) {
138             out_buffer.append(" id=\"");
139             out_buffer.append(in_id);
140             out_buffer.append("\"");
141         }
142         out_buffer.append(">");
143         
144         out_buffer.append(in_item);
145
146         out_buffer.append("</td>");
147     }
148     /**
149      * Finish to render a line.
150      */

151     public void doEndItems(StringBuffer JavaDoc out_buffer) {
152         out_buffer.append("</tr>");
153     }
154     /**
155      * Init the collection.
156      */

157     public void init(PageContext JavaDoc pg, String JavaDoc in_styleClass, TagSupport JavaDoc in_panel) throws JspException JavaDoc {
158         super.init(pg, in_styleClass, in_panel);
159         collectionTag = (CollectionTag) in_panel;
160         pageContext = pg;
161     }
162 }
Popular Tags