--- /dev/null
+/*\r
+ * Copyright 2008 ZXing authors\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+package com.google.zxing.client.rim.util;\r
+\r
+import java.util.Enumeration;\r
+import java.util.Hashtable;\r
+\r
+/**\r
+ * Used to decode URL encoded characters.\r
+ *\r
+ * This code was contributed by LifeMarks.\r
+ *\r
+ * @author Matt York (matt@lifemarks.mobi)\r
+ */\r
+public final class URLDecoder {\r
+\r
+ private URLDecoder() {\r
+ }\r
+\r
+ private static final Hashtable decodingMap;\r
+ static {\r
+ decodingMap = new Hashtable(37);\r
+ decodingMap.put("%21", "!");\r
+ decodingMap.put("%2A", "*");\r
+ decodingMap.put("%2a", "*");\r
+ decodingMap.put("%27", "'");\r
+ decodingMap.put("%28", "(");\r
+ decodingMap.put("%29", ")");\r
+ decodingMap.put("%3B", ";");\r
+ decodingMap.put("%3b", ";");\r
+ decodingMap.put("%3A", ":");\r
+ decodingMap.put("%3a", ":");\r
+ decodingMap.put("%40", "@");\r
+ decodingMap.put("%26", "&");\r
+ decodingMap.put("%3D", "=");\r
+ decodingMap.put("%3d", "=");\r
+ decodingMap.put("%3B", "+");\r
+ decodingMap.put("%3b", "+");\r
+ decodingMap.put("%24", "$");\r
+ decodingMap.put("%2C", "`");\r
+ decodingMap.put("%2c", "`");\r
+ decodingMap.put("%2F", "/");\r
+ decodingMap.put("%2f", "/");\r
+ decodingMap.put("%3F", "?");\r
+ decodingMap.put("%3f", "?");\r
+ decodingMap.put("%25", "%");\r
+ decodingMap.put("%23", "#");\r
+ decodingMap.put("%5B", "[");\r
+ decodingMap.put("%5b", "[");\r
+ decodingMap.put("%5D", "]");\r
+ decodingMap.put("%5d", "]");\r
+ }\r
+\r
+ public static String decode(String uri) {\r
+ Log.info("Original uri: " + uri);\r
+ if (uri.indexOf('%') >= 0) { // skip this if no encoded chars\r
+ Enumeration keys = decodingMap.keys();\r
+ while (keys.hasMoreElements()) {\r
+ String encodedChar = (String) keys.nextElement();\r
+ int encodedCharIndex = uri.indexOf(encodedChar);\r
+ while (encodedCharIndex != -1) {\r
+ uri = uri.substring(0, encodedCharIndex) + decodingMap.get(encodedChar) + uri.substring(encodedCharIndex + encodedChar.length());\r
+ encodedCharIndex = uri.indexOf(encodedChar, encodedCharIndex);\r
+ }\r
+ }\r
+ }\r
+ Log.info("Final URI: " + uri);\r
+ return uri;\r
+ }\r
+}\r