KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > table > CellBuilderImpl


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.jpivot.table;
14
15 import org.apache.log4j.Logger;
16 import org.w3c.dom.Element JavaDoc;
17
18 import com.tonbeller.jpivot.olap.model.Cell;
19 import com.tonbeller.jpivot.olap.model.Property;
20 import com.tonbeller.jpivot.table.span.PropertyUtils;
21
22 /**
23  * Created on 18.10.2002
24  *
25  * @author av
26  */

27 public class CellBuilderImpl extends PartBuilderSupport implements CellBuilder {
28
29   private static final Logger logger = Logger.getLogger(CellBuilderImpl.class);
30   private static final String JavaDoc STYLE = "style";
31   private static final String JavaDoc NBSP = "\u00a0";
32   /**
33    * renders DOM element of cell
34    */

35   public Element JavaDoc build(Cell cell, boolean even) {
36     Element JavaDoc cellElem = table.elem("cell");
37     String JavaDoc s = cell.isNull() ? NBSP : cell.getFormattedValue();
38     s = s.trim();
39     if (s.length() == 0)
40       s = NBSP;
41     cellElem.setAttribute("value", s);
42     if (logger.isDebugEnabled())
43       logger.debug("building cell " + s);
44
45     PropertyUtils.addProperties(cellElem, cell.getProperties());
46     Property style = cell.getProperty(STYLE);
47     if (style != null) {
48       String JavaDoc value = style.getValue();
49       if (value != null && value.length() > 0)
50         cellElem.setAttribute(STYLE, value);
51       else
52         cellElem.setAttribute(STYLE, even ? "even" : "odd");
53     }
54     else
55       cellElem.setAttribute(STYLE, even ? "even" : "odd");
56
57     return cellElem;
58   }
59
60 }
61
Popular Tags