PageRenderTime 35ms CodeModel.GetById 8ms app.highlight 24ms RepoModel.GetById 1ms app.codeStats 0ms

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