cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject git commit: CB-5403: Backwards-compatibility with file:// urls where possible
Date Mon, 16 Dec 2013 05:26:09 GMT
Updated Branches:
  refs/heads/dev a2b90737e -> eb28b7a29


CB-5403: Backwards-compatibility with file:// urls where possible


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/eb28b7a2
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/tree/eb28b7a2
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/diff/eb28b7a2

Branch: refs/heads/dev
Commit: eb28b7a29dff03b86802a9f2d4b5f8fd304977dc
Parents: a2b9073
Author: Ian Clelland <iclelland@chromium.org>
Authored: Sun Dec 15 23:35:34 2013 -0500
Committer: Ian Clelland <iclelland@chromium.org>
Committed: Mon Dec 16 00:24:39 2013 -0500

----------------------------------------------------------------------
 src/android/ContentFilesystem.java |  6 ++++++
 src/android/FileUtils.java         | 35 +++++++++++++++++++++++++++++++--
 src/android/Filesystem.java        |  2 ++
 src/android/LocalFilesystem.java   |  9 +++++++++
 src/ios/CDVFile.m                  | 20 +++++++++++++++++--
 www/android/FileSystem.js          |  3 ++-
 www/ios/FileSystem.js              |  3 ++-
 7 files changed, 72 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/eb28b7a2/src/android/ContentFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/ContentFilesystem.java b/src/android/ContentFilesystem.java
index b1d397e..e19f5bc 100644
--- a/src/android/ContentFilesystem.java
+++ b/src/android/ContentFilesystem.java
@@ -129,4 +129,10 @@ public class ContentFilesystem implements Filesystem {
         }
         return null;
     }
+
+	@Override
+	public LocalFilesystemURL URLforFilesystemPath(String path) {
+		// TODO Auto-generated method stub
+		return null;
+	}
 }

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/eb28b7a2/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 1ae7d0c..25ea6b4 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -398,7 +398,20 @@ public class FileUtils extends CordovaPlugin {
         }
     }
 
