]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
added support for fo:footnote
authorPeter Herweg <pherweg@apache.org>
Sat, 10 Jan 2004 19:43:58 +0000 (19:43 +0000)
committerPeter Herweg <pherweg@apache.org>
Sat, 10 Jan 2004 19:43:58 +0000 (19:43 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@197155 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/fo/FOInputHandler.java
src/java/org/apache/fop/fo/FOTreeHandler.java
src/java/org/apache/fop/fo/flow/Footnote.java
src/java/org/apache/fop/fo/flow/FootnoteBody.java
src/java/org/apache/fop/render/mif/MIFHandler.java
src/java/org/apache/fop/render/rtf/RTFHandler.java
src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfFootnote.java [new file with mode: 0644]
src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfTextrun.java

index 49c99bf0656e006c2ac3d01813c14d4fc19aad28..ea01d73fb37430a6f52bb2f3d9c00acb457a33be 100644 (file)
@@ -58,6 +58,8 @@ import org.apache.fop.apps.FOPException;
 import org.apache.fop.fo.flow.BasicLink;
 import org.apache.fop.fo.flow.Block;
 import org.apache.fop.fo.flow.ExternalGraphic;
+import org.apache.fop.fo.flow.Footnote;
+import org.apache.fop.fo.flow.FootnoteBody;
 import org.apache.fop.fo.flow.Inline;
 import org.apache.fop.fo.flow.InstreamForeignObject;
 import org.apache.fop.fo.flow.Leader;
@@ -365,9 +367,28 @@ public abstract class FOInputHandler extends AbstractLogEnabled {
     public abstract void foreignObject(InstreamForeignObject ifo);
 
     /**
-     * Process a footnote.
+     * Process the start of a footnote.
+     * @param footnote Footnote that is starting
      */
-    public abstract void footnote();
+    public abstract void startFootnote(Footnote footnote);
+    
+    /**
+     * Process the ending of a footnote.
+     * @param footnote Footnote that is ending
+     */
+    public abstract void endFootnote(Footnote footnote);
+
+    /**
+     * Process the start of a footnote body.
+     * @param body FootnoteBody that is starting
+     */
+    public abstract void startFootnoteBody(FootnoteBody body);
+    
+    /**
+     * Process the ending of a footnote body.
+     * @param body FootnoteBody that is ending
+     */
+    public abstract void endFootnoteBody(FootnoteBody body);
 
     /**
      * Process a Leader.
index 25ddc66a1f0d619df90a077ce94fe59ee0669986..ab8fd5adda73027a9f22ca60f10b03e4f36a7963 100644 (file)
@@ -62,6 +62,8 @@ import org.apache.fop.apps.FOPException;
 import org.apache.fop.fo.flow.BasicLink;
 import org.apache.fop.fo.flow.Block;
 import org.apache.fop.fo.flow.ExternalGraphic;
+import org.apache.fop.fo.flow.Footnote;
+import org.apache.fop.fo.flow.FootnoteBody;
 import org.apache.fop.fo.flow.InstreamForeignObject;
 import org.apache.fop.fo.flow.Inline;
 import org.apache.fop.fo.flow.Leader;
@@ -446,11 +448,29 @@ public class FOTreeHandler extends FOInputHandler {
     }
 
     /**
-     * @see org.apache.fop.fo.FOInputHandler#footnote()
+     * @see org.apache.fop.fo.FOInputHandler#startFootnote()
      */
-    public void footnote() {
+    public void startFootnote(Footnote footnote) {
     }
-
+    
+    /**
+     * @see org.apache.fop.fo.FOInputHandler#endFootnote()
+     */
+    public void endFootnote(Footnote footnote) {
+    }
+    
+    /**
+     * @see org.apache.fop.fo.FOInputHandler#startFootnoteBody()
+     */
+    public void startFootnoteBody(FootnoteBody body) {
+    }
+    
+    /**
+     * @see org.apache.fop.fo.FOInputHandler#endFootnoteBody()
+     */
+    public void endFootnoteBody(FootnoteBody body) {
+    }
+    
     /**
      * @see org.apache.fop.fo.FOInputHandler#leader(Leader)
      */
index 8c5dd69324532941c8178c1b5caae04e8ee18624..ce9e0d06dc4e84775df7a188cb8c82307fc6f157 100644 (file)
  */
 package org.apache.fop.fo.flow;
 
+// XML
+import org.xml.sax.Attributes;
+
+// FOP
+import org.apache.fop.apps.FOPException;
 import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.FOTreeVisitor;
 import org.apache.fop.fo.FObj;
@@ -95,6 +100,20 @@ public class Footnote extends FObj {
     public void acceptVisitor(FOTreeVisitor fotv) {
         fotv.serveFootnote(this);
     }
+    
+    /**
+     * @see org.apache.fop.fo.FObj#handleAttrs
+     */
+    public void handleAttrs(Attributes attlist) throws FOPException {
+        super.handleAttrs(attlist);
+
+        getFOTreeControl().getFOInputHandler().startFootnote(this);
+    }
 
+    protected void end() {
+        super.end();
+        
+        getFOTreeControl().getFOInputHandler().endFootnote(this);
+    }
 }
 
index dec8cde436474d2df59261b4848259f6cfee9bee..05596b1c4a72bdd1046bc81f70a5a106a03b6c6c 100644 (file)
  */
 package org.apache.fop.fo.flow;
 
+// XML
+import org.xml.sax.Attributes;
+
 // FOP
+import org.apache.fop.apps.FOPException;
 import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.FObj;
 import org.apache.fop.fo.FOTreeVisitor;
@@ -79,4 +83,18 @@ public class FootnoteBody extends FObj {
         fotv.serveFootnoteBody(this);
     }
 
+    /**
+     * @see org.apache.fop.fo.FObj#handleAttrs
+     */
+    public void handleAttrs(Attributes attlist) throws FOPException {
+        super.handleAttrs(attlist);
+
+        getFOTreeControl().getFOInputHandler().startFootnoteBody(this);
+    }
+
+    protected void end() {
+        super.end();
+        
+        getFOTreeControl().getFOInputHandler().endFootnoteBody(this);
+    }
 }
index 63eab22a056e9f9fc97854e32511544211dc9412..9b787c8c99c48883fa4cf94e5900d66d55a25293 100644 (file)
@@ -60,6 +60,8 @@ import org.apache.fop.fo.FOInputHandler;
 import org.apache.fop.fo.flow.BasicLink;
 import org.apache.fop.fo.flow.Block;
 import org.apache.fop.fo.flow.ExternalGraphic;
+import org.apache.fop.fo.flow.Footnote;
+import org.apache.fop.fo.flow.FootnoteBody;
 import org.apache.fop.fo.flow.InstreamForeignObject;
 import org.apache.fop.fo.flow.Inline;
 import org.apache.fop.fo.flow.Leader;
@@ -429,11 +431,29 @@ public class MIFHandler extends FOInputHandler {
     }
 
     /**
-     * @see org.apache.fop.fo.FOInputHandler#footnote()
+     * @see org.apache.fop.fo.FOInputHandler#startFootnote()
      */
-    public void footnote() {
+    public void startFootnote(Footnote footnote) {
     }
-
+    
+    /**
+     * @see org.apache.fop.fo.FOInputHandler#endFootnote()
+     */
+    public void endFootnote(Footnote footnote) {
+    }
+    
+    /**
+     * @see org.apache.fop.fo.FOInputHandler#startFootnoteBody()
+     */
+    public void startFootnoteBody(FootnoteBody body) {
+    }
+    
+    /**
+     * @see org.apache.fop.fo.FOInputHandler#endFootnoteBody()
+     */
+    public void endFootnoteBody(FootnoteBody body) {
+    }
+    
     /**
      * @see org.apache.fop.fo.FOInputHandler#leader(Leader)
      */
index f3122b3324e314f2717222a1609f4e55fef9d7f7..7a1ffe0a6b3ba069f3ddcb576e672bf1bbb210f6 100644 (file)
@@ -64,6 +64,8 @@ import org.apache.fop.datatypes.FixedLength;
 import org.apache.fop.fo.flow.BasicLink;
 import org.apache.fop.fo.flow.Block;
 import org.apache.fop.fo.flow.ExternalGraphic;
+import org.apache.fop.fo.flow.Footnote;
+import org.apache.fop.fo.flow.FootnoteBody;
 import org.apache.fop.fo.flow.Inline;
 import org.apache.fop.fo.flow.InstreamForeignObject;
 import org.apache.fop.fo.flow.Leader;
@@ -96,6 +98,7 @@ import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfDocumentArea;
 import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfElement;
 import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfExternalGraphic;
 import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfFile;
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfFootnote;
 import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfHyperLink;
 import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfList;
 import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfListItem;
@@ -852,9 +855,80 @@ public class RTFHandler extends FOInputHandler {
     }
 
     /**
-     * @see org.apache.fop.fo.FOInputHandler#footnote()
+     * @see org.apache.fop.fo.FOInputHandler#startFootnote()
      */
-    public void footnote() {
+    public void startFootnote(Footnote footnote) {
+        try {
+            RtfAttributes rtfAttr
+                = TextAttributesConverter.convertAttributes(footnote.propertyList, null);
+                    
+            IRtfTextrunContainer container 
+                = (IRtfTextrunContainer)builderContext.getContainer(
+                    IRtfTextrunContainer.class,
+                    true, this);
+
+            RtfTextrun textrun = container.getTextrun();
+            RtfFootnote rtfFootnote = textrun.addFootnote();
+            
+            builderContext.pushContainer(rtfFootnote);
+            
+        } catch (IOException ioe) {
+            // TODO could we throw Exception in all FOInputHandler events?
+            log.error("startFootnote: " + ioe.getMessage());
+            throw new Error("IOException: " + ioe);
+        } catch (Exception e) {
+            log.error("startFootnote: " + e.getMessage());
+            throw new Error("Exception: " + e);
+        }
+    }
+    
+    /**
+     * @see org.apache.fop.fo.FOInputHandler#endFootnote()
+     */
+    public void endFootnote(Footnote footnote) {
+        builderContext.popContainer();
+    }
+    
+    /**
+     * @see org.apache.fop.fo.FOInputHandler#startFootnoteBody()
+     */
+    public void startFootnoteBody(FootnoteBody body) {
+        try {
+            RtfFootnote rtfFootnote
+                = (RtfFootnote)builderContext.getContainer(
+                    RtfFootnote.class,
+                    true, this);
+
+            rtfFootnote.startBody();
+        } catch (IOException ioe) {
+            // TODO could we throw Exception in all FOInputHandler events?
+            log.error("startFootnoteBody: " + ioe.getMessage());
+            throw new Error("IOException: " + ioe);
+        } catch (Exception e) {
+            log.error("startFootnoteBody: " + e.getMessage());
+            throw new Error("Exception: " + e);
+        }
+    }
+    
+    /**
+     * @see org.apache.fop.fo.FOInputHandler#endFootnoteBody()
+     */
+    public void endFootnoteBody(FootnoteBody body) {
+        try {
+            RtfFootnote rtfFootnote
+                = (RtfFootnote)builderContext.getContainer(
+                    RtfFootnote.class,
+                    true, this);
+
+            rtfFootnote.endBody();
+        } catch (IOException ioe) {
+            // TODO could we throw Exception in all FOInputHandler events?
+            log.error("endFootnoteBody: " + ioe.getMessage());
+            throw new Error("IOException: " + ioe);
+        } catch (Exception e) {
+            log.error("endFootnoteBody: " + e.getMessage());
+            throw new Error("Exception: " + e);
+        }
     }
 
     /**
diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfFootnote.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/RtfFootnote.java
new file mode 100644 (file)
index 0000000..3594655
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * $Id$
+ * ============================================================================
+ *                    The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ *    this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ *    this list of conditions and the following disclaimer in the documentation
+ *    and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ *    include the following acknowledgment: "This product includes software
+ *    developed by the Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself, if
+ *    and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "FOP" and "Apache Software Foundation" must not be used to
+ *    endorse or promote products derived from this software without prior
+ *    written permission. For written permission, please contact
+ *    apache@apache.org.
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ *    "Apache" appear in their name, without prior written permission of the
+ *    Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ============================================================================
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation and was originally created by
+ * James Tauber <jtauber@jtauber.com>. For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/>.
+ */
+
+package org.apache.fop.render.rtf.rtflib.rtfdoc;
+
+//Java
+import java.io.Writer;
+import java.io.IOException;
+
+//FOP
+import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfTextrun;
+
+/**  Model of an RTF footnote
+ *  @author Peter Herweg, pherweg@web.de
+ */
+public class RtfFootnote extends RtfContainer
+        implements IRtfTextrunContainer {
+    RtfTextrun textrunInline = null;
+    RtfTextrun textrunBody = null;
+    boolean bBody = false;
+
+    /** Create an RTF list item as a child of given container with default attributes */
+    RtfFootnote(RtfContainer parent, Writer w) throws IOException {
+        super(parent, w);
+        textrunInline = new RtfTextrun(this, writer, null);
+        textrunBody = new RtfTextrun(this, writer, null);
+    }
+
+    public RtfTextrun getTextrun() throws IOException {
+        if (bBody) {
+            return textrunBody;
+        } else {
+            return textrunInline;
+        }
+    }
+
+    /**
+    * write RTF code of all our children
+    * @throws IOException for I/O problems
+    */
+    protected void writeRtfContent() throws IOException {
+        textrunInline.writeRtfContent();
+        
+        writeGroupMark(true);
+        writeControlWord("footnote");
+        writeControlWord("ftnalt");      
+        textrunBody.writeRtfContent();
+        writeGroupMark(false);
+    }
+    
+    public void startBody() {
+        bBody = true;
+    }
+    
+    public void endBody() {
+        bBody = false;
+    }
+}
index 378b98db2f6b4eb64277d5ea84a542a422fe35c2..79f71dcb03c157014300341d3088586a0236b9d6 100644 (file)
@@ -164,6 +164,10 @@ public class RtfTextrun extends RtfContainer {
         RtfString r = new RtfString(this, writer, s);
     }
     
+    public RtfFootnote addFootnote() throws IOException {
+        return new RtfFootnote(this, writer);
+    }
+    
     public void addParagraphBreak() throws IOException {
         RtfParagraphBreak r = new RtfParagraphBreak(this, writer);
     }