PageRenderTime 40ms CodeModel.GetById 13ms app.highlight 24ms RepoModel.GetById 1ms app.codeStats 0ms

/Source/externals/GData/Source/Clients/Photos/GDataEXIFTags.m

http://google-email-uploader-mac.googlecode.com/
Objective C | 193 lines | 116 code | 47 blank | 30 comment | 10 complexity | dfb85081707bfd52b693c5a6b8e3e777 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//  GDataEXIFTag.m
 18//
 19
 20#if !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_PHOTOS_SERVICE
 21
 22#import "GDataEXIFTags.h"
 23#import "GDataPhotoConstants.h"
 24
 25@implementation GDataEXIFTag 
 26
 27+ (NSString *)extensionElementPrefix { return kGDataNamespacePhotosEXIFPrefix; }
 28+ (NSString *)extensionElementURI { return kGDataNamespacePhotosEXIF; }
 29+ (NSString *)extensionElementLocalName { 
 30  // wildcard * matches all elements with the proper namespace URI
 31  return @"*"; 
 32}
 33
 34#pragma mark -
 35
 36+ (GDataEXIFTag *)tagWithName:(NSString *)name
 37                        value:(NSString *)value {
 38  GDataEXIFTag *obj = [GDataEXIFTag valueWithString:value];
 39
 40  NSString *qualifiedName = [NSString stringWithFormat:@"%@:%@",
 41                             kGDataNamespacePhotosEXIFPrefix, name];
 42  [obj setElementName:qualifiedName];
 43  return obj;
 44}
 45
 46- (NSString *)name {
 47  NSString *qualifiedName = [self elementName];
 48  NSString *localName = [NSXMLNode localNameForName:qualifiedName];
 49  return localName;
 50}
 51
 52@end
 53
 54@implementation GDataEXIFTags 
 55// for exif:tags, like 
 56// <exif:tags> 
 57//   <exif:fstop>0.0</exif:fstop>
 58//   <exif:make>Nokia</exif:make> 
 59// </exif:tags>
 60
 61+ (NSString *)extensionElementURI       { return kGDataNamespacePhotosEXIF; }
 62+ (NSString *)extensionElementPrefix    { return kGDataNamespacePhotosEXIFPrefix; }
 63+ (NSString *)extensionElementLocalName { return @"tags"; }
 64
 65+ (GDataEXIFTags *)EXIFTags {
 66  GDataEXIFTags *obj = [self object];
 67  return obj;
 68}
 69
 70- (void)addExtensionDeclarations {
 71  
 72  [super addExtensionDeclarations];
 73  
 74  // media:group may contain media:content
 75  [self addExtensionDeclarationForParentClass:[self class]
 76                                   childClass:[GDataEXIFTag class]];  
 77}
 78
 79
 80- (BOOL)isEqual:(GDataEXIFTags *)other {
 81  if (self == other) return YES;
 82  if (![other isKindOfClass:[GDataEXIFTags class]]) return NO;
 83  
 84  return [super isEqual:other];
 85}
 86
 87- (id)copyWithZone:(NSZone *)zone {
 88  GDataEXIFTags* newObj = [super copyWithZone:zone];
 89  return newObj;
 90}
 91
 92
 93#if !GDATA_SIMPLE_DESCRIPTIONS
 94- (NSMutableArray *)itemsForDescription {
 95  NSMutableArray *items = [NSMutableArray array];
 96  
 97  // make an array of "name:value" items for each tag
 98  NSArray *tags = [self tags];
 99  NSEnumerator *tagsEnum = [tags objectEnumerator];
100  NSMutableArray *tagsArray = [NSMutableArray array];
101  GDataEXIFTag *tag;
102  while ((tag = [tagsEnum nextObject]) != nil) {
103    NSString *string = [NSString stringWithFormat:@"%@:%@", 
104                        [tag name], [tag stringValue]];
105    [tagsArray addObject:string];
106  }
107 
108  
109  [self addToArray:items
110 objectDescriptionIfNonNil:[tagsArray componentsJoinedByString:@" "]
111          withName:@"tags"];
112  
113  return items;
114}
115#endif
116
117- (NSXMLElement *)XMLElement {
118  
119  NSXMLElement *element = [self XMLElementWithExtensionsAndDefaultName:@"exif:tags"];
120  return element;
121}
122
123#pragma mark -
124
125- (NSArray *)tags {
126  NSArray *tags = [self objectsForExtensionClass:[GDataEXIFTag class]];
127  return tags;
128}
129
130- (void)setTags:(NSArray *)tags {
131  [self setObjects:tags forExtensionClass:[GDataEXIFTag class]];   
132}
133
134- (void)addTag:(GDataEXIFTag *)tag {
135  [self addObject:tag forExtensionClass:[GDataEXIFTag class]];
136}
137
138#pragma mark -
139
140- (GDataEXIFTag *)tagWithName:(NSString *)name {
141  NSArray *tags = [self tags];
142  GDataEXIFTag *tag = nil;
143
144  for (tag in tags) {
145    if (AreEqualOrBothNil([tag name], name)) {
146      break;
147    }
148  }
149  return tag;
150}
151
152- (NSString *)valueForTagName:(NSString *)name {
153  return [[self tagWithName:name] stringValue];
154}
155
156- (void)removeTagWithName:(NSString *)name {
157  GDataEXIFTag *tag = [self tagWithName:name];
158  if (tag) {
159    [self removeObject:tag forExtensionClass:[GDataEXIFTag class]]; 
160  }
161}
162
163- (void)setTagWithName:(NSString *)name
164             textValue:(NSString *)value {
165  [self removeTagWithName:name];
166
167  GDataEXIFTag *newTag = [GDataEXIFTag tagWithName:name value:value];
168
169  [self addObject:newTag forExtensionClass:[GDataEXIFTag class]];
170}
171
172
173// EXIFTagDictionary returns a dictionary of exif tags, with
174// xml element names as keys, and tag values as values.  
175// This is to facilitate key-value coding access to the attributes
176- (NSDictionary *)tagDictionary {
177  
178  NSMutableDictionary *dict = [NSMutableDictionary dictionary];
179  NSArray *tags = [self tags];
180
181  // Add in reverse order so the first tag in the array wins in the case of
182  // duplicates.
183  for (NSInteger idx = [tags count] - 1; idx >= 0; idx--) { 
184    
185    GDataEXIFTag *tag = [tags objectAtIndex:idx];
186    [dict setObject:[tag stringValue] forKey:[tag name]];
187  }
188  return dict;
189}
190
191@end
192
193#endif // !GDATA_REQUIRE_SERVICE_INCLUDES || GDATA_INCLUDE_PHOTOS_SERVICE