From a08f9a06c42141d92a0dce3c8d7e3c551ad5901b Mon Sep 17 00:00:00 2001 From: Steve Coffman Date: Thu, 30 Aug 2001 23:21:40 +0000 Subject: [PATCH] Applies lmckenzi@ca.ibm.com's patch, which would have been very hard 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 --- .../apache/fop/datatypes/IDReferences.java | 63 ++++++++++++++++++- src/org/apache/fop/pdf/PDFDocument.java | 11 +++- 2 files changed, 71 insertions(+), 3 deletions(-) diff --git a/src/org/apache/fop/datatypes/IDReferences.java b/src/org/apache/fop/datatypes/IDReferences.java index a27408794..3701c6662 100644 --- a/src/org/apache/fop/datatypes/IDReferences.java +++ b/src/org/apache/fop/datatypes/IDReferences.java @@ -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 diff --git a/src/org/apache/fop/pdf/PDFDocument.java b/src/org/apache/fop/pdf/PDFDocument.java index a545ab40f..b30280dc2 100644 --- a/src/org/apache/fop/pdf/PDFDocument.java +++ b/src/org/apache/fop/pdf/PDFDocument.java @@ -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); -- 2.39.5