/core/externals/update-engine/externals/gdata-objectivec-client/Source/Elements/GDataPerson.m

http://macfuse.googlecode.com/ · Objective C · 138 lines · 86 code · 27 blank · 25 comment · 0 complexity · 0d1080bf44cee90ec17880aabc83e4d1 MD5 · raw file

  1. /* Copyright (c) 2007 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. // GDataPerson.m
  17. //
  18. #import "GDataPerson.h"
  19. #import "GDataValueConstruct.h"
  20. static NSString *const kLangAttr = @"xml:lang";
  21. // name, like <atom:name>Fred Flintstone<atom:name>
  22. @interface GDataPersonName : GDataValueElementConstruct <GDataExtension>
  23. @end
  24. @implementation GDataPersonName
  25. + (NSString *)extensionElementURI { return kGDataNamespaceAtom; }
  26. + (NSString *)extensionElementPrefix { return kGDataNamespaceAtomPrefix; }
  27. + (NSString *)extensionElementLocalName { return @"name"; }
  28. @end
  29. // email, like <atom:email>fred@flintstone.com<atom:email>
  30. @interface GDataPersonEmail : GDataValueElementConstruct <GDataExtension>
  31. @end
  32. @implementation GDataPersonEmail
  33. + (NSString *)extensionElementURI { return kGDataNamespaceAtom; }
  34. + (NSString *)extensionElementPrefix { return kGDataNamespaceAtomPrefix; }
  35. + (NSString *)extensionElementLocalName { return @"email"; }
  36. @end
  37. // URI, like <atom:uri>http://flintstone.com/resource<atom:uri>
  38. @interface GDataPersonURI : GDataValueElementConstruct <GDataExtension>
  39. @end
  40. @implementation GDataPersonURI
  41. + (NSString *)extensionElementURI { return kGDataNamespaceAtom; }
  42. + (NSString *)extensionElementPrefix { return kGDataNamespaceAtomPrefix; }
  43. + (NSString *)extensionElementLocalName { return @"uri"; }
  44. @end
  45. @implementation GDataPerson
  46. // a person, as in
  47. // <author>
  48. // <name>Fred Flintstone</name>
  49. // <email>fred@flintstone.com</email>
  50. // </author>
  51. + (NSString *)extensionElementURI { return kGDataNamespaceAtom; }
  52. + (NSString *)extensionElementPrefix { return kGDataNamespaceAtomPrefix; }
  53. + (NSString *)extensionElementLocalName { return @"author"; }
  54. + (GDataPerson *)personWithName:(NSString *)name email:(NSString *)email {
  55. GDataPerson* obj = [self object];
  56. [obj setName:name];
  57. [obj setEmail:email];
  58. return obj;
  59. }
  60. - (void)addParseDeclarations {
  61. [self addLocalAttributeDeclarations:[NSArray arrayWithObject:kLangAttr]];
  62. }
  63. - (void)addExtensionDeclarations {
  64. [super addExtensionDeclarations];
  65. [self addExtensionDeclarationForParentClass:[self class]
  66. childClasses:
  67. [GDataPersonName class],
  68. [GDataPersonEmail class],
  69. [GDataPersonURI class],
  70. nil];
  71. }
  72. #if !GDATA_SIMPLE_DESCRIPTIONS
  73. - (NSMutableArray *)itemsForDescription {
  74. NSMutableArray *items = [super itemsForDescription];
  75. [self addToArray:items objectDescriptionIfNonNil:[self name] withName:@"name"];
  76. [self addToArray:items objectDescriptionIfNonNil:[self URI] withName:@"URI"];
  77. [self addToArray:items objectDescriptionIfNonNil:[self email] withName:@"email"];
  78. return items;
  79. }
  80. #endif
  81. - (NSString *)name {
  82. GDataPersonName *obj = [self objectForExtensionClass:[GDataPersonName class]];
  83. return [obj stringValue];
  84. }
  85. - (void)setName:(NSString *)str {
  86. GDataPersonName *obj = [GDataPersonName valueWithString:str];
  87. [self setObject:obj forExtensionClass:[GDataPersonName class]];
  88. }
  89. - (NSString *)nameLang {
  90. return [self stringValueForAttribute:kLangAttr];
  91. }
  92. - (void)setNameLang:(NSString *)str {
  93. [self setStringValue:str forAttribute:kLangAttr];
  94. }
  95. - (NSString *)URI {
  96. GDataPersonURI *obj = [self objectForExtensionClass:[GDataPersonURI class]];
  97. return [obj stringValue];
  98. }
  99. - (void)setURI:(NSString *)str {
  100. GDataPersonURI *obj = [GDataPersonURI valueWithString:str];
  101. [self setObject:obj forExtensionClass:[GDataPersonURI class]];
  102. }
  103. - (NSString *)email {
  104. GDataPersonEmail *obj = [self objectForExtensionClass:[GDataPersonEmail class]];
  105. return [obj stringValue];
  106. }
  107. - (void)setEmail:(NSString *)str {
  108. GDataPersonEmail *obj = [GDataPersonEmail valueWithString:str];
  109. [self setObject:obj forExtensionClass:[GDataPersonEmail class]];
  110. }
  111. @end