cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shaz...@apache.org
Subject cordova-plugins git commit: Added preliminary /asset-library/ and /local-filesystem/ support, incomplete.
Date Tue, 18 Nov 2014 01:48:50 GMT
Repository: cordova-plugins
Updated Branches:
  refs/heads/master fddacd6d6 -> 5d8ef21dc


Added preliminary /asset-library/ and /local-filesystem/ support, incomplete.


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugins/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugins/commit/5d8ef21d
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugins/tree/5d8ef21d
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugins/diff/5d8ef21d

Branch: refs/heads/master
Commit: 5d8ef21dcbde1f99d60e1b52ae3a3800e4c185d9
Parents: fddacd6
Author: Shazron Abdullah <shazron@apache.org>
Authored: Mon Nov 17 17:48:48 2014 -0800
Committer: Shazron Abdullah <shazron@apache.org>
Committed: Mon Nov 17 17:48:48 2014 -0800

----------------------------------------------------------------------
 local-webserver/plugin.xml                      |  7 +++
 .../ios/CDVAssetLibraryFileSystem+NativeURL.h   | 28 ++++++++++++
 .../ios/CDVAssetLibraryFileSystem+NativeURL.m   | 47 ++++++++++++++++++++
 .../src/ios/CDVLocalFileSystem+NativeURL.h      | 28 ++++++++++++
 .../src/ios/CDVLocalFileSystem+NativeURL.m      | 47 ++++++++++++++++++++
 local-webserver/src/ios/CDVLocalWebServer.m     | 44 +++++++++++++++++-
 6 files changed, 200 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/5d8ef21d/local-webserver/plugin.xml
----------------------------------------------------------------------
diff --git a/local-webserver/plugin.xml b/local-webserver/plugin.xml
index facd678..dc7e677 100644
--- a/local-webserver/plugin.xml
+++ b/local-webserver/plugin.xml
@@ -25,6 +25,8 @@
     
     <hook type="after_plugin_install" src="scripts/after_install.js" />
     <hook type="before_plugin_uninstall" src="scripts/before_uninstall.js" />
+    
+    <dependency id="org.apache.cordova.file" version=">=1.0.1" />
 
     <engines>
         <engine name="cordova" version=">=3.7.0" />
@@ -43,6 +45,11 @@
 
 	    <header-file src="src/ios/CDVLocalWebServer.h" />
 	    <source-file src="src/ios/CDVLocalWebServer.m" />
