]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Applies lmckenzi@ca.ibm.com's patch, which would have been very hard
authorSteve Coffman <gears@apache.org>
Thu, 30 Aug 2001 23:21:40 +0000 (23:21 +0000)
committerSteve Coffman <gears@apache.org>
Thu, 30 Aug 2001 23:21:40 +0000 (23:21 +0000)
to characterize had he not already done so. That he fixed it is just gravy.
There is one line I'm not sure about, but it passed my tests, so I'll
leave it in and just comment it.

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

src/org/apache/fop/datatypes/IDReferences.java
src/org/apache/fop/pdf/PDFDocument.java

index a27408794ef36fa00589fd9729199bb815dd5c90..3701c6662231cd63aea6d85c284153ffbe5ff4f8 100644 (file)
@@ -27,9 +27,15 @@ import org.apache.fop.apps.FOPException;
   Modified by Mark Lillywhite mark-fop@inomial.com. Added
   getInvalidElements() so that StreamRenderer cna tell what
   hasn't been determined yet.
+
+  Modified by lmckenzi@ca.ibm.com
+  Sometimes IDs are created, but not validated. This code fixes
+  the incorrect complaint that the ID already exists which prevents
+  basic-links from working (sometimes).
+   
   */
 public class IDReferences {
-    private Hashtable idReferences, idValidation;
+    private Hashtable idReferences, idValidation, idUnvalidated;
 
     final static int ID_PADDING = 5000;    // space to add before id y position
 
@@ -39,6 +45,7 @@ public class IDReferences {
     public IDReferences() {
         idReferences = new Hashtable();
         idValidation = new Hashtable();
+        idUnvalidated = new Hashtable();
     }
 
 
@@ -64,7 +71,12 @@ public class IDReferences {
      */
     public void createID(String id) throws FOPException {
         if (id != null &&!id.equals("")) {
-            if (doesIDExist(id)) {
+            if (doesUnvalidatedIDExist(id)) {
+                removeFromUnvalidatedIDList(id);
+                //Steve's (gears@apache.org) comment: Is this right? 
+                removeFromIdValidationList(id);
+            }
+            else if (doesIDExist(id)) {
                 throw new FOPException("The id \"" + id
                                        + "\" already exists in this document");
             } else {
@@ -75,6 +87,53 @@ public class IDReferences {
         }
     }
 
+    /**
+     * Creates id entry that hasn't been validated
+     *
+     * @param id     The id to create
+     * @exception FOPException
+     */
+    public void createUnvalidatedID(String id) {
+        if (id != null &&!id.equals("")) {
+            if (!doesIDExist(id)) {
+                createNewId(id);
+                addToUnvalidatedIdList(id);
+            } 
+        }
+    }
+
+    /**
+     * Adds created id list of unvalidated ids that have already 
+     * been created. This should be used if it is unsure whether
+     * the id is valid but it must be anyhow.
+     *
+     * @param id     The id to create
+     */
+    public void addToUnvalidatedIdList(String id) {
+        idUnvalidated.put(id,"");
+    }
+
+    /**
+     * Removes id from list of unvalidated ids.
+     * This should be used if the id has been determined 
+     * to be valid. 
+     *
+     * @param id     The id to remove
+     */
+    public void removeFromUnvalidatedIDList(String id) {
+        idUnvalidated.remove(id);
+    }
+
+    /**
+     * Determines whether specified id already exists in
+     * idUnvalidated
+     *
+     * @param id     The id to search for
+     * @return true if ID was found, false otherwise
+     */
+    public boolean doesUnvalidatedIDExist(String id) {
+        return idUnvalidated.containsKey(id);
+    }
 
     /**
      * Configures this id
index a545ab40f319298084b37bd801a497785e36cfd9..b30280dc26ac1a180f3c21f6b81b0b52059a7e81 100644 (file)
@@ -51,6 +51,10 @@ import java.awt.Rectangle;
  * ability to write the /Pages object after writing the rest
  * of the document; ability to write to a stream and flush
  * the object list; enhanced trailer output; cleanups.
+ *
+ * Modified by lmckenzi@ca.ibm.com
+ * Sometimes IDs are created, but not validated. This tracks
+ * the difference.
  */
 public class PDFDocument {
     private static final Integer locationPlaceholder = new Integer(0);
@@ -1006,7 +1010,12 @@ public class PDFDocument {
                 addTrailerObject(idReferences.getPDFGoTo(destination));
             }
         } else {        // id was not found, so create it
-            idReferences.createNewId(destination);
+
+            //next line by lmckenzi@ca.ibm.com
+            //solves when IDNode made before IDReferences.createID called
+            //idReferences.createNewId(destination);
+            idReferences.createUnvalidatedID(destination); 
             idReferences.addToIdValidationList(destination);
             goToReference = idReferences.createInternalLinkGoTo(destination,
                             ++this.objectcount);