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
public IDReferences() {
idReferences = new Hashtable();
idValidation = new Hashtable();
+ idUnvalidated = new Hashtable();
}
*/
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 {
}
}
+ /**
+ * 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
* 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);
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);