ObjFW  Diff

Differences From Artifact [1474c4b15e]:

To Artifact [d295443a31]:


21
22
23
24
25
26
27


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75








76
77
78
79
80
81
82

#import "OFXMLElement.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFDataArray.h"
#import "OFXMLAttribute.h"


#import "OFXMLParser.h"
#import "OFXMLElementBuilder.h"
#import "OFAutoreleasePool.h"

#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFMalformedXMLException.h"
#import "OFNotImplementedException.h"
#import "OFUnboundNamespaceException.h"

#import "macros.h"

/* References for static linking */
void _references_to_categories_of_OFXMLElement(void)
{
	_OFXMLElement_Serialization_reference = 1;
}




@interface OFXMLElement_OFXMLElementBuilderDelegate: OFObject
{
@public
	OFXMLElement *element;
}
@end

@implementation OFXMLElement_OFXMLElementBuilderDelegate
- (void)elementBuilder: (OFXMLElementBuilder*)builder
       didBuildElement: (OFXMLElement*)element_
{
	/*
	 * Make sure we don't take whitespaces before or after the root element
	 * into account.
	 */
	if ([element_ name] != nil) {
		assert(element == nil);
		element = [element_ retain];
	}
}

- (void)dealloc
{
	[element release];

	[super dealloc];
}
@end

@implementation OFXMLElement








+ elementWithName: (OFString*)name
{
	return [[[self alloc] initWithName: name] autorelease];
}

+ elementWithName: (OFString*)name
      stringValue: (OFString*)stringValue







>
>

















>
>
>












<
<
<
<
<
|

<











>
>
>
>
>
>
>
>







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61





62
63

64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

#import "OFXMLElement.h"
#import "OFString.h"
#import "OFArray.h"
#import "OFDictionary.h"
#import "OFDataArray.h"
#import "OFXMLAttribute.h"
#import "OFXMLCharacters.h"
#import "OFXMLCDATA.h"
#import "OFXMLParser.h"
#import "OFXMLElementBuilder.h"
#import "OFAutoreleasePool.h"

#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFMalformedXMLException.h"
#import "OFNotImplementedException.h"
#import "OFUnboundNamespaceException.h"

#import "macros.h"

/* References for static linking */
void _references_to_categories_of_OFXMLElement(void)
{
	_OFXMLElement_Serialization_reference = 1;
}

static Class charactersClass = Nil;
static Class CDATAClass = Nil;

@interface OFXMLElement_OFXMLElementBuilderDelegate: OFObject
{
@public
	OFXMLElement *element;
}
@end

@implementation OFXMLElement_OFXMLElementBuilderDelegate
- (void)elementBuilder: (OFXMLElementBuilder*)builder
       didBuildElement: (OFXMLElement*)element_
{





	if (element == nil)
		element = [element_ retain];

}

- (void)dealloc
{
	[element release];

	[super dealloc];
}
@end

@implementation OFXMLElement
+ (void)initialize
{
	if (self == [OFXMLElement class]) {
		charactersClass = [OFXMLCharacters class];
		CDATAClass = [OFXMLCDATA class];
	}
}

+ elementWithName: (OFString*)name
{
	return [[[self alloc] initWithName: name] autorelease];
}

+ elementWithName: (OFString*)name
      stringValue: (OFString*)stringValue
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
      stringValue: (OFString*)stringValue
{
	return [[[self alloc] initWithName: name
				 namespace: ns
			       stringValue: stringValue] autorelease];
}

+ elementWithCharacters: (OFString*)characters
{
	return [[[self alloc] initWithCharacters: characters] autorelease];
}

+ elementWithCDATA: (OFString*)CDATA
{
	return [[[self alloc] initWithCDATA: CDATA] autorelease];
}

+ elementWithComment: (OFString*)comment
{
	return [[[self alloc] initWithComment: comment] autorelease];
}

+ elementWithElement: (OFXMLElement*)element
{
	return [[[self alloc] initWithElement: element] autorelease];
}

