]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
PR:
authorGlen Mazza <gmazza@apache.org>
Tue, 14 Dec 2004 23:16:44 +0000 (23:16 +0000)
committerGlen Mazza <gmazza@apache.org>
Tue, 14 Dec 2004 23:16:44 +0000 (23:16 +0000)
Obtained from:
Submitted by:
Reviewed by:
AreaTreeModel detached from BookmarkData; more code commenting.

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

src/java/org/apache/fop/area/AreaTreeHandler.java
src/java/org/apache/fop/area/BookmarkData.java
src/java/org/apache/fop/area/OffDocumentItem.java

index 3439baa548966172f4a2ff84ea2eaf3d941d5a8c..186ae558f441d1ac4c835fb0b2955553d06c046c 100644 (file)
@@ -249,8 +249,7 @@ public class AreaTreeHandler extends FOEventHandler {
             return;
         }
 
-        log.debug("adding bookmarks to area tree");
-        BookmarkData data = new BookmarkData(model);
+        BookmarkData data = new BookmarkData();
         for (int count = 0; count < bookmarks.getOutlines().size(); count++) {
             Outline out = (Outline)(bookmarks.getOutlines()).get(count);
             data.addSubData(createBookmarkData(out));
@@ -281,21 +280,27 @@ public class AreaTreeHandler extends FOEventHandler {
      * Add a OffDocumentItem to the area tree model
      * This checks if the OffDocumentItem is resolvable and attempts
      * to resolve or add the resolvable ids for later resolution.
-     * @param ext the OffDocumentItem to add.
+     * @param odi the OffDocumentItem to add.
      */
-    private void addOffDocumentItem(OffDocumentItem ext) {
-        if (ext instanceof Resolvable) {
-            Resolvable res = (Resolvable) ext;
+    private void addOffDocumentItem(OffDocumentItem odi) {
+        if (odi instanceof Resolvable) {
+            Resolvable res = (Resolvable) odi;
             String[] ids = res.getIDs();
             for (int count = 0; count < ids.length; count++) {
                 if (idLocations.containsKey(ids[count])) {
                     res.resolveIDRef(ids[count], (List) idLocations.get(ids[count]));
                 } else {
+                    log.warn(odi.getName() + ": Unresolved id reference \"" 
+                        + ids[count] + "\" found.");
                     addUnresolvedIDRef(ids[count], res);
                 }
             }
+            // check to see if ODI is now fully resolved, if so process it
+            if (res.isResolved()) {
+                model.handleOffDocumentItem(odi);
+            }
         } else {
-            model.handleOffDocumentItem(ext);
+            model.handleOffDocumentItem(odi);
         }
     }
 }
index 70bc1fa365ffbd2daf1ee791abfdd1d8988f1e7d..5384a7cdf82076fd5566b74a9ca6c691e86ff0c0 100644 (file)
@@ -23,29 +23,32 @@ import java.util.List;
 import java.util.HashMap;
 
 /**
- * This class holds the PDF bookmark OffDocumentItem
+ * An instance of this class is either a PDF bookmark OffDocumentItem and
+ * its child bookmarks.
  */
 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;
+    // bookmark label
+    private String label = null;
 
+    // ID Reference for this bookmark
     private String idRef;
+
+    // PageViewport that the idRef item refers to
     private PageViewport pageRef = null;
-    private String label = null;
+
+    // unresolved idrefs by this bookmark and child bookmarks below it
+    private HashMap unresolvedIDRefs = new HashMap();
 
     /**
      * Create a new bookmark data object.
      * This should only be call by the top level element as its
      * idref will be null.
      *
-     * @param model the AreaTreeModel for this object
      */
-    public BookmarkData(AreaTreeModel model) {
+    public BookmarkData() {
         idRef = null;
-        areaTreeModel = model;
         whenToProcess = END_OF_DOC;
     }
 
@@ -58,7 +61,7 @@ public class BookmarkData extends OffDocumentItem implements Resolvable {
      */
     public BookmarkData(String id) {
         idRef = id;
-        idRefs.put(idRef, this);
+        unresolvedIDRefs.put(idRef, this);
     }
 
     /**
@@ -78,10 +81,10 @@ public class BookmarkData extends OffDocumentItem implements Resolvable {
      */
     public void addSubData(BookmarkData sub) {
         subData.add(sub);
-        idRefs.put(sub.getID(), sub);
+        unresolvedIDRefs.put(sub.getID(), sub);
         String[] ids = sub.getIDs();
         for (int count = 0; count < ids.length; count++) {
-            idRefs.put(ids[count], sub);
+            unresolvedIDRefs.put(ids[count], sub);
         }
     }
 
@@ -138,7 +141,7 @@ public class BookmarkData extends OffDocumentItem implements Resolvable {
      * @return true if this has been resolved
      */
     public boolean isResolved() {
-        return idRefs == null;
+        return unresolvedIDRefs == null;
     }
 
     /**
@@ -148,7 +151,7 @@ public class BookmarkData extends OffDocumentItem implements Resolvable {
      * @return the array of id references
      */
     public String[] getIDs() {
-        return (String[])idRefs.keySet().toArray(new String[] {});
+        return (String[])unresolvedIDRefs.keySet().toArray(new String[] {});
     }
 
     /**
@@ -164,8 +167,8 @@ public class BookmarkData extends OffDocumentItem implements Resolvable {
     public void resolveIDRef(String id, List pages) {
         // this method is buggy
         if (!id.equals(idRef)) {
-            BookmarkData bd = (BookmarkData)idRefs.get(id);
-            idRefs.remove(id);
+            BookmarkData bd = (BookmarkData)unresolvedIDRefs.get(id);
+            unresolvedIDRefs.remove(id);
             if (bd != null) {
                 bd.resolveIDRef(id, pages);
                 if (bd.isResolved()) {
@@ -179,18 +182,22 @@ public class BookmarkData extends OffDocumentItem implements Resolvable {
                 pageRef = (PageViewport)pages.get(0);
             }
             // TODO get rect area of id on page
-            idRefs.remove(idRef);
+            unresolvedIDRefs.remove(idRef);
             checkFinish();
         }
     }
 
     private void checkFinish() {
-        if (idRefs.size() == 0) {
-            idRefs = null;
-            if (areaTreeModel != null) {
-                areaTreeModel.handleOffDocumentItem(this);
-            }
+        if (unresolvedIDRefs.size() == 0) {
+            unresolvedIDRefs = null;
         }
     }
+    
+    /**
+     * @see org.apache.fop.area.OffDocumentItem#getName()
+     */
+    public String getName() {
+        return "Bookmarks";
+    }
 }
 
index 8f740bb1a4fe73c0d92f82db3fc5333ee48cd248..72f3b2e378a9d73c4b4df0f4aa6eb79fe8b0ec22 100644 (file)
@@ -54,4 +54,10 @@ public abstract class OffDocumentItem {
     public int getWhenToProcess() {
         return whenToProcess;
     }
+
+    /**
+     * Return a human-readable name for this ODI (for error messages, etc.)
+     * @return String name of ODI
+     */
+    public abstract String getName();
 }