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

http://macfuse.googlecode.com/ · Objective C · 118 lines · 63 code · 26 blank · 29 comment · 4 complexity · c35101f9c9c4c4287771e115fe9f8454 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. // GDataAtomCategoryGroup.m
  17. //
  18. #if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_SERVICE_INTROSPECTION
  19. #import "GDataAtomCategoryGroup.h"
  20. #import "GDataCategory.h"
  21. static NSString* const kHrefAttr = @"href";
  22. static NSString* const kSchemeAttr = @"scheme";
  23. static NSString* const kFixedAttr = @"fixed";
  24. @implementation GDataAtomCategoryGroup
  25. // a collection in a service document for introspection,
  26. // per http://tools.ietf.org/html/rfc5023#section-7.2
  27. //
  28. // <categories fixed="yes">
  29. // <atom:category scheme="http://example.org/extra-cats/" term="joke" />
  30. // <atom:category scheme="http://example.org/extra-cats/" term="serious" />
  31. // </categories>
  32. //
  33. // or
  34. //
  35. // <categories href="http://example.com/cats/forMain.cats" />
  36. + (NSString *)extensionElementURI { return kGDataNamespaceAtomPub; }
  37. + (NSString *)extensionElementPrefix { return kGDataNamespaceAtomPubPrefix; }
  38. + (NSString *)extensionElementLocalName { return @"categories"; }
  39. - (void)addParseDeclarations {
  40. NSArray *attrs = [NSArray arrayWithObjects:
  41. kHrefAttr, kSchemeAttr, kFixedAttr, nil];
  42. [self addLocalAttributeDeclarations:attrs];
  43. }
  44. - (void)addExtensionDeclarations {
  45. [super addExtensionDeclarations];
  46. [self addExtensionDeclarationForParentClass:[self class]
  47. childClass:[GDataCategory class]];
  48. }
  49. #if !GDATA_SIMPLE_DESCRIPTIONS
  50. - (NSMutableArray *)itemsForDescription {
  51. static struct GDataDescriptionRecord descRecs[] = {
  52. { @"fixed", @"isFixed", kGDataDescBooleanPresent },
  53. { @"href", @"href", kGDataDescValueLabeled },
  54. { @"scheme", @"scheme", kGDataDescValueLabeled },
  55. { @"categories", @"categories", kGDataDescArrayDescs },
  56. { nil, nil, (GDataDescRecTypes)0 }
  57. };
  58. NSMutableArray *items = [super itemsForDescription];
  59. [self addDescriptionRecords:descRecs toItems:items];
  60. return items;
  61. }
  62. #endif
  63. #pragma mark -
  64. - (NSString *)href {
  65. return [self stringValueForAttribute:kHrefAttr];
  66. }
  67. - (void)setHref:(NSString *)str {
  68. [self setStringValue:str forAttribute:kHrefAttr];
  69. }
  70. - (NSString *)scheme {
  71. return [self stringValueForAttribute:kSchemeAttr];
  72. }
  73. - (void)setScheme:(NSString *)str {
  74. [self setStringValue:str forAttribute:kSchemeAttr];
  75. }
  76. - (BOOL)isFixed {
  77. // absence of the fixed attribute means no
  78. NSString *str = [self stringValueForAttribute:kFixedAttr];
  79. if (str == nil) return NO;
  80. return ([str caseInsensitiveCompare:@"yes"] == NSOrderedSame);
  81. }
  82. - (void)setIsFixed:(BOOL)flag {
  83. [self setStringValue:(flag ? @"yes" : nil) forAttribute:kFixedAttr];
  84. }
  85. - (NSArray *)categories {
  86. return [self objectsForExtensionClass:[GDataCategory class]];
  87. }
  88. - (void)setCategories:(NSArray *)array {
  89. [self setObjects:array forExtensionClass:[GDataCategory class]];
  90. }
  91. @end
  92. #endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_SERVICE_INTROSPECTION