From 35057a6f4b1faa330c5973bd7ea0608b844939f3 Mon Sep 17 00:00:00 2001 From: Simon Pepping Date: Thu, 12 Jan 2006 20:40:08 +0000 Subject: [PATCH] Allow some xsl-function calls with omitted args, patch contributed by Gerhard Oettl, bug 38098. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@368462 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/fo/expr/FromParentFunction.java | 9 ++- .../fop/fo/expr/FromTableColumnFunction.java | 13 +++- src/java/org/apache/fop/fo/expr/Function.java | 9 ++- .../org/apache/fop/fo/expr/FunctionBase.java | 9 ++- .../fop/fo/expr/InheritedPropFunction.java | 9 ++- .../fop/fo/expr/NearestSpecPropFunction.java | 9 ++- .../apache/fop/fo/expr/PropertyParser.java | 16 +++-- .../properties_omitted_propertyname.fo | 69 +++++++++++++++++++ 8 files changed, 129 insertions(+), 14 deletions(-) create mode 100644 test/fotree/testcases/properties_omitted_propertyname.fo diff --git a/src/java/org/apache/fop/fo/expr/FromParentFunction.java b/src/java/org/apache/fop/fo/expr/FromParentFunction.java index f2e1c252f..6ddafe490 100644 --- a/src/java/org/apache/fop/fo/expr/FromParentFunction.java +++ b/src/java/org/apache/fop/fo/expr/FromParentFunction.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,6 +35,13 @@ public class FromParentFunction extends FunctionBase { return 1; } + /** + * @return true (allow padding of arglist with property name) + */ + public boolean padArgsWithPropertyName() { + return true; + } + /** * @param args array of arguments, which should either be empty, or the * first of which should contain an NCName corresponding to property name diff --git a/src/java/org/apache/fop/fo/expr/FromTableColumnFunction.java b/src/java/org/apache/fop/fo/expr/FromTableColumnFunction.java index a076eee4c..101cfb179 100644 --- a/src/java/org/apache/fop/fo/expr/FromTableColumnFunction.java +++ b/src/java/org/apache/fop/fo/expr/FromTableColumnFunction.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2005 The Apache Software Foundation. + * Copyright 1999-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,6 +33,13 @@ public class FromTableColumnFunction extends FunctionBase { return 1; } + /** + * @return true (allow padding of arglist with property name) + */ + public boolean padArgsWithPropertyName() { + return true; + } + /** * * @param args array of arguments, which should either be empty, or the @@ -45,10 +52,12 @@ public class FromTableColumnFunction extends FunctionBase { */ public Property eval(Property[] args, PropertyInfo pInfo) throws PropertyException { + /* uncomment when implementing String propName = args[0].getString(); if (propName == null) { - //TODO Determine on which property this method was called. + throw new PropertyException("Incorrect parameter to from-table-column function"); } + */ throw new PropertyException("The from-table-column() function is not implemented, yet!"); } diff --git a/src/java/org/apache/fop/fo/expr/Function.java b/src/java/org/apache/fop/fo/expr/Function.java index 514843d5a..df4ca9f4c 100644 --- a/src/java/org/apache/fop/fo/expr/Function.java +++ b/src/java/org/apache/fop/fo/expr/Function.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,5 +47,10 @@ public interface Function { */ Property eval(Property[] args, PropertyInfo propInfo) throws PropertyException; -} + /** + * @return if it is allowed to fill up the property list with + * the property name if only one arg is missing. + */ + boolean padArgsWithPropertyName(); +} diff --git a/src/java/org/apache/fop/fo/expr/FunctionBase.java b/src/java/org/apache/fop/fo/expr/FunctionBase.java index bc5088830..1854222dd 100644 --- a/src/java/org/apache/fop/fo/expr/FunctionBase.java +++ b/src/java/org/apache/fop/fo/expr/FunctionBase.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,5 +32,10 @@ public abstract class FunctionBase implements Function { return null; } + /** + * @return false (by default don't pad arglist with property-name) + */ + public boolean padArgsWithPropertyName() { + return false; + } } - diff --git a/src/java/org/apache/fop/fo/expr/InheritedPropFunction.java b/src/java/org/apache/fop/fo/expr/InheritedPropFunction.java index 8956a49dc..9b2bd4296 100644 --- a/src/java/org/apache/fop/fo/expr/InheritedPropFunction.java +++ b/src/java/org/apache/fop/fo/expr/InheritedPropFunction.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,6 +35,13 @@ public class InheritedPropFunction extends FunctionBase { return 1; } + /** + * @return true (allow padding of arglist with property name) + */ + public boolean padArgsWithPropertyName() { + return true; + } + /** * * @param args arguments to be evaluated diff --git a/src/java/org/apache/fop/fo/expr/NearestSpecPropFunction.java b/src/java/org/apache/fop/fo/expr/NearestSpecPropFunction.java index 00bd9596b..b9190a2d8 100644 --- a/src/java/org/apache/fop/fo/expr/NearestSpecPropFunction.java +++ b/src/java/org/apache/fop/fo/expr/NearestSpecPropFunction.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2004 The Apache Software Foundation. + * Copyright 1999-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,6 +35,13 @@ public class NearestSpecPropFunction extends FunctionBase { return 1; } + /** + * @return true (allow padding of arglist with property name) + */ + public boolean padArgsWithPropertyName() { + return true; + } + /** * * @param args array of arguments for the function diff --git a/src/java/org/apache/fop/fo/expr/PropertyParser.java b/src/java/org/apache/fop/fo/expr/PropertyParser.java index 47b4584d6..d08f7631c 100644 --- a/src/java/org/apache/fop/fo/expr/PropertyParser.java +++ b/src/java/org/apache/fop/fo/expr/PropertyParser.java @@ -1,5 +1,5 @@ /* - * Copyright 1999-2005 The Apache Software Foundation. + * Copyright 1999-2006 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -308,7 +308,7 @@ public final class PropertyParser extends PropertyTokenizer { next(); // Push new function (for function context: getPercentBase()) propInfo.pushFunction(function); - prop = function.eval(parseArgs(function.nbArgs()), propInfo); + prop = function.eval(parseArgs(function), propInfo); propInfo.popFunction(); return prop; @@ -324,13 +324,15 @@ public final class PropertyParser extends PropertyTokenizer { * Parse a comma separated list of function arguments. Each argument * may itself be an expression. This method consumes the closing right * parenthesis of the argument list. - * @param nbArgs The number of arguments expected by the function. + * @param function The function object for which the arguments are + * collected. * @return An array of Property objects representing the arguments * found. * @throws PropertyException If the number of arguments found isn't equal * to the number expected. */ - Property[] parseArgs(int nbArgs) throws PropertyException { + Property[] parseArgs(Function function) throws PropertyException { + int nbArgs = function.nbArgs(); Property[] args = new Property[nbArgs]; Property prop; int i = 0; @@ -352,8 +354,12 @@ public final class PropertyParser extends PropertyTokenizer { } expectRpar(); } + if (i == nbArgs - 1 && function.padArgsWithPropertyName()) { + args[i++] = new StringProperty(propInfo.getPropertyMaker().getName()); + } if (nbArgs != i) { - throw new PropertyException("Wrong number of args for function"); + throw new PropertyException("Expected " + nbArgs + + ", but got " + i + " args for function"); } return args; } diff --git a/test/fotree/testcases/properties_omitted_propertyname.fo b/test/fotree/testcases/properties_omitted_propertyname.fo new file mode 100644 index 000000000..3ded0a105 --- /dev/null +++ b/test/fotree/testcases/properties_omitted_propertyname.fo @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + Top Level Block: font-size="13pt" background-color="#00ff00" + + + Nested Block: font-size="inherited-property-value() + 3pt" + (calculate with an inherited value) + + + + + Top Level Block: font-size="24pt" background-color="#ff0000" + + + + Nested Block: + font-size="from-parent() + 2pt"(inherited value and calculate) + background-color="from-parent()" (calculate with an inherited value) + + + + + Top Level Block: font-size="24pt" background-color="#0000ff" + + + Nested Block: background-color=default + + + Nested Block: background-color="from-nearest-specified-value()" + + + + + + + + + -- 2.39.5