[FOray-commit] SF.net SVN: foray:[12974] trunk/foray/foray-fotree/src
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2022-12-28 22:18:55
|
Revision: 12974
http://sourceforge.net/p/foray/code/12974
Author: victormote
Date: 2022-12-28 22:18:53 +0000 (Wed, 28 Dec 2022)
Log Message:
-----------
Add checks on some functions.
Modified Paths:
--------------
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/PropertyId.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/axsl/AxslPropertyId.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/FoPropertyId.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/value/Function.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/xml/XmlPropertyId.java
trunk/foray/foray-fotree/src/test/java/org/foray/fotree/value/FnFromPageMasterRegionTests.java
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/PropertyId.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/PropertyId.java 2022-12-28 21:12:29 UTC (rev 12973)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/PropertyId.java 2022-12-28 22:18:53 UTC (rev 12974)
@@ -39,7 +39,7 @@
*/
enum Atomicity {
- /** The property has a one-to-one relationship with traits. */
+ /** The property has a one-to-one relationship with a trait. */
ATOMIC,
/** The property is a shorthand for more than one trait. */
@@ -61,10 +61,9 @@
* Returns the general atomicity of this property.
* Knowing whether a property is shorthand or compound is useful when evaluating certain functions, such as
* inherited-property-value().
- * This information is used when evala
* @return The general atomicity of this property.
*/
- Atomicity getType();
+ Atomicity getAtomicity();
/**
* Indicates whether this property is inherited or not.
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/axsl/AxslPropertyId.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/axsl/AxslPropertyId.java 2022-12-28 21:12:29 UTC (rev 12973)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/axsl/AxslPropertyId.java 2022-12-28 22:18:53 UTC (rev 12974)
@@ -78,7 +78,7 @@
}
@Override
- public Atomicity getType() {
+ public Atomicity getAtomicity() {
return Atomicity.ATOMIC;
}
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/FoPropertyId.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/FoPropertyId.java 2022-12-28 21:12:29 UTC (rev 12973)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/FoPropertyId.java 2022-12-28 22:18:53 UTC (rev 12974)
@@ -1189,7 +1189,7 @@
}
@Override
- public Atomicity getType() {
+ public Atomicity getAtomicity() {
return this.atomicity;
}
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/value/Function.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/value/Function.java 2022-12-28 21:12:29 UTC (rev 12973)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/value/Function.java 2022-12-28 22:18:53 UTC (rev 12974)
@@ -63,15 +63,15 @@
/**
* Factory method for the various function types.
- * @param functionType The integral value of the function type.
+ * @param functionName The name of the function being processed.
* @param arguments The array of arguments to this function.
- * @param propertyType The property which is calling this function.
+ * @param callingProperty The property which is calling this function.
* @return A newly-constructed instance of a FunctionAbstract subclass.
* @throws PropertyException For invalid arguments to the function.
*/
- public static Function makeFunction(final String functionType, final Expr[] arguments,
- final PropertyId propertyType) throws PropertyException {
- switch (functionType) {
+ public static Function makeFunction(final String functionName, final Expr[] arguments,
+ final PropertyId callingProperty) throws PropertyException {
+ switch (functionName) {
case "abs": {
return new FnAbs(arguments);
}
@@ -85,24 +85,33 @@
return new FnFloor(arguments);
}
case "from-nearest-specified-value": {
- final FoPropertyId propertyId = computeNamedPropertyOperand(functionType, arguments, propertyType);
- return FnFromNearestSpecifiedValue.procureInstance(propertyId);
+ final FoPropertyId foPropertyId = computeNamedPropertyOperand(functionName, arguments, callingProperty);
+ return FnFromNearestSpecifiedValue.procureInstance(foPropertyId);
}
case "from-page-master-region": {
- final FoPropertyId propertyId = computeNamedPropertyOperand(functionType, arguments, propertyType);
- return FnFromPageMasterRegion.procureInstance(propertyId);
+ if (callingProperty != FoPropertyId.WRITING_MODE
+ && callingProperty != FoPropertyId.REFERENCE_ORIENTATION) {
+ throw new PropertyException("Function from-page-master-region() can only be the value of either "
+ + "the writing-mode or reference-orientation properties.");
+ }
+ final FoPropertyId foPropertyId = computeNamedPropertyOperand(functionName, arguments, callingProperty);
+ return FnFromPageMasterRegion.procureInstance(foPropertyId);
}
case "from-parent": {
- final FoPropertyId propertyId = computeNamedPropertyOperand(functionType, arguments, propertyType);
- return FnFromParent.procureInstance(propertyId);
+ final FoPropertyId foPropertyId = computeNamedPropertyOperand(functionName, arguments, callingProperty);
+ return FnFromParent.procureInstance(foPropertyId);
}
case "from-table-column": {
- final FoPropertyId propertyId = computeNamedPropertyOperand(functionType, arguments, propertyType);
- return FnFromTableColumn.procureInstance(propertyId);
+ final FoPropertyId foPropertyId = computeNamedPropertyOperand(functionName, arguments, callingProperty);
+ return FnFromTableColumn.procureInstance(foPropertyId);
}
case "inherited-property-value": {
- final FoPropertyId propertyId = computeNamedPropertyOperand(functionType, arguments, propertyType);
- return FnInheritedPropertyValue.procureInstance(propertyId);
+ final FoPropertyId foPropertyId = computeNamedPropertyOperand(functionName, arguments, callingProperty);
+ if (! foPropertyId.isInherited()) {
+ throw new PropertyException(
+ "Function inherited-property-value() must operate on an inherited property.");
+ }
+ return FnInheritedPropertyValue.procureInstance(foPropertyId);
}
case "label-end": {
return new FnLabelEnd(arguments);
@@ -111,8 +120,8 @@
return new FnMax(arguments);
}
case "merge-property-values": {
- final FoPropertyId propertyId = computeNamedPropertyOperand(functionType, arguments, propertyType);
- return FnMergePropertyValues.procureInstance(propertyId);
+ final FoPropertyId foPropertyId = computeNamedPropertyOperand(functionName, arguments, callingProperty);
+ return FnMergePropertyValues.procureInstance(foPropertyId);
}
case "min": {
return new FnMin(arguments);
@@ -133,7 +142,7 @@
return new FnSystemColor(arguments);
}
case "system-font": {
- return new FnSystemFont(arguments, propertyType);
+ return new FnSystemFont(arguments, callingProperty);
}
default: {
return null;
@@ -208,16 +217,16 @@
* Computes the operand of a named property function from the arguments and property type.
* @param functionName The name of the function being parsed.
* @param arguments The arguments to this function.
- * @param propertyType The property which is calling this function.
+ * @param callingProperty The property which is calling this function.
* @return The operand to be used for {@code arguments} and {@code propertyType}.
* @throws PropertyException For errors creating this function.
*/
private static FoPropertyId computeNamedPropertyOperand(final String functionName, final Expr[] arguments,
- final PropertyId propertyType) throws PropertyException {
+ final PropertyId callingProperty) throws PropertyException {
final DtName name = validateNoneOrOneName(functionName, arguments);
if (name == null) {
- if (propertyType instanceof FoPropertyId) {
- return (FoPropertyId) propertyType;
+ if (callingProperty instanceof FoPropertyId) {
+ return (FoPropertyId) callingProperty;
} else {
throw new PropertyException("Function " + functionName
+ " is valid only for properties in the fo: "
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/xml/XmlPropertyId.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/xml/XmlPropertyId.java 2022-12-28 21:12:29 UTC (rev 12973)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/xml/XmlPropertyId.java 2022-12-28 22:18:53 UTC (rev 12974)
@@ -75,7 +75,7 @@
}
@Override
- public Atomicity getType() {
+ public Atomicity getAtomicity() {
return Atomicity.SHORTHAND;
}
Modified: trunk/foray/foray-fotree/src/test/java/org/foray/fotree/value/FnFromPageMasterRegionTests.java
===================================================================
--- trunk/foray/foray-fotree/src/test/java/org/foray/fotree/value/FnFromPageMasterRegionTests.java 2022-12-28 21:12:29 UTC (rev 12973)
+++ trunk/foray/foray-fotree/src/test/java/org/foray/fotree/value/FnFromPageMasterRegionTests.java 2022-12-28 22:18:53 UTC (rev 12974)
@@ -29,8 +29,10 @@
package org.foray.fotree.value;
import org.foray.fotree.PropertyException;
+import org.foray.fotree.fo.FoPropertyId;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import org.junit.jupiter.api.Test;
/**
@@ -39,12 +41,10 @@
public class FnFromPageMasterRegionTests {
/** Constant used for testing. */
- private static final DtName NAME_1 = new DtName("orphans");
+ private static final Expr[] OPERAND_ARRAY_ORPHANS = {new DtName("orphans")};
/** Constant used for testing. */
- private static final Expr[] OPERAND_ARRAY_1 = new Expr[] {
- FnFromPageMasterRegionTests.NAME_1,
- };
+ private static final Expr[] OPERAND_ARRAY_WRITING_MODE = {new DtName("writing-mode")};
/**
* Unit test of a function creation.
@@ -53,8 +53,23 @@
@Test
public void testBasic() throws PropertyException {
final Function fn = Function.makeFunction("from-page-master-region",
- FnFromPageMasterRegionTests.OPERAND_ARRAY_1, null);
+ FnFromPageMasterRegionTests.OPERAND_ARRAY_WRITING_MODE, FoPropertyId.WRITING_MODE);
assertTrue(fn instanceof FnFromPageMasterRegion);
}
+ /**
+ * Unit test of a function creation.
+ * @throws PropertyException For errors during function creation.
+ */
+ @Test
+ public void invalidPropertyShouldFail() throws PropertyException {
+ try {
+ Function.makeFunction("from-page-master-region",
+ FnFromPageMasterRegionTests.OPERAND_ARRAY_ORPHANS, FoPropertyId.ORPHANS);
+ fail("Expected PropertyException for invalid operand");
+ } catch (final PropertyException e) {
+ /* This is the expected path. */
+ }
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|