You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2015/03/11 16:35:19 UTC

[08/13] cordova-plugin-file git commit: android: Use Uri.parse rather than manual parsing in resolveLocalFileSystemURI

android: Use Uri.parse rather than manual parsing in resolveLocalFileSystemURI


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/commit/4d1c2770
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/4d1c2770
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/4d1c2770

Branch: refs/heads/master
Commit: 4d1c27708df6aaff82ff1ebafda330d13cbbfc8b
Parents: 1a79a05
Author: Andrew Grieve <ag...@chromium.org>
Authored: Mon Mar 9 13:48:58 2015 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Wed Mar 11 11:35:07 2015 -0400

----------------------------------------------------------------------
 src/android/FileUtils.java | 34 ++++++++--------------------------
 1 file changed, 8 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/4d1c2770/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index cd6f9c1..0063b43 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -584,44 +584,26 @@ public class FileUtils extends CordovaPlugin {
     /**
      * Allows the user to look up the Entry for a file or directory referred to by a local URI.
      *
-     * @param url of the file/directory to look up
+     * @param uriString of the file/directory to look up
      * @return a JSONObject representing a Entry from the filesystem
      * @throws MalformedURLException if the url is not valid
      * @throws FileNotFoundException if the file does not exist
      * @throws IOException if the user can't read the file
      * @throws JSONException
      */
-    private JSONObject resolveLocalFileSystemURI(String url) throws IOException, JSONException {
+    private JSONObject resolveLocalFileSystemURI(String uriString) throws IOException, JSONException {
     	LocalFilesystemURL inputURL;
-    	if (url == null) {
+    	if (uriString == null) {
     		throw new MalformedURLException("Unrecognized filesystem URL");
     	}
-    	
-		/* Backwards-compatibility: Check for file:// urls */
-        if (url.startsWith("file:/")) {
-            if (!url.startsWith("file://")) {
-                url = "file:///" + url.substring(6);
-            }
-            String decoded = URLDecoder.decode(url, "UTF-8");
-    		/* This looks like a file url. Get the path, and see if any handlers recognize it. */
-    		String path;
-	        int questionMark = decoded.indexOf("?");
-            int pathEnd;
-	        if (questionMark < 0) {
-                pathEnd = decoded.length();
-	        } else {
-                pathEnd = questionMark;
-            }
+    	Uri uri = Uri.parse(uriString);
 
-            int thirdSlash = decoded.indexOf("/", 7);
-            if (thirdSlash < 0 || thirdSlash > pathEnd) {
-                path = "";
-            } else {
-                path = decoded.substring(thirdSlash, pathEnd);
-	        }
+		/* Backwards-compatibility: Check for file:// urls */
+        if ("file".equals(uri.getScheme())) {
+            String path = uri.getPath();
     		inputURL = this.filesystemURLforLocalPath(path);
     	} else {
-    		inputURL = new LocalFilesystemURL(url);
+    		inputURL = new LocalFilesystemURL(uri);
     	}
 
         try {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org