+++ /dev/null
-/*
- * Copyright 1999-2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.render.rtf;
-
-import java.util.Stack;
-import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfOptions;
-import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfContainer;
-
-
-/** A BuilderContext holds context information when building an RTF document
- *
- * @author Bertrand Delacretaz <bdelacretaz@codeconsult.ch>
- * @author putzi
- * @author Peter Herweg <pherweg@web.de>
- *
- * This class was originally developed by Bertrand Delacretaz bdelacretaz@codeconsult.ch
- * for the JFOR project and is now integrated into FOP.
- */
-
-public class BuilderContext {
- /** stack of RtfContainers */
- private final Stack containers = new Stack();
-
- /** stack of TableContexts */
- private final Stack tableContexts = new Stack();
-
- /** stack of IBuilders */
- private final Stack builders = new Stack();
-
- /** Rtf options */
- private IRtfOptions options;
-
- public BuilderContext(IRtfOptions rtfOptions) {
- options = rtfOptions;
- }
-
- /** find first object of given class from top of stack s
- * @return null if not found
- */
- private Object getObjectFromStack(Stack s, Class desiredClass) {
- Object result = null;
- final Stack copy = (Stack)s.clone();
- while (!copy.isEmpty()) {
- final Object o = copy.pop();
- if (desiredClass.isAssignableFrom(o.getClass())) {
- result = o;
- break;
- }
- }
- return result;
- }
-
- /* find the "nearest" IBuilder of given class /
- public Object getBuilder(Class builderClass,boolean required)
- throws Exception
- {
- final IBuilder result = (IBuilder)getObjectFromStack(builders,builderClass);
- if(result == null && required) {
- throw new Exception(
- "IBuilder of class '" + builderClass.getName() + "' not found on builders stack"
- );
- }
- return result;
- }*/
-
- /** find the "nearest" container that implements the given interface on our stack
- * @param required if true, ConverterException is thrown if no container found
- * @param forWhichBuilder used in error message if container not found
- */
- public RtfContainer getContainer(Class containerClass, boolean required,
- Object /*IBuilder*/ forWhichBuilder) throws Exception {
- // TODO what to do if the desired container is not at the top of the stack?
- // close top-of-stack container?
- final RtfContainer result = (RtfContainer)getObjectFromStack(containers,
- containerClass);
-
- if (result == null && required) {
- throw new Exception(
- "No RtfContainer of class '" + containerClass.getName()
- + "' available for '" + forWhichBuilder.getClass().getName() + "' builder"
- );
- }
-
- return result;
- }
-
- /** push an RtfContainer on our stack */
- public void pushContainer(RtfContainer c) {
- containers.push(c);
- }
-
- /**
- * In some cases an RtfContainer must be replaced by another one on the
- * stack. This happens when handling nested fo:blocks for example: after
- * handling a nested block the enclosing block must switch to a new
- * paragraph container to handle what follows the nested block.
- * TODO: what happens to elements that are "more on top" than oldC on the
- * stack? shouldn't they be closed or something?
- */
- public void replaceContainer(RtfContainer oldC, RtfContainer newC)
- throws Exception {
- // treating the Stack as a Vector allows such manipulations (yes, I hear you screaming ;-)
- final int index = containers.indexOf(oldC);
- if (index < 0) {
- throw new Exception("container to replace not found:" + oldC);
- }
- containers.setElementAt(newC, index);
- }
-
- /** pop the topmost RtfContainer from our stack */
- public void popContainer() {
- containers.pop();
- }
-
- /* push an IBuilder to our stack /
- public void pushBuilder(IBuilder b)
- {
- builders.push(b);
- }*/
-
- /** pop the topmost IBuilder from our stack and return previous builder on stack
- * @return null if builders stack is empty
-
- public IBuilder popBuilderAndGetPreviousOne()
- {
- IBuilder result = null;
- builders.pop();
- if(!builders.isEmpty()) {
- result = (IBuilder)builders.peek();
- }
- return result;
- }
- */
- /** return the current TableContext */
- public TableContext getTableContext() {
- return (TableContext)tableContexts.peek();
- }
-
- /** push a TableContext to our stack */
- public void pushTableContext(TableContext tc) {
- tableContexts.push(tc);
- }
-
- /** pop a TableContext from our stack */
- public void popTableContext() {
- tableContexts.pop();
- }
-
-}
import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTableRow;
import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTableCell;
import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfTableContainer;
+import org.apache.fop.render.rtf.rtflib.tools.BuilderContext;
+import org.apache.fop.render.rtf.rtflib.tools.TableContext;
import org.apache.fop.fonts.FontSetup;
/**
+++ /dev/null
-/*
- * Copyright 1999-2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-package org.apache.fop.render.rtf;
-
-import java.util.List;
-
-import org.apache.commons.logging.impl.SimpleLog;
-import org.apache.commons.logging.Log;
-import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAttributes;
-import org.apache.fop.render.rtf.rtflib.interfaces.ITableColumnsInfo;
-
-
-/** Used when handling fo:table to hold information to build the table.
- *
- * Contributor(s):
- * @author Bertrand Delacretaz <bdelacretaz@codeconsult.ch>
- * @author Trembicki-Guy, Ed <GuyE@DNB.com>
- * @author Boris Poudérous <boris.pouderous@eads-telecom.com>
- * @author Peter Herweg <pherweg@web.de>
- *
- * This class was originally developed for the JFOR project and
- * is now integrated into FOP.
- */
-
-public class TableContext implements ITableColumnsInfo {
- private final Log log = new SimpleLog("FOP/RTF");
- private final BuilderContext context;
- private final List colWidths = new java.util.ArrayList();
- private int colIndex;
-
- /**
- * Added by Peter Herweg on 2002-06-29
- * This ArrayList contains one element for each column in the table.
- * value == 0 means there is no row-spanning
- * value > 0 means there is row-spanning
- * Each value in the list is decreased by 1 after each finished table-row
- */
- private final List colRowSpanningNumber = new java.util.ArrayList();
-
- /**
- * Added by Peter Herweg on 2002-06-29
- * If there has a vertical merged cell to be created, its attributes are
- * inherited from the corresponding MERGE_START-cell.
- * For this purpose the attributes of a cell are stored in this array, as soon
- * as a number-rows-spanned attribute has been found.
- */
- private final List colRowSpanningAttrs = new java.util.ArrayList();
-
- private boolean bNextRowBelongsToHeader = false;
-
- public void setNextRowBelongsToHeader(boolean value) {
- this.bNextRowBelongsToHeader = value;
- }
-
- public boolean getNextRowBelongsToHeader() {
- return bNextRowBelongsToHeader;
- }
-
- public TableContext(BuilderContext ctx) {
- context = ctx;
- }
-
- public void setNextColumnWidth(Float width)
- throws Exception {
- colWidths.add(width);
- }
-
- //Added by Peter Herweg on 2002-06-29
- public RtfAttributes getColumnRowSpanningAttrs() {
- return (RtfAttributes)colRowSpanningAttrs.get(colIndex);
- }
-
- //Added by Peter Herweg on 2002-06-29
- public Integer getColumnRowSpanningNumber() {
- return (Integer)colRowSpanningNumber.get(colIndex);
- }
-
- //Added by Peter Herweg on 2002-06-29
- public void setCurrentColumnRowSpanning(Integer iRowSpanning, RtfAttributes attrs)
- throws Exception {
-
- if (colIndex < colRowSpanningNumber.size()) {
- colRowSpanningNumber.set(colIndex, iRowSpanning);
- colRowSpanningAttrs.set(colIndex, attrs);
- } else {
- colRowSpanningNumber.add(iRowSpanning);
- colRowSpanningAttrs.add(colIndex, attrs);
- }
- }
-
- //Added by Peter Herweg on 2002-06-29
- public void setNextColumnRowSpanning(Integer iRowSpanning,
- RtfAttributes attrs) {
- colRowSpanningNumber.add(iRowSpanning);
- colRowSpanningAttrs.add(colIndex, attrs);
- }
-
- /**
- * Added by Peter Herweg on 2002-06-29
- * This function is called after each finished table-row.
- * It decreases all values in colRowSpanningNumber by 1. If a value
- * reaches 0 row-spanning is finished, and the value won't be decreased anymore.
- */
- public void decreaseRowSpannings() {
- for (int z = 0; z < colRowSpanningNumber.size(); ++z) {
- Integer i = (Integer)colRowSpanningNumber.get(z);
-
- if (i.intValue() > 0) {
- i = new Integer(i.intValue() - 1);
- }
-
- colRowSpanningNumber.set(z, i);
-
- if (i.intValue() == 0) {
- colRowSpanningAttrs.set(z, null);
- }
- }
- }
-
- /**
- * Reset the column iteration index, meant to be called when creating a new row
- * The 'public' modifier has been added by Boris Poudérous for
- * 'number-columns-spanned' processing
- */
- public void selectFirstColumn() {
- colIndex = 0;
- }
-
- /**
- * Increment the column iteration index
- * The 'public' modifier has been added by Boris Poudérous for
- * 'number-columns-spanned' processing
- */
- public void selectNextColumn() {
- colIndex++;
- }
-
- /**
- * Get current column width according to column iteration index
- * @return INVALID_COLUMN_WIDTH if we cannot find the value
- * The 'public' modifier has been added by Boris Poudérous for
- * 'number-columns-spanned' processing
- */
- public float getColumnWidth() {
- try {
- return ((Float)colWidths.get(colIndex)).floatValue();
- } catch (IndexOutOfBoundsException ex) {
- // this code contributed by Trembicki-Guy, Ed <GuyE@DNB.com>
- log.warn("fo:table-column width not defined, using " + INVALID_COLUM_WIDTH);
- return INVALID_COLUM_WIDTH;
- }
- }
-
- /** Added by Boris Poudérous on 07/22/2002 */
- public int getColumnIndex() {
- return colIndex;
- }
- /** - end - */
-
- /** Added by Boris Poudérous on 07/22/2002 */
- public int getNumberOfColumns() {
- return colWidths.size();
- }
- /** - end - */
-}
-
+++ /dev/null
-/*
- * Copyright 1999-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* $Id$ */
-
-
-/*
- * This file is part of the RTF library of the FOP project, which was originally
- * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
- * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
- * the FOP project.
- */
-
-package org.apache.fop.render.rtf.rtflib.interfaces;
-
-/** Used to get information about tables, for example when handling nested tables
- * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
- */
-
-public interface ITableColumnsInfo {
- /** value for invalid column width */
- float INVALID_COLUM_WIDTH = 200f;
-
- /** reset the column iteration index, meant to be called when creating a new row */
- void selectFirstColumn();
-
- /** increment the column iteration index */
- void selectNextColumn();
-
- /** get current column width according to column iteration index
- * @return INVALID_COLUMN_WIDTH if we cannot find the value
- */
- float getColumnWidth();
-
- /** @return current column iteration index */
- int getColumnIndex();
-
- /** @return number of columns */
- int getNumberOfColumns();
-}
\ No newline at end of file
+++ /dev/null
-<HTML>
-<TITLE>org.apache.fop.render.rtf.rtflib.interfaces</TITLE>
-<BODY>
-<P>Interfaces used to build RTF documents.</P>
-</BODY>
-</HTML>
\ No newline at end of file
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.apache.fop.render.rtf.rtflib.rtfdoc;
import java.io.IOException;
-import org.apache.fop.render.rtf.rtflib.interfaces.ITableColumnsInfo;
/**
* Interface for RtfElements that can contain RtfTables
--- /dev/null
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+
+/*
+ * This file is part of the RTF library of the FOP project, which was originally
+ * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
+ * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
+ * the FOP project.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+/** Used to get information about tables, for example when handling nested tables
+ * @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ */
+
+public interface ITableColumnsInfo {
+ /** value for invalid column width */
+ float INVALID_COLUM_WIDTH = 200f;
+
+ /** reset the column iteration index, meant to be called when creating a new row */
+ void selectFirstColumn();
+
+ /** increment the column iteration index */
+ void selectNextColumn();
+
+ /** get current column width according to column iteration index
+ * @return INVALID_COLUMN_WIDTH if we cannot find the value
+ */
+ float getColumnWidth();
+
+ /** @return current column iteration index */
+ int getColumnIndex();
+
+ /** @return number of columns */
+ int getNumberOfColumns();
+}
\ No newline at end of file
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import java.io.Writer;
import java.io.IOException;
-import org.apache.fop.render.rtf.rtflib.interfaces.ITableColumnsInfo;
/** Common code for RtfAfter and RtfBefore
* @author Andreas Lambert <andreas.lambert@cronidesoft.com>
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import java.util.LinkedList;
import java.util.Iterator;
import java.util.Collections;
-import org.apache.fop.render.rtf.rtflib.interfaces.ITableColumnsInfo;
/**
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import java.io.Writer;
import java.io.IOException;
-import org.apache.fop.render.rtf.rtflib.interfaces.ITableColumnsInfo;
/** Models a section in an RTF document
* @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import java.io.Writer;
import java.io.IOException;
-import org.apache.fop.render.rtf.rtflib.interfaces.ITableColumnsInfo;
/** Container for RtfRow elements
* @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
import java.io.Writer;
import java.io.IOException;
import java.util.Iterator;
-import org.apache.fop.render.rtf.rtflib.interfaces.ITableColumnsInfo;
/** A cell in an RTF table, container for paragraphs, lists, etc.
* @author Bertrand Delacretaz bdelacretaz@codeconsult.ch
--- /dev/null
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id: BuilderContext.java 227252 2005-08-03 19:30:55Z jeremias $ */
+
+package org.apache.fop.render.rtf.rtflib.tools;
+
+import java.util.Stack;
+
+import org.apache.fop.render.rtf.rtflib.rtfdoc.IRtfOptions;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfContainer;
+
+
+/** A BuilderContext holds context information when building an RTF document
+ *
+ * @author Bertrand Delacretaz <bdelacretaz@codeconsult.ch>
+ * @author putzi
+ * @author Peter Herweg <pherweg@web.de>
+ *
+ * This class was originally developed by Bertrand Delacretaz bdelacretaz@codeconsult.ch
+ * for the JFOR project and is now integrated into FOP.
+ */
+
+public class BuilderContext {
+ /** stack of RtfContainers */
+ private final Stack containers = new Stack();
+
+ /** stack of TableContexts */
+ private final Stack tableContexts = new Stack();
+
+ /** stack of IBuilders */
+ private final Stack builders = new Stack();
+
+ /** Rtf options */
+ private IRtfOptions options;
+
+ public BuilderContext(IRtfOptions rtfOptions) {
+ options = rtfOptions;
+ }
+
+ /** find first object of given class from top of stack s
+ * @return null if not found
+ */
+ private Object getObjectFromStack(Stack s, Class desiredClass) {
+ Object result = null;
+ final Stack copy = (Stack)s.clone();
+ while (!copy.isEmpty()) {
+ final Object o = copy.pop();
+ if (desiredClass.isAssignableFrom(o.getClass())) {
+ result = o;
+ break;
+ }
+ }
+ return result;
+ }
+
+ /* find the "nearest" IBuilder of given class /
+ public Object getBuilder(Class builderClass,boolean required)
+ throws Exception
+ {
+ final IBuilder result = (IBuilder)getObjectFromStack(builders,builderClass);
+ if(result == null && required) {
+ throw new Exception(
+ "IBuilder of class '" + builderClass.getName() + "' not found on builders stack"
+ );
+ }
+ return result;
+ }*/
+
+ /** find the "nearest" container that implements the given interface on our stack
+ * @param required if true, ConverterException is thrown if no container found
+ * @param forWhichBuilder used in error message if container not found
+ */
+ public RtfContainer getContainer(Class containerClass, boolean required,
+ Object /*IBuilder*/ forWhichBuilder) throws Exception {
+ // TODO what to do if the desired container is not at the top of the stack?
+ // close top-of-stack container?
+ final RtfContainer result = (RtfContainer)getObjectFromStack(containers,
+ containerClass);
+
+ if (result == null && required) {
+ throw new Exception(
+ "No RtfContainer of class '" + containerClass.getName()
+ + "' available for '" + forWhichBuilder.getClass().getName() + "' builder"
+ );
+ }
+
+ return result;
+ }
+
+ /** push an RtfContainer on our stack */
+ public void pushContainer(RtfContainer c) {
+ containers.push(c);
+ }
+
+ /**
+ * In some cases an RtfContainer must be replaced by another one on the
+ * stack. This happens when handling nested fo:blocks for example: after
+ * handling a nested block the enclosing block must switch to a new
+ * paragraph container to handle what follows the nested block.
+ * TODO: what happens to elements that are "more on top" than oldC on the
+ * stack? shouldn't they be closed or something?
+ */
+ public void replaceContainer(RtfContainer oldC, RtfContainer newC)
+ throws Exception {
+ // treating the Stack as a Vector allows such manipulations (yes, I hear you screaming ;-)
+ final int index = containers.indexOf(oldC);
+ if (index < 0) {
+ throw new Exception("container to replace not found:" + oldC);
+ }
+ containers.setElementAt(newC, index);
+ }
+
+ /** pop the topmost RtfContainer from our stack */
+ public void popContainer() {
+ containers.pop();
+ }
+
+ /* push an IBuilder to our stack /
+ public void pushBuilder(IBuilder b)
+ {
+ builders.push(b);
+ }*/
+
+ /** pop the topmost IBuilder from our stack and return previous builder on stack
+ * @return null if builders stack is empty
+
+ public IBuilder popBuilderAndGetPreviousOne()
+ {
+ IBuilder result = null;
+ builders.pop();
+ if(!builders.isEmpty()) {
+ result = (IBuilder)builders.peek();
+ }
+ return result;
+ }
+ */
+ /** return the current TableContext */
+ public TableContext getTableContext() {
+ return (TableContext)tableContexts.peek();
+ }
+
+ /** push a TableContext to our stack */
+ public void pushTableContext(TableContext tc) {
+ tableContexts.push(tc);
+ }
+
+ /** pop a TableContext from our stack */
+ public void popTableContext() {
+ tableContexts.pop();
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 1999-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id: TableContext.java 227252 2005-08-03 19:30:55Z jeremias $ */
+
+package org.apache.fop.render.rtf.rtflib.tools;
+
+import java.util.List;
+
+import org.apache.commons.logging.impl.SimpleLog;
+import org.apache.commons.logging.Log;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.ITableColumnsInfo;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAttributes;
+
+
+/** Used when handling fo:table to hold information to build the table.
+ *
+ * Contributor(s):
+ * @author Bertrand Delacretaz <bdelacretaz@codeconsult.ch>
+ * @author Trembicki-Guy, Ed <GuyE@DNB.com>
+ * @author Boris Poudérous <boris.pouderous@eads-telecom.com>
+ * @author Peter Herweg <pherweg@web.de>
+ *
+ * This class was originally developed for the JFOR project and
+ * is now integrated into FOP.
+ */
+
+public class TableContext implements ITableColumnsInfo {
+ private final Log log = new SimpleLog("FOP/RTF");
+ private final BuilderContext context;
+ private final List colWidths = new java.util.ArrayList();
+ private int colIndex;
+
+ /**
+ * Added by Peter Herweg on 2002-06-29
+ * This ArrayList contains one element for each column in the table.
+ * value == 0 means there is no row-spanning
+ * value > 0 means there is row-spanning
+ * Each value in the list is decreased by 1 after each finished table-row
+ */
+ private final List colRowSpanningNumber = new java.util.ArrayList();
+
+ /**
+ * Added by Peter Herweg on 2002-06-29
+ * If there has a vertical merged cell to be created, its attributes are
+ * inherited from the corresponding MERGE_START-cell.
+ * For this purpose the attributes of a cell are stored in this array, as soon
+ * as a number-rows-spanned attribute has been found.
+ */
+ private final List colRowSpanningAttrs = new java.util.ArrayList();
+
+ private boolean bNextRowBelongsToHeader = false;
+
+ public void setNextRowBelongsToHeader(boolean value) {
+ this.bNextRowBelongsToHeader = value;
+ }
+
+ public boolean getNextRowBelongsToHeader() {
+ return bNextRowBelongsToHeader;
+ }
+
+ public TableContext(BuilderContext ctx) {
+ context = ctx;
+ }
+
+ public void setNextColumnWidth(Float width)
+ throws Exception {
+ colWidths.add(width);
+ }
+
+ //Added by Peter Herweg on 2002-06-29
+ public RtfAttributes getColumnRowSpanningAttrs() {
+ return (RtfAttributes)colRowSpanningAttrs.get(colIndex);
+ }
+
+ //Added by Peter Herweg on 2002-06-29
+ public Integer getColumnRowSpanningNumber() {
+ return (Integer)colRowSpanningNumber.get(colIndex);
+ }
+
+ //Added by Peter Herweg on 2002-06-29
+ public void setCurrentColumnRowSpanning(Integer iRowSpanning, RtfAttributes attrs)
+ throws Exception {
+
+ if (colIndex < colRowSpanningNumber.size()) {
+ colRowSpanningNumber.set(colIndex, iRowSpanning);
+ colRowSpanningAttrs.set(colIndex, attrs);
+ } else {
+ colRowSpanningNumber.add(iRowSpanning);
+ colRowSpanningAttrs.add(colIndex, attrs);
+ }
+ }
+
+ //Added by Peter Herweg on 2002-06-29
+ public void setNextColumnRowSpanning(Integer iRowSpanning,
+ RtfAttributes attrs) {
+ colRowSpanningNumber.add(iRowSpanning);
+ colRowSpanningAttrs.add(colIndex, attrs);
+ }
+
+ /**
+ * Added by Peter Herweg on 2002-06-29
+ * This function is called after each finished table-row.
+ * It decreases all values in colRowSpanningNumber by 1. If a value
+ * reaches 0 row-spanning is finished, and the value won't be decreased anymore.
+ */
+ public void decreaseRowSpannings() {
+ for (int z = 0; z < colRowSpanningNumber.size(); ++z) {
+ Integer i = (Integer)colRowSpanningNumber.get(z);
+
+ if (i.intValue() > 0) {
+ i = new Integer(i.intValue() - 1);
+ }
+
+ colRowSpanningNumber.set(z, i);
+
+ if (i.intValue() == 0) {
+ colRowSpanningAttrs.set(z, null);
+ }
+ }
+ }
+
+ /**
+ * Reset the column iteration index, meant to be called when creating a new row
+ * The 'public' modifier has been added by Boris Poudérous for
+ * 'number-columns-spanned' processing
+ */
+ public void selectFirstColumn() {
+ colIndex = 0;
+ }
+
+ /**
+ * Increment the column iteration index
+ * The 'public' modifier has been added by Boris Poudérous for
+ * 'number-columns-spanned' processing
+ */
+ public void selectNextColumn() {
+ colIndex++;
+ }
+
+ /**
+ * Get current column width according to column iteration index
+ * @return INVALID_COLUMN_WIDTH if we cannot find the value
+ * The 'public' modifier has been added by Boris Poudérous for
+ * 'number-columns-spanned' processing
+ */
+ public float getColumnWidth() {
+ try {
+ return ((Float)colWidths.get(colIndex)).floatValue();
+ } catch (IndexOutOfBoundsException ex) {
+ // this code contributed by Trembicki-Guy, Ed <GuyE@DNB.com>
+ log.warn("fo:table-column width not defined, using " + INVALID_COLUM_WIDTH);
+ return INVALID_COLUM_WIDTH;
+ }
+ }
+
+ /** Added by Boris Poudérous on 07/22/2002 */
+ public int getColumnIndex() {
+ return colIndex;
+ }
+ /** - end - */
+
+ /** Added by Boris Poudérous on 07/22/2002 */
+ public int getNumberOfColumns() {
+ return colWidths.size();
+ }
+ /** - end - */
+}
+