[Schmitzm-commits] r969 - in trunk: src/schmitzm/geotools/feature src/schmitzm/geotools/styling src_junit/schmitzm/geotools/styling

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Aug 12 13:02:46 CEST 2010


Author: alfonx
Date: 2010-08-12 13:02:45 +0200 (Thu, 12 Aug 2010)
New Revision: 969

Modified:
   trunk/src/schmitzm/geotools/feature/FeatureUtil.java
   trunk/src/schmitzm/geotools/styling/StylingUtil.java
   trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java
Log:
NPE Bugfix for RasterSymbolizer in StylingUtil.correctAttributeNames

Modified: trunk/src/schmitzm/geotools/feature/FeatureUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2010-08-12 09:37:37 UTC (rev 968)
+++ trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2010-08-12 11:02:45 UTC (rev 969)
@@ -168,7 +168,7 @@
 			// Ignore number literals
 			try {
 				Number parsed = NumberFormat.getInstance().parse(attName);
-				
+
 				// Acjhtung "34hf" wird hier einfach geparsed!!
 				if (parsed.toString().length() == attName.length())
 					continue;
@@ -2293,8 +2293,9 @@
 	 * has no attributes, an exception is thrown.
 	 * 
 	 * @param schema
-	 *            SimpleFeatureType to check against
-	 * @param name
+	 *            SimpleFeatureType to check against. if <code>null</code>, a
+	 *            new NameImpl is returned with empty namespace.
+	 * @param localName
 	 *            localname of an attribte to look for
 	 * 
 	 * @return If no match is found, the first attribute is returned.
@@ -2302,6 +2303,9 @@
 	public static Name findBestMatchingAttributeFallBackFirst(
 			SimpleFeatureType schema, String localName) {
 
+		if (schema == null)
+			return new NameImpl(localName);
+
 		Name bestmatch = findBestMatchingAttribute(schema, localName);
 
 		if (bestmatch == null)

Modified: trunk/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/styling/StylingUtil.java	2010-08-12 09:37:37 UTC (rev 968)
+++ trunk/src/schmitzm/geotools/styling/StylingUtil.java	2010-08-12 11:02:45 UTC (rev 969)
@@ -2484,6 +2484,8 @@
 	 * Styles need GeometryProperty set to "geom" to work. This method checks
 	 * all referenced AttributeNames and checks them against the schema.
 	 * 
+	 * @param Schema may be <code>null</code>, e.g. for raster layers
+	 * 
 	 * @retun <code>true</code> if something has been change, otherwise
 	 *        <code>false</code>.
 	 */
@@ -2493,10 +2495,10 @@
 		DuplicatingStyleVisitor dsv = new DuplicatingStyleVisitor() {
 			public void visit(RasterSymbolizer sym) {
 				if (!sym.getGeometryPropertyName().equals("geom")) {
-					LOGGER
-							.debug("Corrected one RasterSymbolizer with GeometryPropertyName '"
-									+ sym.getGeometryPropertyName()
-									+ "' to 'geom'.");
+//					LOGGER
+//							.debug("Corrected one RasterSymbolizer with GeometryPropertyName '"
+//									+ sym.getGeometryPropertyName()
+//									+ "' to 'geom'.");
 					sym.setGeometryPropertyName("geom");
 				}
 				super.visit(sym);
@@ -2537,14 +2539,6 @@
 				if (sym.getPriority() != null)
 					sym.setPriority(copy(sym.getPriority()));
 
-				// if (sym.getPriority() instanceof PropertyName) {
-				// PropertyName propertyname = (PropertyName) sym
-				// .getPriority();
-				// sym.setPriority(ff.property(FeatureUtil
-				// .findBestMatchingAttributeFallBackFirst(schema,
-				// propertyname.getPropertyName())));
-				// }
-
 				super.visit(sym);
 			}
 
@@ -2667,10 +2661,6 @@
 					prop2 = attributeNames[0];
 				}
 
-				// LOGGER.debug("The second property for \n" + filterExpression
-				// + "\n is "
-				// + prop2);
-
 				return FilterUtil.FILTER_FAC2.property(prop2);
 			}
 		}

Modified: trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java
===================================================================
--- trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java	2010-08-12 09:37:37 UTC (rev 968)
+++ trunk/src_junit/schmitzm/geotools/styling/StylingUtilTest.java	2010-08-12 11:02:45 UTC (rev 969)
@@ -18,7 +18,9 @@
 import org.geotools.map.DefaultMapContext;
 import org.geotools.map.DefaultMapLayer;
 import org.geotools.renderer.lite.StreamingRenderer;
+import org.geotools.styling.RasterSymbolizer;
 import org.geotools.styling.Style;
+import org.geotools.styling.StyleBuilder;
 import org.junit.Test;
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.feature.simple.SimpleFeatureType;
@@ -30,8 +32,24 @@
 public class StylingUtilTest extends TestCase {
 
 	boolean INTERACTIVE = !GraphicsEnvironment.isHeadless();
+	
 
 	@Test
+	public void testCorrectPropertyNamesWithRasterSymbolizer() {
+		
+		StyleBuilder sb = StylingUtil.STYLE_BUILDER;
+		RasterSymbolizer rs = sb.createRasterSymbolizer();
+		Style style = sb.createStyle(rs);
+		
+		assertNotNull(style);
+		
+		// Once we NPEs here.
+		StylingUtil.correctPropertyNames(style, null);
+		
+		assertNotNull(style);
+	}
+
+	@Test
 	public void testSelectionStyles() throws Throwable {
 
 		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil2



More information about the Schmitzm-commits mailing list