+ elementWithXMLString: (OFString*)string
{







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







104
105
106
107
108
109
110















111
112
113
114
115
116
117
      stringValue: (OFString*)stringValue
{
	return [[[self alloc] initWithName: name
				 namespace: ns
			       stringValue: stringValue] autorelease];
}
















+ elementWithElement: (OFXMLElement*)element
{
	return [[[self alloc] initWithElement: element] autorelease];
}

+ elementWithXMLString: (OFString*)string
{
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
		[self release];
		@throw e;
	}

	return self;
}

- initWithCharacters: (OFString*)characters_
{
	self = [super init];

	@try {
		if (characters_ == nil)
			@throw [OFInvalidArgumentException
			    exceptionWithClass: isa
				      selector: _cmd];

		characters = [characters_ copy];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- initWithCDATA: (OFString*)CDATA_
{
	self = [super init];

	@try {
		if (CDATA_ == nil)
			@throw [OFInvalidArgumentException
			    exceptionWithClass: isa
				      selector: _cmd];

		CDATA = [CDATA_ copy];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- initWithComment: (OFString*)comment_
{
	self = [super init];

	@try {
		if (comment_ == nil)
			@throw [OFInvalidArgumentException
			    exceptionWithClass: isa
				      selector: _cmd];

		comment = [comment_ copy];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- initWithElement: (OFXMLElement*)element
{
	self = [super init];

	@try {
		if (element == nil)
			@throw [OFInvalidArgumentException
			    exceptionWithClass: isa
				      selector: _cmd];

		name = [element->name copy];
		ns = [element->ns copy];
		defaultNamespace = [element->defaultNamespace copy];
		attributes = [element->attributes mutableCopy];
		namespaces = [element->namespaces mutableCopy];
		children = [element->children mutableCopy];
		characters = [element->characters copy];
		CDATA = [element->CDATA copy];
		comment = [element->comment copy];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
















<
<
<







180
181
182
183
184
185
186

























































187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202



203
204
205
206
207
208
209
		[self release];
		@throw e;
	}

	return self;
}


























































- initWithElement: (OFXMLElement*)element
{
	self = [super init];

	@try {
		if (element == nil)
			@throw [OFInvalidArgumentException
			    exceptionWithClass: isa
				      selector: _cmd];

		name = [element->name copy];
		ns = [element->ns copy];
		defaultNamespace = [element->defaultNamespace copy];
		attributes = [element->attributes mutableCopy];
		namespaces = [element->namespaces mutableCopy];
		children = [element->children mutableCopy];



	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
				      selector: _cmd];

		name = [[[element attributeForName: @"name"] stringValue] copy];
		ns = [[[element attributeForName: @"namespace"] stringValue]
		    copy];
		defaultNamespace = [[[element attributeForName:
		    @"defaultNamespace"] stringValue] copy];
		characters = [[[element
		    elementForName: @"characters"
			 namespace: OF_SERIALIZATION_NS] stringValue] copy];
		CDATA = [[[element
		    elementForName: @"CDATA"
			 namespace: OF_SERIALIZATION_NS] stringValue] copy];
		comment = [[[element
		    elementForName: @"comment"
			 namespace: OF_SERIALIZATION_NS] stringValue] copy];

		attributesElement = [[[element
		    elementForName: @"attributes"
			 namespace: OF_SERIALIZATION_NS] elementsForNamespace:
		    OF_SERIALIZATION_NS] firstObject];
		namespacesElement = [[[element
		    elementForName: @"namespaces"
			 namespace: OF_SERIALIZATION_NS] elementsForNamespace:
		    OF_SERIALIZATION_NS] firstObject];
		childrenElement = [[[element
		    elementForName: @"children"
			 namespace: OF_SERIALIZATION_NS] elementsForNamespace:
		    OF_SERIALIZATION_NS] firstObject];

		attributes = [[attributesElement objectByDeserializing] copy];
		namespaces = [[namespacesElement objectByDeserializing] copy];
		children = [[childrenElement objectByDeserializing] copy];

		if (!((name != nil || ns != nil || defaultNamespace != nil ||
		    [attributes count] > 0 || [namespaces count] > 0 ||
		    [children count] > 0) ^ (characters != nil) ^
		    (CDATA != nil) ^ (comment != nil)))
			@throw [OFInvalidArgumentException
			    exceptionWithClass: isa
				      selector: _cmd];

		[pool release];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)setName: (OFString*)name_
{
	if (name == nil)
		@throw [OFInvalidArgumentException exceptionWithClass: isa
							     selector: _cmd];

	OF_SETTER(name, name_, YES, YES)
}

- (OFString*)name
{
	return [[name copy] autorelease];
}

- (void)setNamespace: (OFString*)ns_
{
	if (name == nil)
		@throw [OFInvalidArgumentException exceptionWithClass: isa
							     selector: _cmd];

	OF_SETTER(ns, ns_, YES, YES)
}

- (OFString*)namespace
{
	return [[ns copy] autorelease];
}







<
<
<
<
<
<
<
<
<


















<
<
<
|















|













<
<
<
<







296
297
298
299
300
301
302









303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320



321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350




351
352
353
354
355
356
357
				      selector: _cmd];

		name = [[[element attributeForName: @"name"] stringValue] copy];
		ns = [[[element attributeForName: @"namespace"] stringValue]
		    copy];
		defaultNamespace = [[[element attributeForName:
		    @"defaultNamespace"] stringValue] copy];










		attributesElement = [[[element
		    elementForName: @"attributes"
			 namespace: OF_SERIALIZATION_NS] elementsForNamespace:
		    OF_SERIALIZATION_NS] firstObject];
		namespacesElement = [[[element
		    elementForName: @"namespaces"
			 namespace: OF_SERIALIZATION_NS] elementsForNamespace:
		    OF_SERIALIZATION_NS] firstObject];
		childrenElement = [[[element
		    elementForName: @"children"
			 namespace: OF_SERIALIZATION_NS] elementsForNamespace:
		    OF_SERIALIZATION_NS] firstObject];

		attributes = [[attributesElement objectByDeserializing] copy];
		namespaces = [[namespacesElement objectByDeserializing] copy];
		children = [[childrenElement objectByDeserializing] copy];




		if (name == nil)
			@throw [OFInvalidArgumentException
			    exceptionWithClass: isa
				      selector: _cmd];

		[pool release];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (void)setName: (OFString*)name_
{
	if (name_ == nil)
		@throw [OFInvalidArgumentException exceptionWithClass: isa
							     selector: _cmd];

	OF_SETTER(name, name_, YES, YES)
}

- (OFString*)name
{
	return [[name copy] autorelease];
}

- (void)setNamespace: (OFString*)ns_
{




	OF_SETTER(ns, ns_, YES, YES)
}

- (OFString*)namespace
{
	return [[ns copy] autorelease];
}
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
}

- (void)setStringValue: (OFString*)stringValue
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];

	[self setChildren: [OFArray arrayWithObject:
	    [OFXMLElement elementWithCharacters: stringValue]]];

	[pool release];
}

- (OFString*)stringValue
{
	OFAutoreleasePool *pool;
	OFMutableString *ret;
	OFXMLElement **cArray;
	size_t i, count = [children count];

	if (count == 0)
		return @"";

	ret = [OFMutableString string];
	cArray = [children cArray];
	pool = [[OFAutoreleasePool alloc] init];

	for (i = 0; i < count; i++) {
		if (cArray[i]->characters != nil)
			[ret appendString: cArray[i]->characters];
		else if (cArray[i]->CDATA != nil)
			[ret appendString: cArray[i]->CDATA];
		else if (cArray[i]->comment == nil) {
			[ret appendString: [cArray[i] stringValue]];
			[pool releaseObjects];
		}
	}

	[ret makeImmutable];

	[pool release];

	return ret;
}

- (OFString*)_XMLStringWithParent: (OFXMLElement*)parent
		       namespaces: (OFDictionary*)allNamespaces
		      indentation: (unsigned int)indentation
			    level: (size_t)level
{
	OFAutoreleasePool *pool, *pool2;
	char *cString;
	size_t length, i, j, attributesCount;
	OFString *prefix, *parentPrefix;
	OFXMLAttribute **attributesCArray;
	OFString *ret;
	OFString *defaultNS;

	if (characters != nil)
		return [characters stringByXMLEscaping];

	if (CDATA != nil)
		return [OFString stringWithFormat: @"<![CDATA[%@]]>", CDATA];

	if (comment != nil) {
		if (indentation > 0 && level > 0) {
			char *whitespaces = [self
			    allocMemoryWithSize: (level * indentation) + 1];
			memset(whitespaces, ' ', level * indentation);
			whitespaces[level * indentation] = 0;

			@try {
				ret = [OFString
				    stringWithFormat: @"%s<!--%@-->",
						      whitespaces, comment];
			} @finally {
				[self freeMemory: whitespaces];
			}
		} else
			ret = [OFString stringWithFormat: @"<!--%@-->",
							  comment];

		return ret;
	}

	pool = [[OFAutoreleasePool alloc] init];

	parentPrefix = [allNamespaces objectForKey:
	    (parent != nil && parent->ns != nil ? parent->ns : (OFString*)@"")];

	/* Add the namespaces of the current element */
	if (allNamespaces != nil) {







|



















<
<
<
<
<
|
|
<












|









<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400





401
402

403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424



























425
426
427
428
429
430
431
}

- (void)setStringValue: (OFString*)stringValue
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];

	[self setChildren: [OFArray arrayWithObject:
	    [OFXMLCharacters charactersWithString: stringValue]]];

	[pool release];
}

- (OFString*)stringValue
{
	OFAutoreleasePool *pool;
	OFMutableString *ret;
	OFXMLElement **cArray;
	size_t i, count = [children count];

	if (count == 0)
		return @"";

	ret = [OFMutableString string];
	cArray = [children cArray];
	pool = [[OFAutoreleasePool alloc] init];

	for (i = 0; i < count; i++) {





		[ret appendString: [cArray[i] stringValue]];
		[pool releaseObjects];

	}

	[ret makeImmutable];

	[pool release];

	return ret;
}

- (OFString*)_XMLStringWithParent: (OFXMLElement*)parent
		       namespaces: (OFDictionary*)allNamespaces
		      indentation: (unsigned int)indentation
			    level: (unsigned int)level
{
	OFAutoreleasePool *pool, *pool2;
	char *cString;
	size_t length, i, j, attributesCount;
	OFString *prefix, *parentPrefix;
	OFXMLAttribute **attributesCArray;
	OFString *ret;
	OFString *defaultNS;




























	pool = [[OFAutoreleasePool alloc] init];

	parentPrefix = [allNamespaces objectForKey:
	    (parent != nil && parent->ns != nil ? parent->ns : (OFString*)@"")];

	/* Add the namespaces of the current element */
	if (allNamespaces != nil) {
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695

696
697
698
699


700
701
702
703
704




705
706
707
708
709
710
711
		OFDataArray *tmp = [OFDataArray dataArray];
		BOOL indent;

		if (indentation > 0) {
			indent = YES;

			for (j = 0; j < childrenCount; j++) {
				if (childrenCArray[j]->characters != nil ||
				    childrenCArray[j]->CDATA != nil) {
					indent = NO;
					break;
				}
			}
		} else
			indent = NO;

		for (j = 0; j < childrenCount; j++) {
			OFString *child;


			if (indent)
				[tmp addItem: "\n"];



			child = [childrenCArray[j]
			    _XMLStringWithParent: self
				      namespaces: allNamespaces
				     indentation: (indent ? indentation : 0)
					   level: level + 1];





			[tmp addNItems: [child UTF8StringLength]
			    fromCArray: [child UTF8String]];
		}

		if (indent)
			[tmp addItem: "\n"];







|
|









>

|


>
>
|
|
|
|
|
>
>
>
>







561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
		OFDataArray *tmp = [OFDataArray dataArray];
		BOOL indent;

		if (indentation > 0) {
			indent = YES;

			for (j = 0; j < childrenCount; j++) {
				if (childrenCArray[j]->isa == charactersClass ||
				    childrenCArray[j]->isa == CDATAClass) {
					indent = NO;
					break;
				}
			}
		} else
			indent = NO;

		for (j = 0; j < childrenCount; j++) {
			OFString *child;
			unsigned int ind = (indent ? indentation : 0);

			if (ind)
				[tmp addItem: "\n"];

			if ([childrenCArray[j] isKindOfClass:
			    [OFXMLElement class]])
				child = [childrenCArray[j]
				    _XMLStringWithParent: self
					      namespaces: allNamespaces
					     indentation: ind
						   level: level + 1];
			else
				child = [childrenCArray[j]
				    XMLStringWithIndentation: ind
						       level: level + 1];

			[tmp addNItems: [child UTF8StringLength]
			    fromCArray: [child UTF8String]];
		}

		if (indent)
			[tmp addItem: "\n"];
777
778
779
780
781
782
783









784
785
786
787
788
789
790
- (OFString*)XMLStringWithIndentation: (unsigned int)indentation
{
	return [self _XMLStringWithParent: nil
			       namespaces: nil
			      indentation: indentation
				    level: 0];
}










- (OFXMLElement*)XMLElementBySerializing
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFXMLElement *element;

	element = [OFXMLElement elementWithName: [self className]







>
>
>
>
>
>
>
>
>







667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
- (OFString*)XMLStringWithIndentation: (unsigned int)indentation
{
	return [self _XMLStringWithParent: nil
			       namespaces: nil
			      indentation: indentation
				    level: 0];
}

- (OFString*)XMLStringWithIndentation: (unsigned int)indentation
				level: (unsigned int)level
{
	return [self _XMLStringWithParent: nil
			       namespaces: nil
			      indentation: indentation
				    level: level];
}

- (OFXMLElement*)XMLElementBySerializing
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFXMLElement *element;

	element = [OFXMLElement elementWithName: [self className]
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899

900
901
902
903
904
905
906
		childrenElement =
		    [OFXMLElement elementWithName: @"children"
					namespace: OF_SERIALIZATION_NS];
		[childrenElement addChild: [children XMLElementBySerializing]];
		[element addChild: childrenElement];
	}

	if (characters != nil)
		[element addChild:
		    [OFXMLElement elementWithName: @"characters"
					namespace: OF_SERIALIZATION_NS
				      stringValue: characters]];

	if (CDATA != nil) {
		OFXMLElement *CDATAElement =
		    [OFXMLElement elementWithName: @"CDATA"
					namespace: OF_SERIALIZATION_NS];
		[CDATAElement addChild: [OFXMLElement elementWithCDATA: CDATA]];
		[element addChild: CDATAElement];
	}

	if (comment != nil)
		[element addChild:
		    [OFXMLElement elementWithName: @"comment"
					namespace: OF_SERIALIZATION_NS
				      stringValue: comment]];

	[element retain];
	[pool release];
	[element autorelease];

	return element;
}

- (void)addAttribute: (OFXMLAttribute*)attribute
{
	if (name == nil)
		@throw [OFInvalidArgumentException exceptionWithClass: isa
							     selector: _cmd];

	if (attributes == nil)
		attributes = [[OFMutableArray alloc] init];

	if ([self attributeForName: attribute->name
			 namespace: attribute->ns] == nil)
		[attributes addObject: attribute];
}

- (void)addAttributeWithName: (OFString*)name_
		 stringValue: (OFString*)stringValue
{
	[self addAttributeWithName: name_
			 namespace: nil
		       stringValue: stringValue];
}

- (void)addAttributeWithName: (OFString*)name_
		   namespace: (OFString*)ns_
		 stringValue: (OFString*)stringValue
{
	OFAutoreleasePool *pool;

	if (name == nil)
		@throw [OFInvalidArgumentException exceptionWithClass: isa
							     selector: _cmd];

	pool = [[OFAutoreleasePool alloc] init];
	[self addAttribute: [OFXMLAttribute attributeWithName: name_
						    namespace: ns_
						  stringValue: stringValue]];

	[pool release];
}

- (OFXMLAttribute*)attributeForName: (OFString*)attributeName
{
	OFXMLAttribute **cArray = [attributes cArray];
	size_t i, count = [attributes count];







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<









<
<
<
<




















|

<
<
<
<
<



>







729
730
731
732
733
734
735




















736
737
738
739
740
741
742
743
744




745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766





767
768
769
770
771
772
773
774
775
776
777
		childrenElement =
		    [OFXMLElement elementWithName: @"children"
					namespace: OF_SERIALIZATION_NS];
		[childrenElement addChild: [children XMLElementBySerializing]];
		[element addChild: childrenElement];
	}





















	[element retain];
	[pool release];
	[element autorelease];

	return element;
}

- (void)addAttribute: (OFXMLAttribute*)attribute
{




	if (attributes == nil)
		attributes = [[OFMutableArray alloc] init];

	if ([self attributeForName: attribute->name
			 namespace: attribute->ns] == nil)
		[attributes addObject: attribute];
}

- (void)addAttributeWithName: (OFString*)name_
		 stringValue: (OFString*)stringValue
{
	[self addAttributeWithName: name_
			 namespace: nil
		       stringValue: stringValue];
}

- (void)addAttributeWithName: (OFString*)name_
		   namespace: (OFString*)ns_
		 stringValue: (OFString*)stringValue
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];






	[self addAttribute: [OFXMLAttribute attributeWithName: name_
						    namespace: ns_
						  stringValue: stringValue]];

	[pool release];
}

