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

http://macfuse.googlecode.com/ · Objective C · 196 lines · 137 code · 37 blank · 22 comment · 18 complexity · 3a3748de39d79b98e9e2724d07bd8e17 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. // GDataSpreadsheetCell.m
  17. //
  18. #if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_SPREADSHEET_SERVICE
  19. #import "GDataSpreadsheetCell.h"
  20. #import "GDataEntrySpreadsheet.h" // for namespaces
  21. @implementation GDataSpreadsheetCell
  22. // For spreadsheet cells like:
  23. // <gs:cell row="2" col="4" inputValue="=FLOOR(R[0]C[-1]/(R[0]C[-2]*60),.0001)"
  24. // numericValue="0.0033">0.0033</gs:cell>
  25. //
  26. // http://code.google.com/apis/spreadsheets/reference.html#gs_reference
  27. + (NSString *)extensionElementURI { return kGDataNamespaceGSpread; }
  28. + (NSString *)extensionElementPrefix { return kGDataNamespaceGSpreadPrefix; }
  29. + (NSString *)extensionElementLocalName { return @"cell"; }
  30. + (GDataSpreadsheetCell *)cellWithRow:(NSInteger)row
  31. column:(NSInteger)column
  32. inputString:(NSString *)inputStr
  33. numericValue:(NSNumber *)numericValue
  34. resultString:(NSString *)resultStr {
  35. GDataSpreadsheetCell *obj = [self object];
  36. [obj setRow:row];
  37. [obj setColumn:column];
  38. [obj setInputString:inputStr];
  39. [obj setNumericValue:numericValue];
  40. [obj setResultString:resultStr];
  41. return obj;
  42. }
  43. - (id)init {
  44. self = [super init];
  45. if (self) {
  46. row_ = -1;
  47. column_ = -1;
  48. }
  49. return self;
  50. }
  51. - (id)initWithXMLElement:(NSXMLElement *)element
  52. parent:(GDataObject *)parent {
  53. self = [super initWithXMLElement:element
  54. parent:parent];
  55. if (self) {
  56. NSString *rowStr = [self stringForAttributeName:@"row"
  57. fromElement:element];
  58. if (rowStr) {
  59. [self setRow:[rowStr intValue]];
  60. }
  61. NSString *columnStr = [self stringForAttributeName:@"col"
  62. fromElement:element];
  63. if (columnStr) {
  64. [self setColumn:[columnStr intValue]];
  65. }
  66. [self setInputString:[self stringForAttributeName:@"inputValue"
  67. fromElement:element]];
  68. [self setNumericValue:[self doubleNumberForAttributeName:@"numericValue"
  69. fromElement:element]];
  70. [self setResultString:[self stringValueFromElement:element]];
  71. }
  72. return self;
  73. }
  74. - (void)dealloc {
  75. [inputString_ release];
  76. [numericValue_ release];
  77. [resultString_ release];
  78. [super dealloc];
  79. }
  80. - (id)copyWithZone:(NSZone *)zone {
  81. GDataSpreadsheetCell* newObj = [super copyWithZone:zone];
  82. [newObj setRow:[self row]];
  83. [newObj setColumn:[self column]];
  84. [newObj setInputString:[self inputString]];
  85. [newObj setNumericValue:[self numericValue]];
  86. [newObj setResultString:[self resultString]];
  87. return newObj;
  88. }
  89. - (BOOL)isEqual:(GDataSpreadsheetCell *)other {
  90. if (self == other) return YES;
  91. if (![other isKindOfClass:[GDataSpreadsheetCell class]]) return NO;
  92. return [super isEqual:other]
  93. && ([self row] == [other row])
  94. && ([self column] == [other column])
  95. && AreEqualOrBothNil([self inputString], [other inputString])
  96. && AreEqualOrBothNil([self numericValue], [other numericValue])
  97. && AreEqualOrBothNil([self resultString], [other resultString]);
  98. }
  99. #if !GDATA_SIMPLE_DESCRIPTIONS
  100. - (NSMutableArray *)itemsForDescription {
  101. NSMutableArray *items = [NSMutableArray array];
  102. [self addToArray:items objectDescriptionIfNonNil:inputString_ withName:@"inputString"];
  103. [self addToArray:items objectDescriptionIfNonNil:numericValue_ withName:@"numericValue"];
  104. [self addToArray:items objectDescriptionIfNonNil:resultString_ withName:@"resultString"];
  105. return items;
  106. }
  107. #endif
  108. - (NSXMLElement *)XMLElement {
  109. NSXMLElement *element = [self XMLElementWithExtensionsAndDefaultName:@"gs:cell"];
  110. if (row_ > 0) {
  111. [self addToElement:element attributeValueWithInteger:row_ withName:@"row"];
  112. }
  113. if (column_ > 0) {
  114. [self addToElement:element attributeValueWithInteger:column_ withName:@"col"];
  115. }
  116. [self addToElement:element attributeValueIfNonNil:inputString_ withName:@"inputValue"];
  117. [self addToElement:element
  118. attributeValueIfNonNil:[numericValue_ stringValue]
  119. withName:@"numericValue"];
  120. if ([resultString_ length] > 0) {
  121. [element addStringValue:resultString_];
  122. }
  123. return element;
  124. }
  125. - (NSInteger)row {
  126. return row_;
  127. }
  128. - (void)setRow:(NSInteger)row {
  129. row_ = row;
  130. }
  131. - (NSInteger)column {
  132. return column_;
  133. }
  134. - (void)setColumn:(NSInteger)column {
  135. column_ = column;
  136. }
  137. - (NSString *)inputString {
  138. return inputString_;
  139. }
  140. - (void)setInputString:(NSString *)str {
  141. [inputString_ autorelease];
  142. inputString_ = [str copy];
  143. }
  144. - (NSNumber *)numericValue {
  145. return numericValue_;
  146. }
  147. - (void)setNumericValue:(NSNumber *)num {
  148. [numericValue_ autorelease];
  149. numericValue_ = [num copy];
  150. }
  151. - (NSString *)resultString {
  152. return resultString_;
  153. }
  154. - (void)setResultString:(NSString *)str {
  155. [resultString_ autorelease];
  156. resultString_ = [str copy];
  157. }
  158. @end
  159. #endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_SPREADSHEET_SERVICE