PageRenderTime 70ms CodeModel.GetById 19ms app.highlight 46ms RepoModel.GetById 2ms app.codeStats 0ms

/core/externals/update-engine/externals/gdata-objectivec-client/Source/Clients/Spreadsheets/GDataSpreadsheetCustomElement.m

http://macfuse.googlecode.com/
Objective C | 136 lines | 79 code | 36 blank | 21 comment | 8 complexity | c92bdabd2a5f9d1f55ed98df62b2d11e 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#if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_SPREADSHEET_SERVICE
 17
 18#import "GDataSpreadsheetCustomElement.h"
 19
 20#import "GDataEntrySpreadsheet.h" // for namespaces
 21
 22@implementation GDataSpreadsheetCustomElement 
 23
 24// arbitrary spreadsheet custom tag, like
 25//  <gsx:e-mail>fitz@gmail.com</gsx:e-mail>
 26//
 27// http://code.google.com/apis/spreadsheets/reference.html#gsx_reference
 28
 29// this object may be an extension, so declare its extension characteristics
 30
 31+ (NSString *)extensionElementURI       { return kGDataNamespaceGSpreadCustom; }
 32+ (NSString *)extensionElementPrefix    { return kGDataNamespaceGSpreadCustomPrefix; }
 33+ (NSString *)extensionElementLocalName { 
 34  // wildcard * matches all elements with the proper namespace URI
 35  return @"*"; 
 36}
 37
 38+ (GDataSpreadsheetCustomElement *)elementWithName:(NSString *)name
 39                                       stringValue:(NSString *)stringValue {
 40  
 41  GDataSpreadsheetCustomElement *obj = [self object];
 42  [obj setName:name];
 43  [obj setStringValue:stringValue];
 44  
 45  // we don't want the element to have the default name gsx:*
 46  [obj setElementName:[NSString stringWithFormat:@"%@:%@", 
 47    [self extensionElementPrefix], name]];
 48  return obj;
 49}
 50
 51- (id)initWithXMLElement:(NSXMLElement *)element
 52                  parent:(GDataObject *)parent {
 53  self = [super initWithXMLElement:element
 54                            parent:parent];
 55  if (self) {
 56        
 57    name_ = [[element localName] copy];
 58    stringValue_ = [[self stringValueFromElement:element] copy];
 59  }
 60  return self;
 61}
 62
 63- (void)dealloc {
 64  [name_ release];
 65  [stringValue_ release];
 66  [super dealloc];
 67}
 68
 69#pragma mark -
 70
 71
 72
 73- (id)copyWithZone:(NSZone *)zone {
 74  GDataSpreadsheetCustomElement* newObj = [super copyWithZone:zone];
 75  
 76  [newObj setName:[self name]];
 77  [newObj setStringValue:[self stringValue]];
 78  
 79  return newObj;
 80}
 81
 82- (BOOL)isEqual:(GDataSpreadsheetCustomElement *)other {
 83  
 84  if (self == other) return YES;
 85  if (![other isKindOfClass:[GDataSpreadsheetCustomElement class]]) return NO;
 86  
 87  return [super isEqual:other]
 88    && AreEqualOrBothNil([self name], [other name])
 89    && AreEqualOrBothNil([self stringValue], [other stringValue]);
 90}
 91
 92#if !GDATA_SIMPLE_DESCRIPTIONS
 93- (NSMutableArray *)itemsForDescription {
 94  NSMutableArray *items = [NSMutableArray array];
 95  
 96  [self addToArray:items objectDescriptionIfNonNil:name_ withName:@"name"];
 97  [self addToArray:items objectDescriptionIfNonNil:stringValue_ withName:@"stringValue"];
 98  
 99  return items;
100}
101#endif
102
103- (NSXMLElement *)XMLElement {
104
105  NSXMLElement *element = [self XMLElementWithExtensionsAndDefaultName:[self elementName]];
106   
107  if (stringValue_) {
108    [element addStringValue:stringValue_];
109  }
110  
111  return element;
112}
113
114#pragma mark -
115
116- (NSString *)name {
117  return name_;
118}
119
120- (void)setName:(NSString *)str {
121  [name_ autorelease];
122  name_ = [str copy];
123}
124
125- (NSString *)stringValue {
126  return stringValue_;
127}
128
129- (void)setStringValue:(NSString *)str {
130  [stringValue_ autorelease];
131  stringValue_ = [str copy];
132}
133
134@end
135
136#endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_SPREADSHEET_SERVICE