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

http://macfuse.googlecode.com/ · Objective C · 142 lines · 89 code · 32 blank · 21 comment · 6 complexity · d3e806f45f47dbc61c27ed6ae3138121 MD5 · raw file

  1. /* Copyright (c) 2007-2008 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. // GDataEntryLink.m
  17. //
  18. #import "GDataEntryLink.h"
  19. #import "GDataEntryBase.h"
  20. static NSString* const kHrefAttr = @"href";
  21. static NSString* const kReadOnlyAttr = @"readOnly";
  22. static NSString* const kRelAttr = @"rel";
  23. @implementation GDataEntryLink
  24. // used instead GDataWhere, a link to an entry, like
  25. // <gd:entryLink href="http://gmail.com/jo/contacts/Jo">
  26. + (NSString *)extensionElementURI { return kGDataNamespaceGData; }
  27. + (NSString *)extensionElementPrefix { return kGDataNamespaceGDataPrefix; }
  28. + (NSString *)extensionElementLocalName { return @"entryLink"; }
  29. + (GDataEntryLink *)entryLinkWithHref:(NSString *)href
  30. isReadOnly:(BOOL)isReadOnly {
  31. GDataEntryLink* entryLink = [self object];
  32. [entryLink setHref:href];
  33. [entryLink setIsReadOnly:isReadOnly];
  34. return entryLink;
  35. }
  36. - (void)addParseDeclarations {
  37. NSArray *attrs = [NSArray arrayWithObjects:
  38. kHrefAttr, kReadOnlyAttr, kRelAttr, nil];
  39. [self addLocalAttributeDeclarations:attrs];
  40. }
  41. - (id)initWithXMLElement:(NSXMLElement *)element
  42. parent:(GDataObject *)parent {
  43. self = [super initWithXMLElement:element
  44. parent:parent];
  45. if (self) {
  46. // GDataEntryBase, the base class for entries, is not an extension,
  47. // so we parse it manually
  48. [self setEntry:[self objectForChildOfElement:element
  49. qualifiedName:@"entry"
  50. namespaceURI:kGDataNamespaceAtom
  51. objectClass:nil]];
  52. }
  53. return self;
  54. }
  55. - (void)dealloc {
  56. [entry_ release];
  57. [super dealloc];
  58. }
  59. - (id)copyWithZone:(NSZone *)zone {
  60. GDataEntryLink* newLink = [super copyWithZone:zone];
  61. [newLink setEntry:[[[self entry] copyWithZone:zone] autorelease]];
  62. return newLink;
  63. }
  64. - (BOOL)isEqual:(GDataEntryLink *)other {
  65. if (self == other) return YES;
  66. if (![other isKindOfClass:[GDataEntryLink class]]) return NO;
  67. return [super isEqual:other]
  68. && (AreEqualOrBothNil([self entry], [other entry]));
  69. }
  70. #if !GDATA_SIMPLE_DESCRIPTIONS
  71. - (NSMutableArray *)itemsForDescription {
  72. NSMutableArray *items = [super itemsForDescription];
  73. [self addToArray:items objectDescriptionIfNonNil:entry_ withName:@"entry"];
  74. return items;
  75. }
  76. #endif
  77. - (NSXMLElement *)XMLElement {
  78. NSXMLElement *element = [self XMLElementWithExtensionsAndDefaultName:nil];
  79. if ([self entry]) {
  80. [element addChild:[entry_ XMLElement]];
  81. }
  82. return element;
  83. }
  84. #pragma mark -
  85. - (NSString *)href {
  86. return [self stringValueForAttribute:kHrefAttr];
  87. }
  88. - (void)setHref:(NSString *)str {
  89. [self setStringValue:str forAttribute:kHrefAttr];
  90. }
  91. - (BOOL)isReadOnly {
  92. return [self boolValueForAttribute:kReadOnlyAttr defaultValue:NO];
  93. }
  94. - (void)setIsReadOnly:(BOOL)isReadOnly {
  95. [self setBoolValue:isReadOnly defaultValue:NO forAttribute:kReadOnlyAttr];
  96. }
  97. - (NSString *)rel {
  98. return [self stringValueForAttribute:kRelAttr];
  99. }
  100. - (void)setRel:(NSString *)str {
  101. [self setStringValue:str forAttribute:kRelAttr];
  102. }
  103. - (GDataEntryBase *)entry {
  104. return entry_;
  105. }
  106. - (void)setEntry:(GDataEntryBase *)entry {
  107. [entry_ autorelease];
  108. entry_ = [entry retain];
  109. }
  110. @end