]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Refactor: combine the two convertAttributeToProperty() methods.
authorWilliam Victor Mote <vmote@apache.org>
Thu, 1 May 2003 07:48:53 +0000 (07:48 +0000)
committerWilliam Victor Mote <vmote@apache.org>
Thu, 1 May 2003 07:48:53 +0000 (07:48 +0000)
This change makes a logic change also. Since the FONTSIZEATTR now uses the same method as all other properties, it will now (I think) inherit from its ancestors. AFAIK, this is the desired behavior.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196384 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/fo/PropertyListBuilder.java

index 2a6c5a31928169e87e9f665b267a6de0a8b9fa1d..5e7b22af05739593c908dfe7726c8144eefb461a 100644 (file)
@@ -56,6 +56,7 @@ import org.xml.sax.Attributes;
 
 // FOP
 import org.apache.fop.apps.FOPException;
+import org.apache.fop.fo.Property.*;
 
 public class PropertyListBuilder {
 
@@ -156,64 +157,21 @@ public class PropertyListBuilder {
         /** @todo When we do "shorthand" properties, must handle the "font"
          * property as well to see if font-size is set.
          */
-        convertAttributeToProperty(attributes, FONTSIZEATTR, validProperties, p, parentFO);
+        String attributeName = FONTSIZEATTR;
+        String attributeValue = attributes.getValue(attributeName);
+        convertAttributeToProperty(attributes, attributeName, validProperties,
+                                   p, parentFO, attributeValue);
 
         for (int i = 0; i < attributes.getLength(); i++) {
-            String attributeName = attributes.getQName(i);
-            convertAttributeToProperty(attributes, attributeName, validProperties, p, parentFO, i);
+            attributeName = attributes.getQName(i);
+            attributeValue = attributes.getValue(i);
+            convertAttributeToProperty(attributes, attributeName,
+                                       validProperties, p, parentFO,
+                                       attributeValue);
         }
         return p;
     }
 
-    private void convertAttributeToProperty(Attributes attributes,
-                                            String attributeName,
-                                            HashMap validProperties,
-                                            PropertyList p,
-                                            FObj parentFO,
-                                            int i) {
-        /* Handle "compound" properties, ex. space-before.minimum */
-        String basePropName = findBasePropertyName(attributeName);
-        String subPropName = findSubPropertyName(attributeName);
-        Property propVal = null;
-
-        Property.Maker propertyMaker = findMaker(validProperties, basePropName);
-
-        if (propertyMaker != null) {
-            try {
-                if (subPropName != null) {
-                    Property baseProp = p.getExplicitBaseProp(basePropName);
-                    if (baseProp == null) {
-                        // See if it is specified later in this list
-                        String baseValue = attributes.getValue(basePropName);
-                        if (baseValue != null) {
-                            baseProp = propertyMaker.make(p, baseValue,
-                                                          parentFO);
-                        }
-                        // else baseProp = propertyMaker.makeCompound(p, parentFO);
-                    }
-                    propVal = propertyMaker.make(baseProp, subPropName,
-                                                 p,
-                                                 attributes.getValue(i),
-                                                 parentFO);
-                } else {
-                    propVal = propertyMaker.make(p,
-                                                 attributes.getValue(i),
-                                                 parentFO);
-                }
-                if (propVal != null) {
-                    p.put(basePropName, propVal);
-                }
-            } catch (FOPException e) { /* Do other props. */
-                //log.error(e.getMessage());
-            }
-        } else {
-            if (!attributeName.startsWith("xmlns")) {
-                //log.error("property '"
-                //                       + attributeName + "' ignored");
-            }
-        }
-    }
-
     /**
      *
      * @param attributes Collection of attributes
@@ -226,22 +184,69 @@ public class PropertyListBuilder {
     private void convertAttributeToProperty(Attributes attributes,
                                             String attributeName,
                                             HashMap validProperties,
-                                            PropertyList propList,
-                                            FObj parentFO) {
-        String attributeValue = attributes.getValue(attributeName);
-        if (attributeValue == null) {
+                                            PropertyList p,
+                                            FObj parentFO,
+                                            String attributeValue) {
+        /* Handle "compound" properties, ex. space-before.minimum */
+        String basePropName = findBasePropertyName(attributeName);
+        String subPropName = findSubPropertyName(attributeName);
+
+        Property.Maker propertyMaker = findMaker(validProperties, basePropName);
+        if (propertyMaker == null) {
+            handleInvalidProperty(attributeName);
             return;
         }
-        Property.Maker propertyMaker = findMaker(validProperties, attributeName);
-        if (propertyMaker == null) {
+        if (attributeValue == null) {
             return;
         }
         try {
-            propList.put(attributeName,
-                propertyMaker.make(propList, attributeValue, parentFO));
+            Property prop = null;
+            if (subPropName == null) {
+                prop = propertyMaker.make(p, attributeValue, parentFO);
+            }
+            else {
+                prop = findSubPropValue(attributes, p, parentFO, basePropName, subPropName, prop, propertyMaker, attributeValue);
+            }
+            if (prop != null) {
+                p.put(basePropName, prop);
+            }
         }
         catch (FOPException e) {
             /**@todo log this exception */
+            // log.error(e.getMessage());
+        }
+    }
+
+    private Property findSubPropValue(Attributes attributes,
+                                      PropertyList p,
+                                      FObj parentFO,
+                                      String basePropName,
+                                      String subPropName,
+                                      Property propVal,
+                                      Maker propertyMaker,
+                                      String attributeValue)
+            throws FOPException {
+        Property baseProp = p.getExplicitBaseProp(basePropName);
+        if (baseProp == null) {
+            // See if it is specified later in this list
+            String baseValue = attributes.getValue(basePropName);
+            if (baseValue != null) {
+                baseProp = propertyMaker.make(p, baseValue,
+                                              parentFO);
+            }
+            // else baseProp = propertyMaker.makeCompound(p, parentFO);
+        }
+        propVal = propertyMaker.make(baseProp, subPropName,
+                                     p,
+                                     attributeValue,
+                                     parentFO);
+        return propVal;
+    }
+
+    private void handleInvalidProperty(String attributeName) {
+        if (!attributeName.startsWith("xmlns")) {
+            //log.error("property '"
+            //                       + attributeName + "' ignored");
         }
     }