diff options
author | Andreas L. Delmelle <adelmelle@apache.org> | 2008-05-13 07:58:31 +0000 |
---|---|---|
committer | Andreas L. Delmelle <adelmelle@apache.org> | 2008-05-13 07:58:31 +0000 |
commit | 6ddc5c33ed8f5281590b6242520171b7cc7ca7ae (patch) | |
tree | 62165dd36112a0a880ee9736db928c6b9c2b60fa /src | |
parent | fd57079cbeda429803cff6cf2b8142146f5fef45 (diff) | |
download | xmlgraphics-fop-6ddc5c33ed8f5281590b6242520171b7cc7ca7ae.tar.gz xmlgraphics-fop-6ddc5c33ed8f5281590b6242520171b7cc7ca7ae.zip |
Added support for auto-generated initial value for the "id" property.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@655766 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r-- | src/java/org/apache/fop/fo/FOEventHandler.java | 12 | ||||
-rw-r--r-- | src/java/org/apache/fop/fo/FOPropertyMapping.java | 2 | ||||
-rw-r--r-- | src/java/org/apache/fop/fo/properties/StringProperty.java | 47 |
3 files changed, 60 insertions, 1 deletions
diff --git a/src/java/org/apache/fop/fo/FOEventHandler.java b/src/java/org/apache/fop/fo/FOEventHandler.java index 5a9a5bb9d..a2a67d594 100644 --- a/src/java/org/apache/fop/fo/FOEventHandler.java +++ b/src/java/org/apache/fop/fo/FOEventHandler.java @@ -96,6 +96,11 @@ public abstract class FOEventHandler { private boolean inMarker = false; /** + * Keeps track of automatically generated ids in the current document + */ + private long lastGeneratedId = 1; + + /** * Main constructor * @param foUserAgent the apps.FOUserAgent instance for this process */ @@ -169,6 +174,13 @@ public abstract class FOEventHandler { } /** + * Return the next value for automatically generated ids + */ + public long getNextId() { + return this.lastGeneratedId++; + } + + /** * This method is called to indicate the start of a new document run. * @throws SAXException In case of a problem */ diff --git a/src/java/org/apache/fop/fo/FOPropertyMapping.java b/src/java/org/apache/fop/fo/FOPropertyMapping.java index 8fed90a35..96cbc5329 100644 --- a/src/java/org/apache/fop/fo/FOPropertyMapping.java +++ b/src/java/org/apache/fop/fo/FOPropertyMapping.java @@ -2503,7 +2503,7 @@ public final class FOPropertyMapping implements Constants { addPropertyMaker("content-type", m); // id - m = new StringProperty.Maker(PR_ID); + m = new StringProperty.IdMaker(PR_ID); m.setInherited(false); m.setDefault(""); addPropertyMaker("id", m); diff --git a/src/java/org/apache/fop/fo/properties/StringProperty.java b/src/java/org/apache/fop/fo/properties/StringProperty.java index 194170fec..e7c477a27 100644 --- a/src/java/org/apache/fop/fo/properties/StringProperty.java +++ b/src/java/org/apache/fop/fo/properties/StringProperty.java @@ -21,6 +21,11 @@ package org.apache.fop.fo.properties; import org.apache.fop.fo.FObj; import org.apache.fop.fo.PropertyList; +import org.apache.fop.fo.FOValidationEventProducer; +import org.apache.fop.fo.ValidationException; +import org.apache.fop.fo.expr.PropertyException; + +import java.util.Set; /** * Exists primarily as a container for its Maker inner class, which is @@ -77,6 +82,48 @@ public final class StringProperty extends Property { } + /** + * Inner class dedicated to the "id" property, which should provide a random + * unique identifier as an initial value. + * The values for "id" are never cached, as they're typically valid for one + * document. + */ + public static class IdMaker extends PropertyMaker { + + /** + * @param propId the id of the property for which the maker should be created + */ + public IdMaker(int propId) { + super(propId); + } + + /** {@inheritDoc} */ + public Property make(PropertyList propertyList) throws PropertyException { + String newId = "FO#"; + newId += propertyList.getFObj().getFOEventHandler().getNextId(); + return new StringProperty(newId); + } + + /** {@inheritDoc} */ + public Property make(PropertyList propertyList, + String value, + FObj fo) throws PropertyException { + + Property idProp; + + //no parsing necessary; just return a new StringProperty + //TODO: Should we move validation here? (see FObj#checkId()) + if ("".equals(value)) { + //if an empty string was specified, return the default + idProp = this.make(propertyList); + } else { + idProp = new StringProperty(value); + } + + return idProp; + } + } + /** cache containing all canonical StringProperty instances */ private static final PropertyCache cache = new PropertyCache(StringProperty.class); |