- (OFXMLAttribute*)attributeForName: (OFString*)attributeName
{
	OFXMLAttribute **cArray = [attributes cArray];
	size_t i, count = [attributes count];
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
		}
	}
}

- (void)setPrefix: (OFString*)prefix
     forNamespace: (OFString*)ns_
{
	if (name == nil || prefix == nil || [prefix isEqual: @""])
		@throw [OFInvalidArgumentException exceptionWithClass: isa
							     selector: _cmd];
	if (ns_ == nil)
		ns_ = @"";

	[namespaces setObject: prefix
		       forKey: ns_];







|







839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
		}
	}
}

- (void)setPrefix: (OFString*)prefix
     forNamespace: (OFString*)ns_
{
	if (prefix == nil || [prefix isEqual: @""])
		@throw [OFInvalidArgumentException exceptionWithClass: isa
							     selector: _cmd];
	if (ns_ == nil)
		ns_ = @"";

	[namespaces setObject: prefix
		       forKey: ns_];
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
	[self addAttributeWithName: prefix
			 namespace: @"http://www.w3.org/2000/xmlns/"
		       stringValue: ns_];
}

- (OFString*)defaultNamespace
{
	if (name == nil)
		@throw [OFInvalidArgumentException exceptionWithClass: isa
							     selector: _cmd];

	return [[defaultNamespace retain] autorelease];
}

