You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ph...@apache.org on 2012/12/13 12:41:52 UTC

svn commit: r1421238 - in /xmlgraphics/fop/trunk: ./ src/java/org/apache/fop/area/inline/ src/java/org/apache/fop/fo/ src/java/org/apache/fop/fo/properties/

Author: phancock
Date: Thu Dec 13 11:41:49 2012
New Revision: 1421238

URL: http://svn.apache.org/viewvc?rev=1421238&view=rev
Log:
Bugzilla 37114: Implementation of changes necessary to warn of invalid property values.
Contributed by Robert Meyer.

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/InlineArea.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/InlineParent.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FObj.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/PropertyList.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/GenericShorthandParser.java
    xmlgraphics/fop/trunk/status.xml

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/InlineArea.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/InlineArea.java?rev=1421238&r1=1421237&r2=1421238&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/InlineArea.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/InlineArea.java Thu Dec 13 11:41:49 2012
@@ -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

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/InlineParent.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/InlineParent.java?rev=1421238&r1=1421237&r2=1421238&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/InlineParent.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/area/inline/InlineParent.java Thu Dec 13 11:41:49 2012
@@ -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 Inline
     /**
      * 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

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FObj.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FObj.java?rev=1421238&r1=1421237&r2=1421238&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FObj.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/FObj.java Thu Dec 13 11:41:49 2012
@@ -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 FONod
         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";
     }
 
     /**

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/PropertyList.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/PropertyList.java?rev=1421238&r1=1421237&r2=1421238&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/PropertyList.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/PropertyList.java Thu Dec 13 11:41:49 2012
@@ -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.LogFac
 
 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

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/GenericShorthandParser.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/GenericShorthandParser.java?rev=1421238&r1=1421237&r2=1421238&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/GenericShorthandParser.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/GenericShorthandParser.java Thu Dec 13 11:41:49 2012
@@ -88,6 +88,7 @@ public class GenericShorthandParser impl
         while (iprop.hasNext() && prop == null) {
             Property p = (Property)iprop.next();
             prop = maker.convertShorthandProperty(propertyList, p, null);
+            propertyList.validatePropertyValue(p.getNCname(), prop, property);
         }
         return prop;
     }

Modified: xmlgraphics/fop/trunk/status.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/status.xml?rev=1421238&r1=1421237&r2=1421238&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/status.xml (original)
+++ xmlgraphics/fop/trunk/status.xml Thu Dec 13 11:41:49 2012
@@ -59,6 +59,9 @@
       documents. Example: the fix of marks layering will be such a case when it's done.
     -->
     <release version="FOP Trunk" date="TBD">
+      <action context="Code" dev="PH" type="fix" fixes-bug="37114" due-to="Robert Meyer">
+        Implementation of changes necessary to warn of invalid property values.
+      </action>
       <action context="Layout" dev="PH" type="fix" fixes-bug="FOP-2171" due-to="Simon Steiner">
        Missing Glyph in Postscript using DejaVuSans.
       </action>



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org