]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Bugzilla #35998
authorJeremias Maerki <jeremias@apache.org>
Fri, 5 Aug 2005 19:14:10 +0000 (19:14 +0000)
committerJeremias Maerki <jeremias@apache.org>
Fri, 5 Aug 2005 19:14:10 +0000 (19:14 +0000)
Context classes into the tools package.
Lonely interface ITableColumnsInfo to the others.
Suggested by: Guillaume Déflache <guillaume.at.anyware-tech.com>

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@230499 13f79535-47bb-0310-9956-ffa450edef68

14 files changed:
src/java/org/apache/fop/render/rtf/BuilderContext.java [deleted file]
src/java/org/apache/fop/render/rtf/RTFHandler.java
src/java/org/apache/fop/render/rtf/TableContext.java [deleted file]
src/java/org/apache/fop/render/rtf/rtflib/interfaces/ITableColumnsInfo.java [deleted file]
src/java/org/apache/fop/render/rtf/rtflib/interfaces/package.html [deleted file]
src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/IRtfTableContainer.java
src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ITableColumnsInfo.java [new file with mode: 0644]
src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfAfterBeforeBase.java
src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfExtraRowSet.java
src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfSection.java
src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTable.java
src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTableCell.java
src/java/org/apache/fop/render/rtf/rtflib/tools/BuilderContext.java [new file with mode: 0644]
src/java/org/apache/fop/render/rtf/rtflib/tools/TableContext.java [new file with mode: 0644]

diff --git a/src/java/org/apache/fop/render/rtf/BuilderContext.java b/src/java/org/apache/fop/render/rtf/BuilderContext.java
deleted file mode 100644 (file)
index d9b73f0..0000000
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * 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();
-    }
-
-}
index 06e02f9ffe8239b96f9334888adfbce741473f18..86b8487ddc2bdb618f965be074df341c38b1aeca 100644 (file)
@@ -82,6 +82,8 @@ import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTable;
 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;
 
 /**
diff --git a/src/java/org/apache/fop/render/rtf/TableContext.java b/src/java/org/apache/fop/render/rtf/TableContext.java
deleted file mode 100644 (file)
index 8ae98a9..0000000
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * 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 - */
-}
-
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/interfaces/ITableColumnsInfo.java b/src/java/org/apache/fop/render/rtf/rtflib/interfaces/ITableColumnsInfo.java
deleted file mode 100644 (file)
index 92da999..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/interfaces/package.html b/src/java/org/apache/fop/render/rtf/rtflib/interfaces/package.html
deleted file mode 100644 (file)
index 3403d00..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-<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
index 9e153aea0090e1cfac3a85398c54fe103214093a..a9dac056c73466f300798f90db318a2bc027ff68 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -27,7 +27,6 @@
 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
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ITableColumnsInfo.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ITableColumnsInfo.java
new file mode 100644 (file)
index 0000000..1f0f2c4
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * 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
index 7e7c32b7a5e56f3fca5b26079f226959d2108fe7..c91125bd4fdc9144990fdccbc0e90e684c457319 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -28,7 +28,6 @@ package org.apache.fop.render.rtf.rtflib.rtfdoc;
 
 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>
index af227e486979a2230471f27b566518c597f51e24..07090cfb394453de96533fe908740e4261c25dac 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -32,7 +32,6 @@ import java.util.List;
 import java.util.LinkedList;
 import java.util.Iterator;
 import java.util.Collections;
-import org.apache.fop.render.rtf.rtflib.interfaces.ITableColumnsInfo;
 
 
 /**
index 833a41ca1340128bad2505cfedbe845c39a6dbb4..b46d42703ced25417d29c5227a27de929049e600 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -28,7 +28,6 @@ package org.apache.fop.render.rtf.rtflib.rtfdoc;
 
 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
index 8cb39bf8698a14678a4dfb15100e967725a469ae..e376ff5a34526e93a8771df30b7f28654eb66c76 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * 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.
@@ -28,7 +28,6 @@ package org.apache.fop.render.rtf.rtflib.rtfdoc;
 
 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
index d772605ea5d7982e81676be0914b0e15403ebdbb..bf763133fab0daa1a234ffb5475b4542268a1faa 100644 (file)
@@ -29,7 +29,6 @@ package org.apache.fop.render.rtf.rtflib.rtfdoc;
 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
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/tools/BuilderContext.java b/src/java/org/apache/fop/render/rtf/rtflib/tools/BuilderContext.java
new file mode 100644 (file)
index 0000000..257d4a5
--- /dev/null
@@ -0,0 +1,166 @@
+/*
+ * 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();
+    }
+
+}
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/tools/TableContext.java b/src/java/org/apache/fop/render/rtf/rtflib/tools/TableContext.java
new file mode 100644 (file)
index 0000000..c97d022
--- /dev/null
@@ -0,0 +1,182 @@
+/*
+ * 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 - */
+}
+