[Schmitzm-commits] r1142 - trunk/src/schmitzm/geotools/io

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sat Oct 16 23:32:08 CEST 2010


Author: alfonx
Date: 2010-10-16 23:32:08 +0200 (Sat, 16 Oct 2010)
New Revision: 1142

Modified:
   trunk/src/schmitzm/geotools/io/GeoImportUtil.java
Log:


Modified: trunk/src/schmitzm/geotools/io/GeoImportUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/io/GeoImportUtil.java	2010-10-16 20:59:01 UTC (rev 1141)
+++ trunk/src/schmitzm/geotools/io/GeoImportUtil.java	2010-10-16 21:32:08 UTC (rev 1142)
@@ -292,22 +292,10 @@
 		/**
 		 * .cpg ?
 		 */
-		try {
-			for (URL cpgURL : getCharsetUrls(url)) {
-				String charsetName = IOUtil.readURLasString(cpgURL);
-				if (charsetName != null && !charsetName.equals("")) {
-					store.setStringCharset(Charset.forName(charsetName));
-					break;
-				}
-			}
+		Charset readCharset = readCharset(url);
+		if (readCharset != null)
+			store.setStringCharset(readCharset);
 
-		} catch (Exception err) {
-			LOGGER.warn(" CRS.parseWKT mit Ex\n: ", err);
-			LOGGER.warn(" No projection found for file. Default is used.");
-			LOGGER.warn(" NOT calling forceSchemaCRS now... please provide a URL to an existing .prj file!");
-			// store.forceSchemaCRS(DEFAULT_CRS);
-		}
-
 		FeatureCollection<SimpleFeatureType, SimpleFeature> fc = store
 				.getFeatureSource().getFeatures();
 
@@ -1387,6 +1375,8 @@
 	/**
 	 * The URLs where a <code>.cpg</code> or <code>.cst</code> file describing
 	 * the {@link Charset} could be found.
+	 * 
+	 * @param url_ must be an {@link URL} with an extension. The extensions will then the changed for possible charset containing extensions. 
 	 */
 	public static URL[] getCharsetUrls(URL url_) {
 		return new URL[] { IOUtil.changeUrlExt(url_, "cpg"),
@@ -1394,4 +1384,28 @@
 				IOUtil.changeUrlExt(url_, "CPG"),
 				IOUtil.changeUrlExt(url_, "CST") };
 	}
+
+	/**
+	 * Tries to read a file containing {@link Charset} information next to a {@link URL}.
+	 * 
+	 * @return <code>null</code> is nothing found.
+	 */
+	public static Charset readCharset(URL url) {
+		URL[] cpgUrls = GeoImportUtil.getCharsetUrls( url);
+		for (URL cpgUrl : cpgUrls) {
+			try {
+				String charsetName = IOUtil.readURLasString(cpgUrl);
+
+				if (charsetName.equals(""))
+					continue;
+				
+				return Charset.forName(charsetName);
+
+			} 
+			catch (Exception e) {
+//					 LOGGER.warn("Reading .cpg file failed for "+cpgUrl+". Using default. ");
+			}
+		}
+		return null;
+	}
 }



More information about the Schmitzm-commits mailing list