]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
PR:
authorGlen Mazza <gmazza@apache.org>
Thu, 28 Oct 2004 00:06:47 +0000 (00:06 +0000)
committerGlen Mazza <gmazza@apache.org>
Thu, 28 Oct 2004 00:06:47 +0000 (00:06 +0000)
Obtained from:
Submitted by:
Reviewed by:

1.) Changed OffDocumentItem from an interface to an abstract base class.

2.) Removed the "extensions" package.

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

src/java/org/apache/fop/area/AreaTreeHandler.java
src/java/org/apache/fop/area/AreaTreeModel.java
src/java/org/apache/fop/area/BookmarkData.java [new file with mode: 0644]
src/java/org/apache/fop/area/OffDocumentItem.java
src/java/org/apache/fop/area/RenderPagesModel.java
src/java/org/apache/fop/area/StorePagesModel.java
src/java/org/apache/fop/area/extensions/BookmarkData.java [deleted file]
src/java/org/apache/fop/render/pdf/PDFRenderer.java

index ca5d2a2a0b76f8c59ef4f4c3342e20bd0fc88eac..911def5bed4a46878c44283910f87fde11f30e13 100644 (file)
@@ -33,7 +33,6 @@ import org.xml.sax.SAXException;
 // Apache
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.apps.FOUserAgent;
-import org.apache.fop.area.extensions.BookmarkData;
 import org.apache.fop.fo.FOEventHandler;
 import org.apache.fop.fo.extensions.Outline;
 import org.apache.fop.fo.extensions.Bookmarks;
@@ -317,7 +316,7 @@ public class AreaTreeHandler extends FOEventHandler {
                 }
             }
         } else {
-            model.handleOffDocumentItem(ext, OffDocumentItem.IMMEDIATELY);
+            model.handleOffDocumentItem(ext);
         }
     }
 }