- (void)setDefaultNamespace: (OFString*)ns_
{
	if (name == nil)
		@throw [OFInvalidArgumentException exceptionWithClass: isa
							     selector: _cmd];

	OFString *old = defaultNamespace;
	defaultNamespace = [ns_ copy];
	[old release];
}

- (void)addChild: (OFXMLElement*)child
{
	if (name == nil)
		@throw [OFInvalidArgumentException exceptionWithClass: isa
							     selector: _cmd];

	if (children == nil)
		children = [[OFMutableArray alloc] init];

	[children addObject: child];
}

- (void)removeChild: (OFXMLElement*)child
{
	if (name == nil)
		@throw [OFInvalidArgumentException exceptionWithClass: isa
							     selector: _cmd];

	[children removeObject: child];
}

- (OFXMLElement*)elementForName: (OFString*)elementName







<
<
<
<
|




<
<
<
<
<
|
<


|

|









|

|







861
862
863
864
865
866
867




868
869
870
871
872





873

874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
	[self addAttributeWithName: prefix
			 namespace: @"http://www.w3.org/2000/xmlns/"
		       stringValue: ns_];
}

- (OFString*)defaultNamespace
{




	OF_GETTER(defaultNamespace, YES)
}

- (void)setDefaultNamespace: (OFString*)ns_
{





	OF_SETTER(defaultNamespace, ns_, YES, YES)

}

