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

http://macfuse.googlecode.com/ · Objective C · 153 lines · 87 code · 41 blank · 25 comment · 3 complexity · 867b1daf8655030a520d8aba73add2a7 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. // GDataEntryWorksheet.m
  17. //
  18. #if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_SPREADSHEET_SERVICE
  19. #define GDATAENTRYWORKSHEET_DEFINE_GLOBALS 1
  20. #import "GDataEntryWorksheet.h"
  21. #import "GDataSpreadsheetConstants.h"
  22. #import "GDataRowColumnCount.h"
  23. @implementation GDataEntryWorksheet
  24. + (GDataEntryWorksheet *)worksheetEntry {
  25. GDataEntryWorksheet *entry = [self object];
  26. [entry setNamespaces:[GDataSpreadsheetConstants spreadsheetNamespaces]];
  27. return entry;
  28. }
  29. #pragma mark -
  30. + (NSString *)coreProtocolVersionForServiceVersion:(NSString *)serviceVersion {
  31. return [GDataSpreadsheetConstants coreProtocolVersionForServiceVersion:serviceVersion];
  32. }
  33. + (NSString *)standardEntryKind {
  34. // spreadsheet categories do not use the standard Kind scheme
  35. // (kGDataCategoryScheme) so cannot be init'd by GDataEntryBase
  36. return nil;
  37. }
  38. + (void)load {
  39. // spreadsheet categories do not use the standard Kind scheme
  40. // (kGDataCategoryScheme) so cannot be registered with +registerEntryClass
  41. [GDataEntryBase registerEntryClass:[self class]
  42. forCategoryWithScheme:kGDataCategorySchemeSpreadsheet
  43. term:kGDataCategoryWorksheet];
  44. }
  45. - (void)addExtensionDeclarations {
  46. [super addExtensionDeclarations];
  47. Class entryClass = [self class];
  48. // Worksheet extensions
  49. [self addExtensionDeclarationForParentClass:entryClass
  50. childClass:[GDataColumnCount class]];
  51. [self addExtensionDeclarationForParentClass:entryClass
  52. childClass:[GDataRowCount class]];
  53. }
  54. #if !GDATA_SIMPLE_DESCRIPTIONS
  55. - (NSMutableArray *)itemsForDescription {
  56. NSMutableArray *items = [super itemsForDescription];
  57. NSString *colStr = [NSString stringWithFormat:@"%d", (int) [self columnCount]];
  58. NSString *rowStr = [NSString stringWithFormat:@"%d", (int) [self rowCount]];
  59. [self addToArray:items objectDescriptionIfNonNil:colStr withName:@"cols"];
  60. [self addToArray:items objectDescriptionIfNonNil:rowStr withName:@"rows"];
  61. return items;
  62. }
  63. #endif
  64. - (id)init {
  65. self = [super init];
  66. if (self) {
  67. [self addCategory:[GDataCategory categoryWithScheme:kGDataCategorySchemeSpreadsheet
  68. term:kGDataCategoryWorksheet]];
  69. // set a default row & column count, as in the Java
  70. [self setRowCount:100];
  71. [self setColumnCount:20];
  72. }
  73. return self;
  74. }
  75. + (NSString *)defaultServiceVersion {
  76. return kGDataSpreadsheetDefaultServiceVersion;
  77. }
  78. #pragma mark -
  79. - (NSInteger)rowCount {
  80. GDataRowCount *rowCount = [self objectForExtensionClass:[GDataRowCount class]];
  81. return [rowCount count];
  82. }
  83. - (void)setRowCount:(NSInteger)val {
  84. GDataRowCount *obj = [GDataRowCount rowCountWithInt:val];
  85. [self setObject:obj forExtensionClass:[GDataRowCount class]];
  86. }
  87. - (NSInteger)columnCount {
  88. GDataColumnCount *columnCount = [self objectForExtensionClass:[GDataColumnCount class]];
  89. return [columnCount count];
  90. }
  91. - (void)setColumnCount:(NSInteger)val {
  92. GDataColumnCount *obj = [GDataColumnCount columnCountWithInt:val];
  93. [self setObject:obj forExtensionClass:[GDataColumnCount class]];
  94. }
  95. #pragma mark -
  96. - (GDataLink *)spreadsheetLink {
  97. return [self alternateLink];
  98. }
  99. - (GDataLink *)cellsLink {
  100. return [self linkWithRelAttributeValue:kGDataLinkCellsFeed];
  101. }
  102. - (NSURL *)listFeedURL {
  103. // the worksheets feed URL is the URI in the entry's content element
  104. GDataEntryContent *content = [self content];
  105. if ([[content type] hasPrefix:@"application/atom+xml"]) {
  106. return [content sourceURL];
  107. }
  108. // prior to V2 feeds, the URL is in a link
  109. return [[self linkWithRelAttributeValue:kGDataLinkListFeed] URL];
  110. }
  111. @end
  112. #endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_SPREADSHEET_SERVICE