+
+	    <header-file src="src/ios/CDVAssetLibraryFileSystem+NativeURL.h" />
+	    <source-file src="src/ios/CDVAssetLibraryFileSystem+NativeURL.m" />
+	    <header-file src="src/ios/CDVLocalFileSystem+NativeURL.h" />
+	    <source-file src="src/ios/CDVLocalFileSystem+NativeURL.m" />
 	    
 	    <header-file src="src/ios/GCDWebServer+LocalhostOnlyBaseHandler.h" />
 	    <source-file src="src/ios/GCDWebServer+LocalhostOnlyBaseHandler.m" />

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/5d8ef21d/local-webserver/src/ios/CDVAssetLibraryFileSystem+NativeURL.h
----------------------------------------------------------------------
diff --git a/local-webserver/src/ios/CDVAssetLibraryFileSystem+NativeURL.h b/local-webserver/src/ios/CDVAssetLibraryFileSystem+NativeURL.h
new file mode 100644
index 0000000..6462535
--- /dev/null
+++ b/local-webserver/src/ios/CDVAssetLibraryFileSystem+NativeURL.h
@@ -0,0 +1,28 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+ 
+ http://www.apache.org/licenses/LICENSE-2.0
+ 
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <Foundation/Foundation.h>
+#import "CDVAssetLibraryFileSystem.h"
+
+
+@interface CDVAssetLibraryFilesystem (LocalWebServerNativeURL)
+
+@property (nonatomic, copy) NSURL* localWebServerURL;
+
+@end

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/5d8ef21d/local-webserver/src/ios/CDVAssetLibraryFileSystem+NativeURL.m
----------------------------------------------------------------------
diff --git a/local-webserver/src/ios/CDVAssetLibraryFileSystem+NativeURL.m b/local-webserver/src/ios/CDVAssetLibraryFileSystem+NativeURL.m
new file mode 100644
index 0000000..21771b2
--- /dev/null
+++ b/local-webserver/src/ios/CDVAssetLibraryFileSystem+NativeURL.m
@@ -0,0 +1,47 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+ 
+ http://www.apache.org/licenses/LICENSE-2.0
+ 
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "CDVAssetLibraryFileSystem+NativeURL.h"
+
+#import <objc/runtime.h>
+
+static void* LocalWebServerURLPropertyKey = &LocalWebServerURLPropertyKey;
+
+@implementation CDVAssetLibraryFilesystem (LocalWebServerNativeURL)
+
+
+- (NSString*) nativeURL:(NSString*)fullPath
+{
+    return [NSString stringWithFormat:@"%@://%@:%lu/assets-library/%@",
+            self.localWebServerURL.scheme,
+            self.localWebServerURL.host,
+            [self.localWebServerURL.port unsignedIntegerValue],
+            fullPath];
+}
+
+- (void) setLocalWebServerURL:(NSURL *)localWebServerURL {
+    objc_setAssociatedObject(self, LocalWebServerURLPropertyKey, localWebServerURL, OBJC_ASSOCIATION_COPY_NONATOMIC);
+}
+
+- (NSURL*) localWebServerURL {
+    return objc_getAssociatedObject(self, LocalWebServerURLPropertyKey);
+}
+
+
+@end

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/5d8ef21d/local-webserver/src/ios/CDVLocalFileSystem+NativeURL.h
----------------------------------------------------------------------
diff --git a/local-webserver/src/ios/CDVLocalFileSystem+NativeURL.h b/local-webserver/src/ios/CDVLocalFileSystem+NativeURL.h
new file mode 100644
index 0000000..426ba5e
--- /dev/null
+++ b/local-webserver/src/ios/CDVLocalFileSystem+NativeURL.h
@@ -0,0 +1,28 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+ 
+ http://www.apache.org/licenses/LICENSE-2.0
+ 
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import <Foundation/Foundation.h>
+#import "CDVLocalFileSystem.h"
+
+
+@interface CDVLocalFilesystem (LocalWebServerNativeURL)
+
+@property (nonatomic, copy) NSURL* localWebServerURL;
+
+@end

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/5d8ef21d/local-webserver/src/ios/CDVLocalFileSystem+NativeURL.m
----------------------------------------------------------------------
diff --git a/local-webserver/src/ios/CDVLocalFileSystem+NativeURL.m b/local-webserver/src/ios/CDVLocalFileSystem+NativeURL.m
new file mode 100644
index 0000000..74f47ff
--- /dev/null
+++ b/local-webserver/src/ios/CDVLocalFileSystem+NativeURL.m
@@ -0,0 +1,47 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+ 
+ http://www.apache.org/licenses/LICENSE-2.0
+ 
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "CDVLocalFileSystem+NativeURL.h"
+
+#import <objc/runtime.h>
+
+static void* LocalWebServerURLPropertyKey = &LocalWebServerURLPropertyKey;
+
+@implementation CDVLocalFilesystem (LocalWebServerNativeURL)
+
+
+- (NSString*) nativeURL:(NSString*)fullPath
+{
+    return [NSString stringWithFormat:@"%@://%@:%lu/local-filesystem/%@",
+            self.localWebServerURL.scheme,
+            self.localWebServerURL.host,
+            [self.localWebServerURL.port unsignedIntegerValue],
+            fullPath];
+}
+
+- (void) setLocalWebServerURL:(NSURL *)localWebServerURL {
+    objc_setAssociatedObject(self, LocalWebServerURLPropertyKey, localWebServerURL, OBJC_ASSOCIATION_COPY_NONATOMIC);
+}
+
+- (NSURL*) localWebServerURL {
+    return objc_getAssociatedObject(self, LocalWebServerURLPropertyKey);
+}
+
+
+@end