- (void)addChild: (OFXMLNode*)child
{
	if ([child isKindOfClass: [OFXMLAttribute class]])
		@throw [OFInvalidArgumentException exceptionWithClass: isa
							     selector: _cmd];

	if (children == nil)
		children = [[OFMutableArray alloc] init];

	[children addObject: child];
}

- (void)removeChild: (OFXMLNode*)child
{
	if ([child isKindOfClass: [OFXMLAttribute class]])
		@throw [OFInvalidArgumentException exceptionWithClass: isa
							     selector: _cmd];

	[children removeObject: child];
}

- (OFXMLElement*)elementForName: (OFString*)elementName
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069

1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085

1086
1087
1088
1089
1090
1091
1092
1093
- (OFArray*)elements
{
	OFMutableArray *ret = [OFMutableArray array];
	OFXMLElement **cArray = [children cArray];
	size_t i, count = [children count];

	for (i = 0; i < count; i++)
		if (cArray[i]->name != nil)
			[ret addObject: cArray[i]];

	[ret makeImmutable];

	return ret;
}

- (OFArray*)elementsForName: (OFString*)elementName
{
	OFMutableArray *ret = [OFMutableArray array];
	OFXMLElement **cArray = [children cArray];
	size_t i, count = [children count];

	for (i = 0; i < count; i++)

		if (cArray[i]->ns == nil &&
		    [cArray[i]->name isEqual: elementName])
			[ret addObject: cArray[i]];

	[ret makeImmutable];

	return ret;
}

