[Schmitzm-commits] r1367 - in branches/2.3.x: src/schmitzm/io src_junit/schmitzm/io

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Jan 14 12:33:08 CET 2011


Author: alfonx
Date: 2011-01-14 12:33:06 +0100 (Fri, 14 Jan 2011)
New Revision: 1367

Modified:
   branches/2.3.x/src/schmitzm/io/IOUtil.java
   branches/2.3.x/src_junit/schmitzm/io/IOUtilTest.java
Log:
Bugfixed a problem with spaces in the filenames of Files  imported into Geopublisher atlas

Modified: branches/2.3.x/src/schmitzm/io/IOUtil.java
===================================================================
--- branches/2.3.x/src/schmitzm/io/IOUtil.java	2011-01-13 09:25:51 UTC (rev 1366)
+++ branches/2.3.x/src/schmitzm/io/IOUtil.java	2011-01-14 11:33:06 UTC (rev 1367)
@@ -848,6 +848,20 @@
 	public static String cleanFilename(String filename) {
 
 		final String orig = filename;
+		
+
+		// When getting URL encoded filenames, the spaces might already be
+		// converted to %20 etc... So we try to treat this filename as a URL-encoded filename
+		try {
+			URL asUrl = new URL("file://localhost/" + filename);
+			filename = DataUtilities.urlToFile(asUrl).getName();
+//			filename = asUrl.getFile();
+//			if (filename.startsWith("/"))
+//				filename = filename.substring(1);
+		} catch (Exception e) {
+//			System.out.println(e);
+		}
+
 		filename = filename.toLowerCase();
 		filename = filename.replace(" ", "_");
 

Modified: branches/2.3.x/src_junit/schmitzm/io/IOUtilTest.java
===================================================================
--- branches/2.3.x/src_junit/schmitzm/io/IOUtilTest.java	2011-01-13 09:25:51 UTC (rev 1366)
+++ branches/2.3.x/src_junit/schmitzm/io/IOUtilTest.java	2011-01-14 11:33:06 UTC (rev 1367)
@@ -74,4 +74,11 @@
 		assertEquals("exterme",
 				IOUtil.getFilename(new URL("http://www.bahn.de/exterme")));
 	}
+
+	@Test
+	public void testCleanFilename()
+	{
+		assertEquals( "geopublisher_poster.pdf", IOUtil.cleanFilename("Geopublisher Poster.pdf"));
+		assertEquals( "geopublisher_poster.pdf", IOUtil.cleanFilename("Geopublisher%20Poster.pdf"));
+	}
 }



More information about the Schmitzm-commits mailing list