[Schmitzm-commits] r1534 - in trunk/schmitzm-core/src: main/java/de/schmitzm/io test/java/de/schmitzm/testing

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Mar 21 15:12:46 CET 2011


Author: mojays
Date: 2011-03-21 15:12:45 +0100 (Mon, 21 Mar 2011)
New Revision: 1534

Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java
   trunk/schmitzm-core/src/test/java/de/schmitzm/testing/TestingClass.java
Log:
new helper method IOUtil.decodeURL(.)

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java	2011-03-20 19:45:02 UTC (rev 1533)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java	2011-03-21 14:12:45 UTC (rev 1534)
@@ -51,6 +51,7 @@
 import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLDecoder;
+import java.net.URLEncoder;
 import java.nio.channels.FileChannel;
 import java.nio.charset.Charset;
 import java.security.MessageDigest;
@@ -1104,6 +1105,33 @@
 			return false;
 		}
 	}
+	
+	/**
+	 * Decodes an encoded string several times, so that the string
+	 * is also decoded, if the source string was encoded multiple
+	 * times. The decoding procedure is looped until the there
+	 * are no changes.
+	 * @param encodedStr encoded string
+	 * @return empty string if source is {@code null}
+	 * @see URLDecoder#decode(String, String)
+	 */
+	public static String decodeURL(String encodedStr) {
+	  if ( encodedStr == null )
+	    return "";
+	  String decodedStr = null;
+	  try {
+	    do {
+	      // except the first loop use the decoded string
+	      // of the last loop as source
+	      if ( decodedStr != null )
+	        encodedStr = decodedStr; 
+	      decodedStr = URLDecoder.decode(encodedStr, "UTF-8");
+	    } while( !decodedStr.equals( encodedStr ) );
+	  } catch (UnsupportedEncodingException err) {
+	    // ignore
+	  }
+	  return decodedStr;
+	}
 
 	/**
 	 * Bereinigt Pfadangaben, z.b. "C:\Programme" zu "C:\\Programme" und

Modified: trunk/schmitzm-core/src/test/java/de/schmitzm/testing/TestingClass.java
===================================================================
--- trunk/schmitzm-core/src/test/java/de/schmitzm/testing/TestingClass.java	2011-03-20 19:45:02 UTC (rev 1533)
+++ trunk/schmitzm-core/src/test/java/de/schmitzm/testing/TestingClass.java	2011-03-21 14:12:45 UTC (rev 1534)
@@ -2,6 +2,8 @@
 
 import org.apache.log4j.Logger;
 
+import de.schmitzm.lang.LangUtil;
+
 /**
  * Abstract super class for our test classes to initialize some general stuff,
  * e.g. logger.
@@ -9,6 +11,8 @@
  * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
  */
 public abstract class TestingClass {
+    protected Logger LOGGER = LangUtil.createLogger(this);
+  
 	// instantiate TestingUtil to initialize the Log4J appender
 	static {
 		new TestingUtil();



More information about the Schmitzm-commits mailing list