You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2015/03/07 06:06:18 UTC

cordova-plugin-file git commit: CB-8032 - File Plugin - Add nativeURL external method support for CDVFileSystem->makeEntryForPath:isDirectory: (closes #96)

Repository: cordova-plugin-file
Updated Branches:
  refs/heads/master 64bfc38ac -> 2ed379c7c


CB-8032 - File Plugin - Add nativeURL external method support for CDVFileSystem->makeEntryForPath:isDirectory: (closes #96)


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

Branch: refs/heads/master
Commit: 2ed379c7c99b88a639f5541f9df8d772b2b81bfe
Parents: 64bfc38
Author: Shazron Abdullah <sh...@apache.org>
Authored: Thu Dec 11 13:03:34 2014 -0800
Committer: Shazron Abdullah <sh...@gmail.com>
Committed: Fri Mar 6 21:03:40 2015 -0800

----------------------------------------------------------------------
 src/ios/CDVAssetLibraryFilesystem.m |  9 +++++++--
 src/ios/CDVFile.h                   |  1 +
 src/ios/CDVFile.m                   | 19 +++++++++++++++++++
 src/ios/CDVLocalFilesystem.m        | 10 ++++++++--
 4 files changed, 35 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/2ed379c7/src/ios/CDVAssetLibraryFilesystem.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVAssetLibraryFilesystem.m b/src/ios/CDVAssetLibraryFilesystem.m
index 2354ce9..5e3a20d 100644
--- a/src/ios/CDVAssetLibraryFilesystem.m
+++ b/src/ios/CDVAssetLibraryFilesystem.m
@@ -29,7 +29,7 @@ NSString* const kCDVAssetsLibraryPrefix = @"assets-library://";
 NSString* const kCDVAssetsLibraryScheme = @"assets-library";
 
 @implementation CDVAssetLibraryFilesystem
-@synthesize name=_name;
+@synthesize name=_name, urlTransformer;
 
 
 /*
@@ -71,7 +71,12 @@ NSString* const kCDVAssetsLibraryScheme = @"assets-library";
     [dirEntry setObject:fullPath forKey:@"fullPath"];
     [dirEntry setObject:lastPart forKey:@"name"];
     [dirEntry setObject:self.name forKey: @"filesystemName"];
-    dirEntry[@"nativeURL"] = [NSString stringWithFormat:@"assets-library:/%@",fullPath];
+    
+    NSURL* nativeURL = [NSURL URLWithString:[NSString stringWithFormat:@"assets-library:/%@",fullPath]];
+    if (self.urlTransformer) {
+        nativeURL = self.urlTransformer(nativeURL);
+    }
+    dirEntry[@"nativeURL"] = [nativeURL absoluteString];
 
     return dirEntry;
 }

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/2ed379c7/src/ios/CDVFile.h
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.h b/src/ios/CDVFile.h
index 74c0146..33630c0 100644
--- a/src/ios/CDVFile.h
+++ b/src/ios/CDVFile.h
@@ -80,6 +80,7 @@ typedef int CDVFileError;
 - (NSDictionary*)makeEntryForPath:(NSString*)fullPath isDirectory:(BOOL)isDir;
 
 @property (nonatomic,strong) NSString *name;
+@property (nonatomic, copy) NSURL*(^urlTransformer)(NSURL*);
 
 @optional
 - (NSString *)filesystemPathForURL:(CDVFilesystemURL *)localURI;

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/2ed379c7/src/ios/CDVFile.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m
index 4e9db14..d06174a 100644
--- a/src/ios/CDVFile.m
+++ b/src/ios/CDVFile.m
@@ -21,6 +21,7 @@
 #import "CDVFile.h"
 #import "CDVLocalFilesystem.h"
 #import "CDVAssetLibraryFilesystem.h"
+#import <objc/message.h>
 
 CDVFile *filePlugin = nil;
 
@@ -173,6 +174,24 @@ NSString* const kCDVFilesystemURLPrefix = @"cdvfile";
 @synthesize rootDocsPath, appDocsPath, appLibraryPath, appTempPath, userHasAllowed, fileSystems=fileSystems_;
 
 - (void)registerFilesystem:(NSObject<CDVFileSystem> *)fs {
+    __weak CDVFile* weakSelf = self;
+    SEL sel = NSSelectorFromString(@"urlTransformer");
+    // for backwards compatibility - we check if this property is there
+    // we create a wrapper block because the urlTransformer property
+    // on the commandDelegate might be set dynamically at a future time
+    // (and not dependent on plugin loading order)
+    if ([self.commandDelegate respondsToSelector:sel]) {
+        fs.urlTransformer = ^NSURL*(NSURL* urlToTransform) {
+            // grab the block from the commandDelegate
+            NSURL* (^urlTransformer)(NSURL*) = ((id(*)(id, SEL))objc_msgSend)(weakSelf.commandDelegate, sel);
+            // if block is not null, we call it
+            if (urlTransformer) {
+                return urlTransformer(urlToTransform);
+            } else { // else we return the same url
+                return urlToTransform;
+            }
+        };
+    }
     [fileSystems_ addObject:fs];
 }
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-file/blob/2ed379c7/src/ios/CDVLocalFilesystem.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVLocalFilesystem.m b/src/ios/CDVLocalFilesystem.m
index 932c0db..72bc421 100644
--- a/src/ios/CDVLocalFilesystem.m
+++ b/src/ios/CDVLocalFilesystem.m
@@ -24,7 +24,7 @@
 #import <sys/xattr.h>
 
 @implementation CDVLocalFilesystem
-@synthesize name=_name, fsRoot=_fsRoot;
+@synthesize name=_name, fsRoot=_fsRoot, urlTransformer;
 
 - (id) initWithName:(NSString *)name root:(NSString *)fsRoot
 {
@@ -78,7 +78,13 @@
     [dirEntry setObject:fullPath forKey:@"fullPath"];
     [dirEntry setObject:lastPart forKey:@"name"];
     [dirEntry setObject:self.name forKey: @"filesystemName"];
-    dirEntry[@"nativeURL"] = [[NSURL fileURLWithPath:[self filesystemPathForFullPath:fullPath]] absoluteString];
+    
+    NSURL* nativeURL = [NSURL fileURLWithPath:[self filesystemPathForFullPath:fullPath]];
+    if (self.urlTransformer) {
+        nativeURL = self.urlTransformer(nativeURL);
+    }
+    
+    dirEntry[@"nativeURL"] = [nativeURL absoluteString];
 
     return dirEntry;
 }


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