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

http://macfuse.googlecode.com/ · Objective C · 168 lines · 110 code · 36 blank · 22 comment · 7 complexity · 51f56e0ef7630effe508d0c18d692500 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. // GDataFeedLink.m
  17. //
  18. #import "GDataFeedLink.h"
  19. #import "GDataFeedBase.h"
  20. static NSString *const kHrefAttr = @"href";
  21. static NSString *const kRelAttr = @"rel";
  22. static NSString *const KReadOnlyAttr = @"readOnly";
  23. static NSString *const kCountHintAttr = @"countHint";
  24. @implementation GDataFeedLink
  25. // a link to a feed, like
  26. // <gd:feedLink href="http://example.com/Jo/posts/MyFirstPost/comments" countHint="10">
  27. //
  28. // http://code.google.com/apis/gdata/common-elements.html#gdFeedLink
  29. + (NSString *)extensionElementURI { return kGDataNamespaceGData; }
  30. + (NSString *)extensionElementPrefix { return kGDataNamespaceGDataPrefix; }
  31. + (NSString *)extensionElementLocalName { return @"feedLink"; }
  32. - (void)addParseDeclarations {
  33. NSArray *attrs = [NSArray arrayWithObjects:
  34. kHrefAttr, kRelAttr, KReadOnlyAttr, kCountHintAttr, nil];
  35. [self addLocalAttributeDeclarations:attrs];
  36. }
  37. + (id)feedLinkWithHref:(NSString *)href
  38. isReadOnly:(BOOL)isReadOnly {
  39. GDataFeedLink* feedLink = [self object];
  40. [feedLink setHref:href];
  41. [feedLink setIsReadOnly:isReadOnly];
  42. return feedLink;
  43. }
  44. - (id)initWithXMLElement:(NSXMLElement *)element
  45. parent:(GDataObject *)parent {
  46. self = [super initWithXMLElement:element
  47. parent:parent];
  48. if (self) {
  49. [self setFeed:[self objectForChildOfElement:element
  50. qualifiedName:@"feed"
  51. namespaceURI:kGDataNamespaceAtom
  52. objectClass:nil]];
  53. }
  54. return self;
  55. }
  56. - (void)dealloc {
  57. [feed_ release];
  58. [super dealloc];
  59. }
  60. - (id)copyWithZone:(NSZone *)zone {
  61. GDataFeedLink* newLink = [super copyWithZone:zone];
  62. [newLink setFeed:[[[self feed] copyWithZone:zone] autorelease]];
  63. return newLink;
  64. }
  65. - (BOOL)isEqual:(GDataFeedLink *)other {
  66. if (self == other) return YES;
  67. if (![other isKindOfClass:[GDataFeedLink class]]) return NO;
  68. return [super isEqual:other]
  69. && AreEqualOrBothNil([self feed], [other feed]);
  70. }
  71. #if !GDATA_SIMPLE_DESCRIPTIONS
  72. - (NSMutableArray *)itemsForDescription {
  73. static struct GDataDescriptionRecord descRecs[] = {
  74. { @"href", @"href", kGDataDescValueLabeled },
  75. { @"readOnly", @"isReadOnly", kGDataDescBooleanPresent },
  76. { @"countHint", @"countHint.stringValue", kGDataDescValueLabeled },
  77. { @"feed", @"feed", kGDataDescValueLabeled },
  78. { @"rel", @"rel", kGDataDescValueLabeled },
  79. { nil, nil, (GDataDescRecTypes)0 }
  80. };
  81. NSMutableArray *items = [super itemsForDescription];
  82. [self addDescriptionRecords:descRecs toItems:items];
  83. return items;
  84. }
  85. #endif
  86. - (NSXMLElement *)XMLElement {
  87. NSXMLElement *element = [self XMLElementWithExtensionsAndDefaultName:nil];
  88. if ([self feed]) {
  89. [element addChild:[[self feed] XMLElement]];
  90. }
  91. return element;
  92. }
  93. - (NSString *)href {
  94. return [self stringValueForAttribute:kHrefAttr];
  95. }
  96. - (void)setHref:(NSString *)str {
  97. [self setStringValue:str forAttribute:kHrefAttr];
  98. }
  99. - (BOOL)isReadOnly {
  100. return [self boolValueForAttribute:KReadOnlyAttr defaultValue:NO];
  101. }
  102. - (void)setIsReadOnly:(BOOL)isReadOnly {
  103. [self setBoolValue:isReadOnly defaultValue:NO forAttribute:KReadOnlyAttr];
  104. }
  105. - (NSNumber *)countHint {
  106. return [self intNumberForAttribute:kCountHintAttr];
  107. }
  108. -(void)setCountHint:(NSNumber *)val {
  109. [self setStringValue:[val stringValue] forAttribute:kCountHintAttr];
  110. }
  111. - (NSString *)rel {
  112. return [self stringValueForAttribute:kRelAttr];
  113. }
  114. - (void)setRel:(NSString *)str {
  115. [self setStringValue:str forAttribute:kRelAttr];
  116. }
  117. - (GDataFeedBase *)feed {
  118. return feed_;
  119. }
  120. - (void)setFeed:(GDataFeedBase *)feed {
  121. [feed_ autorelease];
  122. feed_ = [feed retain];
  123. }
  124. // convenience method
  125. - (NSURL *)URL {
  126. NSString *href = [self href];
  127. if ([href length] > 0) {
  128. return [NSURL URLWithString:href];
  129. }
  130. return nil;
  131. }
  132. @end