/core/externals/update-engine/externals/gdata-objectivec-client/Source/Introspection/GDataAtomCollection.m

http://macfuse.googlecode.com/ · Objective C · 147 lines · 81 code · 34 blank · 32 comment · 4 complexity · 545060ee8f5e40332576659b2f03fe4d 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. // GDataAtomCollection.m
  17. //
  18. #if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_SERVICE_INTROSPECTION
  19. #import "GDataAtomCollection.h"
  20. #import "GDataAtomCategoryGroup.h"
  21. #import "GDataBaseElements.h"
  22. static NSString* const kHrefAttr = @"href";
  23. @implementation GDataAtomAccept
  24. + (NSString *)extensionElementURI { return kGDataNamespaceAtomPub; }
  25. + (NSString *)extensionElementPrefix { return kGDataNamespaceAtomPubPrefix; }
  26. + (NSString *)extensionElementLocalName { return @"accept"; }
  27. @end
  28. @implementation GDataAtomCollection
  29. // a collection in a service document for introspection,
  30. // per http://tools.ietf.org/html/rfc5023#section-8.3.3
  31. //
  32. // For example,
  33. // <app:collection href="http://photos.googleapis.com/data/feed/api/user/user%40gmail.com?v=2">
  34. // <atom:title>gregrobbins</atom:title>
  35. // <app:accept>image/jpeg</app:accept>
  36. // <app:accept>video/*</app:accept>
  37. // <app:categories fixed="yes">
  38. // <atom:category scheme="http://example.org/extra-cats/" term="joke" />
  39. // </app:categories>
  40. // </app:collection>
  41. + (NSString *)extensionElementURI { return kGDataNamespaceAtomPub; }
  42. + (NSString *)extensionElementPrefix { return kGDataNamespaceAtomPubPrefix; }
  43. + (NSString *)extensionElementLocalName { return @"collection"; }
  44. - (void)addParseDeclarations {
  45. NSArray *attrs = [NSArray arrayWithObject:kHrefAttr];
  46. [self addLocalAttributeDeclarations:attrs];
  47. }
  48. - (void)addExtensionDeclarations {
  49. [super addExtensionDeclarations];
  50. [self addExtensionDeclarationForParentClass:[self class]
  51. childClasses:
  52. [GDataAtomCategoryGroup class],
  53. [GDataAtomAccept class],
  54. [GDataAtomTitle class],
  55. nil];
  56. }
  57. #if !GDATA_SIMPLE_DESCRIPTIONS
  58. - (NSMutableArray *)itemsForDescription {
  59. static struct GDataDescriptionRecord descRecs[] = {
  60. { @"title", @"title.stringValue", kGDataDescValueLabeled },
  61. { @"href", @"href", kGDataDescValueLabeled },
  62. { @"categoryGroup", @"categoryGroup", kGDataDescValueLabeled },
  63. { @"accepts", @"serviceAcceptStrings", kGDataDescArrayDescs },
  64. { nil, nil, (GDataDescRecTypes)0 }
  65. };
  66. NSMutableArray *items = [super itemsForDescription];
  67. [self addDescriptionRecords:descRecs toItems:items];
  68. return items;
  69. }
  70. #endif
  71. #pragma mark -
  72. - (NSString *)href {
  73. return [self stringValueForAttribute:kHrefAttr];
  74. }
  75. - (void)setHref:(NSString *)str {
  76. [self setStringValue:str forAttribute:kHrefAttr];
  77. }
  78. - (GDataTextConstruct *)title {
  79. return [self objectForExtensionClass:[GDataAtomTitle class]];
  80. }
  81. - (void)setTitle:(GDataTextConstruct *)obj {
  82. [self setObject:obj forExtensionClass:[GDataAtomTitle class]];
  83. }
  84. - (GDataAtomCategoryGroup *)categoryGroup {
  85. return [self objectForExtensionClass:[GDataAtomCategoryGroup class]];
  86. }
  87. - (void)setCategoryGroup:(GDataAtomCategoryGroup *)obj {
  88. [self setObject:obj forExtensionClass:[GDataAtomCategoryGroup class]];
  89. }
  90. - (NSArray *)serviceAcceptStrings {
  91. NSArray *acceptObjs;
  92. acceptObjs = [self objectsForExtensionClass:[GDataAtomAccept class]];
  93. if ([acceptObjs count] > 0) {
  94. // using KVC, make an array of the strings in each accept element
  95. return [acceptObjs valueForKey:@"stringValue"];
  96. }
  97. return nil;
  98. }
  99. - (void)setServiceAcceptStrings:(NSArray *)array {
  100. NSMutableArray *objArray = nil;
  101. // make an accept object for each string in the array
  102. NSUInteger numberOfStrings = [array count];
  103. if (numberOfStrings > 0) {
  104. objArray = [NSMutableArray arrayWithCapacity:numberOfStrings];
  105. for (NSString *str in array) {
  106. [objArray addObject:[GDataAtomAccept valueWithString:str]];
  107. }
  108. }
  109. // if objArray is still nil, the extensions will be removed
  110. [self setObjects:objArray forExtensionClass:[GDataAtomAccept class]];
  111. }
  112. @end
  113. #endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_SERVICE_INTROSPECTION