- (OFArray*)elementsForNamespace: (OFString*)elementNS
{
	OFMutableArray *ret = [OFMutableArray array];
	OFXMLElement **cArray = [children cArray];
	size_t i, count = [children count];

	for (i = 0; i < count; i++)

		if (cArray[i]->name != nil &&
		    [cArray[i]->ns isEqual: elementNS])
			[ret addObject: cArray[i]];

	[ret makeImmutable];

	return ret;
}







|














>
|















>
|







909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
- (OFArray*)elements
{
	OFMutableArray *ret = [OFMutableArray array];
	OFXMLElement **cArray = [children cArray];
	size_t i, count = [children count];

	for (i = 0; i < count; i++)
		if ([cArray[i] isKindOfClass: [OFXMLElement class]])
			[ret addObject: cArray[i]];

	[ret makeImmutable];

	return ret;
}

- (OFArray*)elementsForName: (OFString*)elementName
{
	OFMutableArray *ret = [OFMutableArray array];
	OFXMLElement **cArray = [children cArray];
	size_t i, count = [children count];

	for (i = 0; i < count; i++)
		if ([cArray[i] isKindOfClass: [OFXMLElement class]] &&
		    cArray[i]->ns == nil &&
		    [cArray[i]->name isEqual: elementName])
			[ret addObject: cArray[i]];

	[ret makeImmutable];

	return ret;
}

