From de684f74d0a9f0409f12b4437f7d82d255cbd210 Mon Sep 17 00:00:00 2001 From: Peter Bernard West Date: Tue, 7 May 2002 05:40:16 +0000 Subject: [PATCH] Initial commit of experimental property expression handling files. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@194779 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/fo/expr/AbstractPropertyValue.java | 119 +++++++++ .../apache/fop/fo/expr/PropertyTriplet.java | 205 ++++++++++++++++ src/org/apache/fop/fo/expr/PropertyValue.java | 48 ++++ .../apache/fop/fo/expr/PropertyValueList.java | 227 ++++++++++++++++++ src/org/apache/fop/fo/expr/package.html | 6 + 5 files changed, 605 insertions(+) create mode 100644 src/org/apache/fop/fo/expr/AbstractPropertyValue.java create mode 100644 src/org/apache/fop/fo/expr/PropertyTriplet.java create mode 100644 src/org/apache/fop/fo/expr/PropertyValue.java create mode 100644 src/org/apache/fop/fo/expr/PropertyValueList.java create mode 100644 src/org/apache/fop/fo/expr/package.html diff --git a/src/org/apache/fop/fo/expr/AbstractPropertyValue.java b/src/org/apache/fop/fo/expr/AbstractPropertyValue.java new file mode 100644 index 000000000..0f8127cfe --- /dev/null +++ b/src/org/apache/fop/fo/expr/AbstractPropertyValue.java @@ -0,0 +1,119 @@ +package org.apache.fop.fo.expr; + +import org.apache.fop.fo.PropertyConsts; +import org.apache.fop.fo.PropNames; +import org.apache.fop.fo.Properties; +import org.apache.fop.fo.expr.PropertyException; +import org.apache.fop.fo.expr.PropertyValue; + +/* + * AbstractPropertyValue.java + * $Id$ + * + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * @author Peter B. West + * @version $Revision$ $Name$ + */ +/** + * Base abstract class for all property value types. + */ + +public abstract class AbstractPropertyValue + implements PropertyValue, Cloneable + { + + /** + * An integer index to the type of property of which this is a value. + */ + protected int property; + + /** + * N.B. Constructor allows for property 0, which is a dummy + * property number. + * @param index int index of the property in the property arrays. + */ + public AbstractPropertyValue(int index) throws PropertyException { + if (index < 0 || index > PropNames.LAST_PROPERTY_INDEX) + throw new PropertyException("Invalid property index: " + index); + property = index; + } + + /** + * @param propertyName a String containing the property name. + */ + public AbstractPropertyValue(String propertyName) + throws PropertyException + { + property = PropertyConsts.getPropertyIndex(propertyName); + } + + /** + * @return int property index. + */ + public int getProperty() { + return property; + } + + public void setProperty(int index) throws PropertyException { + if (index < 0 || index > PropNames.LAST_PROPERTY_INDEX) + throw new PropertyException("Invalid property index: " + index); + property = index; + } + + /** + * In some circumstances, the property against which a type is to be + * validated may not be the same as the property against which this + * AbstractPropertyValue is defined. + * A specific property argument is then required. + * @param testProperty int property index of the property + * for which the type is to be validated. + * @param type int bitmap of data types to check for + * validity against this property. + */ + public void validate(int testProperty, int type) + throws PropertyException + { + // N.B. PROPERTY_SPECIFIC inheritance may require more specialized + // checks. Only line-height comes into this category. + + // N.B. The first commented-out condition means that I cannot validate + // unless the property is NOT inherited. + // I can't remember why I put this + // condition in here. Removing it. pbw 2002/02/18 + //if (PropertyConsts.inherited.get(testProperty) == Properties.NO + //&& (PropertyConsts.dataTypes.get(testProperty) & type) == 0) { + + if ((PropertyConsts.dataTypes.get(testProperty) & type) == 0) { + String pname = PropNames.getPropertyName(testProperty); + throw new PropertyException + ("Datatype(s) " + + Properties.listDataTypes(type) + + " not defined on " + pname); + } + } + + /** + * @param type int bitmap of data types to check for + * validity against this property. + */ + public void validate(int type) throws PropertyException { + // N.B. PROPERTY_SPECIFIC inheritance may require more specialized + // checks. Only line-height comes into this category. + validate(property, type); + } + + public String toString() { + try { + return "Property: " + PropNames.getPropertyName(property) + + " Index: " + property; + } catch (PropertyException e) { + throw new RuntimeException(e.getMessage()); + } + } + + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } +} diff --git a/src/org/apache/fop/fo/expr/PropertyTriplet.java b/src/org/apache/fop/fo/expr/PropertyTriplet.java new file mode 100644 index 000000000..19176ed09 --- /dev/null +++ b/src/org/apache/fop/fo/expr/PropertyTriplet.java @@ -0,0 +1,205 @@ +package org.apache.fop.fo.expr; + +import org.apache.fop.fo.PropertyConsts; +import org.apache.fop.fo.PropNames; +import org.apache.fop.fo.expr.PropertyException; + +/** + * PropertyTriplet.java + * $Id$ + * + * Created: Tue Nov 20 22:18:11 2001 + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * @author Peter B. West + * @version $Revision$ $Name$ + */ +/** + * A PropertyTriplet is a set of possible values of an + * instance of a property at a given point in the FO tree. The three + * possible values are specified, computed and actual. All three values + * are represented by a subclass of PropertyValue. In addition + * the object may contain a string with the specified expression. + *

+ * Values may, and frequently will be, null, especially specified and actual. + */ + +public class PropertyTriplet { + + private int property; + private PropertyValue specified; + private PropertyValue computed; + private PropertyValue actual; + private String expression; + + public PropertyTriplet() { + // PropertyValues and expression are null + } + + /** + * @param property an int property index. + * @param specified a PropertyValue. + * @param computed a PropertyValue. + * @param actual a PropertyValue. + * @param expression a String. + * @exception PropertyException if property is not within the + * range of valid property indices. + */ + public PropertyTriplet(int property, PropertyValue specified, + PropertyValue computed, PropertyValue actual, + String expression) + throws PropertyException + { + if (property < 0 || property > PropNames.LAST_PROPERTY_INDEX) + throw new PropertyException("Invalid property index."); + + this.property = property; + this.specified = specified; + this.computed = computed; + this.actual = actual; + this.expression = expression; + } + + /** + * @param propertyName a String containing property name. + * @param specified a PropertyValue. + * @param computed a PropertyValue. + * @param actual a PropertyValue. + * @param expression a String. + * @exception PropertyException if property is not within the + * range of valid property indices. + */ + public PropertyTriplet(String propertyName, PropertyValue specified, + PropertyValue computed, PropertyValue actual, + String expression) + throws PropertyException + { + this(PropertyConsts.getPropertyIndex(propertyName), + specified, computed, actual, expression); + } + + /** + * @param property an int property index. + * @param specified a PropertyValue. + */ + public PropertyTriplet(int property, PropertyValue specified) + throws PropertyException + { + this(property, specified, null, null, null); + } + + /** + * @param property an int property index. + * @param expression a String. + * @param specified a PropertyValue. + */ + public PropertyTriplet(int property, PropertyValue specified, + String expression) + throws PropertyException + { + this(property, specified, null, null, expression); + } + + /** + * @param property an int property index. + * @param specified a PropertyValue. + * @param computed a PropertyValue. + */ + public PropertyTriplet + (int property, PropertyValue specified, PropertyValue computed) + throws PropertyException + { + this(property, specified, computed, null, null); + } + + /** + * @param property an int property index. + * @param specified a PropertyValue. + * @param computed a PropertyValue. + * @param expression a String. + */ + public PropertyTriplet + (int property, PropertyValue specified, PropertyValue computed, + String expression) + throws PropertyException + { + this(property, specified, computed, null, expression); + } + + /** + * N.B. This sets expression to null as a side-effect. + * @param value a PropertyValue. + */ + public void setSpecified(PropertyValue value) { + specified = value; + expression = null; + } + + /** + * @param value a PropertyValue. + * @param expr a String, the specified expression. + */ + public void setSpecified(PropertyValue value, String expr) { + specified = value; + expression = expr; + } + + public void setComputed(PropertyValue value) { + computed = value; + } + + public void setActual(PropertyValue value) { + actual = value; + } + + public String getExpression() { + return expression; + } + + public PropertyValue getSpecified() { + return specified; + } + + public PropertyValue getComputed() { + return computed; + } + + public PropertyValue getActual() { + return actual; + } + + public int getProperty() { + return property; + } + + public int getSpecifiedProperty() { + return specified.getProperty(); + } + + public int getComputedProperty() { + return computed.getProperty(); + } + + public int getActualProperty() { + return actual.getProperty(); + } + + public String toString() { + String tmpstr = "Specified: "; + if (specified != null) tmpstr += specified.toString(); + else tmpstr += "null"; + tmpstr += "\nExpression: "; + if (expression != null) tmpstr += expression; + else tmpstr += "null"; + tmpstr += "\nComputed: "; + if (computed != null) tmpstr += computed.toString(); + else tmpstr += "null"; + tmpstr += "\nActual: "; + if (actual != null) tmpstr += actual.toString(); + else tmpstr += "null"; + tmpstr += "\n"; + return tmpstr; + } + +} diff --git a/src/org/apache/fop/fo/expr/PropertyValue.java b/src/org/apache/fop/fo/expr/PropertyValue.java new file mode 100644 index 000000000..dd48d6004 --- /dev/null +++ b/src/org/apache/fop/fo/expr/PropertyValue.java @@ -0,0 +1,48 @@ +package org.apache.fop.fo.expr; + +import org.apache.fop.fo.expr.PropertyException; + +/* + * PropertyValue.java + * $Id$ + * + * Created: Tue Nov 20 22:18:11 2001 + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * @author Peter B. West + * @version $Revision$ $Name$ + */ +/** + * Base class for all property value types. + */ + +public interface PropertyValue { + + /** + * @return int property index. + */ + public int getProperty(); + public void setProperty(int index) throws PropertyException; + + /** + * In some circumstances, the property against which a type is to be + * validated may not be the same as the property against which this + * PropertyValue is defined. A specific property argument is + * then required. + * @param testProperty int property index of the property + * for which the type is to be validated. + * @param type int bitmap of data types to check for + * validity against this property. + */ + public void validate(int testProperty, int type) + throws PropertyException; + + /** + * @param type int bitmap of data types to check for + * validity against this property. + */ + public void validate(int type) throws PropertyException; + public Object clone() throws CloneNotSupportedException; + +} diff --git a/src/org/apache/fop/fo/expr/PropertyValueList.java b/src/org/apache/fop/fo/expr/PropertyValueList.java new file mode 100644 index 000000000..9073ab7c7 --- /dev/null +++ b/src/org/apache/fop/fo/expr/PropertyValueList.java @@ -0,0 +1,227 @@ +package org.apache.fop.fo.expr; + +import java.util.LinkedList; +import java.util.Collection; +import java.util.Iterator; + +import org.apache.fop.fo.Properties; +import org.apache.fop.fo.PropertyConsts; +import org.apache.fop.fo.PropNames; +import org.apache.fop.fo.expr.PropertyValue; +import org.apache.fop.fo.expr.PropertyException; + +/* + * PropertyValueList.java + * $Id$ + * + * Created: Tue Dec 11 22:37:16 2001 + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + * @author Peter B. West + * @version $Revision$ $Name$ + */ +/** + * A list of PropertyValue elements. + */ + +public class PropertyValueList extends LinkedList implements PropertyValue { + + /** + * An integer index to the type of property of which this is a value. + */ + protected int property; + + /** + * @param property int index of the property. + */ + public PropertyValueList(int property) { + super(); + this.property = property; + } + + /** + * @param propertyName a String containing the property name. + */ + public PropertyValueList(String propertyName) + throws PropertyException + { + super(); + property = PropertyConsts.getPropertyIndex(propertyName); + } + + /** + * Constructor with a Collection. Pass through to superclass + * only if the collection is another instance of a PropertyValueList. + * @param property int index of the property. + * @param c a Collection, which must be another + * PropertyValueList. + * @exception IllegalArgumentException if the Collection is + * not a PropertyValueList. + */ + public PropertyValueList(int property, Collection c) { + super(c); + // This test only follows the super() call because that call must + // be the first in a constructor. + if (! (c instanceof PropertyValueList)) + throw new IllegalArgumentException + ("Collection is not a PropertyValueList."); + this.property = property; + } + + /** + * Constructor with a Collection. Pass through to superclass + * only if the collection is another instance of a PropertyValueList. + * @param propertyName a String containing the property name. + * @param c a Collection, which must be another + * PropertyValueList. + * @exception IllegalArgumentException if the Collection is + * not a PropertyValueList. + */ + public PropertyValueList(String propertyName, Collection c) + throws PropertyException + { + super(c); + // This test only follows the super() call because that call must + // be the first in a constructor. + if (! (c instanceof PropertyValueList)) + throw new IllegalArgumentException + ("Collection is not a PropertyValueList."); + property = PropertyConsts.getPropertyIndex(propertyName); + } + + /** + * Append a PropertyValue or PropertyValueList to the end of the list. + * @param o a PropertyValue or a ; + * the element to add. Defined as an + * Object to override the definition in LinkedList. + * @return a boolean success or failure(?). + * @exception IllegalArgumentException if the object is not a + * PropertyValue or PropertyValueList. + */ + public boolean add(Object o) { + if (! (o instanceof PropertyValue || o instanceof PropertyValueList)) + throw new IllegalArgumentException + ("Object is not a PropertyValue or a PropertyValueList."); + return super.add(o); + } + + /** + * Insert a PropertyValue or PropertyValueList + * at the beginning of the list. + * @param o a PropertyValue or a ; + * the element to add. Defined as an + * Object to override the definition in LinkedList. + * @exception IllegalArgumentException if the object is not a + * PropertyValue or PropertyValueList. + */ + public void addFirst(Object o) { + if (! (o instanceof PropertyValue || o instanceof PropertyValueList)) + throw new IllegalArgumentException + ("Object is not a PropertyValue or a PropertyValueList."); + super.addFirst(o); + } + + /** + * Append a PropertyValue to the end of the list. + * @param o a PropertyValue; the element to add. Defined as an + * Object to override the definition in LinkedList. + * @return a boolean success or failure(?). + * @exception IllegalArgumentException if the object is not a + * PropertyValue. + */ + public void addLast(Object o) { + add(o); + } + + /* + * Following fields and methods implement the PropertyValue interface + */ + + /** + * @return int property index. + */ + public int getProperty() { + return property; + } + + public void setProperty(int index) throws PropertyException { + if (index < 0 || index > PropNames.LAST_PROPERTY_INDEX) + throw new PropertyException("Invalid property index: " + index); + property = index; + } + + /** + * In some circumstances, the property against which a type is to be + * validated may not be the same as the property against which this + * AbstractPropertyValue is defined. + * A specific property argument is then required. + * @param testProperty int property index of the property + * for which the type is to be validated. + * @param type int bitmap of data types to check for + * validity against this property. + */ + public void validate(int testProperty, int type) + throws PropertyException + { + // N.B. PROPERTY_SPECIFIC inheritance may require more specialized + // checks. Only line-height comes into this category. + + // N.B. The first commented-out condition means that I cannot validate + // unless the property is NOT inherited. + // I can't remember why I put this + // condition in here. Removing it. pbw 2002/02/18 + //if (PropertyConsts.inherited.get(testProperty) == Properties.NO + //&& (PropertyConsts.dataTypes.get(testProperty) & type) == 0) { + + if ((PropertyConsts.dataTypes.get(testProperty) & type) == 0) { + String pname = PropNames.getPropertyName(testProperty); + throw new PropertyException + ("Datatype(s) " + + Properties.listDataTypes(type) + + " not defined on " + pname); + } + } + + /** + * @param type int bitmap of data types to check for + * validity against this property. + */ + public void validate(int type) throws PropertyException { + // N.B. PROPERTY_SPECIFIC inheritance may require more specialized + // checks. Only line-height comes into this category. + validate(property, type); + } + + public String toString() { + String str, cstr; + try { + str = "Property: " + PropNames.getPropertyName(property) + + " Index: " + property + " List contents:\n"; + Iterator contents = iterator(); + while (contents.hasNext()) { + int i = 0, j = 0; + cstr = contents.next().toString(); + while (i < cstr.length() && j >= 0) { + j = cstr.indexOf('\n'); + if (j >= 0) { + str = str + ">" + cstr.substring(i, ++j); + i = j; + } else { + str = str + ">" + cstr.substring(i); + i = cstr.length(); + } + } + } + return str; + + } catch (PropertyException e) { + throw new RuntimeException(e.getMessage()); + } + } + + public Object clone() { + return super.clone(); + } + +}// PropertyValueList diff --git a/src/org/apache/fop/fo/expr/package.html b/src/org/apache/fop/fo/expr/package.html new file mode 100644 index 000000000..07206200c --- /dev/null +++ b/src/org/apache/fop/fo/expr/package.html @@ -0,0 +1,6 @@ + +org.apache.fop.fo.expr Package + +

Classes used in the FO properties expression handler.

+ + -- 2.39.5