cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shaz...@apache.org
Subject cordova-plugin-file git commit: CB-8032 - File Plugin - Add nativeURL external method support for CDVFileSystem->makeEntryForPath:isDirectory:
Date Thu, 11 Dec 2014 21:03:35 GMT
Repository: cordova-plugin-file
Updated Branches:
  refs/heads/CB-8032 [created] 93b17a4c7


CB-8032 - File Plugin - Add nativeURL external method support for CDVFileSystem->makeEntryForPath:isDirectory:


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

Branch: refs/heads/CB-8032
Commit: 93b17a4c7f674269922f5511104dd60cddcd1461
Parents: cc62ca9
Author: Shazron Abdullah <shazron@apache.org>
Authored: Thu Dec 11 13:03:34 2014 -0800
Committer: Shazron Abdullah <shazron@apache.org>
Committed: Thu Dec 11 13:03:34 2014 -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/93b17a4c/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/93b17a4c/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/93b17a4c/src/ios/CDVFile.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVFile.m b/src/ios/CDVFile.m
index c0deb32..5785499 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/93b17a4c/src/ios/CDVLocalFilesystem.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVLocalFilesystem.m b/src/ios/CDVLocalFilesystem.m
index 2793977..cc36820 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


Mime
View raw message