/core/externals/update-engine/externals/gdata-objectivec-client/Source/BaseClasses/GDataObject.h

http://macfuse.googlecode.com/ · C++ Header · 653 lines · 256 code · 137 blank · 260 comment · 0 complexity · 4e7e39befaca2c8435add4f1ff5d29c7 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. // GDataObject.h
  17. //
  18. // This is the base class for most objects in the Objective-C GData implementation.
  19. // Objects should derive from GDataObject in order to support XML parsing and
  20. // generation, and to support the extension model.
  21. // Subclasses will typically implement:
  22. //
  23. // - (void)addExtensionDeclarations; -- declaring extensions
  24. // - (id)initWithXMLElement:(NSXMLElement *)element
  25. // parent:(GDataObject *)parent; -- parsing
  26. // - (NSXMLElement *)XMLElement; -- XML generation
  27. //
  28. // Subclasses should implement other typical NSObject methods, too:
  29. //
  30. // - (NSString *)description;
  31. // - (id)copyWithZone:(NSZone *)zone; (be sure to call superclass)
  32. // - (BOOL)isEqual:(GDataObject *)other; (be sure to call superclass)
  33. // - (void)dealloc;
  34. //
  35. // Subclasses which may be used as extensions should implement the
  36. // simple GDataExtension protocol.
  37. //
  38. //
  39. // Parsing and XML generation
  40. //
  41. // Parsing is done in the subclass's -initWithXMLElement:parent: method.
  42. //
  43. // For each parsed GData XML element, GDataObject maintains lists of
  44. // un-parsed attributes and children (unknownChildren_ and unknownAttributes_)
  45. // as raw NSXMLNodes. Subclasses MUST use the methods in this class's
  46. // "parsing helpers" (below) to extract properties and elements during parsing;
  47. // this ensures that the lists of unknown properties and children are
  48. // accurate. DO NOT parse using NSXMLElement methods.
  49. //
  50. // XML generation is done in the subclass's -XMLElement method.
  51. // That method will call XMLElementWithExtensionsAndDefaultName to get
  52. // a "starter" NSXMLElement, already decorated with extensions, to which
  53. // the subclass can add its unique children and attributes, if any.
  54. //
  55. //
  56. //
  57. // The extension model
  58. //
  59. // Extensions enable elements to contain children about which the element
  60. // may know no details.
  61. //
  62. // Typically, entries add extensions to themselves. For example, a Calendar
  63. // entry declares it may contain a color:
  64. //
  65. // [self addExtensionDeclarationForParentClass:[GDataEntryCalendar class]
  66. // childClass:[GDataColorProperty class]];
  67. //
  68. // This lets the base class handle much of the work of managing the child
  69. // element. The Calendar entry can still provide accessor methods to get
  70. // to the extension by calling into the base class, as in
  71. //
  72. // - (GDataColorProperty *)color {
  73. // return (GDataColorProperty *)
  74. // [self objectForExtensionClass:[GDataColorProperty class]];
  75. // }
  76. //
  77. // - (void)setColor:(GDataColorProperty *)val {
  78. // [self setObject:val forExtensionClass:[GDataColorProperty class]];
  79. // }
  80. //
  81. // The real purpose of extensions is to allow elements to contain children
  82. // they may not know about. For example, a CalendarEventEntry declares
  83. // that GDataLinks contained within the calendar event entry may contain
  84. // GDataWebContent elements:
  85. //
  86. // [self addExtensionDeclarationForParentClass:[GDataLink class]
  87. // childClass:[GDataWebContent class]];
  88. //
  89. // The CalendarEvent has extended GDataLinks without GDataLinks knowing or
  90. // caring. Because GDataLink derives from GDataObject, the GDataLink
  91. // object will automatically parse and maintain and copy and compare
  92. // the GDataWebContents contained within.
  93. //
  94. #import <Foundation/Foundation.h>
  95. #import "GDataDefines.h"
  96. #import "GDataUtilities.h"
  97. #undef _EXTERN
  98. #undef _INITIALIZE_AS
  99. #ifdef GDATAOBJECT_DEFINE_GLOBALS
  100. #define _EXTERN
  101. #define _INITIALIZE_AS(x) =x
  102. #else
  103. #define _EXTERN GDATA_EXTERN
  104. #define _INITIALIZE_AS(x)
  105. #endif
  106. _EXTERN NSString* const kGDataNamespaceAtom _INITIALIZE_AS(@"http://www.w3.org/2005/Atom");
  107. _EXTERN NSString* const kGDataNamespaceAtomPrefix _INITIALIZE_AS(@"atom");
  108. _EXTERN NSString* const kGDataNamespaceAtomPub _INITIALIZE_AS(@"http://www.w3.org/2007/app");
  109. _EXTERN NSString* const kGDataNamespaceAtomPubPrefix _INITIALIZE_AS(@"app");
  110. _EXTERN NSString* const kGDataNamespaceOpenSearch _INITIALIZE_AS(@"http://a9.com/-/spec/opensearch/1.1/");
  111. _EXTERN NSString* const kGDataNamespaceOpenSearchPrefix _INITIALIZE_AS(@"openSearch");
  112. _EXTERN NSString* const kGDataNamespaceXHTML _INITIALIZE_AS(@"http://www.w3.org/1999/xhtml");
  113. _EXTERN NSString* const kGDataNamespaceXHTMLPrefix _INITIALIZE_AS(@"xh");
  114. _EXTERN NSString* const kGDataNamespaceGData _INITIALIZE_AS(@"http://schemas.google.com/g/2005");
  115. _EXTERN NSString* const kGDataNamespaceGDataPrefix _INITIALIZE_AS(@"gd");
  116. _EXTERN NSString* const kGDataNamespaceBatch _INITIALIZE_AS(@"http://schemas.google.com/gdata/batch");
  117. _EXTERN NSString* const kGDataNamespaceBatchPrefix _INITIALIZE_AS(@"batch");
  118. #define GDATA_DEBUG_ASSERT_MIN_SERVICE_VERSION(versionString) \
  119. GDATA_DEBUG_ASSERT([self isServiceVersionAtLeast:versionString], \
  120. @"%@ requires newer version", NSStringFromSelector(_cmd))
  121. #define GDATA_DEBUG_ASSERT_MAX_SERVICE_VERSION(versionString) \
  122. GDATA_DEBUG_ASSERT([self isServiceVersionAtMost:versionString], \
  123. @"%@ deprecated under v%@", NSStringFromSelector(_cmd), [self serviceVersion])
  124. #define GDATA_DEBUG_ASSERT_MIN_SERVICE_V2() \
  125. GDATA_DEBUG_ASSERT_MIN_SERVICE_VERSION(@"2.0")
  126. @class GDataDateTime;
  127. @class GDataCategory;
  128. @protocol GDataExtension
  129. + (NSString *)extensionElementURI;
  130. + (NSString *)extensionElementPrefix;
  131. + (NSString *)extensionElementLocalName;
  132. @end
  133. // GDataAttribute is the base class for attribute extensions.
  134. // It is *not* used for local attributes, which are simply stored in
  135. // GDataObject' attributes_ dictionary.
  136. //
  137. // This returns nil for the attribute's URI and prefix qualifier;
  138. // subclasses must declare at least a local name.
  139. //
  140. // Functionally, this just stores a string value for the attribute.
  141. @interface GDataAttribute : NSObject {
  142. @private
  143. NSString *value_;
  144. }
  145. + (GDataAttribute *)attributeWithValue:(NSString *)str;
  146. - (id)initWithValue:(NSString *)value;
  147. - (void)setStringValue:(NSString *)str;
  148. - (NSString *)stringValue;
  149. @end
  150. // GDataDescriptionRecords are used for describing how the elements
  151. // and attributes of a GDataObject should be reported when -description
  152. // is called.
  153. typedef enum GDataDescRecTypes {
  154. kGDataDescValueLabeled = 1,
  155. kGDataDescLabelIfNonNil,
  156. kGDataDescArrayCount,
  157. kGDataDescArrayDescs,
  158. kGDataDescBooleanLabeled,
  159. kGDataDescBooleanPresent,
  160. kGDataDescNonZeroLength,
  161. kGDataDescValueIsKeyPath
  162. } GDataDescRecTypes;
  163. typedef struct GDataDescriptionRecord {
  164. NSString GDATA_UNSAFE_UNRETAINED *label;
  165. NSString GDATA_UNSAFE_UNRETAINED *keyPath;
  166. GDataDescRecTypes reportType;
  167. } GDataDescriptionRecord;
  168. @interface GDataObject : NSObject <NSCopying> {
  169. @private
  170. // element name from original XML, used for later XML generation
  171. NSString *elementName_;
  172. GDataObject GDATA_UNSAFE_UNRETAINED *parent_; // weak: parent in tree of GData objects
  173. // GDataObjects keep namespaces as {key:prefix value:URI} dictionary entries
  174. NSMutableDictionary *namespaces_;
  175. // extension declaration cache, retained by the topmost parent
  176. //
  177. // keys are classes that have declared their extensions
  178. //
  179. // the values are dictionaries mapping declared parent classes to
  180. // GDataExtensionDeclarations objects
  181. NSMutableDictionary *extensionDeclarationsCache_;
  182. // list of attributes to be parsed for each class
  183. NSMutableDictionary *attributeDeclarationsCache_;
  184. // list of attributes to be parsed for this class (points strongly into the
  185. // attribute declarations cache)
  186. NSMutableArray *attributeDeclarations_;
  187. // arrays of actual extension elements found for this element, keyed by extension class
  188. NSMutableDictionary *extensions_;
  189. // dictionary of attributes set for this element, keyed by attribute name
  190. NSMutableDictionary *attributes_;
  191. // string for element body, if declared as parseable
  192. NSString *contentValue_;
  193. // XMLElements saved from element body but not parsed, if declared by the subclass
  194. NSMutableArray *childXMLElements_;
  195. // arrays of XMLNodes of attributes and child elements not yet parsed
  196. NSMutableArray *unknownChildren_;
  197. NSMutableArray *unknownAttributes_;
  198. BOOL shouldIgnoreUnknowns_;
  199. // mapping of standard classes to user's surrogate subclasses, used when
  200. // creating objects from XML
  201. NSDictionary *surrogates_;
  202. // service version, set for feeds and entries
  203. NSString *serviceVersion_;
  204. // core protocol version, set from the service version when
  205. // -coreProtocolVersion is invoked
  206. NSString *coreProtocolVersion_;
  207. // anything defined by the client; retained but not used internally; not
  208. // copied by copyWithZone:
  209. id userData_;
  210. NSMutableDictionary *userProperties_;
  211. }
  212. ///////////////////////////////////////////////////////////////////////////////
  213. //
  214. // Public methods
  215. //
  216. // These methods are intended for users of the library
  217. //
  218. + (id)object;
  219. - (id)copyWithZone:(NSZone *)zone;
  220. - (id)initWithServiceVersion:(NSString *)serviceVersion;
  221. - (id)initWithXMLElement:(NSXMLElement *)element
  222. parent:(GDataObject *)parent; // subclasses must override
  223. - (NSXMLElement *)XMLElement; // subclasses must override
  224. - (NSXMLDocument *)XMLDocument; // returns this XMLElement wrapped in an NSXMLDocument
  225. // setters/getters
  226. // namespaces here are a dictionary mapping prefix to URI; they are not
  227. // NSXML namespace objects
  228. - (void)setNamespaces:(NSDictionary *)namespaces;
  229. - (void)addNamespaces:(NSDictionary *)namespaces;
  230. - (NSDictionary *)namespaces;
  231. // return a dictionary containing all namespaces
  232. // in this object and its parent objects
  233. - (NSDictionary *)completeNamespaces;
  234. // if a prefix is explicitly defined the same for a parent as it is locally,
  235. // remove it, since we can rely on the parent's definition
  236. - (void)pruneInheritedNamespaces;
  237. // name from original XML; this will be used during XML generation
  238. - (void)setElementName:(NSString *)elementName;
  239. - (NSString *)elementName;
  240. // parent in object tree (weak reference)
  241. - (void)setParent:(GDataObject *)obj;
  242. - (GDataObject *)parent;
  243. // surrogate lists for when alloc'ing classes from XML
  244. - (void)setSurrogates:(NSDictionary *)surrogates;
  245. - (NSDictionary *)surrogates;
  246. // service API version
  247. + (NSString *)defaultServiceVersion;
  248. // a side-effect of setServiceVersion: is that the coreProtocolVersion is
  249. // reset
  250. - (void)setServiceVersion:(NSString *)str;
  251. - (NSString *)serviceVersion;
  252. - (BOOL)isServiceVersionAtLeast:(NSString *)otherVersion;
  253. - (BOOL)isServiceVersionAtMost:(NSString *)otherVersion;
  254. // calling -coreProtocolVersion sets the initial core protocol version based
  255. // on the service version
  256. - (NSString *)coreProtocolVersion;
  257. - (void)setCoreProtocolVersion:(NSString *)str;
  258. - (BOOL)isCoreProtocolVersion1;
  259. // userData is available for client use; retained by GDataObject, but not
  260. // copied by the copyWithZone
  261. - (void)setUserData:(id)obj;
  262. - (id)userData;
  263. // properties are supported for client convenience, but are not copied by
  264. // copyWithZone. Properties keys beginning with _ are reserved by the library.
  265. - (void)setProperties:(NSDictionary *)dict;
  266. - (NSDictionary *)properties;
  267. - (void)setProperty:(id)obj forKey:(NSString *)key; // pass nil obj to remove property
  268. - (id)propertyForKey:(NSString *)key;
  269. // XMLNode children not parsed; primarily for internal use by the framework
  270. - (void)setUnknownChildren:(NSArray *)arr;
  271. - (NSArray *)unknownChildren;
  272. // XMLNode attributes not parsed; primarily for internal use by the framework
  273. - (void)setUnknownAttributes:(NSArray *)arr;
  274. - (NSArray *)unknownAttributes;
  275. // feeds and their elements may exclude tracking of unknown child elements
  276. // and unknown attributes; see GDataServiceBase for more information
  277. - (void)setShouldIgnoreUnknowns:(BOOL)flag;
  278. - (BOOL)shouldIgnoreUnknowns;
  279. ///////////////////////////////////////////////////////////////////////////////
  280. //
  281. // Protected methods
  282. //
  283. // All remaining methods are intended for use only by subclasses
  284. // of GDataObject.
  285. //
  286. // this init method should be used only when creating the base of a tree
  287. // containing surrogates (the surrogate map is a dictionary of
  288. // standard GDataObject classes to replacement subclasses); this method
  289. // calls through to [self initWithXMLElement:parent:]
  290. - (id)initWithXMLElement:(NSXMLElement *)element
  291. parent:(GDataObject *)parent
  292. serviceVersion:(NSString *)serviceVersion
  293. surrogates:(NSDictionary *)surrogates
  294. shouldIgnoreUnknowns:(BOOL)shouldIgnoreUnknowns;
  295. - (void)addExtensionDeclarations; // subclasses may override this to declare extensions
  296. - (void)addParseDeclarations; // subclasses may override this to declare local attributes and content value
  297. - (void)clearExtensionDeclarationsCache; // used by GDataServiceBase and by subclasses
  298. // content stream and upload data: these always return NO/nil for objects
  299. // other than entries
  300. - (BOOL)generateContentInputStream:(NSInputStream **)outInputStream
  301. length:(unsigned long long *)outLength
  302. headers:(NSDictionary **)outHeaders;
  303. - (NSString *)uploadMIMEType;
  304. - (NSData *)uploadData;
  305. - (NSFileHandle *)uploadFileHandle;
  306. - (NSURL *)uploadLocationURL;
  307. - (BOOL)shouldUploadDataOnly;
  308. //
  309. // Extensions
  310. //
  311. // declaring a potential extension; applies to this object and its children
  312. - (void)addExtensionDeclarationForParentClass:(Class)parentClass
  313. childClass:(Class)childClass;
  314. - (void)addExtensionDeclarationForParentClass:(Class)parentClass
  315. childClasses:(Class)firstChildClass, ...;
  316. - (void)removeExtensionDeclarationForParentClass:(Class)parentClass
  317. childClass:(Class)childClass;
  318. - (void)addAttributeExtensionDeclarationForParentClass:(Class)parentClass
  319. childClass:(Class)childClass;
  320. - (void)removeAttributeExtensionDeclarationForParentClass:(Class)parentClass
  321. childClass:(Class)childClass;
  322. // accessing actual extensions in this object
  323. - (NSArray *)objectsForExtensionClass:(Class)theClass;
  324. - (id)objectForExtensionClass:(Class)theClass;
  325. - (NSString *)attributeValueForExtensionClass:(Class)theClass;
  326. // replacing or adding actual extensions in this object
  327. - (void)setObjects:(NSArray *)objects forExtensionClass:(Class)theClass;
  328. - (void)setObject:(id)object forExtensionClass:(Class)theClass; // removes all previous objects for this class
  329. - (void)addObject:(id)object forExtensionClass:(Class)theClass;
  330. - (void)removeObject:(id)object forExtensionClass:(Class)theClass;
  331. - (void)setAttributeValue:(NSString *)str forExtensionClass:(Class)theClass;
  332. //
  333. // Local attributes
  334. //
  335. // derived classes may override parseAttributesForElement if they need to
  336. // inspect attributes prior to parsing of element content
  337. - (void)parseAttributesForElement:(NSXMLElement *)element;
  338. // derived classes should call -addLocalAttributeDeclarations in their
  339. // -addParseDeclarations method if they want element attributes to
  340. // automatically be parsed
  341. - (void)addLocalAttributeDeclarations:(NSArray *)attributeLocalNames;
  342. - (NSString *)stringValueForAttribute:(NSString *)name;
  343. - (NSNumber *)intNumberForAttribute:(NSString *)name;
  344. - (NSNumber *)doubleNumberForAttribute:(NSString *)name;
  345. - (NSNumber *)longLongNumberForAttribute:(NSString *)name;
  346. - (NSDecimalNumber *)decimalNumberForAttribute:(NSString *)name;
  347. - (GDataDateTime *)dateTimeForAttribute:(NSString *)name;
  348. - (BOOL)boolValueForAttribute:(NSString *)name defaultValue:(BOOL)defaultVal;
  349. // setting nil value for attribute removes it
  350. - (void)setStringValue:(NSString *)str forAttribute:(NSString *)name;
  351. - (void)setBoolValue:(BOOL)flag defaultValue:(BOOL)defaultVal forAttribute:(NSString *)name;
  352. - (void)setExplicitBoolValue:(BOOL)flag forAttribute:(NSString *)name;
  353. - (void)setDecimalNumberValue:(NSDecimalNumber *)num forAttribute:(NSString *)name;
  354. - (void)setDateTimeValue:(GDataDateTime *)cdate forAttribute:(NSString *)name;
  355. // dictionary of all local attributes actually found in the XML element
  356. - (void)setAttributes:(NSDictionary *)dict;
  357. - (NSDictionary *)attributes;
  358. //
  359. // Element Content Value
  360. //
  361. // derived classes should call -addContentValueDeclaration in their
  362. // -addParseDeclarations method if they want element content to
  363. // automatically be parsed as a string
  364. - (void)addContentValueDeclaration;
  365. - (BOOL)hasDeclaredContentValue;
  366. - (void)setContentStringValue:(NSString *)str;
  367. - (NSString *)contentStringValue;
  368. //
  369. // Unparsed XML child elements
  370. //
  371. // derived classes should call -addXMLValuesDeclaration in their
  372. // -addParseDeclarations method if they want all child elements to
  373. // be held as an array of NSXMLElements
  374. - (void)addChildXMLElementsDeclaration;
  375. - (BOOL)hasDeclaredChildXMLElements;
  376. - (NSArray *)childXMLElements;
  377. - (void)setChildXMLElements:(NSArray *)array;
  378. - (void)addChildXMLElement:(NSXMLNode *)node;
  379. //
  380. // Dynamic GDataObject generation
  381. //
  382. // Feeds and entries can register themselves in their + (void)load
  383. // methods. When XML is being parsed, if a matching category
  384. // is found, the proper class is instantiated.
  385. //
  386. // The scheme or term in a category may be nil (during
  387. // registration and lookup) to match any values.
  388. // class registration method
  389. + (void)registerClass:(Class)theClass
  390. inMap:(NSMutableDictionary **)map
  391. forCategoryWithScheme:(NSString *)scheme
  392. term:(NSString *)term;
  393. + (Class)classForCategoryWithScheme:(NSString *)scheme
  394. term:(NSString *)term
  395. fromMap:(NSDictionary *)map;
  396. // objectClassForXMLElement: returns a found registered feed
  397. // or entry class for the XML according to its contained category
  398. //
  399. // If no registered class is found with a matching category,
  400. // this returns GDataFeedBase for feed elements, GDataEntryBase
  401. // for entry elements.
  402. //
  403. // If the element is not a <feed> or <entry> then nil is returned
  404. + (Class)objectClassForXMLElement:(NSXMLElement *)element;
  405. //
  406. // XML parsing helpers (used in initWithXMLElement:parent:)
  407. //
  408. // Use these parsing helpers, since they remove the parsed items from the
  409. // "unknown children" list for this object.
  410. //
  411. // this creates a single object of the specified class for the first XML child
  412. // element with the specified name. Returns nil if no child element is present.
  413. - (id)objectForChildOfElement:(NSXMLElement *)parentElement
  414. qualifiedName:(NSString *)qualifiedName
  415. namespaceURI:(NSString *)namespaceURI
  416. objectClass:(Class)objectClass;
  417. // this creates an array of objects of the specified class for each XML child
  418. // element with the specified name
  419. - (id)objectOrArrayForChildrenOfElement:(NSXMLElement *)parentElement
  420. qualifiedName:(NSString *)qualifiedName
  421. namespaceURI:(NSString *)namespaceURI
  422. objectClass:(Class)objectClass;
  423. // childOfElement:withName returns the element with the name, or nil of there
  424. // are not exactly one of the element
  425. - (NSXMLElement *)childWithQualifiedName:(NSString *)localName
  426. namespaceURI:(NSString *)namespaceURI
  427. fromElement:(NSXMLElement *)parentElement;
  428. // searches up the parent tree to find a surrogate for the standard class;
  429. // if there is no surrogate, returns the standard class itself
  430. - (Class)classOrSurrogateForClass:(Class)standardClass;
  431. // element parsing
  432. + (NSDictionary *)dictionaryForElementNamespaces:(NSXMLElement *)element;
  433. // this method avoids the "recursive descent" behavior of NSXMLElement's
  434. // stringValue; the element parameter may be nil
  435. - (NSString *)stringValueFromElement:(NSXMLElement *)element;
  436. - (GDataDateTime *)dateTimeFromElement:(NSXMLElement *)element;
  437. - (NSNumber *)intNumberValueFromElement:(NSXMLElement *)element;
  438. - (NSNumber *)doubleNumberValueFromElement:(NSXMLElement *)element;
  439. // attribute parsing
  440. - (NSString *)stringForAttributeName:(NSString *)attributeName
  441. fromElement:(NSXMLElement *)element;
  442. - (NSString *)stringForAttributeLocalName:(NSString *)localName
  443. URI:(NSString *)attributeURI
  444. fromElement:(NSXMLElement *)element;
  445. - (GDataDateTime *)dateTimeForAttributeName:(NSString *)attributeName
  446. fromElement:(NSXMLElement *)element;
  447. - (NSXMLNode *)attributeForName:(NSString *)attributeName
  448. fromElement:(NSXMLElement *)element;
  449. - (BOOL)boolForAttributeName:(NSString *)attributeName
  450. fromElement:(NSXMLElement *)element;
  451. - (NSNumber *)doubleNumberForAttributeName:(NSString *)attributeName
  452. fromElement:(NSXMLElement *)element;
  453. - (NSNumber *)intNumberForAttributeName:(NSString *)attributeName
  454. fromElement:(NSXMLElement *)element;
  455. //
  456. // XML generation helpers
  457. //
  458. // subclasses start their -XMLElement method by calling this
  459. - (NSXMLElement *)XMLElementWithExtensionsAndDefaultName:(NSString *)defaultName;
  460. // adding attributes
  461. - (NSXMLNode *)addToElement:(NSXMLElement *)element
  462. attributeValueIfNonNil:(NSString *)val
  463. withName:(NSString *)name;
  464. - (NSXMLNode *)addToElement:(NSXMLElement *)element
  465. attributeValueIfNonNil:(NSString *)val
  466. withQualifiedName:(NSString *)qName
  467. URI:(NSString *)attributeURI;
  468. - (NSXMLNode *)addToElement:(NSXMLElement *)element
  469. attributeValueWithInteger:(NSInteger)val
  470. withName:(NSString *)name;
  471. // adding child elements
  472. - (NSXMLNode *)addToElement:(NSXMLElement *)element
  473. childWithStringValueIfNonEmpty:(NSString *)str
  474. withName:(NSString *)name;
  475. - (void)addToElement:(NSXMLElement *)element
  476. XMLElementForObject:(id)object;
  477. - (void)addToElement:(NSXMLElement *)element
  478. XMLElementsForArray:(NSArray *)arrayOfGDataObjects;
  479. //
  480. // decription method helpers
  481. //
  482. // the final descRecord in the list should be { nil, nil, 0 }
  483. - (void)addDescriptionRecords:(GDataDescriptionRecord *)descRecordList
  484. toItems:(NSMutableArray *)items;
  485. - (void)addToArray:(NSMutableArray *)stringItems
  486. objectDescriptionIfNonNil:(id)obj
  487. withName:(NSString *)name;
  488. - (void)addAttributeDescriptionsToArray:(NSMutableArray *)stringItems;
  489. - (void)addContentDescriptionToArray:(NSMutableArray *)stringItems
  490. withName:(NSString *)name;
  491. // optional methods for overriding
  492. //
  493. // subclasses may implement -itemsForDescription and add to or
  494. // replace the superclass's array of items
  495. //
  496. // The base class itemsForDescription provides items for local attributes and
  497. // content, but not for any element extensions or attribute extensions
  498. - (NSMutableArray *)itemsForDescription;
  499. - (NSString *)descriptionWithItems:(NSArray *)items;
  500. - (NSString *)description;
  501. // coreProtocolVersionForServiceVersion maps the service version to the
  502. // underlying core protocol version. The default implementation returns
  503. // the service version as the core protocol version.
  504. //
  505. // Entry and feed subclasses will need to implement this if their service
  506. // version numbers deviate from the core protocol version numbers.
  507. + (NSString *)coreProtocolVersionForServiceVersion:(NSString *)str;
  508. @end
  509. @interface NSXMLElement (GDataObjectExtensions)
  510. // XML generation helpers
  511. // NSXMLNode's setStringValue: wipes out other children, so we'll use this
  512. // instead
  513. - (void)addStringValue:(NSString *)str;
  514. // creating objects from child elements
  515. + (id)elementWithName:(NSString *)name attributeName:(NSString *)attrName attributeValue:(NSString *)attrValue;
  516. @end