From: Peter Hancock Date: Thu, 13 Dec 2012 11:41:49 +0000 (+0000) Subject: Bugzilla 37114: Implementation of changes necessary to warn of invalid property values. X-Git-Tag: fop-2_0~257 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3f386d59ca9abaf9eecbee57966fd3ada3a6e8c6;p=xmlgraphics-fop.git 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 --- 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 inlines = new java.util.ArrayList(); + protected List inlines = new ArrayList(); /** Controls whether the IPD is automatically adjusted based on the area's children. */ protected transient boolean autoSize; - + /** The offset of the beforest child area of this area. */ protected int minChildOffset; - + /** * The offset of the afterest 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 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 @@ -84,6 +92,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 getUnknownPropertyValues() { + return unknownPropertyHandler.getUnknownPropertyValues(); + } + /** * @return the FObj object attached to the parentPropetyList */ @@ -107,6 +134,36 @@ public abstract class PropertyList { return p; } + /** + * 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 unknownPropertyValues = new HashMap(); + + /** + * A list of known properties which have already been processed + */ + private Set knownProperties = new HashSet(); + + 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 getUnknownPropertyValues() { + return unknownPropertyValues; + } + } + /** * Return the value explicitly specified on this FO. * @param propId The ID of the property whose value is desired. @@ -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; } diff --git a/status.xml b/status.xml index 0d6141553..1cae0afb1 100644 --- a/status.xml +++ b/status.xml @@ -59,6 +59,9 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + Implementation of changes necessary to warn of invalid property values. + Missing Glyph in Postscript using DejaVuSans.