[Schmitzm-commits] r779 - trunk/src/schmitzm/geotools/feature

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Mar 30 12:29:42 CEST 2010


Author: alfonx
Date: 2010-03-30 12:29:42 +0200 (Tue, 30 Mar 2010)
New Revision: 779

Modified:
   trunk/src/schmitzm/geotools/feature/FeatureUtil.java
Log:
findBestMathcingAttributeName now also checks for a "_" added infront of attribNames that start with a number.

Modified: trunk/src/schmitzm/geotools/feature/FeatureUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2010-03-29 10:53:14 UTC (rev 778)
+++ trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2010-03-30 10:29:42 UTC (rev 779)
@@ -2240,8 +2240,10 @@
 
 	/**
 	 * Checks whether the given attribute local name exists in the schema. If no
-	 * exact match is found, an ingnoreCase match is performed. If the schema
-	 * has no attributes, an exception is thrown.
+	 * exact match is found, an ingnoreCase match is performed. Another rule
+	 * that is attnames starting with "_" may have been constructed to avoid
+	 * names starting with a number.<br/>
+	 * If the schema has no attributes, an exception is thrown.
 	 * 
 	 * @param schema
 	 *            SimpleFeatureType to check against
@@ -2251,8 +2253,8 @@
 	 * 
 	 * @return If no match is found, <code>null</code> is returned.
 	 */
-	public static NameImpl findBestMatchingAttribute(
-			SimpleFeatureType schema, String localName) {
+	public static NameImpl findBestMatchingAttribute(SimpleFeatureType schema,
+			String localName) {
 
 		if (localName == null) {
 			return null;
@@ -2268,26 +2270,67 @@
 		// Checking for exact match
 		for (AttributeDescriptor d : attributeDescriptors) {
 			if (d.getName().getLocalPart().equals(localName))
-				return new NameImpl( d.getName().getNamespaceURI(), d.getName().getLocalPart() );
+				return new NameImpl(d.getName().getNamespaceURI(), d.getName()
+						.getLocalPart());
 		}
-		// Checking for irgnoreCase match
+		// Checking for ignoreCase match
 		for (AttributeDescriptor d : attributeDescriptors) {
 			if (d.getName().getLocalPart().equalsIgnoreCase(localName)) {
-//				LOGGER.error("Corrected attributeName '" + localName + "' to "
-//						+ d.getName().getLocalPart());
-				return new NameImpl( d.getName().getNamespaceURI(), d.getName().getLocalPart() );
+				return new NameImpl(d.getName().getNamespaceURI(), d.getName()
+						.getLocalPart());
 			}
 		}
 
-		// Checking for irgnoreCase match with empty spaces converted to _
+		// Checking for exact match with empty spaces converted to _
 		for (AttributeDescriptor d : attributeDescriptors) {
+			if (d.getName().getLocalPart().replace(" ", "_").equals(
+					localName.replace(" ", "_"))) {
+				return new NameImpl(d.getName().getNamespaceURI(), d.getName()
+						.getLocalPart());
+			}
+		}
+
+		// Checking for ignoreCase match with empty spaces converted to _
+		for (AttributeDescriptor d : attributeDescriptors) {
 			if (d.getName().getLocalPart().replace(" ", "_").equalsIgnoreCase(
 					localName.replace(" ", "_"))) {
-//				LOGGER.error("Corrected attributeName '" + localName + "' to "
-//						+ d.getName().getLocalPart());
-				return new NameImpl( d.getName().getNamespaceURI(), d.getName().getLocalPart() );
+				return new NameImpl(d.getName().getNamespaceURI(), d.getName()
+						.getLocalPart());
 			}
 		}
+
+		// Checking for excact match with a _ infront of the schema name
+		for (AttributeDescriptor d : attributeDescriptors) {
+			if (("_" + d.getName().getLocalPart()).equals(localName)) {
+				return new NameImpl(d.getName().getNamespaceURI(), d.getName()
+						.getLocalPart());
+			}
+		}
+		
+		// Checking for excact match with a _ infront of the seached name 
+		for (AttributeDescriptor d : attributeDescriptors) {
+			if ((d.getName().getLocalPart()).equals("_" + localName)) {
+				return new NameImpl(d.getName().getNamespaceURI(), d.getName()
+						.getLocalPart());
+			}
+		}
+		
+		// Checking for excact match with a _ infront of the schema name
+		for (AttributeDescriptor d : attributeDescriptors) {
+			if (("_" + d.getName().getLocalPart()).equalsIgnoreCase(localName)) {
+				return new NameImpl(d.getName().getNamespaceURI(), d.getName()
+						.getLocalPart());
+			}
+		}
+		
+		// Checking for excact match with a _ infront of the seached name 
+		for (AttributeDescriptor d : attributeDescriptors) {
+			if ((d.getName().getLocalPart()).equalsIgnoreCase("_" + localName)) {
+				return new NameImpl(d.getName().getNamespaceURI(), d.getName()
+						.getLocalPart());
+			}
+		}
+
 		return null;
 	}
 



More information about the Schmitzm-commits mailing list