- (OFArray*)elementsForNamespace: (OFString*)elementNS
{
	OFMutableArray *ret = [OFMutableArray array];
	OFXMLElement **cArray = [children cArray];
	size_t i, count = [children count];

	for (i = 0; i < count; i++)
		if ([cArray[i] isKindOfClass: [OFXMLElement class]] &&
		    cArray[i]->name != nil &&
		    [cArray[i]->ns isEqual: elementNS])
			[ret addObject: cArray[i]];

	[ret makeImmutable];

	return ret;
}
1103
1104
1105
1106
1107
1108
1109

1110
1111
1112
1113
1114
1115
1116
1117
		return [self elementsForName: elementName];

	ret = [OFMutableArray array];
	cArray = [children cArray];
	count = [children count];

	for (i = 0; i < count; i++)

		if ([cArray[i]->ns isEqual: elementNS] &&
		    [cArray[i]->name isEqual: elementName])
			[ret addObject: cArray[i]];

	[ret makeImmutable];

	return ret;
}







>
|







966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
		return [self elementsForName: elementName];

	ret = [OFMutableArray array];
	cArray = [children cArray];
	count = [children count];

	for (i = 0; i < count; i++)
		if ([cArray[i] isKindOfClass: [OFXMLElement class]] &&
		    [cArray[i]->ns isEqual: elementNS] &&
		    [cArray[i]->name isEqual: elementName])
			[ret addObject: cArray[i]];

	[ret makeImmutable];

	return ret;
}
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
		return NO;
	if (otherElement->namespaces != namespaces &&
	    ![otherElement->namespaces isEqual: namespaces])
		return NO;
	if (otherElement->children != children &&
	    ![otherElement->children isEqual: children])
		return NO;
	if (otherElement->characters != characters &&
	    ![otherElement->characters isEqual: characters])
		return NO;
	if (otherElement->CDATA != CDATA &&
	    ![otherElement->CDATA isEqual: CDATA])
		return NO;
	if (otherElement->comment != comment &&
	    ![otherElement->comment isEqual: comment])
		return NO;

	return YES;
}

