aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPeter Hancock <phancock@apache.org>2012-12-13 11:41:49 +0000
committerPeter Hancock <phancock@apache.org>2012-12-13 11:41:49 +0000
commit3f386d59ca9abaf9eecbee57966fd3ada3a6e8c6 (patch)
treef4937adb34e7cb9b5c0f3f1cf1ac3017bef5740c /src
parent50ec77f77b34bcaeec2d2525a9e102da04b9b6fd (diff)
downloadxmlgraphics-fop-3f386d59ca9abaf9eecbee57966fd3ada3a6e8c6.tar.gz
xmlgraphics-fop-3f386d59ca9abaf9eecbee57966fd3ada3a6e8c6.zip
Bugzilla 37114: Implementation of changes necessary to warn of invalid property values.
Contributed by Robert Meyer. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1421238 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/java/org/apache/fop/area/inline/InlineArea.java2
-rw-r--r--src/java/org/apache/fop/area/inline/InlineParent.java8
-rw-r--r--src/java/org/apache/fop/fo/FObj.java28
-rw-r--r--src/java/org/apache/fop/fo/PropertyList.java78
-rw-r--r--src/java/org/apache/fop/fo/properties/GenericShorthandParser.java1
5 files changed, 113 insertions, 4 deletions
diff --git a/src/java/org/apache/fop/area/inline/InlineArea.java b/src/java/org/apache/fop/area/inline/InlineArea.java
index 5fa156ac8..37930f3ba 100644
--- a/src/java/org/apache/fop/area/inline/InlineArea.java
+++ b/src/java/org/apache/fop/area/inline/InlineArea.java
@@ -270,7 +270,7 @@ public class InlineArea extends Area {
storedIPDVariation += ipdVariation;
}
}
-
+
/**
* Returns the offset that this area would have if its offset and size were taking
* children areas into account. The bpd of an inline area is taken from its nominal
diff --git a/src/java/org/apache/fop/area/inline/InlineParent.java b/src/java/org/apache/fop/area/inline/InlineParent.java
index 405d71a50..4d3f27b30 100644
--- a/src/java/org/apache/fop/area/inline/InlineParent.java
+++ b/src/java/org/apache/fop/area/inline/InlineParent.java
@@ -20,7 +20,9 @@
package org.apache.fop.area.inline;
import java.util.Iterator;
+import java.util.ArrayList;
import java.util.List;
+import java.lang.Math;
import org.apache.fop.area.Area;
@@ -35,14 +37,14 @@ public class InlineParent extends InlineArea {
/**
* The list of inline areas added to this inline parent.
*/
- protected List<InlineArea> inlines = new java.util.ArrayList<InlineArea>();
+ protected List<InlineArea> inlines = new ArrayList<InlineArea>();
/** Controls whether the IPD is automatically adjusted based on the area's children. */
protected transient boolean autoSize;
-
+
/** The offset of the <q>beforest</q> child area of this area. */
protected int minChildOffset;
-
+
/**
* The offset of the <q>afterest</q> child area of this area. Offset from the
* before-edge of this area's content-rectangle and the after-edge of the child area's
diff --git a/src/java/org/apache/fop/fo/FObj.java b/src/java/org/apache/fop/fo/FObj.java
index 0e7e55aa9..d50e18b0e 100644
--- a/src/java/org/apache/fop/fo/FObj.java
+++ b/src/java/org/apache/fop/fo/FObj.java
@@ -37,6 +37,7 @@ import org.apache.fop.apps.FOPException;
import org.apache.fop.fo.extensions.ExtensionAttachment;
import org.apache.fop.fo.flow.Marker;
import org.apache.fop.fo.flow.table.TableCell;
+import org.apache.fop.fo.properties.Property;
import org.apache.fop.fo.properties.PropertyMaker;
/**
@@ -125,6 +126,33 @@ public abstract class FObj extends FONode implements Constants {
if (!inMarker() || "marker".equals(elementName)) {
bind(pList);
}
+ warnOnUnknownProperties(attlist, elementName, pList);
+ }
+
+ private void warnOnUnknownProperties(Attributes attlist, String objName, PropertyList propertyList)
+ throws FOPException {
+ Map<String, Property> unknowns = propertyList.getUnknownPropertyValues();
+ for (String propertyValue : unknowns.keySet()) {
+ FOValidationEventProducer producer = FOValidationEventProducer.Provider.get(getUserAgent()
+ .getEventBroadcaster());
+ producer.invalidPropertyValue(this, objName,
+ getAttributeNameForValue(attlist, unknowns.get(propertyValue), propertyList),
+ propertyValue, null,
+ getLocator());
+ }
+ }
+
+ private String getAttributeNameForValue(Attributes attList, Property value, PropertyList propertyList)
+ throws FOPException {
+ for (int i = 0; i < attList.getLength(); i++) {
+ String attributeName = attList.getQName(i);
+ String attributeValue = attList.getValue(i);
+ Property prop = propertyList.getPropertyForAttribute(attList, attributeName, attributeValue);
+ if (prop.equals(value)) {
+ return attributeName;
+ }
+ }
+ return "unknown";
}
/**
diff --git a/src/java/org/apache/fop/fo/PropertyList.java b/src/java/org/apache/fop/fo/PropertyList.java
index c9e9250f0..49bbf48a0 100644
--- a/src/java/org/apache/fop/fo/PropertyList.java
+++ b/src/java/org/apache/fop/fo/PropertyList.java
@@ -20,6 +20,11 @@
package org.apache.fop.fo;
// Java
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
import org.xml.sax.Attributes;
import org.apache.commons.logging.Log;
@@ -27,6 +32,7 @@ import org.apache.commons.logging.LogFactory;
import org.apache.xmlgraphics.util.QName;
+import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.fo.expr.PropertyException;
import org.apache.fop.fo.properties.CommonAbsolutePosition;
@@ -55,6 +61,8 @@ public abstract class PropertyList {
private static Log log = LogFactory.getLog(PropertyList.class);
+ private final UnknownPropertyHandler unknownPropertyHandler = new UnknownPropertyHandler();
+
/**
* Basic constructor.
* @param fObjToAttach the FO this PropertyList should be attached to
@@ -85,6 +93,25 @@ public abstract class PropertyList {
}
/**
+ * Adds an unknown property value to the property list so that if
+ * necessary, a warning can be displayed.
+ * @param propertyValue The unknown property value
+ * @param output The output of the property to validate
+ * @param property The original property containing the full value
+ */
+ public void validatePropertyValue(String propertyValue, Property output, Property property) {
+ unknownPropertyHandler.validatePropertyValue(propertyValue, output, property);
+ }
+
+ /**
+ * Gets the current list of unknown property values
+ * @return The set containing the list of unknown property values
+ */
+ public Map<String, Property> getUnknownPropertyValues() {
+ return unknownPropertyHandler.getUnknownPropertyValues();
+ }
+
+ /**
* @return the FObj object attached to the parentPropetyList
*/
public PropertyList getParentPropertyList() {
@@ -108,6 +135,36 @@ public abstract class PropertyList {
}
/**
+ * A class to handle unknown shorthand property values e.g. border="solit 1pt"
+ */
+ private static class UnknownPropertyHandler {
+
+ /**
+ * A list of unknown properties identified by the value and property in which its featured
+ */
+ private Map<String, Property> unknownPropertyValues = new HashMap<String, Property>();
+
+ /**
+ * A list of known properties which have already been processed
+ */
+ private Set<Property> knownProperties = new HashSet<Property>();
+
+ void validatePropertyValue(String propertyValue, Property output, Property property) {
+ if (!knownProperties.contains(property) && output == null) {
+ if (propertyValue != null) {
+ unknownPropertyValues.put(propertyValue, property);
+ }
+ } else {
+ knownProperties.add(property);
+ }
+ }
+
+ Map<String, Property> getUnknownPropertyValues() {
+ return unknownPropertyValues;
+ }
+ }
+
+ /**
* Return the value explicitly specified on this FO.
* @param propId The ID of the property whose value is desired.
* @return The value if the property is explicitly set, otherwise null.
@@ -357,6 +414,27 @@ public abstract class PropertyList {
&& findSubPropertyName(propertyName) != null));
}
+ public Property getPropertyForAttribute(Attributes attributes, String attributeName, String attributeValue)
+ throws FOPException {
+ if (attributeValue != null) {
+ if (attributeName.startsWith("xmlns:") || "xmlns".equals(attributeName)) {
+ return null;
+ }
+ String basePropertyName = findBasePropertyName(attributeName);
+ String subPropertyName = findSubPropertyName(attributeName);
+
+ int propId = FOPropertyMapping.getPropertyId(basePropertyName);
+ int subpropId = FOPropertyMapping.getSubPropertyId(subPropertyName);
+
+ if (propId == -1 || (subpropId == -1 && subPropertyName != null)) {
+ return null;
+ }
+
+ return getExplicit(propId);
+ }
+ return null;
+ }
+
/**
*
* @param attributes Collection of attributes
diff --git a/src/java/org/apache/fop/fo/properties/GenericShorthandParser.java b/src/java/org/apache/fop/fo/properties/GenericShorthandParser.java
index b008c714d..ac3d4d13a 100644
--- a/src/java/org/apache/fop/fo/properties/GenericShorthandParser.java
+++ b/src/java/org/apache/fop/fo/properties/GenericShorthandParser.java
@@ -88,6 +88,7 @@ public class GenericShorthandParser implements ShorthandParser {
while (iprop.hasNext() && prop == null) {
Property p = (Property)iprop.next();
prop = maker.convertShorthandProperty(propertyList, p, null);
+ propertyList.validatePropertyValue(p.getNCname(), prop, property);
}
return prop;
}