From 343db8abbad5ef198990b24f20883602df9c2e4b Mon Sep 17 00:00:00 2001 From: Peter Bernard West Date: Fri, 28 Jun 2002 03:24:42 +0000 Subject: [PATCH] Added methods to support shorthand expansion git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@194928 13f79535-47bb-0310-9956-ffa450edef68 --- src/org/apache/fop/fo/PropertySets.java | 103 ++++++++++++++++++++---- 1 file changed, 89 insertions(+), 14 deletions(-) diff --git a/src/org/apache/fop/fo/PropertySets.java b/src/org/apache/fop/fo/PropertySets.java index 441e3ba29..48323cbca 100644 --- a/src/org/apache/fop/fo/PropertySets.java +++ b/src/org/apache/fop/fo/PropertySets.java @@ -15,6 +15,9 @@ import java.lang.CloneNotSupportedException; import java.util.Set; import java.util.HashSet; import java.util.HashMap; +import java.util.List; +import java.util.ListIterator; +import java.util.Arrays; import java.util.Collections; import org.apache.fop.fo.expr.PropertyException; @@ -637,8 +640,8 @@ public class PropertySets { /** * Array of ROIntArray in same order as shorthands * ROIntArray. - *

TODO: Full paranoia mode requires that this array - * be expressed in a new data type ROIntROArray. + * If a public view of this is required, use + * Collections.unmodifiableList(Arrays.asList(shorthandExpansions)) */ private static final ROIntArray[] shorthandExpansions = { backgroundExpansion @@ -667,6 +670,29 @@ public class PropertySets { ,xmlLangExpansion }; + /** + * @param property int property index + * @return ROIntArray containing the expansion list for + * this shorthand. + * @exception PropertyException if this is not a valid + * shorthand property + */ + public static ROIntArray getSHandExpansionSet(int property) + throws PropertyException + { + // Is the property of the argument a shorthand? + Integer sHIndex = + (Integer)(shorthandMap.get(Ints.consts.get(property))); + if (sHIndex == null) { + String propname = PropNames.getPropertyName(property); + throw new PropertyException + (propname + " not a shorthand property"); + } + // Get the array of indices of the properties in the + // expansion of this shorthand + return shorthandExpansions[property]; + } + /** * Expand the shorthand property associated with the * PropertyValue argument by copying the given value for each @@ -685,18 +711,7 @@ public class PropertySets { { // The property associated with this PropertyValue int property = value.getProperty(); - // Is the property of the argument a shorthand? - Integer sHIndex = - (Integer)(shorthandMap.get(Ints.consts.get(property))); - if (sHIndex == null) { - String propname = PropNames.getPropertyName(property); - throw new PropertyException - (propname + " not a shorthand property"); - } - - // Get the array of indices of the properties in the - // expansion of this shorthand - ROIntArray expansion = shorthandExpansions[property]; + ROIntArray expansion = getSHandExpansionSet(property); PropertyValueList list = new PropertyValueList(property); for (int i = 0; i < expansion.length; i++) { int expandedProp = expansion.get(i); @@ -714,6 +729,66 @@ public class PropertySets { return list; } + /** + * Generate a list of the intial values of each property in a + * shorthand expansion + * @param foTree the FOTree for which properties are being + * processed + * @param property int property index + * @return PropertyValueList containing the intial value + * expansions for the (shorthand) property + * @exception PropertyException + */ + public static PropertyValueList initialValueExpansion + (FOTree foTree, int property) + throws PropertyException + { + ROIntArray expansion = getSHandExpansionSet(property); + PropertyValueList list = new PropertyValueList(property); + for (int i = 0; i < expansion.length; i++) { + int expandedProp = expansion.get(i); + PropertyValue expandedPropValue; + PropertyValue specified = + foTree.getInitialValue(expandedProp).getSpecified(); + // The PropertyValue must be cloneable + try { + expandedPropValue = (PropertyValue)(specified.clone()); + } catch (CloneNotSupportedException e) { + throw new PropertyException(e.getMessage()); + } + + list.add(expandedPropValue); + } + return list; + } + + /** + * Given a shorthand expansion list and a PropertyValue, + * override the list element corresponding to the PropertyValue. + * Correspondence is based on the property field of the + * PropertyValue. + * @param list the expansion PropertyValueList + * @param value the overriding PropertyValue + * @return PropertyValueList the new list + */ + public static PropertyValueList overrideSHandElement + (PropertyValueList expansionList, PropertyValue element) + throws PropertyException + { + int elementProp = element.getProperty(); + ListIterator elements = expansionList.listIterator(); + while (elements.hasNext()) { + PropertyValue next = (PropertyValue)(elements.next()); + if (next.getProperty() == elementProp) { + elements.set(element); + return expansionList; + } + } + throw new PropertyException + ("Unmatched property " + elementProp + + " in expansion list for " + expansionList.getProperty()); + } + private PropertySets (){} } -- 2.39.5