PageRenderTime 32ms CodeModel.GetById 10ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/update-engine/externals/gdata-objectivec-client/Source/Introspection/GDataAtomCollection.m

http://macfuse.googlecode.com/
Objective C | 147 lines | 81 code | 34 blank | 32 comment | 4 complexity | 545060ee8f5e40332576659b2f03fe4d MD5 | raw file
  1/* Copyright (c) 2009 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//  GDataAtomCollection.m
 18//
 19
 20#if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_SERVICE_INTROSPECTION
 21
 22#import "GDataAtomCollection.h"
 23#import "GDataAtomCategoryGroup.h"
 24#import "GDataBaseElements.h"
 25
 26static NSString* const kHrefAttr = @"href";
 27
 28
 29@implementation GDataAtomAccept
 30+ (NSString *)extensionElementURI       { return kGDataNamespaceAtomPub; }
 31+ (NSString *)extensionElementPrefix    { return kGDataNamespaceAtomPubPrefix; }
 32+ (NSString *)extensionElementLocalName { return @"accept"; }
 33@end
 34
 35
 36@implementation GDataAtomCollection
 37// a collection in a service document for introspection,
 38// per http://tools.ietf.org/html/rfc5023#section-8.3.3
 39//
 40// For example,
 41//  <app:collection href="http://photos.googleapis.com/data/feed/api/user/user%40gmail.com?v=2">
 42//    <atom:title>gregrobbins</atom:title>
 43//    <app:accept>image/jpeg</app:accept>
 44//    <app:accept>video/*</app:accept>
 45//    <app:categories fixed="yes">
 46//      <atom:category scheme="http://example.org/extra-cats/" term="joke" />
 47//    </app:categories>
 48//  </app:collection>
 49
 50+ (NSString *)extensionElementURI       { return kGDataNamespaceAtomPub; }
 51+ (NSString *)extensionElementPrefix    { return kGDataNamespaceAtomPubPrefix; }
 52+ (NSString *)extensionElementLocalName { return @"collection"; }
 53
 54- (void)addParseDeclarations {
 55
 56  NSArray *attrs = [NSArray arrayWithObject:kHrefAttr];
 57
 58  [self addLocalAttributeDeclarations:attrs];
 59}
 60
 61- (void)addExtensionDeclarations {
 62
 63  [super addExtensionDeclarations];
 64
 65  [self addExtensionDeclarationForParentClass:[self class]
 66                                 childClasses:
 67   [GDataAtomCategoryGroup class],
 68   [GDataAtomAccept class],
 69   [GDataAtomTitle class],
 70   nil];
 71}
 72
 73#if !GDATA_SIMPLE_DESCRIPTIONS
 74- (NSMutableArray *)itemsForDescription {
 75  static struct GDataDescriptionRecord descRecs[] = {
 76    { @"title",         @"title.stringValue",    kGDataDescValueLabeled },
 77    { @"href",          @"href",                 kGDataDescValueLabeled },
 78    { @"categoryGroup", @"categoryGroup",        kGDataDescValueLabeled },
 79    { @"accepts",       @"serviceAcceptStrings", kGDataDescArrayDescs },
 80    { nil, nil, (GDataDescRecTypes)0 }
 81  };
 82  
 83  NSMutableArray *items = [super itemsForDescription];
 84  [self addDescriptionRecords:descRecs toItems:items];
 85  return items;
 86}
 87#endif
 88
 89#pragma mark -
 90
 91- (NSString *)href {
 92  return [self stringValueForAttribute:kHrefAttr];
 93}
 94
 95- (void)setHref:(NSString *)str {
 96  [self setStringValue:str forAttribute:kHrefAttr];
 97}
 98
 99- (GDataTextConstruct *)title {
100  return [self objectForExtensionClass:[GDataAtomTitle class]];
101}
102
103- (void)setTitle:(GDataTextConstruct *)obj {
104  [self setObject:obj forExtensionClass:[GDataAtomTitle class]];
105}
106
107- (GDataAtomCategoryGroup *)categoryGroup {
108  return [self objectForExtensionClass:[GDataAtomCategoryGroup class]];
109}
110
111- (void)setCategoryGroup:(GDataAtomCategoryGroup *)obj {
112  [self setObject:obj forExtensionClass:[GDataAtomCategoryGroup class]];
113}
114
115- (NSArray *)serviceAcceptStrings {
116  NSArray *acceptObjs;
117
118  acceptObjs = [self objectsForExtensionClass:[GDataAtomAccept class]];
119
120  if ([acceptObjs count] > 0) {
121    // using KVC, make an array of the strings in each accept element
122    return [acceptObjs valueForKey:@"stringValue"];
123  }
124  return nil;
125}
126
127- (void)setServiceAcceptStrings:(NSArray *)array {
128  NSMutableArray *objArray = nil;
129
130  // make an accept object for each string in the array
131  NSUInteger numberOfStrings = [array count];
132  if (numberOfStrings > 0) {
133
134    objArray = [NSMutableArray arrayWithCapacity:numberOfStrings];
135
136    for (NSString *str in array) {
137      [objArray addObject:[GDataAtomAccept valueWithString:str]];
138    }
139  }
140
141  // if objArray is still nil, the extensions will be removed
142  [self setObjects:objArray forExtensionClass:[GDataAtomAccept class]];
143}
144
145@end
146
147#endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_SERVICE_INTROSPECTION