PageRenderTime 97ms CodeModel.GetById 40ms app.highlight 53ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/update-engine/externals/gdata-objectivec-client/Source/Clients/Docs/GDataEntryDocBase.m

http://macfuse.googlecode.com/
Objective C | 458 lines | 344 code | 92 blank | 22 comment | 12 complexity | b0bb53b573364f53b0814607f4da1b7a 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//
 17//  GDataEntryDocBase.m
 18//
 19
 20#if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_DOCS_SERVICE
 21
 22#import "GDataEntryDocBase.h"
 23#import "GDataDocElements.h"
 24
 25@interface GDataLastViewed : GDataValueElementConstruct <GDataExtension>
 26@end
 27
 28@implementation GDataLastViewed
 29+ (NSString *)extensionElementURI       { return kGDataNamespaceGData; }
 30+ (NSString *)extensionElementPrefix    { return kGDataNamespaceGDataPrefix; }
 31+ (NSString *)extensionElementLocalName { return @"lastViewed"; }
 32@end
 33
 34@interface GDataSharedWithMe : GDataValueElementConstruct <GDataExtension>
 35@end
 36
 37@implementation GDataSharedWithMe
 38+ (NSString *)extensionElementURI       { return kGDataNamespaceDocuments; }
 39+ (NSString *)extensionElementPrefix    { return kGDataNamespaceDocumentsPrefix; }
 40+ (NSString *)extensionElementLocalName { return @"sharedWithMeDate"; }
 41@end
 42
 43@interface GDataLastModifiedByMe : GDataValueElementConstruct <GDataExtension>
 44@end
 45
 46@implementation GDataLastModifiedByMe
 47+ (NSString *)extensionElementURI       { return kGDataNamespaceDocuments; }
 48+ (NSString *)extensionElementPrefix    { return kGDataNamespaceDocumentsPrefix; }
 49+ (NSString *)extensionElementLocalName { return @"modifiedByMeDate"; }
 50@end
 51
 52@interface GDataWritersCanInvite : GDataBoolValueConstruct <GDataExtension>
 53@end
 54
 55@implementation GDataWritersCanInvite
 56+ (NSString *)extensionElementURI       { return kGDataNamespaceDocuments; }
 57+ (NSString *)extensionElementPrefix    { return kGDataNamespaceDocumentsPrefix; }
 58+ (NSString *)extensionElementLocalName { return @"writersCanInvite"; }
 59@end
 60
 61@interface GDataDocDescription : GDataValueElementConstruct <GDataExtension>
 62@end
 63
 64@implementation GDataDocDescription
 65+ (NSString *)extensionElementURI       { return kGDataNamespaceDocuments; }
 66+ (NSString *)extensionElementPrefix    { return kGDataNamespaceDocumentsPrefix; }
 67+ (NSString *)extensionElementLocalName { return @"description"; }
 68@end
 69
 70@interface GDataDocMD5Checksum : GDataValueElementConstruct <GDataExtension>
 71@end
 72
 73@implementation GDataDocMD5Checksum
 74+ (NSString *)extensionElementURI       { return kGDataNamespaceDocuments; }
 75+ (NSString *)extensionElementPrefix    { return kGDataNamespaceDocumentsPrefix; }
 76+ (NSString *)extensionElementLocalName { return @"md5Checksum"; }
 77@end
 78
 79@interface GDataDocChangestamp : GDataValueConstruct <GDataExtension>
 80@end
 81
 82@implementation GDataDocChangestamp
 83+ (NSString *)extensionElementURI       { return kGDataNamespaceDocuments; }
 84+ (NSString *)extensionElementPrefix    { return kGDataNamespaceDocumentsPrefix; }
 85+ (NSString *)extensionElementLocalName { return @"changestamp"; }
 86@end
 87
 88@interface GDataDocRemoved : GDataImplicitValueConstruct <GDataExtension>
 89@end
 90
 91@implementation GDataDocRemoved
 92+ (NSString *)extensionElementURI       { return kGDataNamespaceDocuments; }
 93+ (NSString *)extensionElementPrefix    { return kGDataNamespaceDocumentsPrefix; }
 94+ (NSString *)extensionElementLocalName { return @"removed"; }
 95@end
 96
 97@interface GDataDocFilename : GDataValueElementConstruct <GDataExtension>
 98@end
 99
