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

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Oct 14 23:03:49 CEST 2010


Author: alfonx
Date: 2010-10-14 23:03:48 +0200 (Thu, 14 Oct 2010)
New Revision: 1126

Modified:
   trunk/src/schmitzm/geotools/feature/FeatureUtil.java
Log:


Modified: trunk/src/schmitzm/geotools/feature/FeatureUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2010-10-14 21:02:49 UTC (rev 1125)
+++ trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2010-10-14 21:03:48 UTC (rev 1126)
@@ -51,6 +51,7 @@
 import java.util.SortedMap;
 import java.util.TreeMap;
 import java.util.Vector;
+import java.util.regex.Pattern;
 
 import javax.measure.converter.ConversionException;
 import javax.measure.quantity.Length;
@@ -104,6 +105,7 @@
 
 import schmitzm.geotools.FilterUtil;
 import schmitzm.geotools.GTUtil;
+import schmitzm.io.IOUtil;
 import schmitzm.lang.LangUtil;
 import schmitzm.lang.ResourceProvider;
 import schmitzm.temp.BaseTypeUtil;
@@ -2540,7 +2542,44 @@
 	    
 	  return null;
 	}
+	
 
+	/**
+	 * @returns a "cleaned" (DBF compatible) proposal for a attribute name based
+	 *          on the existing name.
+	 */
+	public static String cleanAttname(String name) {
+		return cleanAttname(name, null);
+	}
+
+	static public final Pattern StringStartsWithNumber = Pattern
+			.compile("^\\d.*$");
+
+	/**
+	 * @returns a "cleaned" (DBF compatible) proposal for a attribute name based
+	 *          on the existing name.
+	 */
+	public static String cleanAttname(String name, Integer counter) {
+
+		String clean = IOUtil.cleanFilename(name);
+		clean = clean.toUpperCase();
+
+		if (StringStartsWithNumber.matcher(clean).find()) {
+			clean = "_" + clean;
+		}
+
+		clean = clean.substring(0, Math.min(11, clean.length() - 1));
+
+		if (!FeatureUtil.checkAttributeNameRestrictions(clean)) {
+			if (counter != null)
+				return "COLUMN" + counter;
+			else
+				return "COLUMN" + new Random().nextInt(9999);
+		}
+
+		return clean;
+	}
+
 	// /**
 	// * Extrahiert alle Geometrien aus einer FeatureCollection. Fuer jedes
 	// * Geometry-Attribut der FeatureCollection wird eine GeometrieCollection



More information about the Schmitzm-commits mailing list