Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

CDVConfigParser.m 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. Licensed to the Apache Software Foundation (ASF) under one
  3. or more contributor license agreements. See the NOTICE file
  4. distributed with this work for additional information
  5. regarding copyright ownership. The ASF licenses this file
  6. to you under the Apache License, Version 2.0 (the
  7. "License"); you may not use this file except in compliance
  8. with the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing,
  11. software distributed under the License is distributed on an
  12. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13. KIND, either express or implied. See the License for the
  14. specific language governing permissions and limitations
  15. under the License.
  16. */
  17. #import "CDVConfigParser.h"
  18. @interface CDVConfigParser ()
  19. @property (nonatomic, readwrite, strong) NSMutableDictionary* pluginsDict;
  20. @property (nonatomic, readwrite, strong) NSMutableDictionary* settings;
  21. @property (nonatomic, readwrite, strong) NSMutableArray* startupPluginNames;
  22. @property (nonatomic, readwrite, strong) NSString* startPage;
  23. @end
  24. @implementation CDVConfigParser
  25. @synthesize pluginsDict, settings, startPage, startupPluginNames;
  26. - (id)init
  27. {
  28. self = [super init];
  29. if (self != nil) {
  30. self.pluginsDict = [[NSMutableDictionary alloc] initWithCapacity:30];
  31. self.settings = [[NSMutableDictionary alloc] initWithCapacity:30];
  32. self.startupPluginNames = [[NSMutableArray alloc] initWithCapacity:8];
  33. featureName = nil;
  34. }
  35. return self;
  36. }
  37. - (void)parser:(NSXMLParser*)parser didStartElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qualifiedName attributes:(NSDictionary*)attributeDict
  38. {
  39. if ([elementName isEqualToString:@"preference"]) {
  40. settings[[attributeDict[@"name"] lowercaseString]] = attributeDict[@"value"];
  41. } else if ([elementName isEqualToString:@"feature"]) { // store feature name to use with correct parameter set
  42. featureName = [attributeDict[@"name"] lowercaseString];
  43. } else if ((featureName != nil) && [elementName isEqualToString:@"param"]) {
  44. NSString* paramName = [attributeDict[@"name"] lowercaseString];
  45. id value = attributeDict[@"value"];
  46. if ([paramName isEqualToString:@"ios-package"]) {
  47. pluginsDict[featureName] = value;
  48. }
  49. BOOL paramIsOnload = ([paramName isEqualToString:@"onload"] && [@"true" isEqualToString : value]);
  50. BOOL attribIsOnload = [@"true" isEqualToString :[attributeDict[@"onload"] lowercaseString]];
  51. if (paramIsOnload || attribIsOnload) {
  52. [self.startupPluginNames addObject:featureName];
  53. }
  54. } else if ([elementName isEqualToString:@"content"]) {
  55. self.startPage = attributeDict[@"src"];
  56. }
  57. }
  58. - (void)parser:(NSXMLParser*)parser didEndElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qualifiedName
  59. {
  60. if ([elementName isEqualToString:@"feature"]) { // no longer handling a feature so release
  61. featureName = nil;
  62. }
  63. }
  64. - (void)parser:(NSXMLParser*)parser parseErrorOccurred:(NSError*)parseError
  65. {
  66. NSAssert(NO, @"config.xml parse error line %ld col %ld", (long)[parser lineNumber], (long)[parser columnNumber]);
  67. }
  68. @end