cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject [2/3] git commit: CB-6057: Add methods to convert from URLs to filesystem paths
Date Thu, 20 Feb 2014 15:48:10 GMT
CB-6057: Add methods to convert from URLs to filesystem paths


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

Branch: refs/heads/dev
Commit: a81b3f4dcaa58169f76e1a96d949424690991503
Parents: 14acde6
Author: Ian Clelland <iclelland@chromium.org>
Authored: Thu Feb 20 10:21:33 2014 -0500
Committer: Ian Clelland <iclelland@chromium.org>
Committed: Thu Feb 20 10:47:42 2014 -0500

----------------------------------------------------------------------
 src/android/FileUtils.java          | 12 ++++++----
 src/android/LocalFilesystemURL.java |  3 +++
 src/ios/CDVFile.h                   |  4 ++++
 src/ios/CDVFile.m                   | 41 +++++++++++++++++++++-----------
 4 files changed, 42 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/a81b3f4d/src/android/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/android/FileUtils.java b/src/android/FileUtils.java
index 00aa564..ac29f0d 100644
--- a/src/android/FileUtils.java
+++ b/src/android/FileUtils.java
@@ -414,7 +414,7 @@ public class FileUtils extends CordovaPlugin {
             final String localURLstr = args.getString(0);
             threadhelper( new FileOp( ){
                 public void run() throws FileNotFoundException, JSONException, MalformedURLException
{
-                    String fname = _filesystemPathForURL(localURLstr);
+                    String fname = filesystemPathForURL(localURLstr);
                     callbackContext.success(fname);
                 }
             },callbackContext);
@@ -425,9 +425,13 @@ public class FileUtils extends CordovaPlugin {
         return true;
     }
 
-    /* Internal method for testing: Get the on-disk location of a local filesystem url.
+    /*
+     * These two native-only methods can be used by other plugins to translate between
+     * device file system paths and URLs. By design, there is no direct JavaScript
+     * interface to these methods.
      */
-    protected String _filesystemPathForURL(String localURLstr) throws MalformedURLException
{
+
+    public String filesystemPathForURL(String localURLstr) throws MalformedURLException {
         try {
             LocalFilesystemURL inputURL = new LocalFilesystemURL(localURLstr);
             Filesystem fs = this.filesystemForURL(inputURL);
@@ -440,7 +444,7 @@ public class FileUtils extends CordovaPlugin {
         }
     }
 
-    protected LocalFilesystemURL filesystemURLforLocalPath(String localPath) {
+    public LocalFilesystemURL filesystemURLforLocalPath(String localPath) {
     	LocalFilesystemURL localURL;
 		for (Filesystem fs: filesystems) {
 			if (fs != null) {

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/a81b3f4d/src/android/LocalFilesystemURL.java
----------------------------------------------------------------------
diff --git a/src/android/LocalFilesystemURL.java b/src/android/LocalFilesystemURL.java
index f18a03a..a8e277e 100644
--- a/src/android/LocalFilesystemURL.java
+++ b/src/android/LocalFilesystemURL.java
@@ -50,4 +50,7 @@ public class LocalFilesystemURL {
 		this(Uri.parse(strURL));
 	}
 	
+    public String toString() {
+        return "cdvfile://localhost/" + this.filesystemName + this.fullPath;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/a81b3f4d/src/ios/CDVFile.h
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.h b/src/ios/CDVFile.h
index 751b9d4..63f744c 100644
--- a/src/ios/CDVFile.h
+++ b/src/ios/CDVFile.h
@@ -51,6 +51,7 @@ typedef int CDVFileError;
 + (CDVFilesystemURL *)fileSystemURLWithString:(NSString *)strURL;
 + (CDVFilesystemURL *)fileSystemURLWithURL:(NSURL *)URL;
 
+- (NSString *)absoluteURL;
 
 @property (atomic) NSURL *url;
 @property (atomic) NSString *fileSystemName;
@@ -134,6 +135,9 @@ typedef int CDVFileError;
 - (NSString*)getMimeTypeFromPath:(NSString*)fullPath;
 - (NSDictionary *)getDirectoryEntry:(NSString *)target isDirectory:(BOOL)bDirRequest;
 
+/* Conversion between filesystem paths and URLs */
+- (NSString *)filesystemPathForURL:(CDVFilesystemURL *)URL;
+
 /* Internal methods for testing */
 - (void)_getLocalFilesystemPath:(CDVInvokedUrlCommand*)command;
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/a81b3f4d/src/ios/CDVFile.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m
index 7e561bf..c9817aa 100644
--- a/src/ios/CDVFile.m
+++ b/src/ios/CDVFile.m
@@ -110,6 +110,11 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
     return [[CDVFilesystemURL alloc] initWithURL:URL];
 }
 
+- (NSString *)absoluteURL
+{
+    return [NSString stringWithFormat:@"cdvfile://localhost/%@%@", self.fileSystemName, self.fullPath];
+}
+
 @end
 
 @implementation CDVFilesystemURLProtocol
@@ -382,11 +387,16 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
     return dirEntry;
 }
 
+- (NSDictionary *)makeEntryForLocalURL:(CDVFilesystemURL *)localURL
+{
+    NSObject<CDVFileSystem> *fs = [self filesystemForURL:localURL];
+    return [fs makeEntryForLocalURL:localURL];
+}
+
 - (NSDictionary *)makeEntryForURL:(NSURL *)URL
 {
     CDVFilesystemURL *fsURL = [CDVFilesystemURL fileSystemURLWithURL:URL];
-    NSObject<CDVFileSystem> *fs = [self filesystemForURL:fsURL];
-    return [fs makeEntryForLocalURL:fsURL];
+    return [self makeEntryForLocalURL:fsURL];
 }
 
 /*
@@ -864,6 +874,20 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
 
 }
 
+#pragma mark Methods for converting between URLs and paths
+
+- (NSString *)filesystemPathForURL:(CDVFilesystemURL *)localURL
+{
+    for (NSObject<CDVFileSystem> *fs in self.fileSystems) {
+        if ([fs.name isEqualToString:localURL.fileSystemName]) {
+            if ([fs respondsToSelector:@selector(filesystemPathForURL:)]) {
+                return [fs filesystemPathForURL:localURL];
+            }
+        }
+    }
+    return nil;
+}
+
 #pragma mark Undocumented Filesystem API
 
 - (void)testFileExists:(CDVInvokedUrlCommand*)command
@@ -928,24 +952,13 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
 #pragma mark Internal methods for testing
 // Internal methods for testing: Get the on-disk location of a local filesystem url.
 // [Currently used for testing file-transfer]
-- (NSString *)_filesystemPathForURL:(CDVFilesystemURL *)localURL
-{
-    for (NSObject<CDVFileSystem> *fs in self.fileSystems) {
-        if ([fs.name isEqualToString:localURL.fileSystemName]) {
-            if ([fs respondsToSelector:@selector(filesystemPathForURL:)]) {
-                return [fs filesystemPathForURL:localURL];
-            }
-        }
-    }
-    return nil;
-}
 
 - (void)_getLocalFilesystemPath:(CDVInvokedUrlCommand*)command
 {
     NSString* localURLstr = [command.arguments objectAtIndex:0];
     CDVFilesystemURL* localURL = [CDVFilesystemURL fileSystemURLWithString:localURLstr];
 
-    NSString* fsPath = [self _filesystemPathForURL:localURL];
+    NSString* fsPath = [self filesystemPathForURL:localURL];
     CDVPluginResult* result;
     if (fsPath) {
         result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:fsPath];


Mime
View raw message