adelmelle
Tue, 13 May 2008 00:58:59 -0700
Author: adelmelle Date: Tue May 13 00:58:31 2008 New Revision: 655766 URL: http://svn.apache.org/viewvc?rev=655766&view=rev Log: Added support for auto-generated initial value for the "id" property. Added: xmlgraphics/fop/trunk/test/fotree/testcases/id_auto.fo (with props) Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOEventHandler.java xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOPropertyMapping.java xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/StringProperty.java Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOEventHandler.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOEventHandler.java?rev=655766&r1=655765&r2=655766&view=diff ============================================================================== --- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOEventHandler.java (original) +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOEventHandler.java Tue May 13 00:58:31 2008 @@ -96,6 +96,11 @@ 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 @@ } /** + * 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 */ Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOPropertyMapping.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOPropertyMapping.java?rev=655766&r1=655765&r2=655766&view=diff ============================================================================== --- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOPropertyMapping.java (original) +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FOPropertyMapping.java Tue May 13 00:58:31 2008 @@ -2503,7 +2503,7 @@ 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); Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/StringProperty.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/StringProperty.java?rev=655766&r1=655765&r2=655766&view=diff ============================================================================== --- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/StringProperty.java (original) +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/StringProperty.java Tue May 13 00:58:31 2008 @@ -21,6 +21,11 @@ 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 @@ } + /** + * 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); + } + + /** [EMAIL PROTECTED] */ + public Property make(PropertyList propertyList) throws PropertyException { + String newId = "FO#"; + newId += propertyList.getFObj().getFOEventHandler().getNextId(); + return new StringProperty(newId); + } + + /** [EMAIL PROTECTED] */ + 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); Added: xmlgraphics/fop/trunk/test/fotree/testcases/id_auto.fo URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/fotree/testcases/id_auto.fo?rev=655766&view=auto ============================================================================== --- xmlgraphics/fop/trunk/test/fotree/testcases/id_auto.fo (added) +++ xmlgraphics/fop/trunk/test/fotree/testcases/id_auto.fo Tue May 13 00:58:31 2008 @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:test="http://xmlgraphics.apache.org/fop/test"> + <test:assert property="id" expected="FO#1" /> + <fo:layout-master-set> + <test:assert property="id" expected="FO#2" /> + <fo:simple-page-master master-name="simpleA4" page-height="29.7cm" page-width="21cm" margin-top="2cm" margin-bottom="2cm" margin-left="2cm" margin-right="2cm"> + <test:assert property="id" expected="FO#3" /> + <fo:region-body> + <test:assert property="id" expected="FO#4" /> + </fo:region-body> + </fo:simple-page-master> + </fo:layout-master-set> + <fo:page-sequence master-reference="simpleA4"> + <test:assert property="id" expected="FO#5" /> + <fo:flow flow-name="xsl-region-body"> + <test:assert property="id" expected="FO#6" /> + <fo:block font-size="14pt" id="block">Hello + <test:assert property="id" expected="block"/> + <fo:inline> World! + <test:assert property="id" expected="FO#7" /> + </fo:inline> + </fo:block> + <fo:block font-family="ZapfDingbats">઎ + <test:assert property="id" expected="FO#8" /> + </fo:block> + </fo:flow> + </fo:page-sequence> +</fo:root> Propchange: xmlgraphics/fop/trunk/test/fotree/testcases/id_auto.fo ------------------------------------------------------------------------------ svn:eol-style = native Propchange: xmlgraphics/fop/trunk/test/fotree/testcases/id_auto.fo ------------------------------------------------------------------------------ svn:keywords = Id --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]