PageRenderTime 39ms CodeModel.GetById 12ms app.highlight 24ms RepoModel.GetById 1ms app.codeStats 0ms

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