/FSKit/Source/Common/enunciate/prod/familytree.m
Objective C | 2598 lines | 1418 code | 343 blank | 837 comment | 233 complexity | f86155998a246f9f696849a4c5e71603 MD5 | raw file
Possible License(s): BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
1#import <familytree.h> 2 3/** 4 * Enunciate-specific C functions. 5 */ 6#ifndef ENUNCIATE_C_UTILITIES 7#define ENUNCIATE_C_UTILITIES 8 9/*******************xml utilities************************************/ 10 11static int xmlTextReaderAdvanceToNextStartOrEndElement(xmlTextReaderPtr reader) { 12 int status = xmlTextReaderRead(reader); 13 while (status && xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT && xmlTextReaderNodeType(reader) != XML_READER_TYPE_END_ELEMENT) { 14 status = xmlTextReaderRead(reader); 15 } 16 return status; 17} 18 19static int xmlTextReaderSkipElement(xmlTextReaderPtr reader) { 20 int status = xmlTextReaderNext(reader); 21 while (status && xmlTextReaderNodeType(reader) != XML_READER_TYPE_ELEMENT && xmlTextReaderNodeType(reader) != XML_READER_TYPE_END_ELEMENT) { 22 status = xmlTextReaderRead(reader); 23 } 24 return status; 25} 26 27static xmlChar *xmlTextReaderReadEntireNodeValue(xmlTextReaderPtr reader) { 28 xmlChar *buffer = calloc(1, sizeof(xmlChar)); 29 const xmlChar *snippet; 30 int status; 31 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_ATTRIBUTE) { 32 return xmlTextReaderValue(reader); 33 } 34 else if (xmlTextReaderIsEmptyElement(reader) == 0) { 35 status = xmlTextReaderRead(reader); 36 while (status && (xmlTextReaderNodeType(reader) == XML_READER_TYPE_TEXT || xmlTextReaderNodeType(reader) == XML_READER_TYPE_CDATA || xmlTextReaderNodeType(reader) == XML_READER_TYPE_ENTITY_REFERENCE)) { 37 snippet = xmlTextReaderConstValue(reader); 38 buffer = realloc(buffer, (xmlStrlen(buffer) + xmlStrlen(snippet) + 1) * sizeof(xmlChar)); 39 xmlStrcat(buffer, snippet); 40 status = xmlTextReaderRead(reader); 41 } 42 } 43 return buffer; 44} 45 46/*******************base 64 utilities************************************/ 47 48/* 49 * Base64 Translation Table as described in RFC1113. 50 * 51 * This code was graciously ripped from http://base64.sourceforge.net 52 */ 53static const char cb64[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; 54 55/* 56 * Base64 Translation Table to decode (created by author) 57 * 58 * This code was graciously ripped from http://base64.sourceforge.net 59 */ 60static const char cd64[]="|$$$}rstuvwxyz{$$$$$$$>?@ABCDEFGHIJKLMNOPQRSTUVW$$$$$$XYZ[\\]^_`abcdefghijklmnopq"; 61 62/* 63 * encode 3 8-bit binary bytes as 4 '6-bit' characters 64 * 65 * This code was graciously ripped from http://base64.sourceforge.net 66 * 67 * @param in the block to encode 68 * @param out the block to encode to 69 * @param len the length of the 'in' block. 70 */ 71static void _encode_base64_block(unsigned char in[3], unsigned char out[4], int len) { 72 out[0] = cb64[ in[0] >> 2 ]; 73 out[1] = cb64[ ((in[0] & 0x03) << 4) | ((in[1] & 0xf0) >> 4) ]; 74 out[2] = (unsigned char) (len > 1 ? cb64[ ((in[1] & 0x0f) << 2) | ((in[2] & 0xc0) >> 6) ] : '='); 75 out[3] = (unsigned char) (len > 2 ? cb64[ in[2] & 0x3f ] : '='); 76} 77 78/* 79 * decode 4 '6-bit' characters into 3 8-bit binary bytes 80 * 81 * This code was graciously ripped from http://base64.sourceforge.net 82 */ 83static void _decode_base64_block( unsigned char in[4], unsigned char out[3] ) 84{ 85 out[ 0 ] = (unsigned char ) (in[0] << 2 | in[1] >> 4); 86 out[ 1 ] = (unsigned char ) (in[1] << 4 | in[2] >> 2); 87 out[ 2 ] = (unsigned char ) (((in[2] << 6) & 0xc0) | in[3]); 88} 89 90/* 91 * base64 encode a stream adding padding and line breaks as per spec. 92 * 93 * This code was graciously ripped from http://base64.sourceforge.net 94 * 95 * @param instream The stream to encode. 96 * @param insize The size of the stream to encode. 97 * @return The encoded string. 98 */ 99xmlChar *_encode_base64(unsigned char *instream, int insize) { 100 unsigned char in[3]; 101 unsigned char out[4]; 102 xmlChar *encoded; 103 int i, in_index = 0, out_index = 0, blocklen; 104 105 if (insize == 0) { 106 return BAD_CAST "\0"; 107 } 108 109 encoded = calloc(((insize / 3) * 4) + 10, sizeof(xmlChar)); 110 while (in_index <= insize) { 111 blocklen = 0; 112 for (i = 0; i < 3; i++) { 113 in[i] = instream[in_index++]; 114 if (in_index <= insize) { 115 blocklen++; 116 } 117 else { 118 in[i] = 0; 119 } 120 } 121 if (blocklen) { 122 _encode_base64_block(in, out, blocklen); 123 for( i = 0; i < 4; i++ ) { 124 encoded[out_index++] = out[i]; 125 } 126 } 127 } 128 129 return encoded; 130} 131 132/* 133 * Decode a base64 encoded stream discarding padding, line breaks and noise 134 * 135 * This code was graciously ripped from http://base64.sourceforge.net 136 * 137 * @param invalue The string to decode. 138 * @param outsize Holder for the length of the returned data. 139 * @return The decoded data. 140 */ 141unsigned char *_decode_base64( const xmlChar *invalue, int *outsize ) { 142 xmlChar in[4]; 143 unsigned char out[3], v; 144 int i, in_index = 0, out_index = 0, blocklen; 145 unsigned char *outstream; 146 147 if (invalue == NULL) { 148 return NULL; 149 } 150 151 outstream = calloc(((xmlStrlen(invalue) / 4) * 3) + 1, sizeof(unsigned char)); 152 while (invalue[in_index] != '\0') { 153 for (blocklen = 0, i = 0; i < 4 && invalue[in_index]; i++) { 154 v = 0; 155 while (invalue[in_index] != '\0' && v == 0) { 156 v = (unsigned char) invalue[in_index++]; 157 v = (unsigned char) ((v < 43 || v > 122) ? 0 : cd64[ v - 43 ]); 158 if (v) { 159 v = (unsigned char) ((v == '$') ? 0 : v - 61); 160 } 161 } 162 163 if (invalue[in_index] != '\0') { 164 blocklen++; 165 if (v) { 166 in[i] = (unsigned char) (v - 1); 167 } 168 } 169 else { 170 in[i] = 0; 171 } 172 } 173 174 if (blocklen) { 175 _decode_base64_block( in, out ); 176 for( i = 0; i < blocklen - 1; i++ ) { 177 outstream[out_index++] = out[i]; 178 } 179 } 180 } 181 182 if (outsize != NULL) { 183 *outsize = out_index; 184 } 185 186 return outstream; 187} 188 189#endif /* ENUNCIATE_C_UTILITIES */ 190 191#ifndef ENUNCIATE_OBJC_CLASSES 192#define ENUNCIATE_OBJC_CLASSES 193 194/** 195 * Protocol defining a JAXB (see https://jaxb.dev.java.net/) type. 196 */ 197@protocol JAXBType 198 199/** 200 * Read an XML type from an XML reader. 201 * 202 * @param reader The reader. 203 * @return An instance of the object defining the JAXB type. 204 */ 205+ (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader; 206 207/** 208 * Initialize the object with an XML reader. 209 * 210 * @param reader The XML reader from which to initialize the values of this type. 211 */ 212- (id) initWithReader: (xmlTextReaderPtr) reader; 213 214/** 215 * Write this instance of a JAXB type to a writer. 216 * 217 * @param writer The writer. 218 */ 219- (void) writeXMLType: (xmlTextWriterPtr) writer; 220 221@end /*protocol JAXBType*/ 222 223 224/** 225 * Protocol defining a JAXB (see https://jaxb.dev.java.net/) element. 226 */ 227@protocol JAXBElement 228 229/** 230 * Read the XML element from an XML reader. It is assumed 231 * that the reader is pointing at the start element (be careful 232 * that it's not still pointing to the XML document). 233 * 234 * @param reader The reader. 235 * @return An instance of the object defining the JAXB element. 236 */ 237+ (id<JAXBElement>) readXMLElement: (xmlTextReaderPtr) reader; 238 239/** 240 * Write this instance of a JAXB element to a writer. 241 * 242 * @param writer The writer. 243 */ 244- (void) writeXMLElement: (xmlTextWriterPtr) writer; 245 246/** 247 * Write this instance of a JAXB element to a writer. 248 * 249 * @param writer The writer. 250 * @param writeNs Whether to write the namespaces for this element to the xml writer. 251 */ 252- (void) writeXMLElement: (xmlTextWriterPtr) writer writeNamespaces: (BOOL) writeNs; 253 254@end /*protocol JAXBElement*/ 255 256 257/** 258 * Protocol defining methods for events that occur 259 * when reading/parsing XML. Intended for internal 260 * use only. 261 */ 262@protocol JAXBReading 263 264/** 265 * Method for reading an attribute. 266 * 267 * @param reader The reader pointing to the attribute. 268 * @return Whether the attribute was read. 269 */ 270- (BOOL) readJAXBAttribute: (xmlTextReaderPtr) reader; 271 272/** 273 * Method for reading the value of an element. 274 * 275 * @param reader The reader pointing to the element containing a value. 276 * @return Whether the value was read. 277 */ 278- (BOOL) readJAXBValue: (xmlTextReaderPtr) reader; 279 280/** 281 * Method for reading a child element. If (and only if) the child 282 * element was handled, the element in the reader should be 283 * "consumed" and the reader will be pointing to the end element. 284 * 285 * @param reader The reader pointing to the child element. 286 * @return Whether the child element was read. 287 */ 288- (BOOL) readJAXBChildElement: (xmlTextReaderPtr) reader; 289 290/** 291 * Method for reading an unknown attribute. 292 * 293 * @param reader The reader pointing to the unknown attribute. 294 * @return Whether the attribute was read. 295 */ 296- (void) readUnknownJAXBAttribute: (xmlTextReaderPtr) reader; 297 298/** 299 * Method for reading an unknown child element. Implementations 300 * must be responsible for "consuming" the child element. 301 * 302 * @param reader The reader pointing to the unknown child element. 303 * @return The status of the reader after having consumed the unknown child element. 304 */ 305- (int) readUnknownJAXBChildElement: (xmlTextReaderPtr) reader; 306 307@end /*protocol JAXBReading*/ 308 309/** 310 * Protocol defining methods for events that occur 311 * when writing XML. Intended for internal 312 * use only. 313 */ 314@protocol JAXBWriting 315 316/** 317 * Method for writing the attributes. 318 * 319 * @param writer The writer. 320 */ 321- (void) writeJAXBAttributes: (xmlTextWriterPtr) writer; 322 323/** 324 * Method for writing the element value. 325 * 326 * @param writer The writer. 327 */ 328- (void) writeJAXBValue: (xmlTextWriterPtr) writer; 329 330/** 331 * Method for writing the child elements. 332 * 333 * @param writer The writer. 334 */ 335- (void) writeJAXBChildElements: (xmlTextWriterPtr) writer; 336 337@end /*protocol JAXBWriting*/ 338 339/** 340 * Declaration of the JAXB type, element, events for a base object. 341 */ 342@interface NSObject (JAXB) <JAXBType, JAXBElement, JAXBReading, JAXBWriting> 343 344@end 345 346/** 347 * Implementation of the JAXB type, element, events for a base object. 348 */ 349@implementation NSObject (JAXB) 350 351/** 352 * Read the XML type from the reader; an instance of NSXMLElement. 353 * 354 * @param reader The reader. 355 * @return An instance of NSXMLElement 356 */ 357+ (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader 358{ 359 return [JAXBBasicXMLNode readXMLType: reader]; 360} 361 362/** 363 * Read an XML type from an XML reader into an existing instance. 364 * 365 * @param reader The reader. 366 * @param existing The existing instance into which to read values. 367 */ 368- (id) initWithReader: (xmlTextReaderPtr) reader 369{ 370 int status, depth; 371 if ((self = [self init])) { 372 if (xmlTextReaderHasAttributes(reader)) { 373 while (xmlTextReaderMoveToNextAttribute(reader)) { 374 if ([self readJAXBAttribute: reader] == NO) { 375 [self readUnknownJAXBAttribute: reader]; 376 } 377 } 378 379 status = xmlTextReaderMoveToElement(reader); 380 if (!status) { 381 //panic: unable to return to the element node. 382 [NSException raise: @"XMLReadError" 383 format: @"Error moving back to element position from attributes."]; 384 } 385 } 386 387 if ([self readJAXBValue: reader] == NO) { 388 //no value handled; attempt to process child elements 389 if (xmlTextReaderIsEmptyElement(reader) == 0) { 390 depth = xmlTextReaderDepth(reader);//track the depth. 391 status = xmlTextReaderAdvanceToNextStartOrEndElement(reader); 392 while (xmlTextReaderDepth(reader) > depth) { 393 if (status < 1) { 394 //panic: XML read error. 395 [NSException raise: @"XMLReadError" 396 format: @"Error handling a child element."]; 397 } 398 else if ([self readJAXBChildElement: reader]) { 399 status = xmlTextReaderAdvanceToNextStartOrEndElement(reader); 400 } 401 else { 402 status = [self readUnknownJAXBChildElement: reader]; 403 } 404 } 405 } 406 } 407 } 408 return self; 409} 410 411/** 412 * Write the XML type value of this object to the writer. 413 * 414 * @param writer The writer. 415 */ 416- (void) writeXMLType: (xmlTextWriterPtr) writer 417{ 418 [self writeJAXBAttributes: writer]; 419 [self writeJAXBValue: writer]; 420 [self writeJAXBChildElements: writer]; 421} 422 423/** 424 * Read the XML element from the reader; an instance of NSXMLElement. 425 * 426 * @param reader The reader. 427 * @return An instance of NSXMLElement 428 */ 429+ (id<JAXBElement>) readXMLElement: (xmlTextReaderPtr) reader 430{ 431 return (id<JAXBElement>) [JAXBBasicXMLNode readXMLType: reader]; 432} 433 434/** 435 * No op; root objects don't have an element name/namespace. Subclasses must override. 436 * 437 * @param writer The writer. 438 */ 439- (void) writeXMLElement: (xmlTextWriterPtr) writer 440{ 441 //no-op 442} 443 444/** 445 * No op; root objects don't have an element name/namespace. Subclasses must override. 446 * 447 * @param writer The writer. 448 * @param writeNs Ignored. 449 */ 450- (void) writeXMLElement: (xmlTextWriterPtr) writer writeNamespaces: (BOOL) writeNs 451{ 452 //no-op 453} 454 455/** 456 * No-op; base objects do not handle any attributes. 457 * 458 * @param reader The reader pointing to the attribute. 459 * @return NO 460 */ 461- (BOOL) readJAXBAttribute: (xmlTextReaderPtr) reader 462{ 463 return NO; 464} 465 466/** 467 * No-op; base objects do not handle any values. 468 * 469 * @param reader The reader pointing to the element containing a value. 470 * @return NO 471 */ 472- (BOOL) readJAXBValue: (xmlTextReaderPtr) reader 473{ 474 return NO; 475} 476 477/** 478 * No-op; base objects do not handle any child elements. 479 * 480 * @param reader The reader pointing to the child element. 481 * @return NO 482 */ 483- (BOOL) readJAXBChildElement: (xmlTextReaderPtr) reader 484{ 485 return NO; 486} 487 488/** 489 * No-op; base objects do not handle any attributes. 490 * 491 * @param reader The reader pointing to the unknown attribute. 492 */ 493- (void) readUnknownJAXBAttribute: (xmlTextReaderPtr) reader 494{ 495} 496 497/** 498 * Just skips the unknown element; base objects do not handle any child elements. 499 * 500 * @param reader The reader pointing to the unknown child element. 501 * @return The status of the reader after skipping the unknown child element. 502 */ 503- (int) readUnknownJAXBChildElement: (xmlTextReaderPtr) reader 504{ 505 return xmlTextReaderSkipElement(reader); 506} 507 508/** 509 * No-op; base objects have no attributes. 510 * 511 * @param writer The writer. 512 */ 513- (void) writeJAXBAttributes: (xmlTextWriterPtr) writer 514{ 515 //no-op. 516} 517 518/** 519 * No-op; base objects have no element value. 520 * 521 * @param writer The writer. 522 */ 523- (void) writeJAXBValue: (xmlTextWriterPtr) writer 524{ 525 //no-op. 526} 527 528/** 529 * No-op; base objects have no child elements. 530 * 531 * @param writer The writer. 532 */ 533- (void) writeJAXBChildElements: (xmlTextWriterPtr) writer 534{ 535 //no-op. 536} 537 538@end /*NSObject (JAXB)*/ 539 540/** 541 * Implementation of the JAXB type, element for an xml element. 542 */ 543@implementation JAXBBasicXMLNode 544 545/** 546 * Accessor for the (local) name of the XML node. 547 * 548 * @return The (local) name of the XML node. 549 */ 550- (NSString *) name 551{ 552 return _name; 553} 554 555/** 556 * Accessor for the (local) name of the XML node. 557 * 558 * @param newName The (local) name of the XML node. 559 */ 560- (void) setName: (NSString *) newName 561{ 562 [newName retain]; 563 [_name release]; 564 _name = newName; 565} 566 567/** 568 * Accessor for the namespace of the XML node. 569 * 570 * @return The namespace of the XML node. 571 */ 572- (NSString *) ns 573{ 574 return _ns; 575} 576 577/** 578 * Accessor for the namespace of the XML node. 579 * 580 * @param newNs The namespace of the XML node. 581 */ 582- (void) setNs: (NSString *) newNs 583{ 584 [newNs retain]; 585 [_ns release]; 586 _ns = newNs; 587} 588 589/** 590 * Accessor for the namespace prefix of the XML node. 591 * 592 * @return The namespace prefix of the XML node. 593 */ 594- (NSString *) prefix 595{ 596 return _prefix; 597} 598 599/** 600 * Accessor for the namespace prefix of the XML node. 601 * 602 * @param newPrefix The namespace prefix of the XML node. 603 */ 604- (void) setPrefix: (NSString *) newPrefix 605{ 606 [newPrefix retain]; 607 [_prefix release]; 608 _prefix = newPrefix; 609} 610 611/** 612 * Accessor for the value of the XML node. 613 * 614 * @return The value of the XML node. 615 */ 616- (NSString *) value 617{ 618 return _value; 619} 620 621/** 622 * Accessor for the value of the XML node. 623 * 624 * @param newValue The value of the XML node. 625 */ 626- (void) setValue: (NSString *) newValue 627{ 628 [newValue retain]; 629 [_value release]; 630 _value = newValue; 631} 632 633/** 634 * Accessor for the child elements of the XML node. 635 * 636 * @return The child elements of the XML node. 637 */ 638- (NSArray *) childElements 639{ 640 return _childElements; 641} 642 643/** 644 * Accessor for the child elements of the XML node. 645 * 646 * @param newValue The child elements of the XML node. 647 */ 648- (void) setChildElements: (NSArray *) newChildElements 649{ 650 [newChildElements retain]; 651 [_childElements release]; 652 _childElements = newChildElements; 653} 654 655/** 656 * Accessor for the attributes of the XML node. 657 * 658 * @return The attributes of the XML node. 659 */ 660- (NSArray *) attributes 661{ 662 return _attributes; 663} 664 665/** 666 * Accessor for the attributes of the XML node. 667 * 668 * @param newAttributes The attributes of the XML node. 669 */ 670- (void) setAttributes: (NSArray *) newAttributes 671{ 672 [newAttributes retain]; 673 [_attributes release]; 674 _attributes = newAttributes; 675} 676 677- (void) dealloc { 678 [self setName: nil]; 679 [self setNs: nil]; 680 [self setPrefix: nil]; 681 [self setValue: nil]; 682 [self setChildElements: nil]; 683 [self setAttributes: nil]; 684 [super dealloc]; 685} 686@end /*implementation JAXBBasicXMLNode*/ 687 688/** 689 * Internal, private interface for JAXB reading and writing. 690 */ 691@interface JAXBBasicXMLNode (JAXB) <JAXBType, JAXBElement> 692 693@end /*interface JAXBBasicXMLNode (JAXB)*/ 694 695@implementation JAXBBasicXMLNode (JAXB) 696 697/** 698 * Read the XML type from the reader; an instance of JAXBBasicXMLNode. 699 * 700 * @param reader The reader. 701 * @return An instance of JAXBBasicXMLNode 702 */ 703+ (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader 704{ 705 JAXBBasicXMLNode *node = [[JAXBBasicXMLNode alloc] init]; 706 NS_DURING 707 { 708 [node initWithReader: reader]; 709 } 710 NS_HANDLER 711 { 712 [node dealloc]; 713 node = nil; 714 [localException raise]; 715 } 716 NS_ENDHANDLER 717 718 [node autorelease]; 719 return node; 720} 721 722/** 723 * Read an XML type from an XML reader into an existing instance of JAXBBasicXMLNode. 724 * 725 * @param reader The reader. 726 * @param existing The existing instance into which to read values. 727 */ 728- (id) initWithReader: (xmlTextReaderPtr) reader 729{ 730 int status, depth; 731 JAXBBasicXMLNode *child; 732 xmlChar *value = NULL; 733 const xmlChar *text; 734 NSMutableArray *children; 735 736 if ((self = [self init])) { 737 depth = xmlTextReaderDepth(reader); 738 [self setName: [NSString stringWithUTF8String: (const char *) xmlTextReaderLocalName(reader)]]; 739 [self setNs: [NSString stringWithUTF8String: (const char *) xmlTextReaderNamespaceUri(reader)]]; 740 [self setPrefix: [NSString stringWithUTF8String: (const char *)xmlTextReaderPrefix(reader)]]; 741 742 if (xmlTextReaderHasAttributes(reader)) { 743 child = nil; 744 children = [[NSMutableArray alloc] init]; 745 while (xmlTextReaderMoveToNextAttribute(reader)) { 746 child = [[JAXBBasicXMLNode alloc] init]; 747 [child setName: [NSString stringWithUTF8String: (const char *) xmlTextReaderLocalName(reader)]]; 748 [child setNs: [NSString stringWithUTF8String: (const char *)xmlTextReaderNamespaceUri(reader)]]; 749 [child setPrefix: [NSString stringWithUTF8String: (const char *) xmlTextReaderPrefix(reader)]]; 750 [child setValue: [NSString stringWithUTF8String: (const char *) xmlTextReaderValue(reader)]]; 751 [children addObject: child]; 752 } 753 [self setAttributes: children]; 754 755 status = xmlTextReaderMoveToElement(reader); 756 if (status < 1) { 757 //panic: unable to return to the element node. 758 [NSException raise: @"XMLReadError" 759 format: @"Error moving to element from attributes."]; 760 } 761 } 762 763 if (xmlTextReaderIsEmptyElement(reader) == 0) { 764 children = [[NSMutableArray alloc] init]; 765 status = xmlTextReaderRead(reader); 766 while (status == 1 && xmlTextReaderDepth(reader) > depth) { 767 switch (xmlTextReaderNodeType(reader)) { 768 case XML_READER_TYPE_ELEMENT: 769 child = (JAXBBasicXMLNode *) [JAXBBasicXMLNode readXMLType: reader]; 770 [children addObject: child]; 771 break; 772 case XML_READER_TYPE_TEXT: 773 case XML_READER_TYPE_CDATA: 774 text = xmlTextReaderConstValue(reader); 775 value = xmlStrncat(value, text, xmlStrlen(text)); 776 break; 777 default: 778 //skip anything else. 779 break; 780 } 781 782 status = xmlTextReaderRead(reader); 783 } 784 785 if (status < 1) { 786 //panic: xml read error 787 [NSException raise: @"XMLReadError" 788 format: @"Error reading child elements."]; 789 } 790 791 if ([children count] > 0) { 792 [self setChildElements: children]; 793 } 794 795 if (value != NULL) { 796 [self setValue: [NSString stringWithUTF8String: (const char *) value]]; 797 } 798 799 } 800 } 801 802 return self; 803} 804 805/** 806 * Read the XML element from the reader; an instance of NSXMLElement. 807 * 808 * @param reader The reader. 809 * @return An instance of NSXMLElement 810 */ 811+ (id<JAXBElement>) readXMLElement: (xmlTextReaderPtr) reader 812{ 813 return (id<JAXBElement>) [JAXBBasicXMLNode readXMLType: reader]; 814} 815 816/** 817 * Write the basic node to an xml writer. 818 * 819 * @param writer The writer. 820 */ 821- (void) writeXMLType: (xmlTextWriterPtr) writer 822{ 823 int status; 824 NSEnumerator *enumerator; 825 JAXBBasicXMLNode *child; 826 xmlChar *childns, *childname, *childprefix, *childvalue; 827 828 status = xmlTextWriterStartElementNS(writer, _prefix ? BAD_CAST [_prefix UTF8String] : NULL, _name ? BAD_CAST [_name UTF8String] : NULL, _ns ? BAD_CAST [_ns UTF8String] : NULL); 829 if (status < 0) { 830 childns = BAD_CAST ""; 831 if (_ns) { 832 childns = BAD_CAST [_ns UTF8String]; 833 } 834 835 childname = BAD_CAST ""; 836 if (_name) { 837 childname = BAD_CAST [_name UTF8String]; 838 } 839 840 [NSException raise: @"XMLWriteError" 841 format: @"Error writing start element {%s}%s for JAXBBasicXMLNode.", childns, childname]; 842 } 843 844 if (_attributes) { 845 enumerator = [_attributes objectEnumerator]; 846 while ( (child = (JAXBBasicXMLNode *)[enumerator nextObject]) ) { 847 childns = NULL; 848 if ([child ns]) { 849 childns = BAD_CAST [[child ns] UTF8String]; 850 } 851 852 childprefix = NULL; 853 if ([child prefix]) { 854 childprefix = BAD_CAST [[child prefix] UTF8String]; 855 } 856 857 childname = NULL; 858 if ([child name]) { 859 childname = BAD_CAST [[child name] UTF8String]; 860 } 861 862 childvalue = NULL; 863 if ([child value]) { 864 childvalue = BAD_CAST [[child value] UTF8String]; 865 } 866 867 status = xmlTextWriterWriteAttributeNS(writer, childprefix, childname, childns, childvalue); 868 if (status < 0) { 869 [NSException raise: @"XMLWriteError" 870 format: @"Error writing attribute {%s}%s for JAXBBasicXMLNode.", childns, childname]; 871 } 872 } 873 } 874 875 if (_value) { 876 status = xmlTextWriterWriteString(writer, BAD_CAST [_value UTF8String]); 877 if (status < 0) { 878 [NSException raise: @"XMLWriteError" 879 format: @"Error writing value of JAXBBasicXMLNode."]; 880 } 881 } 882 883 if (_childElements) { 884 enumerator = [_childElements objectEnumerator]; 885 while ( (child = [enumerator nextObject]) ) { 886 [child writeXMLType: writer]; 887 } 888 } 889 890 status = xmlTextWriterEndElement(writer); 891 if (status < 0) { 892 childns = BAD_CAST ""; 893 if (_ns) { 894 childns = BAD_CAST [_ns UTF8String]; 895 } 896 897 childname = BAD_CAST ""; 898 if (_name) { 899 childname = BAD_CAST [_name UTF8String]; 900 } 901 902 [NSException raise: @"XMLWriteError" 903 format: @"Error writing end element {%s}%s for JAXBBasicXMLNode.", childns, childname]; 904 } 905} 906 907/** 908 * Writes this node to a writer. 909 * 910 * @param writer The writer. 911 */ 912- (void) writeXMLElement: (xmlTextWriterPtr) writer 913{ 914 [self writeXMLType: writer]; 915} 916 917/** 918 * Writes this node to a writer. 919 * 920 * @param writer The writer. 921 * @param writeNs Whether to write the namespaces for this element to the xml writer. 922 */ 923- (void) writeXMLElement: (xmlTextWriterPtr) writer writeNamespaces: (BOOL) writeNs 924{ 925 [self writeXMLType: writer]; 926} 927 928@end /* implementation JAXBBasicXMLNode (JAXB) */ 929 930/** 931 * Declaration of the JAXB type for a string. 932 */ 933@interface NSString (JAXBType) <JAXBType> 934@end 935 936/** 937 * Implementation of the JAXB type for a string. 938 */ 939@implementation NSString (JAXBType) 940 941/** 942 * Read the XML type from the reader. 943 * 944 * @param reader The reader. 945 * @return The NSString that was read from the reader. 946 */ 947+ (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader 948{ 949 return [NSString stringWithUTF8String: (const char *) xmlTextReaderReadEntireNodeValue(reader)]; 950} 951 952/** 953 * Read an XML type from an XML reader into an existing instance. 954 * 955 * @param reader The reader. 956 * @param existing The existing instance into which to read values. 957 */ 958- (id) initWithReader: (xmlTextReaderPtr) reader 959{ 960 [NSException raise: @"XMLReadError" 961 format: @"An existing string cannot be modified."]; 962 return nil; 963} 964 965/** 966 * Write the NSString to the writer. 967 * 968 * @param writer The writer. 969 */ 970- (void) writeXMLType: (xmlTextWriterPtr) writer 971{ 972 xmlTextWriterWriteString(writer, BAD_CAST [self UTF8String]); 973} 974 975@end /*NSString (JAXBType)*/ 976 977 978 979/** 980 * Declaration of the JAXB type for a big number. 981 */ 982@interface NSNumber (JAXBType) <JAXBType> 983@end 984 985/** 986 * Implementation of the JAXB type for a big number. 987 */ 988@implementation NSNumber (JAXBType) 989 990/** 991 * Read the XML type from the reader. 992 * 993 * @param reader The reader. 994 * @return The NSNumber that was read from the reader. 995 */ 996+ (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader 997{ 998 return [NSNumber numberWithLongLong: [[NSString stringWithUTF8String: (const char *) xmlTextReaderReadEntireNodeValue(reader)] longLongValue]]; 999} 1000 1001/** 1002 * Read an XML type from an XML reader into an existing instance. 1003 * 1004 * @param reader The reader. 1005 * @param existing The existing instance into which to read values. 1006 */ 1007- (id) initWithReader: (xmlTextReaderPtr) reader 1008{ 1009 [NSException raise: @"XMLReadError" 1010 format: @"An existing number cannot be modified."]; 1011 return nil; 1012} 1013 1014/** 1015 * Write the NSNumber to the writer. 1016 * 1017 * @param writer The writer. 1018 */ 1019- (void) writeXMLType: (xmlTextWriterPtr) writer 1020{ 1021 xmlTextWriterWriteString(writer, BAD_CAST [[self description] UTF8String]); 1022} 1023 1024@end /*NSNumber (JAXBType)*/ 1025 1026 1027 1028/** 1029 * Declaration of the JAXB type for a big number. 1030 */ 1031@interface NSDecimalNumber (JAXBType) <JAXBType> 1032@end 1033 1034/** 1035 * Implementation of the JAXB type for a big number. 1036 */ 1037@implementation NSDecimalNumber (JAXBType) 1038 1039/** 1040 * Read the XML type from the reader. 1041 * 1042 * @param reader The reader. 1043 * @return The NSDecimalNumber that was read from the reader. 1044 */ 1045+ (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader 1046{ 1047 return [NSDecimalNumber decimalNumberWithString: [NSString stringWithUTF8String: (const char *) xmlTextReaderReadEntireNodeValue(reader)]]; 1048} 1049 1050/** 1051 * Read an XML type from an XML reader into an existing instance. 1052 * 1053 * @param reader The reader. 1054 * @param existing The existing instance into which to read values. 1055 */ 1056- (id) initWithReader: (xmlTextReaderPtr) reader 1057{ 1058 [NSException raise: @"XMLReadError" 1059 format: @"An existing decimal number cannot be modified."]; 1060 return nil; 1061} 1062 1063/** 1064 * Write the NSDecimalNumber to the writer. 1065 * 1066 * @param writer The writer. 1067 */ 1068- (void) writeXMLType: (xmlTextWriterPtr) writer 1069{ 1070 xmlTextWriterWriteString(writer, BAD_CAST [[self description] UTF8String]); 1071} 1072 1073@end /*NSDecimalNumber (JAXBType)*/ 1074 1075 1076 1077/** 1078 * Declaration of the JAXB type for a url. 1079 */ 1080@interface NSURL (JAXBType) <JAXBType> 1081@end 1082 1083/** 1084 * Implementation of the JAXB type for a url. 1085 */ 1086@implementation NSURL (JAXBType) 1087 1088/** 1089 * Read the XML type from the reader. 1090 * 1091 * @param reader The reader. 1092 * @return The NSURL that was read from the reader. 1093 */ 1094+ (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader 1095{ 1096 return [NSURL URLWithString: [NSString stringWithUTF8String: (const char *) xmlTextReaderReadEntireNodeValue(reader)]]; 1097} 1098 1099/** 1100 * Read an XML type from an XML reader into an existing instance. 1101 * 1102 * @param reader The reader. 1103 * @param existing The existing instance into which to read values. 1104 */ 1105- (id) initWithReader: (xmlTextReaderPtr) reader 1106{ 1107 [NSException raise: @"XMLReadError" 1108 format: @"An existing url cannot be modified."]; 1109 return nil; 1110} 1111 1112/** 1113 * Write the NSURL to the writer. 1114 * 1115 * @param writer The writer. 1116 */ 1117- (void) writeXMLType: (xmlTextWriterPtr) writer 1118{ 1119 xmlTextWriterWriteString(writer, BAD_CAST [[self absoluteString] UTF8String]); 1120} 1121 1122@end /*NSURL (JAXBType)*/ 1123 1124 1125 1126/** 1127 * Declaration of the JAXB type for binary data. 1128 */ 1129@interface NSData (JAXBType) <JAXBType> 1130@end 1131 1132/** 1133 * Implementation of the JAXB type for a binary data. 1134 */ 1135@implementation NSData (JAXBType) 1136 1137/** 1138 * Read the XML type from the reader. 1139 * 1140 * @param reader The reader. 1141 * @return The NSData that was read from the reader. 1142 */ 1143+ (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader 1144{ 1145 xmlChar *base64data = xmlTextReaderReadEntireNodeValue(reader); 1146 int len; 1147 unsigned char *data = _decode_base64(base64data, &len); 1148 NSData *wrappedData = [NSData dataWithBytesNoCopy: data length: len]; 1149 free(base64data); 1150 return wrappedData; 1151} 1152 1153/** 1154 * Read an XML type from an XML reader into an existing instance. 1155 * 1156 * @param reader The reader. 1157 * @param existing The existing instance into which to read values. 1158 */ 1159- (id) initWithReader: (xmlTextReaderPtr) reader 1160{ 1161 [NSException raise: @"XMLReadError" 1162 format: @"An existing NSData cannot be modified."]; 1163 return nil; 1164} 1165 1166/** 1167 * Write the NSData to the writer. 1168 * 1169 * @param writer The writer. 1170 */ 1171- (void) writeXMLType: (xmlTextWriterPtr) writer 1172{ 1173 xmlChar *out = _encode_base64((unsigned char *)[self bytes], [self length]); 1174 xmlTextWriterWriteString(writer, out); 1175 free(out); 1176} 1177 1178@end /*NSData (JAXBType)*/ 1179 1180 1181 1182/** 1183 * Declaration of the JAXB type for a big number. 1184 */ 1185@interface NSDate (JAXBType) <JAXBType> 1186@end 1187 1188/** 1189 * Implementation of the JAXB type for a big number. 1190 */ 1191@implementation NSDate (JAXBType) 1192 1193/** 1194 * Read the XML type from the reader. 1195 * 1196 * @param reader The reader. 1197 * @return The NSDate that was read from the reader. 1198 */ 1199+ (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader 1200{ 1201 return [NSCalendarDate readXMLType: reader]; 1202} 1203 1204/** 1205 * Read an XML type from an XML reader into an existing instance. 1206 * 1207 * @param reader The reader. 1208 * @param existing The existing instance into which to read values. 1209 */ 1210- (id) initWithReader: (xmlTextReaderPtr) reader 1211{ 1212 [NSException raise: @"XMLReadError" 1213 format: @"An existing date cannot be modified."]; 1214 return nil; 1215} 1216 1217/** 1218 * Write the NSDate to the writer. 1219 * 1220 * @param writer The writer. 1221 */ 1222- (void) writeXMLType: (xmlTextWriterPtr) writer 1223{ 1224 NSDateFormatter *formatter = [[NSDateFormatter alloc] initWithDateFormat: @"%Y-%m-%dT%H:%M:%S %z" allowNaturalLanguage: NO]; 1225 xmlChar *timevalue = BAD_CAST [[formatter stringForObjectValue: self] UTF8String]; 1226 timevalue[19] = timevalue[20]; 1227 timevalue[20] = timevalue[21]; 1228 timevalue[21] = timevalue[22]; 1229 timevalue[22] = ':'; 1230 xmlTextWriterWriteString(writer, timevalue); 1231 [formatter release]; 1232} 1233@end /*NSDate (JAXBType)*/ 1234 1235 1236 1237/** 1238 * Declaration of the JAXB type for a big number. 1239 */ 1240@interface NSCalendarDate (JAXBType) <JAXBType> 1241@end 1242 1243/** 1244 * Implementation of the JAXB type for a big number. 1245 */ 1246@implementation NSCalendarDate (JAXBType) 1247 1248/** 1249 * Read the XML type from the reader. 1250 * 1251 * @param reader The reader. 1252 * @return The NSCalendarDate that was read from the reader. 1253 */ 1254+ (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader 1255{ 1256 xmlChar *timevalue = xmlTextReaderReadEntireNodeValue(reader); 1257 NSInteger year = 0; 1258 NSUInteger month = 1, day = 1, hour = 0, minute = 0, second = 0; 1259 NSTimeZone *tz = nil; 1260 BOOL skip_time = NO; 1261 int index = 0, token_index = 0, len = xmlStrlen(timevalue), offset_seconds = 0; 1262 char token[len]; 1263 1264 if (len > (index + 5) && timevalue[index + 4] == '-') { 1265 //assume we're at yyyy-MM-dd 1266 token_index = 0; 1267 while (index < len && timevalue[index] != '-') { 1268 token[token_index++] = timevalue[index++]; 1269 } 1270 token[token_index] = '\0'; 1271 if (token_index != 4) { 1272 [NSException raise: @"XMLReadError" 1273 format: @"Unable to read dateTime %s; invalid year: %s", timevalue, token]; 1274 } 1275 year = atoi(token); 1276 index++; 1277 1278 //go to next '-' character. 1279 token_index = 0; 1280 while (index < len && timevalue[index] != '-') { 1281 token[token_index++] = timevalue[index++]; 1282 } 1283 token[token_index] = '\0'; 1284 if (token_index != 2) { 1285 [NSException raise: @"XMLReadError" 1286 format: @"Unable to read dateTime %s; invalid month: %s", timevalue, token]; 1287 } 1288 month = atoi(token); 1289 index++; 1290 1291 //go to 'T', 'Z', '+', or '-' character. 1292 token_index = 0; 1293 while (index < len && timevalue[index] != 'T' && timevalue[index] != 'Z' && timevalue[index] != '-' && timevalue[index] != '+') { 1294 token[token_index++] = timevalue[index++]; 1295 } 1296 token[token_index] = '\0'; 1297 if (token_index != 2) { 1298 [NSException raise: @"XMLReadError" 1299 format: @"Unable to read dateTime %s; invalid day of month: %s", timevalue, token]; 1300 } 1301 day = atoi(token); 1302 if (timevalue[index] != 'T') { 1303 skip_time = YES; 1304 } 1305 if (timevalue[index] != '-') { 1306 index++; 1307 } 1308 } 1309 1310 if (skip_time == NO || (len > (index + 3) && timevalue[index + 2] == ':')) { 1311 //assume we're at HH:mm:ss 1312 1313 //go to ':' character. 1314 token_index = 0; 1315 while (index < len && timevalue[index] != ':') { 1316 token[token_index++] = timevalue[index++]; 1317 } 1318 token[token_index] = '\0'; 1319 if (token_index != 2) { 1320 [NSException raise: @"XMLReadError" 1321 format: @"Unable to read dateTime %s; invalid hour: %s", timevalue, token]; 1322 } 1323 hour = atoi(token); 1324 index++; 1325 1326 //go to ':' character. 1327 token_index = 0; 1328 while (index < len && timevalue[index] != ':') { 1329 token[token_index++] = timevalue[index++]; 1330 } 1331 token[token_index] = '\0'; 1332 if (token_index != 2) { 1333 [NSException raise: @"XMLReadError" 1334 format: @"Unable to read dateTime %s; invalid minute: %s", timevalue, token]; 1335 } 1336 minute = atoi(token); 1337 index++; 1338 1339 //go to '+' or '-' or 'Z' character. 1340 token_index = 0; 1341 while (index < len && timevalue[index] != '+' && timevalue[index] != '-' && timevalue[index] != 'Z') { 1342 token[token_index++] = timevalue[index++]; 1343 } 1344 token[token_index] = '\0'; 1345 if (token_index == 0) { 1346 [NSException raise: @"XMLReadError" 1347 format: @"Unable to read dateTime %s; invalid seconds: %s", timevalue, token]; 1348 } 1349 second = (NSUInteger) atof(token); 1350 if (timevalue[index] != '-') { 1351 index++; 1352 } 1353 } 1354 1355 //go to ':' character. 1356 token_index = 0; 1357 while (index < len && timevalue[index] != ':') { 1358 token[token_index++] = timevalue[index++]; 1359 } 1360 token[token_index] = '\0'; 1361 offset_seconds += atoi(token) * 60 * 60; 1362 index++; 1363 1364 //go to end. 1365 token_index = 0; 1366 while (index < len) { 1367 token[token_index++] = timevalue[index++]; 1368 } 1369 token[token_index] = '\0'; 1370 offset_seconds += atoi(token) * 60; 1371 1372 tz = [NSTimeZone timeZoneForSecondsFromGMT: offset_seconds]; 1373 free(timevalue); 1374 return [NSCalendarDate dateWithYear: year month: month day: day hour: hour minute: minute second: second timeZone: tz]; 1375} 1376 1377/** 1378 * Read an XML type from an XML reader into an existing instance. 1379 * 1380 * @param reader The reader. 1381 * @param existing The existing instance into which to read values. 1382 */ 1383- (id) initWithReader: (xmlTextReaderPtr) reader 1384{ 1385 [NSException raise: @"XMLReadError" 1386 format: @"An existing date cannot be modified."]; 1387 return nil; 1388} 1389 1390/** 1391 * Write the NSDate to the writer. 1392 * 1393 * @param writer The writer. 1394 */ 1395- (void) writeXMLType: (xmlTextWriterPtr) writer 1396{ 1397 [super writeXMLType: writer]; 1398} 1399 1400@end /*NSCalendarDate (JAXBType)*/ 1401#endif /* ENUNCIATE_OBJC_CLASSES */ 1402 1403#ifndef ENUNCIATE_XML_OBJC_PRIMITIVE_FUNCTIONS 1404#define ENUNCIATE_XML_OBJC_PRIMITIVE_FUNCTIONS 1405 1406/*******************boolean************************************/ 1407 1408/** 1409 * Read a boolean value from the reader. 1410 * 1411 * @param reader The reader (pointing at a node with a value). 1412 * @return YES if "true" was read. NO otherwise. 1413 */ 1414static BOOL *xmlTextReaderReadBooleanType(xmlTextReaderPtr reader) { 1415 xmlChar *nodeValue = xmlTextReaderReadEntireNodeValue(reader); 1416 BOOL *value = malloc(sizeof(BOOL)); 1417 *value = (xmlStrcmp(BAD_CAST "true", nodeValue) == 0) ? YES : NO; 1418 free(nodeValue); 1419 return value; 1420} 1421 1422/** 1423 * Write a boolean value to the writer. 1424 * 1425 * @param writer The writer. 1426 * @param value The value to be written. 1427 * @return the bytes written (may be 0 because of buffering) or -1 in case of error. 1428 */ 1429static int xmlTextWriterWriteBooleanType(xmlTextWriterPtr writer, BOOL *value) { 1430 if (*value) { 1431 return xmlTextWriterWriteString(writer, BAD_CAST "false"); 1432 } 1433 else { 1434 return xmlTextWriterWriteString(writer, BAD_CAST "true"); 1435 } 1436} 1437 1438/*******************byte************************************/ 1439 1440/** 1441 * Read a byte value from the reader. 1442 * 1443 * @param reader The reader (pointing at a node with a value). 1444 * @return the byte. 1445 */ 1446static unsigned char *xmlTextReaderReadByteType(xmlTextReaderPtr reader) { 1447 xmlChar *nodeValue = xmlTextReaderReadEntireNodeValue(reader); 1448 unsigned char *value = malloc(sizeof(unsigned char)); 1449 *value = (unsigned char) atoi((char *) nodeValue); 1450 free(nodeValue); 1451 return value; 1452} 1453 1454/** 1455 * Write a byte value to the writer. 1456 * 1457 * @param writer The writer. 1458 * @param value The value to be written. 1459 * @return the bytes written (may be 0 because of buffering) or -1 in case of error. 1460 */ 1461static int xmlTextWriterWriteByteType(xmlTextWriterPtr writer, unsigned char *value) { 1462 return xmlTextWriterWriteFormatString(writer, "%i", *value); 1463} 1464 1465/*******************double************************************/ 1466 1467/** 1468 * Read a double value from the reader. 1469 * 1470 * @param reader The reader (pointing at a node with a value). 1471 * @return the double. 1472 */ 1473static double *xmlTextReaderReadDoubleType(xmlTextReaderPtr reader) { 1474 xmlChar *nodeValue = xmlTextReaderReadEntireNodeValue(reader); 1475 double *value = malloc(sizeof(double)); 1476 *value = atof((char *) nodeValue); 1477 free(nodeValue); 1478 return value; 1479} 1480 1481/** 1482 * Write a double value to the writer. 1483 * 1484 * @param writer The writer. 1485 * @param value The value to be written. 1486 * @return the bytes written (may be 0 because of buffering) or -1 in case of error. 1487 */ 1488static int xmlTextWriterWriteDoubleType(xmlTextWriterPtr writer, double *value) { 1489 return xmlTextWriterWriteFormatString(writer, "%f", *value); 1490} 1491 1492/*******************float************************************/ 1493 1494/** 1495 * Read a float value from the reader. 1496 * 1497 * @param reader The reader (pointing at a node with a value). 1498 * @return the float. 1499 */ 1500static float *xmlTextReaderReadFloatType(xmlTextReaderPtr reader) { 1501 xmlChar *nodeValue = xmlTextReaderReadEntireNodeValue(reader); 1502 float *value = malloc(sizeof(float)); 1503 *value = atof((char *)nodeValue); 1504 free(nodeValue); 1505 return value; 1506} 1507 1508/** 1509 * Write a float value to the writer. 1510 * 1511 * @param writer The writer. 1512 * @param value The value to be written. 1513 * @return the bytes written (may be 0 because of buffering) or -1 in case of error. 1514 */ 1515static int xmlTextWriterWriteFloatType(xmlTextWriterPtr writer, float *value) { 1516 return xmlTextWriterWriteFormatString(writer, "%f", *value); 1517} 1518 1519/*******************int************************************/ 1520 1521/** 1522 * Read a int value from the reader. 1523 * 1524 * @param reader The reader (pointing at a node with a value). 1525 * @param value The value to be written. 1526 * @return the int. 1527 */ 1528static int *xmlTextReaderReadIntType(xmlTextReaderPtr reader) { 1529 xmlChar *nodeValue = xmlTextReaderReadEntireNodeValue(reader); 1530 int *value = malloc(sizeof(int)); 1531 *value = atoi((char *)nodeValue); 1532 free(nodeValue); 1533 return value; 1534} 1535 1536/** 1537 * Write a int value to the writer. 1538 * 1539 * @param writer The writer. 1540 * @param value The value to be written. 1541 * @return the bytes written (may be 0 because of buffering) or -1 in case of error. 1542 */ 1543static int xmlTextWriterWriteIntType(xmlTextWriterPtr writer, int *value) { 1544 return xmlTextWriterWriteFormatString(writer, "%i", *value); 1545} 1546 1547/*******************long************************************/ 1548 1549/** 1550 * Read a long value from the reader. 1551 * 1552 * @param reader The reader (pointing at a node with a value). 1553 * @return the long. 1554 */ 1555static long *xmlTextReaderReadLongType(xmlTextReaderPtr reader) { 1556 xmlChar *nodeValue = xmlTextReaderReadEntireNodeValue(reader); 1557 long *value = malloc(sizeof(long)); 1558 *value = atol((char *)nodeValue); 1559 free(nodeValue); 1560 return value; 1561} 1562 1563/** 1564 * Write a long value to the writer. 1565 * 1566 * @param writer The writer. 1567 * @param value The value to be written. 1568 * @return the bytes written (may be 0 because of buffering) or -1 in case of error. 1569 */ 1570static int xmlTextWriterWriteLongType(xmlTextWriterPtr writer, long *value) { 1571 return xmlTextWriterWriteFormatString(writer, "%ld", *value); 1572} 1573 1574/*******************short************************************/ 1575 1576/** 1577 * Read a short value from the reader. 1578 * 1579 * @param reader The reader (pointing at a node with a value). 1580 * @return the short. 1581 */ 1582static short *xmlTextReaderReadShortType(xmlTextReaderPtr reader) { 1583 xmlChar *nodeValue = xmlTextReaderReadEntireNodeValue(reader); 1584 short *value = malloc(sizeof(short)); 1585 *value = atoi((char *)nodeValue); 1586 free(nodeValue); 1587 return value; 1588} 1589 1590/** 1591 * Write a short value to the writer. 1592 * 1593 * @param writer The writer. 1594 * @param value The value to be written. 1595 * @return the bytes written (may be 0 because of buffering) or -1 in case of error. 1596 */ 1597static int xmlTextWriterWriteShortType(xmlTextWriterPtr writer, short *value) { 1598 return xmlTextWriterWriteFormatString(writer, "%h", *value); 1599} 1600 1601/*******************char************************************/ 1602 1603/** 1604 * Read a character value from the reader. 1605 * 1606 * @param reader The reader (pointing at a node with a value). 1607 * @return the character. 1608 */ 1609static xmlChar *xmlTextReaderReadCharacterType(xmlTextReaderPtr reader) { 1610 return xmlTextReaderReadEntireNodeValue(reader); 1611} 1612 1613/** 1614 * Write a character value to the writer. 1615 * 1616 * @param writer The writer. 1617 * @param value The value to be written. 1618 * @return the bytes written (may be 0 because of buffering) or -1 in case of error. 1619 */ 1620static int xmlTextWriterWriteCharacterType(xmlTextWriterPtr writer, xmlChar *value) { 1621 return xmlTextWriterWriteString(writer, value); 1622} 1623 1624#endif /* ENUNCIATE_XML_OBJC_PRIMITIVE_FUNCTIONS */ 1625 1626 1627/** 1628 * An assertion value. 1629 1630 @author Rob Lyon 1631 1632 */ 1633@implementation FSFAMILYTREEV2AssertionValue 1634 1635/** 1636 * the id of the value. 1637 */ 1638- (NSString *) id 1639{ 1640 return _id; 1641} 1642 1643/** 1644 * the id of the value. 1645 */ 1646- (void) setId: (NSString *) newId 1647{ 1648 [newId retain]; 1649 [_id release]; 1650 _id = newId; 1651} 1652 1653/** 1654 * The title of the type in the case of user-defined characteristics. 1655 */ 1656- (NSString *) title 1657{ 1658 return _title; 1659} 1660 1661/** 1662 * The title of the type in the case of user-defined characteristics. 1663 */ 1664- (void) setTitle: (NSString *) newTitle 1665{ 1666 [newTitle retain]; 1667 [_title release]; 1668 _title = newTitle; 1669} 1670 1671- (void) dealloc 1672{ 1673 [self setId: nil]; 1674 [self setTitle: nil]; 1675 [super dealloc]; 1676} 1677@end /* implementation FSFAMILYTREEV2AssertionValue */ 1678 1679/** 1680 * Internal, private interface for JAXB reading and writing. 1681 */ 1682@interface FSFAMILYTREEV2AssertionValue (JAXB) <JAXBReading, JAXBWriting, JAXBType> 1683 1684@end /*interface FSFAMILYTREEV2AssertionValue (JAXB)*/ 1685 1686/** 1687 * Internal, private implementation for JAXB reading and writing. 1688 */ 1689@implementation FSFAMILYTREEV2AssertionValue (JAXB) 1690 1691/** 1692 * Read an instance of FSFAMILYTREEV2AssertionValue from an XML reader. 1693 * 1694 * @param reader The reader. 1695 * @return An instance of FSFAMILYTREEV2AssertionValue defined by the XML reader. 1696 */ 1697+ (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader 1698{ 1699 FSFAMILYTREEV2AssertionValue *_fSFAMILYTREEV2AssertionValue = [[FSFAMILYTREEV2AssertionValue alloc] init]; 1700 NS_DURING 1701 { 1702 [_fSFAMILYTREEV2AssertionValue initWithReader: reader]; 1703 } 1704 NS_HANDLER 1705 { 1706 [_fSFAMILYTREEV2AssertionValue dealloc]; 1707 _fSFAMILYTREEV2AssertionValue = nil; 1708 [localException raise]; 1709 } 1710 NS_ENDHANDLER 1711 1712 [_fSFAMILYTREEV2AssertionValue autorelease]; 1713 return _fSFAMILYTREEV2AssertionValue; 1714} 1715 1716/** 1717 * Initialize this instance of FSFAMILYTREEV2AssertionValue according to 1718 * the XML being read from the reader. 1719 * 1720 * @param reader The reader. 1721 */ 1722- (id) initWithReader: (xmlTextReaderPtr) reader 1723{ 1724 return [super initWithReader: reader]; 1725} 1726 1727/** 1728 * Write the XML for this instance of FSFAMILYTREEV2AssertionValue to the writer. 1729 * Note that since we're only writing the XML type, 1730 * No start/end element will be written. 1731 * 1732 * @param reader The reader. 1733 */ 1734- (void) writeXMLType: (xmlTextWriterPtr) writer 1735{ 1736 [super writeXMLType:writer]; 1737} 1738 1739//documentation inherited. 1740- (BOOL) readJAXBAttribute: (xmlTextReaderPtr) reader 1741{ 1742 void *_child_accessor; 1743 1744 if ([super readJAXBAttribute: reader]) { 1745 return YES; 1746 } 1747 1748 if ((xmlStrcmp(BAD_CAST "id", xmlTextReaderConstLocalName(reader)) == 0) && (xmlTextReaderConstNamespaceUri(reader) == NULL)) { 1749#if DEBUG_ENUNCIATE > 1 1750 NSLog(@"Attempting to read attribute {}id..."); 1751#endif 1752 [self setId: (NSString*) [NSString readXMLType: reader]]; 1753#if DEBUG_ENUNCIATE > 1 1754 NSLog(@"successfully read attribute {}id..."); 1755#endif 1756 return YES; 1757 } 1758 1759 return NO; 1760} 1761 1762//documentation inherited. 1763- (BOOL) readJAXBValue: (xmlTextReaderPtr) reader 1764{ 1765 return [super readJAXBValue: reader]; 1766} 1767 1768//documentation inherited. 1769- (BOOL) readJAXBChildElement: (xmlTextReaderPtr) reader 1770{ 1771 id __child; 1772 void *_child_accessor; 1773 int status, depth; 1774 1775 if ([super readJAXBChildElement: reader]) { 1776 return YES; 1777 } 1778 if (xmlTextReaderNodeType(reader) == XML_READER_TYPE_ELEMENT 1779 && xmlStrcmp(BAD_CAST "title", xmlTextReaderConstLocalName(reader)) == 0 1780 && xmlStrcmp(BAD_CAST "http://api.familysearch.org/familytree/v2", xmlTextReaderConstNamespaceUri(reader)) == 0) { 1781 1782#if DEBUG_ENUNCIATE > 1 1783 NSLog(@"Attempting to read choice {http://api.familysearch.org/familytree/v2}title of type {http://www.w3.org/2001/XMLSchema}string."); 1784#endif 1785 __child = [NSString readXMLType: reader]; 1786#if DEBUG_ENUNCIATE > 1 1787 NSLog(@"successfully read choice {http://api.familysearch.org/familytree/v2}title of type {http://www.w3.org/2001/XMLSchema}string."); 1788#endif 1789 1790 [self setTitle: __child]; 1791 return YES; 1792 } //end "if choice" 1793 1794 1795 return NO; 1796} 1797 1798//documentation inherited. 1799- (int) readUnknownJAXBChildElement: (xmlTextReaderPtr) reader 1800{ 1801 return [super readUnknownJAXBChildElement: reader]; 1802} 1803 1804//documentation inherited. 1805- (void) readUnknownJAXBAttribute: (xmlTextReaderPtr) reader 1806{ 1807 [super readUnknownJAXBAttribute: reader]; 1808} 1809 1810//documentation inherited. 1811- (void) writeJAXBAttributes: (xmlTextWriterPtr) writer 1812{ 1813 int status; 1814 1815 [super writeJAXBAttributes: writer]; 1816 1817 if ([self id]) { 1818 1819 status = xmlTextWriterStartAttributeNS(writer, NULL, BAD_CAST "id", NULL); 1820 if (status < 0) { 1821 [NSException raise: @"XMLWriteError" 1822 format: @"Error writing start attribute {}id."]; 1823 } 1824 1825#if DEBUG_ENUNCIATE > 1 1826 NSLog(@"writing attribute {}id..."); 1827#endif 1828 [[self id] writeXMLType: writer]; 1829#if DEBUG_ENUNCIATE > 1 1830 NSLog(@"successfully wrote attribute {}id..."); 1831#endif 1832 1833 status = xmlTextWriterEndAttribute(writer); 1834 if (status < 0) { 1835 [NSException raise: @"XMLWriteError" 1836 format: @"Error writing end attribute {}id."]; 1837 } 1838 } 1839} 1840 1841//documentation inherited. 1842- (void) writeJAXBValue: (xmlTextWriterPtr) writer 1843{ 1844 [super writeJAXBValue: writer]; 1845} 1846 1847/** 1848 * Method for writing the child elements. 1849 * 1850 * @param writer The writer. 1851 */ 1852- (void) writeJAXBChildElements: (xmlTextWriterPtr) writer 1853{ 1854 int status; 1855 id __item; 1856 NSEnumerator *__enumerator; 1857 1858 [super writeJAXBChildElements: writer]; 1859 1860 if ([self title]) { 1861 status = xmlTextWriterStartElementNS(writer, BAD_CAST "familytree_v2", BAD_CAST "title", NULL); 1862 if (status < 0) { 1863 [NSException raise: @"XMLWriteError" 1864 format: @"Error writing start child element {http://api.familysearch.org/familytree/v2}title."]; 1865 } 1866 1867#if DEBUG_ENUNCIATE > 1 1868 NSLog(@"writing element {http://api.familysearch.org/familytree/v2}title..."); 1869#endif 1870 [[self title] writeXMLType: writer]; 1871#if DEBUG_ENUNCIATE > 1 1872 NSLog(@"successfully wrote element {http://api.familysearch.org/familytree/v2}title..."); 1873#endif 1874 1875 status = xmlTextWriterEndElement(writer); 1876 if (status < 0) { 1877 [NSException raise: @"XMLWriteError" 1878 format: @"Error writing end child element {http://api.familysearch.org/familytree/v2}title."]; 1879 } 1880 } 1881} 1882@end /* implementation FSFAMILYTREEV2AssertionValue (JAXB) */ 1883 1884/** 1885 * @author Rob Lyon 1886 1887 */ 1888@implementation FSFAMILYTREEV2ChangeAction 1889 1890/** 1891 * the change action type. 1892 */ 1893- (enum FSFAMILYTREEV2ChangeActionType *) type 1894{ 1895 return _type; 1896} 1897 1898/** 1899 * the change action type. 1900 */ 1901- (void) setType: (enum FSFAMILYTREEV2ChangeActionType *) newType 1902{ 1903 if (_type != NULL) { 1904 free(_type); 1905 } 1906 _type = newType; 1907} 1908 1909/** 1910 * the action value. 1911 */ 1912- (NSString *) value 1913{ 1914 return _value; 1915} 1916 1917/** 1918 * the action value. 1919 */ 1920- (void) setValue: (NSString *) newValue 1921{ 1922 [newValue retain]; 1923 [_value release]; 1924 _value = newValue; 1925} 1926 1927- (void) dealloc 1928{ 1929 [self setType: NULL]; 1930 [self setValue: nil]; 1931 [super dealloc]; 1932} 1933@end /* implementation FSFAMILYTREEV2ChangeAction */ 1934 1935/** 1936 * Internal, private interface for JAXB reading and writing. 1937 */ 1938@interface FSFAMILYTREEV2ChangeAction (JAXB) <JAXBReading, JAXBWriting, JAXBType> 1939 1940@end /*interface FSFAMILYTREEV2ChangeAction (JAXB)*/ 1941 1942/** 1943 * Internal, private implementation for JAXB reading and writing. 1944 */ 1945@implementation FSFAMILYTREEV2ChangeAction (JAXB) 1946 1947/** 1948 * Read an instance of FSFAMILYTREEV2ChangeAction from an XML reader. 1949 * 1950 * @param reader The reader. 1951 * @return An instance of FSFAMILYTREEV2ChangeAction defined by the XML reader. 1952 */ 1953+ (id<JAXBType>) readXMLType: (xmlTextReaderPtr) reader 1954{ 1955 FSFAMILYTREEV2ChangeAction *_fSFAMILYTREEV2ChangeAction = [[FSFAMILYTREEV2ChangeAction alloc] init]; 1956 NS_DURING 1957 { 1958 [_fSFAMILYTREEV2ChangeAction initWithReader: reader]; 1959 } 1960 NS_HANDLER 1961 { 1962 [_fSFAMILYTREEV2ChangeAction dealloc]; 1963 _fSFAMILYTREEV2C…
Large files files are truncated, but you can click here to view the full file