KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > jpivot > excel > ExcelCellBuilderDecorator


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 package com.tonbeller.jpivot.excel;
12
13 import org.w3c.dom.Element JavaDoc;
14
15 import com.tonbeller.jpivot.olap.model.Cell;
16 import com.tonbeller.jpivot.table.CellBuilder;
17 import com.tonbeller.jpivot.table.CellBuilderDecorator;
18 import com.tonbeller.wcf.component.RendererParameters;
19 import com.tonbeller.wcf.controller.RequestContext;
20
21 /**
22  * adds excel attributes to cell elements
23  */

24 public class ExcelCellBuilderDecorator extends CellBuilderDecorator {
25
26   protected boolean excelMode;
27
28   public void startBuild(RequestContext context) {
29     super.startBuild(context);
30     this.excelMode= RendererParameters.isExcelMode(context);
31   }
32   
33   public ExcelCellBuilderDecorator(CellBuilder delegate) {
34     super(delegate);
35   }
36   /*
37    * (non-Javadoc)
38    *
39    * @see com.tonbeller.jpivot.table.CellBuilderDecorator#build(com.tonbeller.jpivot.olap.model.Cell,
40    * boolean)
41    */

42   public Element JavaDoc build(Cell cell, boolean even) {
43     Element JavaDoc cellElem = super.build(cell, even);
44     // AR_MOD
45
if (excelMode && !cell.isNull() && (cell.getValue() instanceof Number JavaDoc)) {
46       Object JavaDoc value = cell.getValue();
47       com.tonbeller.jpivot.olap.model.NumberFormat nf = cell.getFormat();
48       String JavaDoc rawValue = value.toString();
49       cellElem.setAttribute("rawvalue", rawValue);
50       Number JavaDoc num = (Number JavaDoc) cell.getValue();
51       String JavaDoc numFormat = "\\#\\#0";
52
53       numFormat = (nf.isGrouping() ? "\\#\\," + numFormat : numFormat);
54       if (nf.getFractionDigits() > 0) {
55         numFormat = numFormat + ".";
56         for (int x = 0; x < nf.getFractionDigits(); x++)
57           numFormat = numFormat + "#";
58       }
59       String JavaDoc msoformat = nf.isPercent() ? "Percent" : numFormat;
60       cellElem.setAttribute("mso-number-format", msoformat);
61     }
62     // AR_MOD END
63
return cellElem;
64   }
65 }
Popular Tags