This repository was archived by the owner on Sep 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathGDataEntryBase.m
786 lines (619 loc) · 23.5 KB
/
GDataEntryBase.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
/* Copyright (c) 2007 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//
// GDataEntryBase.m
//
#define GDATAENTRYBASE_DEFINE_GLOBALS 1
#import "GDataEntryBase.h"
#import "GDataBaseElements.h"
#import "GTMMIMEDocument.h"
@implementation GDataEntryBase
+ (NSString *)standardEntryKind {
// overridden by entry subclasses
//
// Feeds and entries typically have a "kind" atom:category element
// indicating their contents; see
// http://code.google.com/apis/gdata/elements.html#Introduction
//
// Subclasses may override this method with the "term" attribute string
// for their kind category. This is used in the plain -init method,
// and from +registerEntryClass
//
return nil;
}
+ (NSString *)standardKindAttributeValue {
// overridden by entry subclasses
//
// Feeds and entries in core v2.1 and later have a kind attribute rather than
// kind categories
//
// Subclasses may override this method with the proper kind attribute string
// used to identify this class
//
return nil;
}
+ (NSDictionary *)baseGDataNamespaces {
NSDictionary *namespaces = [NSDictionary dictionaryWithObjectsAndKeys:
kGDataNamespaceAtom, @"",
kGDataNamespaceGData, kGDataNamespaceGDataPrefix,
kGDataNamespaceAtomPub, kGDataNamespaceAtomPubPrefix,
nil];
return namespaces;
}
+ (id)entry {
GDataEntryBase *entry = [self object];
[entry setNamespaces:[GDataEntryBase baseGDataNamespaces]];
return entry;
}
- (void)addExtensionDeclarations {
[super addExtensionDeclarations];
Class entryClass = [self class];
[self addExtensionDeclarationForParentClass:entryClass
childClasses:
// GData extensions
[GDataResourceID class],
// Atom extensions
[GDataAtomID class],
[GDataAtomPublishedDate class],
[GDataAtomUpdatedDate class],
[GDataAtomTitle class],
[GDataAtomSummary class],
[GDataAtomContent class],
[GDataAtomRights class],
[GDataLink class],
[GDataAtomAuthor class],
[GDataAtomContributor class],
[GDataCategory class],
// deletion marking support
[GDataDeleted class],
// atom publishing control support
[GDataAtomPubControl class],
[GDataAtomPubEditedDate class],
// batch support
[GDataBatchOperation class], [GDataBatchID class],
[GDataBatchStatus class], [GDataBatchInterrupted class],
nil];
[self addAttributeExtensionDeclarationForParentClass:entryClass
childClass:[GDataETagAttribute class]];
[self addAttributeExtensionDeclarationForParentClass:entryClass
childClass:[GDataFieldsAttribute class]];
[self addAttributeExtensionDeclarationForParentClass:entryClass
childClass:[GDataKindAttribute class]];
}
- (id)init {
self = [super init];
if (self) {
// if the subclass declares a kind, then add a category element or
// a kind attribute
NSString *categoryKind = [[self class] standardEntryKind];
if (categoryKind) {
GDataCategory *category;
category = [GDataCategory categoryWithScheme:kGDataCategoryScheme
term:categoryKind];
[self addCategory:category];
}
NSString *attributeKind = [[self class] standardKindAttributeValue];
if (attributeKind) {
[self setKind:attributeKind];
}
}
return self;
}
- (void)dealloc {
[uploadData_ release];
[uploadFileHandle_ release];
[uploadLocationURL_ release];
[uploadMIMEType_ release];
[uploadSlug_ release];
[super dealloc];
}
- (BOOL)isEqual:(GDataEntryBase *)other {
if (self == other) return YES;
if (![other isKindOfClass:[GDataEntryBase class]]) return NO;
return [super isEqual:other]
&& AreEqualOrBothNil([self uploadData], [other uploadData])
&& AreEqualOrBothNil([self uploadMIMEType], [other uploadMIMEType])
&& AreEqualOrBothNil([self uploadSlug], [other uploadSlug])
&& AreBoolsEqual([self shouldUploadDataOnly], [other shouldUploadDataOnly]);
}
- (id)copyWithZone:(NSZone *)zone {
GDataEntryBase* newEntry = [super copyWithZone:zone];
[newEntry setUploadData:[self uploadData]];
[newEntry setUploadFileHandle:[self uploadFileHandle]];
[newEntry setUploadLocationURL:[self uploadLocationURL]];
[newEntry setUploadMIMEType:[self uploadMIMEType]];
[newEntry setUploadSlug:[self uploadSlug]];
[newEntry setShouldUploadDataOnly:[self shouldUploadDataOnly]];
return newEntry;
}
#if !GDATA_SIMPLE_DESCRIPTIONS
- (NSMutableArray *)itemsForDescription {
// make a list of the interesting parts of links
NSArray *linkNames = [GDataLink linkNamesFromLinks:[self links]];
NSString *linksStr = [linkNames componentsJoinedByString:@","];
struct GDataDescriptionRecord descRecs[] = {
{ @"v", @"serviceVersion", kGDataDescValueLabeled },
{ @"title", @"title.stringValue", kGDataDescValueLabeled },
{ @"summary", @"summary.stringValue", kGDataDescValueLabeled },
{ @"content", @"content.stringValue", kGDataDescValueLabeled },
{ @"contentSrc", @"content.sourceURI", kGDataDescValueLabeled },
{ @"etag", @"ETag", kGDataDescValueLabeled },
{ @"kind", @"kind", kGDataDescValueLabeled },
{ @"fields", @"fieldSelection", kGDataDescValueLabeled },
{ @"resourceID", @"resourceID", kGDataDescValueLabeled },
{ @"authors", @"authors", kGDataDescArrayCount },
{ @"contributors", @"contributors", kGDataDescArrayCount },
{ @"categories", @"categories", kGDataDescArrayCount },
{ @"links", linksStr, kGDataDescValueIsKeyPath },
{ @"edited", @"editedDate.RFC3339String", kGDataDescValueLabeled },
{ @"id", @"identifier", kGDataDescValueLabeled },
{ @"app:control", @"atomPubControl", kGDataDescValueLabeled },
{ @"batchOp", @"batchOperation.type", kGDataDescValueLabeled },
{ @"batchID", @"batchID.stringValue", kGDataDescValueLabeled },
{ @"batchStatus", @"batchStatus.code", kGDataDescValueLabeled },
{ @"batchInterrupted", @"batchInterrupted", kGDataDescValueLabeled },
{ @"MIMEType", @"uploadMIMEType", kGDataDescValueLabeled },
{ @"slug", @"uploadSlug", kGDataDescValueLabeled },
{ @"uploadDataOnly", @"shouldUploadDataOnly", kGDataDescBooleanPresent },
{ @"UploadData", @"uploadData", kGDataDescNonZeroLength },
{ @"deleted", @"isDeleted", kGDataDescBooleanPresent },
{ nil, nil, (GDataDescRecTypes)0 }
};
NSMutableArray *items = [super itemsForDescription];
[self addDescriptionRecords:descRecs toItems:items];
return items;
}
#endif
- (NSXMLElement *)XMLElement {
NSXMLElement *element = [self XMLElementWithExtensionsAndDefaultName:@"entry"];
return element;
}
#pragma mark -
- (NSDictionary *)contentHeaders {
// This is also called from GDataServiceBase so it knows what headers to use
// when uploading data chunked but without XML (so the body is empty.)
return [NSDictionary dictionaryWithObjectsAndKeys:
[self uploadMIMEType], @"Content-Type",
@"1.0", @"MIME-Version",
[self uploadSlug], @"Slug", // slug may be nil
nil];
}
- (BOOL)generateContentInputStream:(NSInputStream **)outInputStream
length:(unsigned long long *)outLength
headers:(NSDictionary **)outHeaders {
// check if a subclass is providing data
NSData *uploadData = [self uploadData];
if (uploadData == nil) {
// read from the file handle, if one was provided
NSFileHandle *fileHandle = [self uploadFileHandle];
if (fileHandle) {
[fileHandle seekToFileOffset:0];
uploadData = [fileHandle readDataToEndOfFile];
}
}
NSString *uploadMIMEType = [self uploadMIMEType];
NSString *slug = [self uploadSlug];
BOOL hasUploadData = ([uploadData length] > 0);
BOOL hasUploadMIMEType = ([uploadMIMEType length] > 0);
GDATA_DEBUG_ASSERT(hasUploadData == hasUploadMIMEType,
@"upload data must be paired with MIME type");
BOOL shouldUploadDataOnly = [self shouldUploadDataOnly];
GDATA_DEBUG_ASSERT(!shouldUploadDataOnly
|| (hasUploadData && hasUploadMIMEType),
@"missing data");
if (shouldUploadDataOnly && hasUploadData && hasUploadMIMEType) {
// we're not uploading the XML, so we don't need a multipart MIME document,
// just a stream with the upload data
*outInputStream = [NSInputStream inputStreamWithData:uploadData];
*outLength = [uploadData length];
*outHeaders = [self contentHeaders];
return YES;
}
if (!hasUploadData || !hasUploadMIMEType) {
// if there's no upload data, just fall back on the superclass since we
// don't need a stream
return [super generateContentInputStream:outInputStream
length:outLength
headers:outHeaders];
}
// make a MIME document with an XML part and a binary part
NSDictionary* xmlHeader = [NSDictionary dictionaryWithObjectsAndKeys:
@"application/atom+xml; charset=UTF-8", @"Content-Type", nil];
NSString *xmlString = [[self XMLElement] XMLString];
NSData *xmlBody = [xmlString dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *binHeader = [NSDictionary dictionaryWithObjectsAndKeys:
uploadMIMEType, @"Content-Type",
@"binary", @"Content-Transfer-Encoding", nil];
GTMMIMEDocument* doc = [GTMMIMEDocument MIMEDocument];
[doc addPartWithHeaders:xmlHeader body:xmlBody];
[doc addPartWithHeaders:binHeader body:uploadData];
// generate the input stream, and make a header which includes the
// boundary used between parts of the mime document
NSString *partBoundary = nil; // typically this will be END_OF_PART
[doc generateInputStream:outInputStream
length:outLength
boundary:&partBoundary];
NSString *const streamTypeTemplate = @"multipart/related; boundary=\"%@\"";
NSString *streamType = [NSString stringWithFormat:streamTypeTemplate,
partBoundary];
*outHeaders = [NSDictionary dictionaryWithObjectsAndKeys:
streamType, @"Content-Type",
@"1.0", @"MIME-Version",
slug, @"Slug", // slug may be nil
nil];
return YES;
}
#pragma mark Dynamic object generation - Entry registration
//
// entry registration & lookup for dynamic object generation
//
static NSMutableDictionary *gEntryClassKindMap = nil;
+ (void)registerEntryClass {
NSString *categoryKind = [self standardEntryKind];
if (categoryKind) {
[self registerClass:self
inMap:&gEntryClassKindMap
forCategoryWithScheme:kGDataCategoryScheme
term:categoryKind];
}
NSString *attributeKind = [self standardKindAttributeValue];
if (attributeKind) {
[self registerClass:self
inMap:&gEntryClassKindMap
forCategoryWithScheme:nil
term:attributeKind];
}
GDATA_DEBUG_ASSERT(attributeKind != nil || categoryKind != nil,
@"cannot register entry without a kind");
}
+ (void)registerEntryClass:(Class)theClass
forCategoryWithScheme:(NSString *)scheme
term:(NSString *)term {
// temporary bridge method - will be removed when subclasses all call
// -registerEntryClass
[self registerClass:theClass
inMap:&gEntryClassKindMap
forCategoryWithScheme:scheme
term:term];
}
+ (Class)entryClassForCategoryWithScheme:(NSString *)scheme
term:(NSString *)term {
return [self classForCategoryWithScheme:scheme
term:term
fromMap:gEntryClassKindMap];
}
+ (Class)entryClassForKindAttributeValue:(NSString *)kind {
return [self classForCategoryWithScheme:nil
term:kind
fromMap:gEntryClassKindMap];
}
#pragma mark Getters and Setters
- (NSString *)ETag {
NSString *str = [self attributeValueForExtensionClass:[GDataETagAttribute class]];
return str;
}
- (void)setETag:(NSString *)str {
[self setAttributeValue:str forExtensionClass:[GDataETagAttribute class]];
}
- (NSString *)fieldSelection {
NSString *str = [self attributeValueForExtensionClass:[GDataFieldsAttribute class]];
return str;
}
- (void)setFieldSelection:(NSString *)str {
[self setAttributeValue:str forExtensionClass:[GDataFieldsAttribute class]];
}
- (NSString *)kind {
NSString *str = [self attributeValueForExtensionClass:[GDataKindAttribute class]];
return str;
}
- (void)setKind:(NSString *)str {
[self setAttributeValue:str forExtensionClass:[GDataKindAttribute class]];
}
- (NSString *)resourceID {
GDataResourceID *obj = [self objectForExtensionClass:[GDataResourceID class]];
return [obj stringValue];
}
- (void)setResourceID:(NSString *)str {
GDataResourceID *obj = [GDataResourceID valueWithString:str];
[self setObject:obj forExtensionClass:[GDataResourceID class]];
}
- (NSString *)identifier {
GDataAtomID *obj = [self objectForExtensionClass:[GDataAtomID class]];
return [obj stringValue];
}
- (void)setIdentifier:(NSString *)str {
GDataAtomID *obj = [GDataAtomID valueWithString:str];
[self setObject:obj forExtensionClass:[GDataAtomID class]];
}
- (GDataDateTime *)publishedDate {
GDataAtomPublishedDate *obj;
obj = [self objectForExtensionClass:[GDataAtomPublishedDate class]];
return [obj dateTimeValue];
}
- (void)setPublishedDate:(GDataDateTime *)dateTime {
GDataAtomPublishedDate *obj;
obj = [GDataAtomPublishedDate valueWithDateTime:dateTime];
[self setObject:obj forExtensionClass:[GDataAtomPublishedDate class]];
}
- (GDataDateTime *)updatedDate {
GDataAtomUpdatedDate *obj;
obj = [self objectForExtensionClass:[GDataAtomUpdatedDate class]];
return [obj dateTimeValue];
}
- (void)setUpdatedDate:(GDataDateTime *)dateTime {
GDataAtomUpdatedDate *obj;
obj = [GDataAtomUpdatedDate valueWithDateTime:dateTime];
[self setObject:obj forExtensionClass:[GDataAtomUpdatedDate class]];
}
- (GDataDateTime *)editedDate {
GDataValueElementConstruct *obj;
obj = [self objectForExtensionClass:[GDataAtomPubEditedDate class]];
return [obj dateTimeValue];
}
- (void)setEditedDate:(GDataDateTime *)dateTime {
GDataValueElementConstruct *obj;
obj = [GDataAtomPubEditedDate valueWithDateTime:dateTime];
[self setObject:obj forExtensionClass:[GDataAtomPubEditedDate class]];
}
- (GDataTextConstruct *)title {
GDataAtomTitle *obj = [self objectForExtensionClass:[GDataAtomTitle class]];
return obj;
}
- (void)setTitle:(GDataTextConstruct *)obj {
[self setObject:obj forExtensionClass:[GDataAtomTitle class]];
}
- (void)setTitleWithString:(NSString *)str {
GDataAtomTitle *obj = [GDataAtomTitle textConstructWithString:str];
[self setObject:obj forExtensionClass:[GDataAtomTitle class]];
}
- (GDataTextConstruct *)summary {
GDataAtomSummary *obj = [self objectForExtensionClass:[GDataAtomSummary class]];
return obj;
}
- (void)setSummary:(GDataTextConstruct *)obj {
[self setObject:obj forExtensionClass:[GDataAtomSummary class]];
}
- (void)setSummaryWithString:(NSString *)str {
GDataAtomSummary *obj = [GDataAtomSummary textConstructWithString:str];
[self setObject:obj forExtensionClass:[GDataAtomSummary class]];
}
- (GDataEntryContent *)content {
GDataAtomContent *obj;
obj = [self objectForExtensionClass:[GDataAtomContent class]];
return obj;
}
- (void)setContent:(GDataEntryContent *)obj {
[self setObject:obj forExtensionClass:[GDataAtomContent class]];
}
- (void)setContentWithString:(NSString *)str {
GDataAtomContent *obj = [GDataAtomContent contentWithString:str];
[self setObject:obj forExtensionClass:[GDataAtomContent class]];
}
- (GDataTextConstruct *)rightsString {
GDataTextConstruct *obj;
obj = [self objectForExtensionClass:[GDataAtomRights class]];
return obj;
}
- (void)setRightsString:(GDataTextConstruct *)obj {
[self setObject:obj forExtensionClass:[GDataAtomRights class]];
}
- (void)setRightsStringWithString:(NSString *)str {
GDataAtomRights *obj;
obj = [GDataAtomRights textConstructWithString:str];
[self setObject:obj forExtensionClass:[GDataAtomRights class]];
}
- (NSArray *)links {
NSArray *array = [self objectsForExtensionClass:[GDataLink class]];
return array;
}
- (void)setLinks:(NSArray *)array {
[self setObjects:array forExtensionClass:[GDataLink class]];
}
- (void)addLink:(GDataLink *)obj {
[self addObject:obj forExtensionClass:[GDataLink class]];
}
- (NSArray *)authors {
NSArray *array = [self objectsForExtensionClass:[GDataAtomAuthor class]];
return array;
}
- (void)setAuthors:(NSArray *)array {
[self setObjects:array forExtensionClass:[GDataAtomAuthor class]];
}
- (void)addAuthor:(GDataPerson *)obj {
[self addObject:obj forExtensionClass:[GDataAtomAuthor class]];
}
- (NSArray *)contributors {
NSArray *array = [self objectsForExtensionClass:[GDataAtomContributor class]];
return array;
}
- (void)setContributors:(NSArray *)array {
[self setObjects:array forExtensionClass:[GDataAtomContributor class]];
}
- (void)addContributor:(GDataPerson *)obj {
[self addObject:obj forExtensionClass:[GDataAtomContributor class]];
}
- (NSArray *)categories {
NSArray *array = [self objectsForExtensionClass:[GDataCategory class]];
return array;
}
- (void)setCategories:(NSArray *)array {
[self setObjects:array forExtensionClass:[GDataCategory class]];
}
- (void)addCategory:(GDataCategory *)obj {
[self addObject:obj forExtensionClass:[GDataCategory class]];
}
- (void)removeCategory:(GDataCategory *)obj {
[self removeObject:obj forExtensionClass:[GDataCategory class]];
}
// File uploading
- (NSData *)uploadData {
return uploadData_;
}
- (void)setUploadData:(NSData *)data {
[uploadData_ autorelease];
uploadData_ = [data retain];
}
- (NSFileHandle *)uploadFileHandle {
return uploadFileHandle_;
}
- (void)setUploadFileHandle:(NSFileHandle *)data {
[uploadFileHandle_ autorelease];
uploadFileHandle_ = [data retain];
}
- (NSURL *)uploadLocationURL {
return uploadLocationURL_;
}
- (void)setUploadLocationURL:(NSURL *)url {
[uploadLocationURL_ autorelease];
uploadLocationURL_ = [url retain];
}
- (NSString *)uploadMIMEType {
return uploadMIMEType_;
}
- (void)setUploadMIMEType:(NSString *)str {
[uploadMIMEType_ autorelease];
uploadMIMEType_ = [str copy];
}
- (NSString *)uploadSlug {
return uploadSlug_;
}
- (void)setUploadSlug:(NSString *)str {
[uploadSlug_ autorelease];
// encode per http://bitworking.org/projects/atom/rfc5023.html#rfc.section.9.7
NSString *encoded = [GDataUtilities stringByPercentEncodingUTF8ForString:str];
uploadSlug_ = [encoded copy];
}
- (BOOL)shouldUploadDataOnly {
return shouldUploadDataOnly_;
}
- (void)setShouldUploadDataOnly:(BOOL)flag {
shouldUploadDataOnly_ = flag;
}
// extension for deletion marking
- (BOOL)isDeleted {
GDataDeleted *deleted = [self objectForExtensionClass:[GDataDeleted class]];
return (deleted != nil);
}
- (void)setIsDeleted:(BOOL)isDeleted {
if (isDeleted) {
// set the extension
[self setObject:[GDataDeleted deleted] forExtensionClass:[GDataDeleted class]];
} else {
// remove the extension
[self setObject:nil forExtensionClass:[GDataDeleted class]];
}
}
// extensions for Atom publishing control
- (GDataAtomPubControl *)atomPubControl {
return [self objectForExtensionClass:[GDataAtomPubControl class]];
}
- (void)setAtomPubControl:(GDataAtomPubControl *)obj {
[self setObject:obj forExtensionClass:[GDataAtomPubControl class]];
}
// extensions for batch support
- (GDataBatchOperation *)batchOperation {
return (GDataBatchOperation *) [self objectForExtensionClass:[GDataBatchOperation class]];
}
- (void)setBatchOperation:(GDataBatchOperation *)obj {
[self setObject:obj forExtensionClass:[GDataBatchOperation class]];
}
- (GDataBatchID *)batchID {
return (GDataBatchID *) [self objectForExtensionClass:[GDataBatchID class]];
}
- (void)setBatchID:(GDataBatchID *)obj {
[self setObject:obj forExtensionClass:[GDataBatchID class]];
}
- (void)setBatchIDWithString:(NSString *)str {
GDataBatchID *obj = [GDataBatchID batchIDWithString:str];
[self setBatchID:obj];
}
- (GDataBatchStatus *)batchStatus {
return (GDataBatchStatus *) [self objectForExtensionClass:[GDataBatchStatus class]];
}
- (void)setBatchStatus:(GDataBatchStatus *)obj {
[self setObject:obj forExtensionClass:[GDataBatchStatus class]];
}
- (GDataBatchInterrupted *)batchInterrupted {
return (GDataBatchInterrupted *) [self objectForExtensionClass:[GDataBatchInterrupted class]];
}
- (void)setBatchInterrupted:(GDataBatchInterrupted *)obj {
[self setObject:obj forExtensionClass:[GDataBatchInterrupted class]];
}
+ (NSDictionary *)batchNamespaces {
NSDictionary *namespaces = [NSDictionary dictionaryWithObjectsAndKeys:
kGDataNamespaceBatch, kGDataNamespaceBatchPrefix, nil];
return namespaces;
}
#pragma mark -
- (NSArray *)categoriesWithScheme:(NSString *)scheme {
NSArray *array = [GDataCategory categoriesWithScheme:scheme
fromCategories:[self categories]];
return array;
}
- (GDataCategory *)kindCategory {
GDataCategory *cat = [GDataUtilities firstObjectFromArray:[self categories]
withValue:kGDataCategoryScheme
forKeyPath:@"scheme"];
return cat;
}
- (NSArray *)linksWithRelAttributeValue:(NSString *)relValue {
NSArray *array = [GDataUtilities objectsFromArray:[self links]
withValue:relValue
forKeyPath:@"rel"];
return array;
}
- (GDataLink *)linkWithRelAttributeValue:(NSString *)rel {
return [GDataLink linkWithRel:rel
type:nil
fromLinks:[self links]];
}
- (GDataLink *)linkWithRelAttributeValue:(NSString *)rel
type:(NSString *)type {
return [GDataLink linkWithRel:rel
type:type
fromLinks:[self links]];
}
- (GDataLink *)feedLink {
return [self linkWithRelAttributeValue:kGDataLinkRelFeed];
}
- (GDataLink *)editLink {
return [self linkWithRelAttributeValue:@"edit"];
}
- (GDataLink *)editMediaLink {
return [self linkWithRelAttributeValue:@"edit-media"];
}
- (GDataLink *)alternateLink {
return [self linkWithRelAttributeValue:@"alternate"];
}
- (GDataLink *)relatedLink {
return [self linkWithRelAttributeValue:@"related"];
}
- (GDataLink *)postLink {
return [self linkWithRelAttributeValue:kGDataLinkRelPost];
}
- (GDataLink *)selfLink {
return [self linkWithRelAttributeValue:@"self"];
}
- (GDataLink *)HTMLLink {
return [self linkWithRelAttributeValue:@"alternate"
type:kGDataLinkTypeHTML];
}
- (GDataLink *)uploadEditLink {
return [self linkWithRelAttributeValue:kGDataLinkRelResumableEdit];
}
- (BOOL)canEdit {
return ([self editLink] != nil);
}
@end