100@implementation GDataDocFilename
101+ (NSString *)extensionElementURI       { return kGDataNamespaceDocuments; }
102+ (NSString *)extensionElementPrefix    { return kGDataNamespaceDocumentsPrefix; }
103+ (NSString *)extensionElementLocalName { return @"filename"; }
104@end
105
106@interface GDataDocSuggestedFilename : GDataValueElementConstruct <GDataExtension>
107@end
108
109@implementation GDataDocSuggestedFilename
110+ (NSString *)extensionElementURI       { return kGDataNamespaceDocuments; }
111+ (NSString *)extensionElementPrefix    { return kGDataNamespaceDocumentsPrefix; }
112+ (NSString *)extensionElementLocalName { return @"suggestedFilename"; }
113@end
114
115@interface GDataDocLastCommented : GDataValueElementConstruct <GDataExtension>
116@end
117
118@implementation GDataDocLastCommented
119+ (NSString *)extensionElementURI       { return kGDataNamespaceDocuments; }
120+ (NSString *)extensionElementPrefix    { return kGDataNamespaceDocumentsPrefix; }
121+ (NSString *)extensionElementLocalName { return @"lastCommented"; }
122@end
123
124@implementation GDataEntryDocBase
125
126+ (NSString *)coreProtocolVersionForServiceVersion:(NSString *)serviceVersion {
127  return [GDataDocConstants coreProtocolVersionForServiceVersion:serviceVersion];
128}
129
130+ (id)documentEntry {
131
132  GDataEntryDocBase *entry = [self object];
133
134  [entry setNamespaces:[GDataDocConstants baseDocumentNamespaces]];
135
136  return entry;
137}
138
139- (void)addExtensionDeclarations {
140
141  [super addExtensionDeclarations];
142
143  // ACL feed URL is in a gd:feedLink
144  [self addExtensionDeclarationForParentClass:[self class]
145                                 childClasses:
146   [GDataFeedLink class],
147   [GDataLastViewed class],
148   [GDataSharedWithMe class],
149   [GDataLastModifiedByMe class],
150   [GDataWritersCanInvite class],
151   [GDataLastModifiedBy class],
152   [GDataQuotaBytesUsed class],
153   [GDataDocDescription class],
154   [GDataDocMD5Checksum class],
155   [GDataDocChangestamp class],
156   [GDataDocFilename class],
157   [GDataDocSuggestedFilename class],
158   [GDataDocLastCommented class],
159   [GDataDocRemoved class],
160   nil];
161}
162
163#if !GDATA_SIMPLE_DESCRIPTIONS
164- (NSMutableArray *)itemsForDescription {
165
166  static struct GDataDescriptionRecord descRecs[] = {
167    { @"lastViewed",        @"lastViewed",          kGDataDescValueLabeled },
168    { @"sharedWithMe",      @"sharedWithMe",        kGDataDescValueLabeled },
169    { @"lastModifiedByMe",  @"lastModifiedByMe",    kGDataDescValueLabeled },
170    { @"writersCanInvite",  @"writersCanInvite",    kGDataDescValueLabeled },
171    { @"lastModifiedBy",    @"lastModifiedBy",      kGDataDescValueLabeled },
172    { @"quotaUsed",         @"quotaBytesUsed",      kGDataDescValueLabeled },
173    { @"desc",              @"documentDescription", kGDataDescValueLabeled },
174    { @"md5",               @"MD5Checksum",         kGDataDescValueLabeled },
175    { @"changestamp",       @"changestamp",         kGDataDescValueLabeled },
176    { @"filename",          @"filename",            kGDataDescValueLabeled },
177    { @"suggestedFilename", @"suggestedFilename",   kGDataDescValueLabeled },
178    { @"lastCommented",     @"lastCommented",       kGDataDescValueLabeled },
179    { @"removed",           @"removed",             kGDataDescBooleanPresent },
180    { nil, nil, (GDataDescRecTypes)0 }
181  };
182
183  NSMutableArray *items = [super itemsForDescription];
184  [self addDescriptionRecords:descRecs toItems:items];
185  return items;
186}
187#endif
188
189#pragma mark -
190
191- (GDataDateTime *)lastViewed {
192  GDataLastViewed *obj = [self objectForExtensionClass:[GDataLastViewed class]];
193  return [obj dateTimeValue];
194}
195
196- (void)setLastViewed:(GDataDateTime *)dateTime {
197  GDataLastViewed *obj = [GDataLastViewed valueWithDateTime:dateTime];
198  [self setObject:obj forExtensionClass:[GDataLastViewed class]];
199}
200
201- (GDataDateTime *)sharedWithMe {
202  GDataSharedWithMe *obj =
203      [self objectForExtensionClass:[GDataSharedWithMe class]];
204  return [obj dateTimeValue];
205}
206
207- (void)setSharedWithMe:(GDataDateTime *)dateTime {
208  GDataSharedWithMe *obj = [GDataSharedWithMe valueWithDateTime:dateTime];
209  [self setObject:obj forExtensionClass:[GDataSharedWithMe class]];
210}
211
212- (GDataDateTime *)lastModifiedByMe {
213  GDataLastModifiedByMe *obj =
214      [self objectForExtensionClass:[GDataLastModifiedByMe class]];
215  return [obj dateTimeValue];
216}
217
218- (void)setLastModifiedByMe:(GDataDateTime *)dateTime {
219  GDataLastModifiedByMe *obj = [GDataLastModifiedByMe valueWithDateTime:dateTime];
220  [self setObject:obj forExtensionClass:[GDataLastModifiedByMe class]];
221}
222
223- (NSNumber *)writersCanInvite { // bool
224  GDataWritersCanInvite *obj = [self objectForExtensionClass:[GDataWritersCanInvite class]];
225  return [obj boolNumberValue];
226}
227
228- (void)setWritersCanInvite:(NSNumber *)num {
229  GDataWritersCanInvite *obj = [GDataWritersCanInvite valueWithNumber:num];
230  [self setObject:obj forExtensionClass:[GDataWritersCanInvite class]];
231}
232
233- (GDataPerson *)lastModifiedBy {
234  GDataLastModifiedBy *obj = [self objectForExtensionClass:[GDataLastModifiedBy class]];
235  return obj;
236}
237
238- (void)setLastModifiedBy:(GDataPerson *)obj {
239  [self setObject:obj forExtensionClass:[GDataLastModifiedBy class]];
240}
241
242- (NSNumber *)quotaBytesUsed { // long long
243  GDataQuotaBytesUsed *obj = [self objectForExtensionClass:[GDataQuotaBytesUsed class]];
244  return [obj longLongNumberValue];
245}
246
247- (void)setQuotaBytesUsed:(NSNumber *)num {
248  GDataQuotaBytesUsed *obj = [GDataQuotaBytesUsed valueWithNumber:num];
249  [self setObject:obj forExtensionClass:[GDataQuotaBytesUsed class]];
250}
251
252- (NSString *)documentDescription {
253  GDataDocDescription *obj;
254  obj = [self objectForExtensionClass:[GDataDocDescription class]];
255  return [obj stringValue];
256}
257
258- (void)setDocumentDescription:(NSString *)str {
259  GDataDocDescription *obj = [GDataDocDescription valueWithString:str];
260  [self setObject:obj forExtensionClass:[GDataDocDescription class]];
261}
262
263- (NSString *)MD5Checksum {
264  GDataDocMD5Checksum *obj;
265  obj = [self objectForExtensionClass:[GDataDocMD5Checksum class]];
266  return [obj stringValue];
267}
268
269- (void)setMD5Checksum:(NSString *)str {
270  GDataDocMD5Checksum *obj = [GDataDocMD5Checksum valueWithString:str];
271  [self setObject:obj forExtensionClass:[GDataDocMD5Checksum class]];
272}
273
274- (NSString *)filename {
275  GDataDocFilename *obj;
276  obj = [self objectForExtensionClass:[GDataDocFilename class]];
277  return [obj stringValue];
278}
279
280- (void)setFilename:(NSString *)str {
281  GDataDocFilename *obj = [GDataDocFilename valueWithString:str];
282  [self setObject:obj forExtensionClass:[GDataDocFilename class]];
283}
284
285- (NSString *)suggestedFilename {
286  GDataDocSuggestedFilename *obj;
287  obj = [self objectForExtensionClass:[GDataDocSuggestedFilename class]];
288  return [obj stringValue];
289}
290
291- (void)setSuggestedFilename:(NSString *)str {
292  GDataDocSuggestedFilename *obj = [GDataDocSuggestedFilename valueWithString:str];
293  [self setObject:obj forExtensionClass:[GDataDocSuggestedFilename class]];
294}
295
296- (GDataDateTime *)lastCommented {
297  GDataDocLastCommented *obj;
298  obj = [self objectForExtensionClass:[GDataDocLastCommented class]];
299  return [obj dateTimeValue];
300}
301
302- (void)setLastCommented:(GDataDateTime *)dateTime {
303  GDataDocLastCommented *obj = [GDataDocLastCommented valueWithDateTime:dateTime];
304  [self setObject:obj forExtensionClass:[GDataDocLastCommented class]];
305}
306
307- (NSNumber *)changestamp {
308  GDataDocChangestamp *obj;
309  obj = [self objectForExtensionClass:[GDataDocChangestamp class]];
310  return [obj longLongNumberValue];
311}
312
313- (void)setChangestamp:(NSNumber *)num {
314  GDataDocChangestamp *obj = [GDataDocChangestamp valueWithNumber:num];
315  [self setObject:obj forExtensionClass:[GDataDocChangestamp class]];
316}
317
318- (BOOL)isRemoved {
319  GDataDocRemoved *obj = [self objectForExtensionClass:[GDataDocRemoved class]];
320  return (obj != nil);
321}
322
323- (void)setIsRemoved:(BOOL)flag {
324  GDataDocRemoved *private = flag ? [GDataDocRemoved implicitValue] : nil;
325  [self setObject:private forExtensionClass:[GDataDocRemoved class]];
326}
327
328- (BOOL)hasPathToRoot {
329  BOOL flag = [GDataCategory categories:[self categories]
330             containsCategoryWithScheme:nil
331                                   term:nil
332                                  label:kGDataCategoryLabelHasPathToRoot];
333  return flag;
334}
335
336- (void)setHasPathToRoot:(BOOL)flag {
337  GDataCategory *cat = [GDataCategory categoryWithLabel:kGDataCategoryLabelHasPathToRoot];
338  if (flag) {
339    [self addCategory:cat];
340  } else {
341    [self removeCategory:cat];
342  }
343}
344
345#pragma mark -
346
347- (BOOL)isStarred {
348  BOOL flag = [GDataCategory categories:[self categories]
349              containsCategoryWithLabel:kGDataCategoryLabelStarred];
350  return flag;
351}
352
353- (void)setIsStarred:(BOOL)flag {
354  GDataCategory *cat = [GDataCategory categoryWithLabel:kGDataCategoryLabelStarred];
355  if (flag) {
356    [self addCategory:cat];
357  } else {
358    [self removeCategory:cat];
359  }
360}
361
362- (BOOL)isHidden {
363  BOOL flag = [GDataCategory categories:[self categories]
364              containsCategoryWithLabel:kGDataCategoryLabelHidden];
365  return flag;
366}
367
368- (void)setIsHidden:(BOOL)flag {
369  GDataCategory *cat = [GDataCategory categoryWithLabel:kGDataCategoryLabelHidden];
370  if (flag) {
371    [self addCategory:cat];
372  } else {
373    [self removeCategory:cat];
374  }
375}
376
377- (BOOL)isViewed {
378  BOOL flag = [GDataCategory categories:[self categories]
379              containsCategoryWithLabel:kGDataCategoryLabelViewed];
380  return flag;
381}
382
383- (void)setIsViewed:(BOOL)flag {
384  GDataCategory *cat = [GDataCategory categoryWithLabel:kGDataCategoryLabelViewed];
385  if (flag) {
386    [self addCategory:cat];
387  } else {
388    [self removeCategory:cat];
389  }
390}
391
392- (BOOL)isShared {
393  BOOL flag = [GDataCategory categories:[self categories]
394              containsCategoryWithLabel:kGDataCategoryLabelShared];
395  return flag;
396}
397
398- (void)setIsShared:(BOOL)flag {
399  GDataCategory *cat = [GDataCategory categoryWithLabel:kGDataCategoryLabelShared];
400  if (flag) {
401    [self addCategory:cat];
402  } else {
403    [self removeCategory:cat];
404  }
405}
406
407#pragma mark -
408
409- (NSArray *)parentLinks {
410  return [self linksWithRelAttributeValue:kGDataCategoryDocParent];
411}
412
413- (GDataLink *)thumbnailLink {
414  return [self linkWithRelAttributeValue:kGDataDocsThumbnailRel];
415}
416
417- (GDataLink *)alternateSelfLink {
418  return [self linkWithRelAttributeValue:kGDataDocsAlternateSelfRel];
419}
420
421
422- (GDataFeedLink *)feedLinkForRel:(NSString *)rel {
423
424  NSArray *feedLinks = [self objectsForExtensionClass:[GDataFeedLink class]];
425  GDataFeedLink *resultFeedLink;
426
427  resultFeedLink = [GDataUtilities firstObjectFromArray:feedLinks
428                                           withValue:rel
429                                          forKeyPath:@"rel"];
430  return resultFeedLink;
431}
432
433- (GDataFeedLink *)ACLFeedLink {
434
435  // GDataEntryACL has an ACLLink method to get an entry's atom:link for
436  // the ACL feed, but the docs feed puts the ACL link into a gd:feedLink
437  // instead of into an atom:link
438
439  // same as kGDataLinkRelACL but avoids the dependence on GDataEntryACL.h
440  NSString* const kACLRel = @"http://schemas.google.com/acl/2007#accessControlList";
441
442  GDataFeedLink *feedLink = [self feedLinkForRel:kACLRel];
443  return feedLink;
444}
445
446
447- (GDataFeedLink *)revisionFeedLink {
448  GDataFeedLink *feedLink = [self feedLinkForRel:kGDataDocsRevisionsRel];
449  return feedLink;
450}
451
452+ (NSString *)defaultServiceVersion {
453  return kGDataDocsDefaultServiceVersion;
454}
455
456@end
457
458#endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_DOCS_SERVICE