cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bra...@apache.org
Subject [5/10] ios commit: Pull the parser delegate into its own files.
Date Fri, 23 Nov 2012 21:26:53 GMT
Pull the parser delegate into its own files.


Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/8936d203
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/8936d203
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/8936d203

Branch: refs/heads/master
Commit: 8936d203596354684d30084df3c25cbfd22b3274
Parents: 5b8608e
Author: Braden Shepherdson <braden@chromium.org>
Authored: Fri Nov 23 14:44:14 2012 -0500
Committer: Braden Shepherdson <braden@chromium.org>
Committed: Fri Nov 23 14:52:00 2012 -0500

----------------------------------------------------------------------
 CordovaLib/Classes/CDVConfigParser.h            |   27 ++++++++
 CordovaLib/Classes/CDVConfigParser.m            |   63 ++++++++++++++++++
 CordovaLib/Classes/CDVViewController.h          |    5 +-
 CordovaLib/Classes/CDVViewController.m          |   50 +++++----------
 CordovaLib/CordovaLib.xcodeproj/project.pbxproj |    8 ++
 5 files changed, 116 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/8936d203/CordovaLib/Classes/CDVConfigParser.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVConfigParser.h b/CordovaLib/Classes/CDVConfigParser.h
new file mode 100644
index 0000000..23cdd01
--- /dev/null
+++ b/CordovaLib/Classes/CDVConfigParser.h
@@ -0,0 +1,27 @@
+/*
+ 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.
+ */
+
+@interface CDVConfigParser : NSObject <NSXMLParserDelegate> {
+}
+
+@property (nonatomic, readonly, strong) NSMutableDictionary* pluginsDict;
+@property (nonatomic, readonly, strong) NSMutableDictionary* settings;
+@property (nonatomic, readonly, strong) NSMutableArray* whitelistHosts;
+
+@end

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/8936d203/CordovaLib/Classes/CDVConfigParser.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVConfigParser.m b/CordovaLib/Classes/CDVConfigParser.m
new file mode 100644
index 0000000..f562a89
--- /dev/null
+++ b/CordovaLib/Classes/CDVConfigParser.m
@@ -0,0 +1,63 @@
+/*
+ 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 "CDVConfigParser.h"
+
+@interface CDVConfigParser ()
+
+@property (nonatomic, readwrite, strong) NSMutableDictionary* pluginsDict;
+@property (nonatomic, readwrite, strong) NSMutableDictionary* settings;
+@property (nonatomic, readwrite, strong) NSMutableArray* whitelistHosts;
+
+@end
+
+@implementation CDVConfigParser
+
+@synthesize pluginsDict, settings, whitelistHosts;
+
+- (id)init
+{
+    self = [super init];
+    self.pluginsDict = [[NSMutableDictionary alloc] initWithCapacity:4];
+    self.settings = [[NSMutableDictionary alloc] initWithCapacity:4];
+    self.whitelistHosts = [[NSMutableArray alloc] initWithCapacity:1];
+    return self;
+}
+
+- (void)parserDidEndDocument:(NSXMLParser*)parser
+{
+}
+
+- (void)parser:(NSXMLParser*)parser didStartElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI
qualifiedName:(NSString*)qualifiedName attributes:(NSDictionary*)attributeDict
+{
+    if ([elementName isEqualToString:@"preference"]) {
+        [settings setObject:[attributeDict objectForKey:@"value"] forKey:[attributeDict objectForKey:@"name"]];
+    } else if ([elementName isEqualToString:@"plugin"]) {
+        [pluginsDict setObject:[attributeDict objectForKey:@"value"] forKey:[attributeDict
objectForKey:@"name"]];
+    } else if ([elementName isEqualToString:@"access"]) {
+        [whitelistHosts addObject:[attributeDict objectForKey:@"origin"]];
+    }
+}
+
+- (void)parser:(NSXMLParser*)parser parseErrorOccurred:(NSError*)parseError
+{
+    NSAssert(NO, @"config.xml parse error line %d col %d", [parser lineNumber], [parser columnNumber]);
+}
+
+@end

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/8936d203/CordovaLib/Classes/CDVViewController.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVViewController.h b/CordovaLib/Classes/CDVViewController.h
index 1432c74..66e6a7f 100644
--- a/CordovaLib/Classes/CDVViewController.h
+++ b/CordovaLib/Classes/CDVViewController.h
@@ -36,11 +36,10 @@
 
 @property (nonatomic, strong) IBOutlet CDVCordovaView* webView;
 
-@property (nonatomic, readonly, strong) NSMutableDictionary* pluginsDict;
+@property (nonatomic, readonly, strong) NSMutableDictionary* pluginObjects;
 @property (nonatomic, readonly, strong) NSDictionary* pluginsMap;
-@property (nonatomic, readonly, strong) NSMutableDictionary* settings;
+@property (nonatomic, readonly, strong) NSDictionary* settings;
 @property (nonatomic, readonly, strong) NSXMLParser* configParser;
-@property (nonatomic, readonly, strong) NSMutableArray* whitelistHosts;
 @property (nonatomic, readonly, strong) CDVWhitelist* whitelist; // readonly for public
 @property (nonatomic, readonly, assign) BOOL loadFromString;
 @property (nonatomic, readwrite, copy)NSString * invokeString CDV_DEPRECATED(2.0, "Use window.handleOpenURL(url
instead. It is called when the app is launched through a custom scheme url.");

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/8936d203/CordovaLib/Classes/CDVViewController.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVViewController.m b/CordovaLib/Classes/CDVViewController.m
index e9f4ca1..5ceab1e 100644
--- a/CordovaLib/Classes/CDVViewController.m
+++ b/CordovaLib/Classes/CDVViewController.m
@@ -21,6 +21,7 @@
 #import "CDV.h"
 #import "CDVCommandQueue.h"
 #import "CDVCommandDelegateImpl.h"
+#import "CDVConfigParser.h"
 
 #define degreesToRadian(x) (M_PI * (x) / 180.0)
 #define CDV_USER_AGENT_KEY @"Cordova-User-Agent"
@@ -29,10 +30,9 @@
 @interface CDVViewController ()
 
 @property (nonatomic, readwrite, strong) NSXMLParser* configParser;
-@property (nonatomic, readwrite, strong) NSMutableDictionary* settings;
+@property (nonatomic, readwrite, strong) NSDictionary* settings;
 @property (nonatomic, readwrite, strong) CDVWhitelist* whitelist;
-@property (nonatomic, readwrite, strong) NSMutableArray* whitelistHosts;
-@property (nonatomic, readwrite, strong) NSMutableDictionary* pluginsDict;
+@property (nonatomic, readwrite, strong) NSMutableDictionary* pluginObjects;
 @property (nonatomic, readwrite, strong) NSDictionary* pluginsMap;
 @property (nonatomic, readwrite, strong) NSArray* supportedOrientations;
 @property (nonatomic, readwrite, assign) BOOL loadFromString;
@@ -46,7 +46,7 @@
 @implementation CDVViewController
 
 @synthesize webView, supportedOrientations;
-@synthesize pluginsDict, pluginsMap, whitelist, whitelistHosts;
+@synthesize pluginObjects, pluginsMap, whitelist;
 @synthesize configParser, settings, loadFromString;
 @synthesize imageView, activityView, useSplashScreen;
 @synthesize wwwFolderName, startPage, invokeString, initialized;
@@ -134,9 +134,7 @@
 
 - (void)loadSettings
 {
-    self.pluginsDict = [[NSMutableDictionary alloc] initWithCapacity:4];
-    self.settings = [[NSMutableDictionary alloc] initWithCapacity:4];
-    self.whitelistHosts = [[NSMutableArray alloc] initWithCapacity:1];
+    CDVConfigParser* delegate = [[CDVConfigParser alloc] init];
 
     // read from Cordova.plist in the app bundle
     NSString* path = [[NSBundle mainBundle] pathForResource:@"config" ofType:@"xml"];
@@ -152,32 +150,16 @@
         NSLog(@"Failed to initialize XML parser.");
         return;
     }
-    [configParser setDelegate:((id<NSXMLParserDelegate>)self)];
+    [configParser setDelegate:((id<NSXMLParserDelegate>) delegate)];
     [configParser parse];
-}
-
-- (void)parserDidEndDocument:(NSXMLParser*)parser
-{
-    // Clone the plugin name dictionary.
-    self.pluginsMap = [pluginsDict dictionaryWithLowercaseKeys];
-    // Build the whitelist from the list of hosts.
-    self.whitelist = [[CDVWhitelist alloc] initWithArray:self.whitelistHosts];
-}
 
-- (void)parser:(NSXMLParser*)parser didStartElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI
qualifiedName:(NSString*)qualifiedName attributes:(NSDictionary*)attributeDict
-{
-    if ([elementName isEqualToString:@"preference"]) {
-        [settings setObject:[attributeDict objectForKey:@"value"] forKey:[attributeDict objectForKey:@"name"]];
-    } else if ([elementName isEqualToString:@"plugin"]) {
-        [pluginsDict setObject:[attributeDict objectForKey:@"value"] forKey:[attributeDict
objectForKey:@"name"]];
-    } else if ([elementName isEqualToString:@"access"]) {
-        [whitelistHosts addObject:[attributeDict objectForKey:@"origin"]];
-    }
-}
+    // Get the plugin dictionary, whitelist and settings from the delegate.
+    self.pluginsMap = [delegate.pluginsDict dictionaryWithLowercaseKeys];
+    self.whitelist = [[CDVWhitelist alloc] initWithArray:delegate.whitelistHosts];
+    self.settings = delegate.settings;
 
-- (void)parser:(NSXMLParser*)parser parseErrorOccurred:(NSError*)parseError
-{
-    NSAssert(NO, @"config.xml parse error line %d col %d", [parser lineNumber], [parser columnNumber]);
+    // Initialize the plugin objects dict.
+    self.pluginObjects = [[NSMutableDictionary alloc] initWithCapacity:4];
 }
 
 // Implement viewDidLoad to do additional setup after loading the view, typically from a
nib.
@@ -489,7 +471,7 @@
     // iterate through all the plugin objects, and call hasPendingOperation
     // if at least one has a pending operation, we don't call [super didReceiveMemoryWarning]
 
-    NSEnumerator* enumerator = [self.pluginsDict objectEnumerator];
+    NSEnumerator* enumerator = [self.pluginObjects objectEnumerator];
     CDVPlugin* plugin;
 
     BOOL doPurge = YES;
@@ -808,7 +790,7 @@ BOOL gSplashScreenShown = NO;
         [plugin setCommandDelegate:_commandDelegate];
     }
 
-    [self.pluginsDict setObject:plugin forKey:className];
+    [self.pluginObjects setObject:plugin forKey:className];
 }
 
 /**
@@ -827,7 +809,7 @@ BOOL gSplashScreenShown = NO;
         return nil;
     }
 
-    id obj = [self.pluginsDict objectForKey:className];
+    id obj = [self.pluginObjects objectForKey:className];
     if (!obj) {
         // attempt to load the settings for this command class
         NSDictionary* classSettings = [self.settings objectForKey:className];
@@ -976,7 +958,7 @@ BOOL gSplashScreenShown = NO;
     self.webView.delegate = nil;
     self.webView = nil;
     [_commandQueue dispose];
-    [[self.pluginsDict allValues] makeObjectsPerformSelector:@selector(dispose)];
+    [[self.pluginObjects allValues] makeObjectsPerformSelector:@selector(dispose)];
 }
 
 @end

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/8936d203/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLib.xcodeproj/project.pbxproj b/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
index e353c3d..1bb7fa7 100644
--- a/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
+++ b/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
@@ -84,6 +84,8 @@
 		EB80C2AD15DEA63D004D9E7B /* CDVEcho.m in Sources */ = {isa = PBXBuildFile; fileRef = EB80C2AB15DEA63D004D9E7B
/* CDVEcho.m */; };
 		EBA3557315ABD38C00F4DE24 /* NSArray+Comparisons.h in Headers */ = {isa = PBXBuildFile;
fileRef = EBA3557115ABD38C00F4DE24 /* NSArray+Comparisons.h */; settings = {ATTRIBUTES = (Public,
); }; };
 		EBA3557515ABD38C00F4DE24 /* NSArray+Comparisons.m in Sources */ = {isa = PBXBuildFile;
fileRef = EBA3557215ABD38C00F4DE24 /* NSArray+Comparisons.m */; };
+		F858FBC6166009A8007DA594 /* CDVConfigParser.h in Headers */ = {isa = PBXBuildFile; fileRef
= F858FBC4166009A8007DA594 /* CDVConfigParser.h */; };
+		F858FBC7166009A8007DA594 /* CDVConfigParser.m in Sources */ = {isa = PBXBuildFile; fileRef
= F858FBC5166009A8007DA594 /* CDVConfigParser.m */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXFileReference section */
@@ -178,6 +180,8 @@
 		EB80C2AB15DEA63D004D9E7B /* CDVEcho.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType
= sourcecode.c.objc; name = CDVEcho.m; path = Classes/CDVEcho.m; sourceTree = "<group>";
};
 		EBA3557115ABD38C00F4DE24 /* NSArray+Comparisons.h */ = {isa = PBXFileReference; fileEncoding
= 4; lastKnownFileType = sourcecode.c.h; name = "NSArray+Comparisons.h"; path = "Classes/NSArray+Comparisons.h";
sourceTree = "<group>"; };
 		EBA3557215ABD38C00F4DE24 /* NSArray+Comparisons.m */ = {isa = PBXFileReference; fileEncoding
= 4; lastKnownFileType = sourcecode.c.objc; name = "NSArray+Comparisons.m"; path = "Classes/NSArray+Comparisons.m";
sourceTree = "<group>"; };
+		F858FBC4166009A8007DA594 /* CDVConfigParser.h */ = {isa = PBXFileReference; fileEncoding
= 4; lastKnownFileType = sourcecode.c.h; name = CDVConfigParser.h; path = Classes/CDVConfigParser.h;
sourceTree = "<group>"; };
+		F858FBC5166009A8007DA594 /* CDVConfigParser.m */ = {isa = PBXFileReference; fileEncoding
= 4; lastKnownFileType = sourcecode.c.objc; name = CDVConfigParser.m; path = Classes/CDVConfigParser.m;
sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -232,6 +236,8 @@
 		3054098714B77FF3009841CA /* Cleaver */ = {
 			isa = PBXGroup;
 			children = (
+				F858FBC4166009A8007DA594 /* CDVConfigParser.h */,
+				F858FBC5166009A8007DA594 /* CDVConfigParser.m */,
 				8852C43614B65FD800F0E735 /* CDVViewController.h */,
 				8852C43714B65FD800F0E735 /* CDVViewController.m */,
 				8852C43814B65FD800F0E735 /* CDVCordovaView.h */,
@@ -402,6 +408,7 @@
 				9D76CF3C1625A4C50008A0F6 /* CDVGlobalization.h in Headers */,
 				3073E9E91656D37700957977 /* CDVInAppBrowser.h in Headers */,
 				3073E9ED1656D51200957977 /* CDVScreenOrientationDelegate.h in Headers */,
+				F858FBC6166009A8007DA594 /* CDVConfigParser.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -495,6 +502,7 @@
 				EB3B357D161F2A45003DBE7D /* CDVCommandDelegateImpl.m in Sources */,
 				9D76CF3D1625A4C50008A0F6 /* CDVGlobalization.m in Sources */,
 				3073E9EA1656D37700957977 /* CDVInAppBrowser.m in Sources */,
+				F858FBC7166009A8007DA594 /* CDVConfigParser.m in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};


Mime
View raw message