index 28d9ff4c508a8a27b77c4442e542cdb8b7609119..c1fe32d1ef4839c985c504a9bc24f0246242bf65 100644 (file)
@@ -45,9 +45,8 @@ public abstract class AreaTreeModel {
     /**
      * Handle an OffDocumentItem 
      * @param ext the extension to handle
-     * @param when when the extension should be handled
      */
-    public abstract void handleOffDocumentItem(OffDocumentItem ext, int when);
+    public abstract void handleOffDocumentItem(OffDocumentItem ext);
 
     /**
      * Signal the end of the document for any processing.
diff --git a/src/java/org/apache/fop/area/BookmarkData.java b/src/java/org/apache/fop/area/BookmarkData.java
new file mode 100644 (file)
index 0000000..6b1ad7c
--- /dev/null
@@ -0,0 +1,205 @@
+/*
+ * 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$ */
+package org.apache.fop.area;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.HashMap;
+
+/**
+ * This class holds the PDF bookmark OffDocumentItem
+ */
+public class BookmarkData extends OffDocumentItem implements Resolvable {
+    private ArrayList subData = new ArrayList();
+    private HashMap idRefs = new HashMap();
+
+    // area tree model for the top level object to activate when resolved
+    private AreaTreeModel areaTreeModel = null;
+
+    private String idRef;
+    private PageViewport pageRef = null;
+    private String label = null;
+
+    /**
+     * Create a new bookmark data object.
+     * This should only be call by the top level element as the
+     * id reference will be null.
+     */
+    public BookmarkData() {
+        idRef = null;
+        whenToProcess = IMMEDIATELY;
+    }
+
+    /**
+     * Create a new pdf bookmark data object.
+     * This is used by the outlines to create a data object
+     * with a id reference. The id reference is to be resolved.
+     *
+     * @param id the id reference
+     */
+    public BookmarkData(String id) {
+        idRef = id;
+        idRefs.put(idRef, this);
+    }
+
+    /**
+     * Set the area tree model
+     * This should only be called for the top level element.
+     * The area tree model is used once resolving is complete.
+     *
+     * @param atm the area tree model for the current document
+     */
+    public void setAreaTreeModel(AreaTreeModel atm) {
+        areaTreeModel = atm;
+    }
+
+    /**
+     * Get the id reference for this data.
+     *
+     * @return the id reference
+     */
+    public String getID() {
+        return idRef;
+    }
+
+    /**
+     * Add the child bookmark data object.
+     * This adds a child bookmark in the bookmark hierarchy.
+     *
+     * @param sub the child bookmark data
+     */
+    public void addSubData(BookmarkData sub) {
+        subData.add(sub);
+        idRefs.put(sub.getID(), sub);
+        String[] ids = sub.getIDs();
+        for (int count = 0; count < ids.length; count++) {
+            idRefs.put(ids[count], sub);
+        }
+    }
+
+    /**
+     * Set the label for this bookmark.
+     *
+     * @param l the string label
+     */
+    public void setLabel(String l) {
+        label = l;
+    }
+
+    /**
+     * Get the label for this bookmark object.
+     *
+     * @return the label string
+     */
+    public String getLabel() {
+        return label;
+    }
+
+    /**
+     * Get the size of child data objects.
+     *
+     * @return the number of child bookmark data
+     */
+    public int getCount() {
+        return subData.size();
+    }
+
+    /**
+     * Get the child data object.
+     *
+     * @param count the index to get
+     * @return the child bookmark data
+     */
+    public BookmarkData getSubData(int count) {
+        return (BookmarkData)subData.get(count);
+    }
+
+    /**
+     * Get the page that this resolves to.
+     *
+     * @return the PageViewport that this extension resolves to
+     */
+    public PageViewport getPage() {
+        return pageRef;
+    }
+
+    /**
+     * Check if this resolvable object has been resolved.
+     * Once the id reference is null then it has been resolved.
+     *
+     * @return true if this has been resolved
+     */
+    public boolean isResolved() {
+        return idRefs == null;
+    }
+
+    /**
+     * Get the id references held by this object.
+     * Also includes all id references of all children.
+     *
+     * @return the array of id references
+     */
+    public String[] getIDs() {
+        return (String[])idRefs.keySet().toArray(new String[] {});
+    }
+
+    /**
+     * Resolve this resolvable object.
+     * This resolves the id reference and if possible also
+     * resolves id references of child elements that have the same
+     * id reference.
+     *
+     * @param id the id reference being resolved
+     * @param pages the list of pages the the id reference resolves to
+     */
+    public void resolve(String id, List pages) {
+        // this method is buggy
+
+        if (!id.equals(idRef)) {
+            BookmarkData bd = (BookmarkData)idRefs.get(id);
+            idRefs.remove(id);
+            if (bd != null) {
+                bd.resolve(id, pages);
+                if (bd.isResolved()) {
+                    checkFinish();
+                }
+            } else if (idRef == null) {
+                checkFinish();
+            }
+        } else {
+            if (pages != null) {
+                pageRef = (PageViewport)pages.get(0);
+            }
+            // TODO get rect area of id on page
+
+            idRefs.remove(idRef);
+            checkFinish();
+        }
+    }
+
+    private void checkFinish() {
+        if (idRefs.size() == 0) {
+            idRefs = null;
+            if (areaTreeModel != null) {
+                areaTreeModel.handleOffDocumentItem(this);
+            }
+        }
+    }
+}
+
index 78ebb6506200d111cd486cefee59ec675c9967e8..8f740bb1a4fe73c0d92f82db3fc5333ee48cd248 100644 (file)
 package org.apache.fop.area;
 
 /**
- * Interface for objects that are processed by the renderer outside
+ * Abstract base class for objects that are processed by the renderer outside
  * of the actual document.
  * This object can be handled by the renderer according to three
  * possibilities, IMMEDIATELY, AFTER_PAGE, or END_OF_DOC.
  */
-public interface OffDocumentItem {
+public abstract class OffDocumentItem {
+
     /**
-     * Render this extension immediately when
+     * Process this extension immediately when
      * being handled by the area tree.
      */
     public static final int IMMEDIATELY = 0;
 
     /**
-     * Render this extension after the next page is rendered
+     * Process this extension after the next page is rendered
      * or prepared when being handled by the area tree.
      */
     public static final int AFTER_PAGE = 1;
 
     /**
-     * Render this extension at the end of the document once
+     * Process this extension at the end of the document once
      * all pages have been fully rendered.
      */
     public static final int END_OF_DOC = 2;
 
+
+    protected int whenToProcess = IMMEDIATELY;
+    
+    /**
+     * Get an indicator of when this item should be processed
+     * @return int constant (IMMEDIATELY, AFTER_PAGE, END_OF_DOC)
+     */
+    public int getWhenToProcess() {
+        return whenToProcess;
+    }
 }
index 16135408e2fe5393ee4731b19cf49b50187e0343..ad8a125b6e27a42d3b3fcf8e53ff2db455816dff 100644 (file)
@@ -52,8 +52,8 @@ public class RenderPagesModel extends StorePagesModel {
      * Pages that have been prepared but not rendered yet.
      */
     protected List prepared = new java.util.ArrayList();
-    private List pendingExt = new java.util.ArrayList();
-    private List endDocExt = new java.util.ArrayList();
+    private List pendingODI = new java.util.ArrayList();
+    private List endDocODI = new java.util.ArrayList();
 
     /**
      * Create a new render pages model with the given renderer.
@@ -126,8 +126,8 @@ public class RenderPagesModel extends StorePagesModel {
         boolean cont = checkPreparedPages(page);
 
         if (cont) {
-            processOffDocumentItems(pendingExt);
-            pendingExt.clear();
+            processOffDocumentItems(pendingODI);
+            pendingODI.clear();
         }
     }
 
@@ -175,41 +175,40 @@ public class RenderPagesModel extends StorePagesModel {
     }
 
     /**
-     * @see org.apache.fop.area.AreaTreeModel#handleOffDocumentItem(OffDocumentItem, int)
+     * @see org.apache.fop.area.AreaTreeModel#handleOffDocumentItem(OffDocumentItem)
      */
-    public void handleOffDocumentItem(OffDocumentItem ext, int when) {
-        switch(when) {
+    public void handleOffDocumentItem(OffDocumentItem oDI) {
+        switch(oDI.getWhenToProcess()) {
             case OffDocumentItem.IMMEDIATELY:
-                renderer.processOffDocumentItem(ext);
+                renderer.processOffDocumentItem(oDI);
                 break;
             case OffDocumentItem.AFTER_PAGE:
-                pendingExt.add(ext);
+                pendingODI.add(oDI);
                 break;
             case OffDocumentItem.END_OF_DOC:
-                endDocExt.add(ext);
+                endDocODI.add(oDI);
                 break;
         }
     }
 
     private void processOffDocumentItems(List list) {
         for (int count = 0; count < list.size(); count++) {
-            OffDocumentItem ext = (OffDocumentItem)list.get(count);
-            renderer.processOffDocumentItem(ext);
+            OffDocumentItem oDI = (OffDocumentItem)list.get(count);
+            renderer.processOffDocumentItem(oDI);
         }
     }
 
     /**
-     * End the document. Render any end document extensions.
+     * End the document. Render any end document OffDocumentItems
      * @see org.apache.fop.area.AreaTreeModel#endDocument()
      */
     public void endDocument() throws SAXException {
         // render any pages that had unresolved ids
         checkPreparedPages(null);
 
-        processOffDocumentItems(pendingExt);
-        pendingExt.clear();
-
-        processOffDocumentItems(endDocExt);
+        processOffDocumentItems(pendingODI);
+        pendingODI.clear();
+        processOffDocumentItems(endDocODI);
         
         try {
             renderer.stopRenderer();
index 7cfe414343a4792ba71773ec2b06d418cf082cbf..e293d5faf4de3cdf4e127683ec16e9129795f287 100644 (file)
@@ -33,7 +33,7 @@ import org.xml.sax.SAXException;
 public class StorePagesModel extends AreaTreeModel {
     private List pageSequence = null;
     private List currSequence;
-    private List extensions = new java.util.ArrayList();
+    private List offDocumentItems = new java.util.ArrayList();
 
     /**
      * Create a new store pages model
@@ -92,11 +92,11 @@ public class StorePagesModel extends AreaTreeModel {
     }
 
     /**
-     * @see org.apache.fop.area.AreaTreeModel#handleOffDocumentItem(OffDocumentItem, int)
+     * @see org.apache.fop.area.AreaTreeModel#handleOffDocumentItem(OffDocumentItem)
      */
-    public void handleOffDocumentItem(OffDocumentItem ext, int when) {
+    public void handleOffDocumentItem(OffDocumentItem ext) {
         int seq, page;
-        switch(when) {
+        switch(ext.getWhenToProcess()) {
             case OffDocumentItem.IMMEDIATELY:
                 seq = pageSequence == null ? 0 : pageSequence.size();
                 page = currSequence == null ? 0 : currSequence.size();
@@ -106,26 +106,26 @@ public class StorePagesModel extends AreaTreeModel {
             case OffDocumentItem.END_OF_DOC:
                 break;
         }
-        extensions.add(ext);
+        offDocumentItems.add(ext);
     }
 
     /**
-     * Get the list of extensions that apply at a particular
+     * Get the list of OffDocumentItems that apply at a particular
      * position in the document.
      * @param seq the page sequence number
      * @param count the page count in the sequence
-     * @return the list of extensions
+     * @return the list of OffDocumentItems
      */
-    public List getExtensions(int seq, int count) {
+    public List getOffDocumentItems(int seq, int count) {
         return null;
     }
 
     /**
-     * Get the end of document extensions for this stroe pages model.
-     * @return the list of end extensions
+     * Get the end of document OffDocumentItems for this store pages model.
+     * @return the list of end OffDocumentItems
      */
-    public List getEndExtensions() {
-        return extensions;
+    public List getEndOffDocumentItems() {
+        return offDocumentItems;
     }
 
     /**
diff --git a/src/java/org/apache/fop/area/extensions/BookmarkData.java b/src/java/org/apache/fop/area/extensions/BookmarkData.java
deleted file mode 100644 (file)
index 3f6a215..0000000
+++ /dev/null
@@ -1,209 +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$ */
-package org.apache.fop.area.extensions;
-
-import org.apache.fop.area.PageViewport;
-import org.apache.fop.area.Resolvable;
-import org.apache.fop.area.OffDocumentItem;
-import org.apache.fop.area.AreaTreeModel;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.HashMap;
-
-/**
- * This class holds the PDF bookmark extension data.
- */
-public class BookmarkData implements Resolvable, OffDocumentItem {
-    private ArrayList subData = new ArrayList();
-    private HashMap idRefs = new HashMap();
-
-    // area tree model for the top level object to activate when resolved
-    private AreaTreeModel areaTreeModel = null;
-
-    private String idRef;
-    private PageViewport pageRef = null;
-    private String label = null;
-
-    /**
-     * Create a new bookmark data object.
-     * This should only be call by the top level element as the
-     * id reference will be null.
-     */
-    public BookmarkData() {
-        idRef = null;
-    }
-
-    /**
-     * Create a new pdf bookmark data object.
-     * This is used by the outlines to create a data object
-     * with a id reference. The id reference is to be resolved.
-     *
-     * @param id the id reference
-     */
-    public BookmarkData(String id) {
-        idRef = id;
-        idRefs.put(idRef, this);
-    }
-
-    /**
-     * Set the area tree model
-     * This should only be called for the top level element.
-     * The area tree model is used once resolving is complete.
-     *
-     * @param atm the area tree model for the current document
-     */
-    public void setAreaTreeModel(AreaTreeModel atm) {
-        areaTreeModel = atm;
-    }
-
-    /**
-     * Get the id reference for this data.
-     *
-     * @return the id reference
-     */
-    public String getID() {
-        return idRef;
-    }
-
-    /**
-     * Add the child bookmark data object.
-     * This adds a child bookmark in the bookmark hierarchy.
-     *
-     * @param sub the child bookmark data
-     */
-    public void addSubData(BookmarkData sub) {
-        subData.add(sub);
-        idRefs.put(sub.getID(), sub);
-        String[] ids = sub.getIDs();
-        for (int count = 0; count < ids.length; count++) {
-            idRefs.put(ids[count], sub);
-        }
-    }
-
-    /**
-     * Set the label for this bookmark.
-     *
-     * @param l the string label
-     */
-    public void setLabel(String l) {
-        label = l;
-    }
-
-    /**
-     * Get the label for this bookmark object.
-     *
-     * @return the label string
-     */
-    public String getLabel() {
-        return label;
-    }
-
-    /**
-     * Get the size of child data objects.
-     *
-     * @return the number of child bookmark data
-     */
-    public int getCount() {
-        return subData.size();
-    }
-
-    /**
-     * Get the child data object.
-     *
-     * @param count the index to get
-     * @return the child bookmark data
-     */
-    public BookmarkData getSubData(int count) {
-        return (BookmarkData)subData.get(count);
-    }
-
-    /**
-     * Get the page that this resolves to.
-     *
-     * @return the PageViewport that this extension resolves to
-     */
-    public PageViewport getPage() {
-        return pageRef;
-    }
-
-    /**
-     * Check if this resolvable object has been resolved.
-     * Once the id reference is null then it has been resolved.
-     *
-     * @return true if this has been resolved
-     */
-    public boolean isResolved() {
-        return idRefs == null;
-    }
-
-    /**
-     * Get the id references held by this object.
-     * Also includes all id references of all children.
-     *
-     * @return the array of id references
-     */
-    public String[] getIDs() {
-        return (String[])idRefs.keySet().toArray(new String[] {});
-    }
-
-    /**
-     * Resolve this resolvable object.
-     * This resolves the id reference and if possible also
-     * resolves id references of child elements that have the same
-     * id reference.
-     *
-     * @param id the id reference being resolved
-     * @param pages the list of pages the the id reference resolves to
-     */
-    public void resolve(String id, List pages) {
-        // this method is buggy
-
-        if (!id.equals(idRef)) {
-            BookmarkData bd = (BookmarkData)idRefs.get(id);
-            idRefs.remove(id);
-            if (bd != null) {
-                bd.resolve(id, pages);
-                if (bd.isResolved()) {
-                    checkFinish();
-                }
-            } else if (idRef == null) {
-                checkFinish();
-            }
-        } else {
-            if (pages != null) {
-                pageRef = (PageViewport)pages.get(0);
-            }
-            // TODO get rect area of id on page
-
-            idRefs.remove(idRef);
-            checkFinish();
-        }
-    }
-
-    private void checkFinish() {
-        if (idRefs.size() == 0) {
-            idRefs = null;
-            if (areaTreeModel != null) {
-                areaTreeModel.handleOffDocumentItem(this, OffDocumentItem.AFTER_PAGE);
-            }
-        }
-    }
-}
-
index 340617580b160f8b848d30a2e3cce63f467672fc..13d1edb1a597aa43e5e8b475967870a44240110b 100644 (file)
@@ -47,7 +47,7 @@ import org.apache.fop.area.PageViewport;
 import org.apache.fop.area.RegionViewport;
 import org.apache.fop.area.Trait;
 import org.apache.fop.area.OffDocumentItem;
-import org.apache.fop.area.extensions.BookmarkData;
+import org.apache.fop.area.BookmarkData;
 import org.apache.fop.area.inline.Character;
 import org.apache.fop.area.inline.TextArea;
 import org.apache.fop.area.inline.Viewport;