KickJava   Java API By Example, From Geeks To Geeks.

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


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.commons.utils.ExpressionUtil;
11 import org.exoplatform.text.template.*;
12 /**
13  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
14  * @since Feb 1, 2005
15  * @version $Id$
16  */

17 public class Column extends Element {
18   protected Value header_ ;
19   protected Value data_ ;
20   
21   public Column(String JavaDoc value) {
22     if(ExpressionUtil.isResourceBindingExpression(value)) {
23       data_ = new ResourceBindingValue(value) ;
24     } else if(ExpressionUtil.isDataBindingExpression(value)) {
25       data_ = new DataBindingValue(value) ;
26     } else {
27       data_ = new StringValue(value) ;
28     }
29   }
30   
31   public Column(String JavaDoc header, String JavaDoc value) {
32     this(value) ;
33     if(ExpressionUtil.isResourceBindingExpression(header)) {
34       header_ = new ResourceBindingValue(header) ;
35     } else {
36       header_ = new StringValue(header) ;
37     }
38   }
39   
40   public Value getHeader() { return header_ ; }
41   
42   public Value getData() { return data_ ; }
43   
44   public void renderHeader(ResourceBundle JavaDoc res, Writer JavaDoc w) throws IOException JavaDoc {
45     w.write("<th>") ;
46     w.write(resolveValueAsString(header_, null, res)) ;
47     w.write("</th>") ;
48   }
49   
50   public void renderCell(XhtmlDataHandlerManager manager,
51                          ResourceBundle JavaDoc res, Writer JavaDoc w) throws IOException JavaDoc {
52     if(cssClass_ == null) {
53       w.write("<td>") ;
54     } else {
55       w.write("<td class='") ; w.write(cssClass_); w.write("'>") ;
56     }
57     DataHandler dhandler = manager.getDataHandler(dataHandlerType_);
58     if(formater_ != null) {
59       formater_.format(w, dhandler.getValue((DataBindingValue)data_)) ;
60     } else {
61       w.write(resolveValueAsString(data_ ,dhandler, res)) ;
62     }
63     w.write("</td>") ;
64   }
65   
66   public void render(XhtmlDataHandlerManager manager,
67                      ResourceBundle JavaDoc res, Writer JavaDoc w) throws IOException JavaDoc {
68     throw new RuntimeException JavaDoc("This method should not be called");
69   }
70 }
Popular Tags