[Schmitzm-commits] r829 - in branches/2.0-GP14/src/schmitzm: jfree/feature/style lang xml

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Wed May 5 17:43:43 CEST 2010


Author: alfonx
Date: 2010-05-05 17:43:39 +0200 (Wed, 05 May 2010)
New Revision: 829

Modified:
   branches/2.0-GP14/src/schmitzm/jfree/feature/style/FeatureChartStyleXMLFactory.java
   branches/2.0-GP14/src/schmitzm/lang/LangUtil.java
   branches/2.0-GP14/src/schmitzm/xml/XMLUtil.java
Log:
Backprted Bugfix for http://wald.intevation.org/tracker/index.php?func=detail&aid=1313&group_id=47&atid=290 
 XML for Aggregation Weight attribute and it's NoDataValues 
 and the required XMLUtil functions.

Modified: branches/2.0-GP14/src/schmitzm/jfree/feature/style/FeatureChartStyleXMLFactory.java
===================================================================
--- branches/2.0-GP14/src/schmitzm/jfree/feature/style/FeatureChartStyleXMLFactory.java	2010-05-05 14:53:08 UTC (rev 828)
+++ branches/2.0-GP14/src/schmitzm/jfree/feature/style/FeatureChartStyleXMLFactory.java	2010-05-05 15:43:39 UTC (rev 829)
@@ -30,6 +30,7 @@
 package schmitzm.jfree.feature.style;
 
 import java.util.List;
+import java.util.Set;
 
 import org.geotools.feature.FeatureCollection;
 import org.jdom.Element;
@@ -88,17 +89,27 @@
     
     // Read all range attribute definitions
     int rangeAttrNo = 0;
-    for (Element featureAttrElem : (List<Element>)featureElement.getChildren("rangeAttr") ) {
-      String featureAttrName = XMLUtil.getAttribute(featureAttrElem, "name");
+    for (Element rangeAttrElem : (List<Element>)featureElement.getChildren("rangeAttr") ) {
+      String featureAttrName = XMLUtil.getAttribute(rangeAttrElem, "name");
       if ( featureAttrName == null )
         throw new UnsupportedOperationException("Attribute 'name' necessary for <rangeAttr> element of FeatureChartStyle!");
       // Apply attributes to style
       rangeAttrNo++;
       chartStyle.setAttributeName(rangeAttrNo, featureAttrName);
       chartStyle.setAttributeNormalized(rangeAttrNo, XMLUtil.getBooleanAttribute(domainAttrElem, "normalize", false));
+
       String aggrFuncStr = XMLUtil.getAttribute(domainAttrElem, "function", (String)null);
       if ( aggrFuncStr != null )
         chartStyle.setAttributeAggregation(rangeAttrNo, AggregationFunction.valueOf(aggrFuncStr) );
+      
+      String aggrFuncWeightAtt = XMLUtil.getAttribute(rangeAttrElem, "weightAttrName", (String)null);
+      if ( aggrFuncWeightAtt != null )
+        chartStyle.setAttributeAggregationWeightAttributeName(rangeAttrNo, aggrFuncWeightAtt );
+      
+      Set<Object> nullAliases = XMLUtil.getSetAttribute(rangeAttrElem, "weightAttrNullAliases");
+      if (nullAliases != null)
+    	  chartStyle.setWeightAttributeNoDataValues(rangeAttrNo, nullAliases);
+
     }
   }
 
@@ -148,7 +159,9 @@
       addChildToElement(attrElem, "rangeAttr", false,
           "name", style.getAttributeName(i),
           "normalize", style.isAttributeNormalized(i),
-          "function", style.getAttributeAggregation(i)
+          "function", style.getAttributeAggregation(i),
+          "weightAttrName", style.getAttributeAggregationWeightAttributeName(i),
+          "weightAttrNullAliases", XMLUtil.convertSetToSeparatedString(style.getWeightAttributeNoDataValues(i))
       );
 
     return root;

Modified: branches/2.0-GP14/src/schmitzm/lang/LangUtil.java
===================================================================
--- branches/2.0-GP14/src/schmitzm/lang/LangUtil.java	2010-05-05 14:53:08 UTC (rev 828)
+++ branches/2.0-GP14/src/schmitzm/lang/LangUtil.java	2010-05-05 15:43:39 UTC (rev 829)
@@ -183,7 +183,7 @@
 	 * @param str
 	 *            aneinanderzuhaengende Stings
 	 */
-	public static String stringConcatWithSep(String sep, String... str) {
+	public static String stringConcatWithSep(String sep, Object... str) {
 		StringBuffer sb = new StringBuffer();
 		for (int i = 0; str != null && i < str.length; i++) {
 			if (i > 0)

Modified: branches/2.0-GP14/src/schmitzm/xml/XMLUtil.java
===================================================================
--- branches/2.0-GP14/src/schmitzm/xml/XMLUtil.java	2010-05-05 14:53:08 UTC (rev 828)
+++ branches/2.0-GP14/src/schmitzm/xml/XMLUtil.java	2010-05-05 15:43:39 UTC (rev 829)
@@ -30,6 +30,9 @@
 package schmitzm.xml;
 
 import java.awt.Color;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.StringTokenizer;
 
 import org.apache.log4j.Logger;
 import org.jdom.Element;
@@ -37,6 +40,7 @@
 import org.jdom.output.Format;
 import org.jdom.output.XMLOutputter;
 
+import schmitzm.lang.LangUtil;
 import schmitzm.swing.SwingUtil;
 import skrueger.i8n.Translation;
 
@@ -210,6 +214,52 @@
     return setAttribute(element, attrName, value, false);
   }
   
+
+  /**
+   * Gets a string-separated attribute value from element as {@code Set<String>}.
+   * @param element  element where the attribute is determined from
+   * @param attrName name of the attribute
+   * @param defValue optional default value returned if attribute is not found (or empty)
+   * @return {@code null} if {@code element} is {@code null} or attribute is not
+   *         specified in element
+   */
+  public static Set<Object> getSetAttribute(Element element, String attrName, Set<Object>... defValue) {
+    String value = getAttribute(element, attrName);
+    if ( value != null )
+      return convertSeparatedStringToSet(value);
+    if ( defValue.length > 0 )
+      return defValue[0];
+    return null;
+  }
+
+  /**
+   * Parses a semicolon-separated string and stores its elements in
+   * a set. 
+   * @param objectString the semicolon-separated string of objects
+   * @return an empty set if the string is empty
+   */
+  public static Set<Object> convertSeparatedStringToSet(String objectString) {
+    Set<Object>     objects = new HashSet<Object>();
+    StringTokenizer st      = new StringTokenizer(objectString,";\n");
+    for (;st.hasMoreTokens();)
+      objects.add( st.nextToken() );
+    return objects; 
+  }
+  
+
+  /**
+   * Creates a semicolon-separated string of the elements of a set. 
+   * @param objects the objects which are transformed to string and
+   *                concatenated
+   * @return {@code null} if the set is empty or {@code null}
+   */
+  public static String convertSetToSeparatedString(Set<Object> objects) {
+    if ( objects == null || objects.isEmpty() )
+      return null;
+    return LangUtil.stringConcatWithSep(";", objects.toArray()); 
+  }
+
+  
 //  /**
 //   * Returns a {@link DocumentBuilder}. If validating is true,
 //   * the contents is validated against the XSD specified in the file.



More information about the Schmitzm-commits mailing list