- (uint32_t)hash
{
	uint32_t hash;

	OF_HASH_INIT(hash);

	OF_HASH_ADD_HASH(hash, [name hash]);
	OF_HASH_ADD_HASH(hash, [ns hash]);
	OF_HASH_ADD_HASH(hash, [defaultNamespace hash]);
	OF_HASH_ADD_HASH(hash, [attributes hash]);
	OF_HASH_ADD_HASH(hash, [namespaces hash]);
	OF_HASH_ADD_HASH(hash, [children hash]);
	OF_HASH_ADD_HASH(hash, [characters hash]);
	OF_HASH_ADD_HASH(hash, [CDATA hash]);
	OF_HASH_ADD_HASH(hash, [comment hash]);

	OF_HASH_FINALIZE(hash);

	return hash;
}

- copy
{
	return [[isa alloc] initWithElement: self];
}

- (void)dealloc
{
	[name release];
	[ns release];
	[defaultNamespace release];
	[attributes release];
	[namespaces release];
	[children release];
	[characters release];
	[CDATA release];
	[comment release];

	[super dealloc];
}
@end







<
<
<
<
<
<
<
<
<
















<
<
<



















<
<
<




1001
1002
1003
1004
1005
1006
1007









1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023



1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042



1043
1044
1045
1046
		return NO;
	if (otherElement->namespaces != namespaces &&
	    ![otherElement->namespaces isEqual: namespaces])
		return NO;
	if (otherElement->children != children &&
	    ![otherElement->children isEqual: children])
		return NO;










	return YES;
}

- (uint32_t)hash
{
	uint32_t hash;

	OF_HASH_INIT(hash);

	OF_HASH_ADD_HASH(hash, [name hash]);
	OF_HASH_ADD_HASH(hash, [ns hash]);
	OF_HASH_ADD_HASH(hash, [defaultNamespace hash]);
	OF_HASH_ADD_HASH(hash, [attributes hash]);
	OF_HASH_ADD_HASH(hash, [namespaces hash]);
	OF_HASH_ADD_HASH(hash, [children hash]);




	OF_HASH_FINALIZE(hash);

	return hash;
}

- copy
{
	return [[isa alloc] initWithElement: self];
}

- (void)dealloc
{
	[name release];
	[ns release];
	[defaultNamespace release];
	[attributes release];
	[namespaces release];
	[children release];




	[super dealloc];
}
@end