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
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 0000000..ba197fb
--- /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 c96e34b..4fc5c4d 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 @@
     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 @@
         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 @@
         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 @@
         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 42b6548..8df6842 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 @@
             }
             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 a315944..e61632a 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 @@
      * @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 0000000..1b038a7
--- /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());
+    }
+}