KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > text > template > xhtml > Rows


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.text.template.xhtml;
6
7 import java.io.IOException JavaDoc;
8 import java.io.Writer JavaDoc;
9 import java.util.ResourceBundle JavaDoc;
10 import org.exoplatform.text.template.CollectionDataHandler;
11 /**
12  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
13  * @since Feb 1, 2005
14  * @version $Id$
15  */

16 public class Rows extends Element {
17   private boolean showHeader_ ;
18   private String JavaDoc cssHeaderClass_ ;
19   private String JavaDoc evenRowClass_ = "odd";
20   private String JavaDoc oddRowClass_ = "even";
21   
22   public Rows() { }
23   
24   public Rows(String JavaDoc odd, String JavaDoc even) {
25     evenRowClass_ = even ;
26     oddRowClass_ = odd ;
27   }
28   
29   public Element add(Element element) {
30     if(element instanceof Column) {
31       return super.add(element) ;
32     }
33     throw new RuntimeException JavaDoc("expect element type of Column") ;
34   }
35   
36   public Element setShowHeader(boolean b) {
37     showHeader_ = b ;
38     return this ;
39   }
40   
41   public Element setCssHeaderClass(String JavaDoc s) {
42     cssHeaderClass_ = s ;
43     return this ;
44   }
45   
46   public void render(XhtmlDataHandlerManager manager,
47                      ResourceBundle JavaDoc res, Writer JavaDoc w) throws IOException JavaDoc {
48     if(showHeader_) {
49       if(cssHeaderClass_ == null) {
50         w.write("<tr>") ;
51       } else {
52         w.write("<tr class='") ; w.write(cssHeaderClass_) ; w.write("'>") ;
53       }
54       for(int i = 0; i < children_.length; i++) {
55         Column column = (Column) children_[i] ;
56         column.renderHeader(res, w) ;
57       }
58       w.write("</tr>") ;
59     }
60     
61     CollectionDataHandler dh = (CollectionDataHandler)manager.getDataHandler(dataHandlerType_) ;
62     boolean even = true ;
63     dh.begin() ;
64     while(dh.nextRow()) {
65       String JavaDoc css = oddRowClass_ ;
66       if(even) css = evenRowClass_ ;
67       if(css == null) {
68         w.write("<tr>") ;
69       } else {
70         w.write("<tr class='") ; w.write(css) ; w.write("'>") ;
71       }
72       for(int i = 0 ; i < children_.length; i++) {
73         Column column = (Column) children_[i] ;
74         column.renderCell(manager, res, w) ;
75       }
76       w.write("</tr>") ;
77       even = !even ;
78     }
79     dh.end() ;
80   }
81 }
Popular Tags