http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/5d8ef21d/local-webserver/src/ios/CDVLocalWebServer.m
----------------------------------------------------------------------
diff --git a/local-webserver/src/ios/CDVLocalWebServer.m b/local-webserver/src/ios/CDVLocalWebServer.m
index 873581f..cfd171d 100644
--- a/local-webserver/src/ios/CDVLocalWebServer.m
+++ b/local-webserver/src/ios/CDVLocalWebServer.m
@@ -21,6 +21,8 @@
 #import "GCDWebServerPrivate.h"
 #import "GCDWebServer+LocalhostOnlyBaseHandler.h"
 #import <Cordova/CDVViewController.h>
+#import "CDVLocalFileSystem+NativeURL.h"
+#import "CDVAssetLibraryFileSystem+NativeURL.h"
 
 @implementation CDVLocalWebServer
 
@@ -50,7 +52,6 @@
         }
     }
 #endif
-    
     if (useLocalWebServer) {
 		// Create server
         self.server = [[GCDWebServer alloc] init];
@@ -58,9 +59,12 @@
 		NSString* authToken = [NSString stringWithFormat:@"cdvToken=%@", [[NSProcessInfo processInfo]
globallyUniqueString]];
         NSString* appPath = [NSString stringWithFormat:@"/%@/", subPath];
 		[self.server addLocalhostOnlyGETHandlerForBasePath:appPath directoryPath:[path stringByDeletingLastPathComponent]
indexFilename:indexPage cacheAge:0 allowRangeRequests:YES authToken:authToken];
+        
         [self.server startWithPort:port bonjourName:nil];
         [GCDWebServer setLogLevel:kGCDWebServerLoggingLevel_Error];
         
+        [self addFileSystemHandlers];
+        
         // Update the startPage (supported in cordova-ios 3.7.0, see https://issues.apache.org/jira/browse/CB-7857)
 		vc.startPage = [NSString stringWithFormat:@"http://localhost:%lu/%@/%@?%@", self.server.port,
subPath, indexPage, authToken];
         
@@ -69,4 +73,42 @@
     }
 }
 
+-  (void) addFileSystemHandlers
+{
+    [self addLocalFileSystemHandler];
+    [self addAssetLibraryFileSystemHandler];
+    
+    CDVFile* filePlugin = (CDVFile*)[self.commandDelegate getCommandInstance:@"File"];
+    NSURL* localServerURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://localhost:%lu",
self.server.port]];
+    
+    // set the localWebServerURL for the Obj-C categories
+    if (filePlugin) {
+        NSArray* fileSystems = filePlugin.fileSystems;
+        for (NSObject<CDVFileSystem>* fileSystem in fileSystems) {
+            SEL sel = NSSelectorFromString(@"setLocalWebServerURL:");
+            if ([fileSystem respondsToSelector:sel]) {
+                ((void (*)(id, SEL, id))[fileSystem methodForSelector:sel])(fileSystem, sel,
localServerURL);
+            }
+        }
+    }
+}
+
+- (void) addLocalFileSystemHandler
+{
+    // TODO:
+    // add the GCD GET handler
+    // extract the path after /local-filesystem/
+    // convert to file URL
+    // stream the file back
+}
+
+- (void) addAssetLibraryFileSystemHandler
+{
+    // TODO:
+    // add the GCD GET handler
+    // extract the path after /asset-library/ prepend "assets-library:/"
+    // use ALAssetsLibrary assetForURL
+    // stream the file back
+}
+
 @end
\ No newline at end of file


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


Mime
View raw message