/core/externals/update-engine/externals/gdata-objectivec-client/Source/Elements/GDataAtomPubControl.m

http://macfuse.googlecode.com/ · Objective C · 108 lines · 59 code · 27 blank · 22 comment · 4 complexity · c1b60a1a09b2b33f2fbe9e22329c9c7c 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. // GDataAtomPubControl.m
  17. //
  18. #import "GDataAtomPubControl.h"
  19. #import "GDataValueConstruct.h"
  20. // app:draft, like
  21. // <app:draft>yes<app:draft>
  22. @interface GDataAtomPubDraft : GDataValueElementConstruct <GDataExtension>
  23. @end
  24. @implementation GDataAtomPubDraft
  25. + (NSString *)extensionElementURI { return kGDataNamespaceAtomPub; }
  26. + (NSString *)extensionElementPrefix { return kGDataNamespaceAtomPubPrefix; }
  27. + (NSString *)extensionElementLocalName { return @"draft"; }
  28. @end
  29. @implementation GDataAtomPubControl
  30. // For app:control, like:
  31. // <app:control><app:draft>yes</app:draft></app:control>
  32. + (NSString *)extensionElementURI { return kGDataNamespaceAtomPub; }
  33. + (NSString *)extensionElementPrefix { return kGDataNamespaceAtomPubPrefix; }
  34. + (NSString *)extensionElementLocalName { return @"control"; }
  35. + (GDataAtomPubControl *)atomPubControl {
  36. GDataAtomPubControl *obj = [self object];
  37. // add the "app" namespace
  38. NSString *nsURI = [[self class] extensionElementURI];
  39. NSDictionary *namespaceDict = [NSDictionary dictionaryWithObject:nsURI
  40. forKey:kGDataNamespaceAtomPubPrefix];
  41. [obj setNamespaces:namespaceDict];
  42. return obj;
  43. }
  44. + (GDataAtomPubControl *)atomPubControlWithIsDraft:(BOOL)isDraft {
  45. GDataAtomPubControl *obj = [self atomPubControl];
  46. [obj setIsDraft:isDraft];
  47. return obj;
  48. }
  49. + (NSString *)defaultServiceVersion {
  50. return @"2.0";
  51. }
  52. - (void)addExtensionDeclarations {
  53. [super addExtensionDeclarations];
  54. [self addExtensionDeclarationForParentClass:[self class]
  55. childClass:[GDataAtomPubDraft class]];
  56. }
  57. #if !GDATA_SIMPLE_DESCRIPTIONS
  58. - (NSMutableArray *)itemsForDescription {
  59. NSMutableArray *items = [NSMutableArray array];
  60. NSString *str = ([self isDraft] ? @"yes" : @"no");
  61. [self addToArray:items objectDescriptionIfNonNil:str
  62. withName:@"isDraft"];
  63. return items;
  64. }
  65. #endif
  66. - (BOOL)isDraft {
  67. GDataValueElementConstruct *obj;
  68. obj = [self objectForExtensionClass:[GDataAtomPubDraft class]];
  69. NSString *str = [obj stringValue];
  70. BOOL isDraft = (str != nil
  71. && [str caseInsensitiveCompare:@"yes"] == NSOrderedSame);
  72. return isDraft;
  73. }
  74. - (void)setIsDraft:(BOOL)isDraft {
  75. id obj = nil;
  76. if (isDraft) {
  77. obj = [GDataAtomPubDraft valueWithString:@"yes"];
  78. }
  79. [self setObject:obj forExtensionClass:[GDataAtomPubDraft class]];
  80. }
  81. @end