--- /dev/null
+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 <a href="mailto:pbwest@powerup.com.au">Peter B. West</a>
+ * @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 <tt>int</tt> 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 <tt>String</tt> containing the property name.
+ */
+ public AbstractPropertyValue(String propertyName)
+ throws PropertyException
+ {
+ property = PropertyConsts.getPropertyIndex(propertyName);
+ }
+
+ /**
+ * @return <tt>int</tt> 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
+ * <i>AbstractPropertyValue</i> is defined.
+ * A specific property argument is then required.
+ * @param testProperty <tt>int</tt> property index of the property
+ * for which the type is to be validated.
+ * @param type <tt>int</tt> 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 <tt>int</tt> 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();
+ }
+}
--- /dev/null
+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 <a href="mailto:pbwest@powerup.com.au">Peter B. West</a>
+ * @version $Revision$ $Name$
+ */
+/**
+ * A <tt><i>PropertyTriplet</i></tt> 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 <tt>PropertyValue</tt>. In addition
+ * the object may contain a string with the specified expression.
+ * <p>
+ * 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 <tt>int</tt> property index.
+ * @param specified a <tt>PropertyValue</tt>.
+ * @param computed a <tt>PropertyValue</tt>.
+ * @param actual a <tt>PropertyValue</tt>.
+ * @param expression a <tt>String</tt>.
+ * @exception PropertyException if <i>property</i> 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 <tt>String</tt> containing property name.
+ * @param specified a <tt>PropertyValue</tt>.
+ * @param computed a <tt>PropertyValue</tt>.
+ * @param actual a <tt>PropertyValue</tt>.
+ * @param expression a <tt>String</tt>.
+ * @exception PropertyException if <i>property</i> 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 <tt>int</tt> property index.
+ * @param specified a <tt>PropertyValue</tt>.
+ */
+ public PropertyTriplet(int property, PropertyValue specified)
+ throws PropertyException
+ {
+ this(property, specified, null, null, null);
+ }
+
+ /**
+ * @param property an <tt>int</tt> property index.
+ * @param expression a <tt>String</tt>.
+ * @param specified a <tt>PropertyValue</tt>.
+ */
+ public PropertyTriplet(int property, PropertyValue specified,
+ String expression)
+ throws PropertyException
+ {
+ this(property, specified, null, null, expression);
+ }
+
+ /**
+ * @param property an <tt>int</tt> property index.
+ * @param specified a <tt>PropertyValue</tt>.
+ * @param computed a <tt>PropertyValue</tt>.
+ */
+ public PropertyTriplet
+ (int property, PropertyValue specified, PropertyValue computed)
+ throws PropertyException
+ {
+ this(property, specified, computed, null, null);
+ }
+
+ /**
+ * @param property an <tt>int</tt> property index.
+ * @param specified a <tt>PropertyValue</tt>.
+ * @param computed a <tt>PropertyValue</tt>.
+ * @param expression a <tt>String</tt>.
+ */
+ 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 <tt>PropertyValue</tt>.
+ */
+ public void setSpecified(PropertyValue value) {
+ specified = value;
+ expression = null;
+ }
+
+ /**
+ * @param value a <tt>PropertyValue</tt>.
+ * @param expr a <tt>String</tt>, 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;
+ }
+
+}
--- /dev/null
+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 <a href="mailto:pbwest@powerup.com.au">Peter B. West</a>
+ * @version $Revision$ $Name$
+ */
+/**
+ * Base class for all property value types.
+ */
+
+public interface PropertyValue {
+
+ /**
+ * @return <tt>int</tt> 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
+ * <i>PropertyValue</i> is defined. A specific property argument is
+ * then required.
+ * @param testProperty <tt>int</tt> property index of the property
+ * for which the type is to be validated.
+ * @param type <tt>int</tt> bitmap of data types to check for
+ * validity against this property.
+ */
+ public void validate(int testProperty, int type)
+ throws PropertyException;
+
+ /**
+ * @param type <tt>int</tt> bitmap of data types to check for
+ * validity against this property.
+ */
+ public void validate(int type) throws PropertyException;
+ public Object clone() throws CloneNotSupportedException;
+
+}
--- /dev/null
+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 <a href="mailto:pbwest@powerup.com.au">Peter B. West</a>
+ * @version $Revision$ $Name$
+ */
+/**
+ * A list of <tt>PropertyValue</tt> 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 <tt>int</tt> index of the property.
+ */
+ public PropertyValueList(int property) {
+ super();
+ this.property = property;
+ }
+
+ /**
+ * @param propertyName a <tt>String</tt> containing the property name.
+ */
+ public PropertyValueList(String propertyName)
+ throws PropertyException
+ {
+ super();
+ property = PropertyConsts.getPropertyIndex(propertyName);
+ }
+
+ /**
+ * Constructor with a <tt>Collection</tt>. Pass through to superclass
+ * only if the collection is another instance of a PropertyValueList.
+ * @param property <tt>int</tt> index of the property.
+ * @param c a <tt>Collection</tt>, which must be another
+ * <i>PropertyValueList</i>.
+ * @exception IllegalArgumentException if the <tt>Collection</tt> is
+ * not a <i>PropertyValueList</i>.
+ */
+ 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 <tt>Collection</tt>. Pass through to superclass
+ * only if the collection is another instance of a PropertyValueList.
+ * @param propertyName a <tt>String</tt> containing the property name.
+ * @param c a <tt>Collection</tt>, which must be another
+ * <i>PropertyValueList</i>.
+ * @exception IllegalArgumentException if the <tt>Collection</tt> is
+ * not a <i>PropertyValueList</i>.
+ */
+ 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 <tt>PropertyValue</tt> or a <PropertyValueList</tt>;
+ * the element to add. Defined as an
+ * <tt>Object</tt> to override the definition in <tt>LinkedList</tt>.
+ * @return a <tt>boolean</tt> success or failure(?).
+ * @exception IllegalArgumentException if the object is not a
+ * <tt>PropertyValue</tt> or <tt>PropertyValueList</tt>.
+ */
+ 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 <tt>PropertyValue</tt> or <tt>PropertyValueList</tt>
+ * at the beginning of the list.
+ * @param o a <tt>PropertyValue</tt> or a <PropertyValueList</tt>;
+ * the element to add. Defined as an
+ * <tt>Object</tt> to override the definition in <tt>LinkedList</tt>.
+ * @exception IllegalArgumentException if the object is not a
+ * <tt>PropertyValue</tt> or <tt>PropertyValueList</tt>.
+ */
+ 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 <tt>PropertyValue</tt>; the element to add. Defined as an
+ * <tt>Object</tt> to override the definition in <tt>LinkedList</tt>.
+ * @return a <tt>boolean</tt> success or failure(?).
+ * @exception IllegalArgumentException if the object is not a
+ * <tt>PropertyValue</tt>.
+ */
+ public void addLast(Object o) {
+ add(o);
+ }
+
+ /*
+ * Following fields and methods implement the PropertyValue interface
+ */
+
+ /**
+ * @return <tt>int</tt> 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
+ * <i>AbstractPropertyValue</i> is defined.
+ * A specific property argument is then required.
+ * @param testProperty <tt>int</tt> property index of the property
+ * for which the type is to be validated.
+ * @param type <tt>int</tt> 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 <tt>int</tt> 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
--- /dev/null
+<HTML>
+<TITLE>org.apache.fop.fo.expr Package</TITLE>
+<BODY>
+<P>Classes used in the FO properties expression handler.</P>
+</BODY>
+</HTML>