KickJava   Java API By Example, From Geeks To Geeks.

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


1 package fr.improve.struts.taglib.layout.util;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
5
6 import javax.servlet.jsp.JspException JavaDoc;
7 import javax.servlet.jsp.PageContext JavaDoc;
8 import javax.servlet.jsp.tagext.TagSupport JavaDoc;
9
10 import fr.improve.struts.taglib.layout.collection.BaseCollectionTag;
11
12 /**
13  * Implementation of the CollectionInterface displaying each element onf the collection in a different panels.
14  * The selected properties of the bean in the collection are displayed on a different line in each panel.
15  *
16  * @author: Jean-NoŽl Ribette
17  */

18 public class NewsCollection extends BasicPanel implements CollectionInterface {
19     private List JavaDoc headers = new ArrayList JavaDoc();
20     private PanelInterface innerPanel = new BasicPanel();
21     private BaseCollectionTag collectionTag;
22     /**
23      * Init the collection.
24      */

25     public void init(PageContext JavaDoc pg, String JavaDoc in_styleClass, TagSupport JavaDoc in_panel) throws JspException JavaDoc {
26         super.init(pg, in_styleClass, in_panel);
27         headers.clear();
28         innerPanel.init(pg, in_styleClass, in_panel);
29         collectionTag = (BaseCollectionTag) in_panel;
30     }
31     /**
32      * Display a special message if the collection is empty.
33      */

34     public void doPrintEmptyCollection(StringBuffer JavaDoc out_buffer, String JavaDoc in_message) {
35         out_buffer.append("<tr><td><span class=\"");
36         out_buffer.append(styleClass);
37         out_buffer.append("\">&nbsp;");
38         out_buffer.append(in_message);
39         out_buffer.append("</span></td></tr>");
40     }
41     /**
42      * Overrides the display ot the title.
43      */

44     public void doPrintTitle(StringBuffer JavaDoc buffer, String JavaDoc title) {
45         if (title!=null) {
46             if (isNested) {
47                 buffer.append("<tr><td colspan=\"");
48                 buffer.append(colspan);
49                 buffer.append("\">");
50             }
51             if (styleClass!=null) {
52                 buffer.append("<p class=\"");
53                 buffer.append(styleClass);
54                 buffer.append("\">");
55             }
56             buffer.append(title);
57             if (styleClass!=null) {
58                 buffer.append("</p>");
59             }
60             if (isNested) {
61                 buffer.append("</td></tr>");
62             }
63         }
64     }
65     /**
66      * Prepare to display the headers.
67      */

68     public void doStartHeaders(StringBuffer JavaDoc out_buffer) {
69         // do nothing.
70
}
71     /**
72      * Display a header.
73      */

74     public void doPrintHeader(StringBuffer JavaDoc out_buffer, String JavaDoc in_header, String JavaDoc in_width, String JavaDoc in_sortUrl) {
75         // Memorize the header.
76
headers.add(in_header);
77     }
78     /**
79      * Finish to render the headers.
80      */

81     public void doEndHeaders(StringBuffer JavaDoc out_buffer) {
82         // do nothing.
83
}
84     /**
85      * Prepare to render a line.
86      */

87     public void doStartItems(StringBuffer JavaDoc out_buffer) {
88         innerPanel.doStartPanel(out_buffer, "center", collectionTag.getWidth());
89     }
90     /**
91      * Render an element in the line.
92      */

93     public void doPrintItem(StringBuffer JavaDoc out_buffer, String JavaDoc in_item, String JavaDoc[] in_styleClass, String JavaDoc in_id) {
94         if (collectionTag.getColumn()==0) {
95             innerPanel.doPrintTitle(out_buffer, in_item);
96             out_buffer.append("<tr><td class=\"");
97             out_buffer.append(in_styleClass[0]);
98             out_buffer.append("\"><table border=0>");
99         } else {
100             out_buffer.append("<tr><td align=right class=");
101             out_buffer.append(styleClass);
102             out_buffer.append(">");
103             out_buffer.append(headers.get(collectionTag.getColumn()));
104             out_buffer.append(" : </td><td class=");
105             out_buffer.append(in_styleClass[0]);
106             out_buffer.append(">");
107             out_buffer.append(in_item);
108             out_buffer.append("</td></tr>");
109         }
110     }
111     /**
112      * Finish to render a line.
113      */

114     public void doEndItems(StringBuffer JavaDoc out_buffer) {
115         out_buffer.append("</table></td></tr>");
116         innerPanel.doEndPanel(out_buffer);
117         out_buffer.append("<br>\n");
118     }
119     public void doStartPanel(StringBuffer JavaDoc buffer, String JavaDoc align, String JavaDoc width) {
120         if (isNested) {
121             buffer.append("<tr><td colspan=\"2\">\n");
122         }
123     }
124     public void doEndPanel(StringBuffer JavaDoc buffer) {
125         if (isNested) {
126             buffer.append("</td></tr>\n");
127         }
128 }
129 }
Popular Tags