-    /* helper to execute functions async and handle the result codes
+    protected LocalFilesystemURL filesystemURLforLocalPath(String localPath) {
+    	LocalFilesystemURL localURL;
+		for (Filesystem fs: filesystems) {
+			if (fs != null) {
+		        localURL = fs.URLforFilesystemPath(localPath);
+		        if (localURL != null)
+		            return localURL;
+			}
+		}
+		return null;
+	}
+
+
+	/* helper to execute functions async and handle the result codes
      *
      */
     private void threadhelper(final FileOp f, final CallbackContext callbackContext){
@@ -462,9 +475,27 @@ public class FileUtils extends CordovaPlugin {
      */
     private JSONObject resolveLocalFileSystemURI(String url) throws IOException, JSONException
{
         String decoded = URLDecoder.decode(url, "UTF-8");
+    	LocalFilesystemURL inputURL;
+    	if (url == null) {
+    		throw new MalformedURLException("Unrecognized filesystem URL");
+    	}
+    	
+		/* Backwards-compatibility: Check for file:// urls */
+    	if (decoded.startsWith("file://")) {
+    		/* This looks like a file url. Get the path, and see if any handlers recognize it.
*/
+    		String path;
+	        int questionMark = decoded.indexOf("?");
+	        if (questionMark < 0) {
+	            path = decoded.substring(7, decoded.length());
+	        } else {
+	            path = decoded.substring(7, questionMark);
+	        }
+    		inputURL = this.filesystemURLforLocalPath(path);
+    	} else {
+    		inputURL = new LocalFilesystemURL(decoded);
+    	}
 
         try {
-        	LocalFilesystemURL inputURL = new LocalFilesystemURL(decoded);
         	Filesystem fs = this.filesystemForURL(inputURL);
         	if (fs == null) {
         		throw new MalformedURLException("No installed handlers for this URL");

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/eb28b7a2/src/android/Filesystem.java
----------------------------------------------------------------------
diff --git a/src/android/Filesystem.java b/src/android/Filesystem.java
index 57e1794..7dd99f2 100644
--- a/src/android/Filesystem.java
+++ b/src/android/Filesystem.java
@@ -40,4 +40,6 @@ public interface Filesystem {
 	// This method should return null if filesystem urls cannot be mapped to paths
 	String filesystemPathForURL(LocalFilesystemURL url);
 
+	LocalFilesystemURL URLforFilesystemPath(String path);
+
 }

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/eb28b7a2/src/android/LocalFilesystem.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystem.java b/src/android/LocalFilesystem.java
index 755a802..6634661 100644
--- a/src/android/LocalFilesystem.java
+++ b/src/android/LocalFilesystem.java
@@ -46,6 +46,15 @@ public class LocalFilesystem implements Filesystem {
 		return null;
 	}
 
+	@Override
+	public LocalFilesystemURL URLforFilesystemPath(String path) {
+	    String fullPath = this.fullPathForFilesystemPath(path);
+	    if (fullPath != null) {
+	        return new LocalFilesystemURL("filesystem://localhost/"+this.name+"/"+fullPath);
+	    }
+	    return null;
+	}
+
     public static JSONObject makeEntryForPath(String path, int fsType, Boolean isDir) throws
JSONException {
         JSONObject entry = new JSONObject();
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/eb28b7a2/src/ios/CDVFile.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m
index 517e349..e53733d 100644
--- a/src/ios/CDVFile.m
+++ b/src/ios/CDVFile.m
@@ -323,9 +323,25 @@ NSString* const kCDVFilesystemURLPrefix = @"filesystem";
 - (void)resolveLocalFileSystemURI:(CDVInvokedUrlCommand*)command
 {
     // arguments
-    CDVFilesystemURL* inputURI = [CDVFilesystemURL fileSystemURLWithString:[command.arguments
objectAtIndex:0]];
+    NSString* localURIstr = [command.arguments objectAtIndex:0];
     CDVPluginResult* result;
-    if (inputURI.fileSystemType == -1) {
+    CDVFilesystemURL* inputURI;
+    
+    /* Backwards-compatibility: Check for file:// urls */
+    if ([localURIstr hasPrefix:@"file://"]) {
+        /* This looks like a file url. Get the path, and see if any handlers recognize it.
*/
+        NSString* path;
+        NSRange questionMark = [localURIstr rangeOfString:@"?"];
+        if (questionMark.location == NSNotFound) {
+            path = [localURIstr substringFromIndex:7];
+        } else {
+            path = [localURIstr substringWithRange:NSMakeRange(7,questionMark.location-7)];
+        }
+        inputURI = [self fileSystemURLforLocalPath:path];
+    } else {
+        inputURI = [CDVFilesystemURL fileSystemURLWithString:localURIstr];
+    }
+    if (inputURI != nil && inputURI.fileSystemType == -1) {
         result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsInt:ENCODING_ERR];
     } else {
         CDVLocalFilesystem *fs = [self.fileSystems objectAtIndex:inputURI.fileSystemType];

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/eb28b7a2/www/android/FileSystem.js
----------------------------------------------------------------------
diff --git a/www/android/FileSystem.js b/www/android/FileSystem.js
index 2017e29..765d4f4 100644
--- a/www/android/FileSystem.js
+++ b/www/android/FileSystem.js
@@ -21,7 +21,8 @@
 
 module.exports = {
     __format__: function(fullPath) {
-        return 'filesystem://localhost/'+this.name+(fullPath[0]==='/'?'':'/')+encodeURI(fullPath);
+        var path = ('/'+this.name+(fullPath[0]==='/'?'':'/')+encodeURI(fullPath)).replace('//','/');
+        return 'filesystem://localhost' + path;
     }
 };
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/eb28b7a2/www/ios/FileSystem.js
----------------------------------------------------------------------
diff --git a/www/ios/FileSystem.js b/www/ios/FileSystem.js
index 2017e29..765d4f4 100644
--- a/www/ios/FileSystem.js
+++ b/www/ios/FileSystem.js
@@ -21,7 +21,8 @@
 
 module.exports = {
     __format__: function(fullPath) {
-        return 'filesystem://localhost/'+this.name+(fullPath[0]==='/'?'':'/')+encodeURI(fullPath);
+        var path = ('/'+this.name+(fullPath[0]==='/'?'':'/')+encodeURI(fullPath)).replace('//','/');
+        return 'filesystem://localhost' + path;
     }
 };
 


Mime
View raw message