001: package com.xoetrope.export.xl;
002:
003: import com.xoetrope.export.FragmentBlock;
004: import com.xoetrope.export.RowBlock;
005: import com.xoetrope.export.XMLHelper;
006: import java.awt.Point;
007: import java.io.Reader;
008: import java.util.Vector;
009: import net.xoetrope.xml.XmlElement;
010: import net.xoetrope.xml.XmlSource;
011: import net.xoetrope.xui.XProject;
012: import net.xoetrope.xui.XProjectManager;
013:
014: /**
015: *
016: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
017: * the GNU Public License (GPL), please see license.txt for more details. If
018: * you make commercial use of this software you must purchase a commercial
019: * license from Xoetrope.</p>
020: * <p> $Revision: 1.2 $</p>
021: */
022: public class XLFragmentBlock extends FragmentBlock implements
023: CursorTracker {
024:
025: int row, col;
026: int offsetX, offsetY;
027: XLExporter xlExporter;
028:
029: /**
030: * The owner project and the context in which this object operates.
031: */
032: protected XProject currentProject = XProjectManager
033: .getCurrentProject();
034:
035: public XLFragmentBlock(XLExporter exporter) {
036: xlExporter = exporter;
037: }
038:
039: public void processFragment(String fragmentName) {
040: try {
041: Reader reader = currentProject.getBufferedReader(
042: fragmentName + "_xl.xml", null);
043: XmlElement ele = XmlSource.read(reader);
044: Vector rows = ele.getChildren();
045: XLTableBlock tableExporter = (XLTableBlock) xlExporter
046: .getTableBlock();
047:
048: int numRows = rows.size();
049: for (int row = 0; row < numRows; row++) {
050: XmlElement rowEle = (XmlElement) rows.get(row);
051: Vector cells = rowEle.getChildren();
052: RowBlock rowBlockItem = tableExporter.addRow();
053: blocks.add(rowBlockItem);
054: int numCells = cells.size();
055: for (int cell = 0; cell < numCells; cell++) {
056: XmlElement cellEle = (XmlElement) cells.get(cell);
057: String value = cellEle.getAttribute("value");
058: String style = cellEle.getAttribute("style");
059: int offsetX = XMLHelper.getAttribAsInt(cellEle,
060: "offsetx", 1);
061: int offsetY = XMLHelper.getAttribAsInt(cellEle,
062: "offsety", 1);
063: int colspan = XMLHelper.getAttribAsInt(cellEle,
064: "colspan", 1);
065: int rowspan = XMLHelper.getAttribAsInt(cellEle,
066: "rowspan", 1);
067: rowBlockItem
068: .addCell(value, style, colspan, rowspan);
069: }
070: }
071: } catch (Exception e) {
072: e.printStackTrace();
073: }
074: }
075:
076: public void setOffset(int x, int y) {
077: offsetX = x;
078: offsetY = y;
079: }
080:
081: public Point getOffset() {
082: return new Point(offsetX, offsetY);
083: }
084:
085: public void setRow(int value) {
086: row = value;
087: }
088:
089: public void setColumn(int value) {
090: col = value;
091: }
092:
093: public int getRow() {
094: return row;
095: }
096:
097: public int getColumn() {
098: return col;
099: }
100:
101: public int getColumnCount() {
102: return col + offsetX;
103: }
104:
105: public int getRowCount() {
106: return row + offsetY;
107: }
108:
109: }
|