/core/externals/update-engine/externals/gdata-objectivec-client/Source/Clients/Maps/GDataEntryMapFeature.m

http://macfuse.googlecode.com/ · Objective C · 157 lines · 102 code · 36 blank · 19 comment · 8 complexity · 27f451c620c09c87b8f947bbe233a62b MD5 · raw file

  1. /* Copyright (c) 2009 Google Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. //
  16. // GDataEntryMapFeature.m
  17. //
  18. #if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_MAPS_SERVICE
  19. #import "GDataMapConstants.h"
  20. #import "GDataEntryMapFeature.h"
  21. @implementation GDataEntryMapFeature
  22. + (id)featureEntryWithTitle:(NSString *)str {
  23. GDataEntryMapFeature *obj = [self object];
  24. [obj setNamespaces:[GDataMapConstants mapsNamespaces]];
  25. [obj setTitleWithString:str];
  26. return obj;
  27. }
  28. #pragma mark -
  29. + (NSString *)standardEntryKind {
  30. return kGDataCategoryMapFeature;
  31. }
  32. + (void)load {
  33. [self registerEntryClass];
  34. }
  35. - (void)addExtensionDeclarations {
  36. [super addExtensionDeclarations];
  37. Class entryClass = [self class];
  38. [self addExtensionDeclarationForParentClass:entryClass
  39. childClasses:
  40. [GDataStructuredPostalAddress class],
  41. [GDataCustomProperty class],
  42. nil];
  43. }
  44. #if !GDATA_SIMPLE_DESCRIPTIONS
  45. - (NSMutableArray *)itemsForDescription {
  46. NSString *kmlString = nil;
  47. NSArray *kmlValues = [self KMLValues];
  48. if ([kmlValues count] > 0) {
  49. NSXMLElement *kmlElem = [kmlValues objectAtIndex:0];
  50. kmlString = [kmlElem XMLString];
  51. }
  52. struct GDataDescriptionRecord descRecs[] = {
  53. { @"postal", @"postalAddress", kGDataDescValueLabeled },
  54. { @"properties", @"customProperties", kGDataDescArrayDescs },
  55. { @"KML", kmlString, kGDataDescValueIsKeyPath },
  56. { nil, nil, (GDataDescRecTypes)0 }
  57. };
  58. NSMutableArray *items = [super itemsForDescription];
  59. [self addDescriptionRecords:descRecs toItems:items];
  60. return items;
  61. }
  62. #endif
  63. + (NSString *)defaultServiceVersion {
  64. return kGDataMapsDefaultServiceVersion;
  65. }
  66. #pragma mark -
  67. - (void)setPostalAddress:(GDataStructuredPostalAddress *)obj {
  68. [self setObject:obj forExtensionClass:[GDataStructuredPostalAddress class]];
  69. }
  70. - (GDataStructuredPostalAddress *)postalAddress {
  71. return [self objectForExtensionClass:[GDataStructuredPostalAddress class]];
  72. }
  73. - (NSArray *)customProperties {
  74. return [self objectsForExtensionClass:[GDataCustomProperty class]];
  75. }
  76. - (void)setCustomProperties:(NSArray *)array {
  77. [self setObjects:array forExtensionClass:[GDataCustomProperty class]];
  78. }
  79. - (void)addCustomProperty:(GDataCustomProperty *)obj {
  80. [self addObject:obj forExtensionClass:[GDataCustomProperty class]];
  81. }
  82. // wrappers around the content element, which contains the KML
  83. - (NSArray *)KMLValues {
  84. NSArray *array = [[self content] XMLValues];
  85. return array;
  86. }
  87. - (void)setKMLValues:(NSArray *)arr {
  88. GDataEntryContent *content = [self content];
  89. if (content == nil) {
  90. content = [GDataEntryContent contentWithXMLValue:nil
  91. type:kGDataContentTypeKML];
  92. [self setContent:content];
  93. } else {
  94. [content setType:kGDataContentTypeKML];
  95. }
  96. [content setChildXMLElements:arr];
  97. }
  98. - (void)addKMLValue:(NSXMLNode *)node {
  99. GDataEntryContent *content = [self content];
  100. if (content == nil) {
  101. content = [GDataEntryContent contentWithXMLValue:node
  102. type:kGDataContentTypeKML];
  103. [self setContent:content];
  104. } else {
  105. [content setType:kGDataContentTypeKML];
  106. [content addChildXMLElement:node];
  107. }
  108. }
  109. // convenience accessors
  110. - (GDataCustomProperty *)customPropertyWithName:(NSString *)name {
  111. NSArray *array = [self customProperties];
  112. GDataCustomProperty *obj = [GDataUtilities firstObjectFromArray:array
  113. withValue:name
  114. forKeyPath:@"name"];
  115. return obj;
  116. }
  117. - (GDataLink *)viewLink {
  118. return [self linkWithRelAttributeValue:kGDataLinkMapView];
  119. }
  120. @end
  121. #endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_MAPS_SERVICE