aboutsummaryrefslogtreecommitdiffstats
path: root/fop-core
diff options
context:
space:
mode:
authorSimon Steiner <ssteiner@apache.org>2021-07-13 06:47:09 +0000
committerSimon Steiner <ssteiner@apache.org>2021-07-13 06:47:09 +0000
commit7edce5dd5880f3c8df10a37079bbcbc83063d238 (patch)
treeef4580ac0d4e8282b60c38cae0319155b40282a6 /fop-core
parentfdde94a7aa524b3ac0e50d1306634fc99c5a2e4d (diff)
downloadxmlgraphics-fop-7edce5dd5880f3c8df10a37079bbcbc83063d238.tar.gz
xmlgraphics-fop-7edce5dd5880f3c8df10a37079bbcbc83063d238.zip
FOP-3021: Improve validation of border property
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1891499 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'fop-core')
-rw-r--r--fop-core/src/main/java/org/apache/fop/fo/BorderShorthandParser.java36
-rw-r--r--fop-core/src/main/java/org/apache/fop/fo/FOPropertyMapping.java10
-rw-r--r--fop-core/src/main/java/org/apache/fop/fo/properties/GenericShorthandParser.java5
-rw-r--r--fop-core/src/main/java/org/apache/fop/fo/properties/PropertyMaker.java2
-rw-r--r--fop-core/src/test/java/org/apache/fop/fo/properties/GenericShorthandParserTestCase.java51
5 files changed, 97 insertions, 7 deletions
diff --git a/fop-core/src/main/java/org/apache/fop/fo/BorderShorthandParser.java b/fop-core/src/main/java/org/apache/fop/fo/BorderShorthandParser.java
new file mode 100644
index 000000000..ba197fb09
--- /dev/null
+++ b/fop-core/src/main/java/org/apache/fop/fo/BorderShorthandParser.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+package org.apache.fop.fo;
+
+import org.apache.fop.fo.properties.GenericShorthandParser;
+import org.apache.fop.fo.properties.Property;
+
+class BorderShorthandParser extends GenericShorthandParser {
+ private FOPropertyMapping propertyMapping;
+
+ BorderShorthandParser(FOPropertyMapping propertyMapping) {
+ this.propertyMapping = propertyMapping;
+ }
+
+ protected void validate(PropertyList propertyList, String propertyString, Property prop, Property property) {
+ if (propertyMapping.genericBorderWidth.checkValueKeywords(propertyString).equals(propertyString)) {
+ propertyList.validatePropertyValue(propertyString, prop, property);
+ }
+ }
+}
diff --git a/fop-core/src/main/java/org/apache/fop/fo/FOPropertyMapping.java b/fop-core/src/main/java/org/apache/fop/fo/FOPropertyMapping.java
index c96e34b32..4fc5c4df2 100644
--- a/fop-core/src/main/java/org/apache/fop/fo/FOPropertyMapping.java
+++ b/fop-core/src/main/java/org/apache/fop/fo/FOPropertyMapping.java
@@ -99,7 +99,7 @@ public final class FOPropertyMapping implements Constants {
private PropertyMaker genericCondPadding;
private PropertyMaker genericPadding;
private PropertyMaker genericCondBorderWidth;
- private PropertyMaker genericBorderWidth;
+ PropertyMaker genericBorderWidth;
private PropertyMaker genericBorderStyle;
private PropertyMaker genericCondCornerRadius;
private PropertyMaker genericBreak;
@@ -2849,7 +2849,7 @@ public final class FOPropertyMapping implements Constants {
m = new ListProperty.Maker(PR_BORDER_BOTTOM);
m.setInherited(false);
m.setDefault("");
- m.setDatatypeParser(new GenericShorthandParser());
+ m.setDatatypeParser(new BorderShorthandParser(this));
addPropertyMaker("border-bottom", m);
// border-color
@@ -2863,14 +2863,14 @@ public final class FOPropertyMapping implements Constants {
m = new ListProperty.Maker(PR_BORDER_LEFT);
m.setInherited(false);
m.setDefault("");
- m.setDatatypeParser(new GenericShorthandParser());
+ m.setDatatypeParser(new BorderShorthandParser(this));
addPropertyMaker("border-left", m);
// border-right
m = new ListProperty.Maker(PR_BORDER_RIGHT);
m.setInherited(false);
m.setDefault("");
- m.setDatatypeParser(new GenericShorthandParser());
+ m.setDatatypeParser(new BorderShorthandParser(this));
addPropertyMaker("border-right", m);
// border-style
@@ -2891,7 +2891,7 @@ public final class FOPropertyMapping implements Constants {
m = new ListProperty.Maker(PR_BORDER_TOP);
m.setInherited(false);
m.setDefault("");
- m.setDatatypeParser(new GenericShorthandParser());
+ m.setDatatypeParser(new BorderShorthandParser(this));
addPropertyMaker("border-top", m);
// border-width
diff --git a/fop-core/src/main/java/org/apache/fop/fo/properties/GenericShorthandParser.java b/fop-core/src/main/java/org/apache/fop/fo/properties/GenericShorthandParser.java
index 42b65486c..8df684236 100644
--- a/fop-core/src/main/java/org/apache/fop/fo/properties/GenericShorthandParser.java
+++ b/fop-core/src/main/java/org/apache/fop/fo/properties/GenericShorthandParser.java
@@ -96,9 +96,12 @@ public class GenericShorthandParser implements ShorthandParser {
}
prop = maker.convertShorthandProperty(propertyList, p, null);
}
- propertyList.validatePropertyValue(vProperty.toString(), prop, property);
+ validate(propertyList, vProperty.toString(), prop, property);
return prop;
}
+ protected void validate(PropertyList propertyList, String propertyString, Property prop, Property property) {
+ propertyList.validatePropertyValue(propertyString, prop, property);
+ }
}
diff --git a/fop-core/src/main/java/org/apache/fop/fo/properties/PropertyMaker.java b/fop-core/src/main/java/org/apache/fop/fo/properties/PropertyMaker.java
index a315944b1..e61632a0b 100644
--- a/fop-core/src/main/java/org/apache/fop/fo/properties/PropertyMaker.java
+++ b/fop-core/src/main/java/org/apache/fop/fo/properties/PropertyMaker.java
@@ -539,7 +539,7 @@ public class PropertyMaker implements Cloneable {
* @return a String containing a parseable equivalent or null if
* the passed value isn't a keyword initializer for this Property
*/
- protected String checkValueKeywords(String keyword) {
+ public String checkValueKeywords(String keyword) {
if (keywords != null) {
String value = (String)keywords.get(keyword);
if (value != null) {
diff --git a/fop-core/src/test/java/org/apache/fop/fo/properties/GenericShorthandParserTestCase.java b/fop-core/src/test/java/org/apache/fop/fo/properties/GenericShorthandParserTestCase.java
new file mode 100644
index 000000000..1b038a74a
--- /dev/null
+++ b/fop-core/src/test/java/org/apache/fop/fo/properties/GenericShorthandParserTestCase.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+package org.apache.fop.fo.properties;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.fop.fo.Constants;
+import org.apache.fop.fo.FOPropertyMapping;
+import org.apache.fop.fo.StaticPropertyList;
+import org.apache.fop.fo.expr.NCnameProperty;
+import org.apache.fop.fo.expr.PropertyException;
+
+public class GenericShorthandParserTestCase {
+ @Test
+ public void testPropertyValidation() throws PropertyException {
+ StaticPropertyList propertyList = new StaticPropertyList(null, null);
+ ListProperty listProperty = new ListProperty(new NCnameProperty("thin"));
+ listProperty.addProperty(new NCnameProperty("solid"));
+ EnumProperty.Maker maker = new EnumProperty.Maker(0);
+ maker.addEnum("solid", EnumProperty.getInstance(0, "solid"));
+ new GenericShorthandParser().convertValueForProperty(0, listProperty, maker, propertyList);
+ Assert.assertTrue(propertyList.getUnknownPropertyValues().isEmpty());
+ }
+
+ @Test
+ public void testPropertyValidationJustThin() throws PropertyException {
+ StaticPropertyList propertyList = new StaticPropertyList(null, null);
+ ListProperty listProperty = new ListProperty(new NCnameProperty("thin"));
+ propertyList.putExplicit(Constants.PR_BORDER_LEFT, listProperty);
+ PropertyMaker borderLeftStyle = FOPropertyMapping.getGenericMappings()[Constants.PR_BORDER_LEFT_STYLE];
+ borderLeftStyle.getShorthand(propertyList);
+ Assert.assertTrue(propertyList.getUnknownPropertyValues().isEmpty());
+ }
+}