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