1 5 package org.exoplatform.text.template.xhtml; 6 7 import java.io.IOException ; 8 import java.io.Writer ; 9 import java.util.ResourceBundle ; 10 import org.exoplatform.text.template.CollectionDataHandler; 11 16 public class Rows extends Element { 17 private boolean showHeader_ ; 18 private String cssHeaderClass_ ; 19 private String evenRowClass_ = "odd"; 20 private String oddRowClass_ = "even"; 21 22 public Rows() { } 23 24 public Rows(String odd, String 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 ("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 s) { 42 cssHeaderClass_ = s ; 43 return this ; 44 } 45 46 public void render(XhtmlDataHandlerManager manager, 47 ResourceBundle res, Writer w) throws IOException { 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 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 |