ObjFW  Diff

Differences From Artifact [bd82ff1d44]:

To Artifact [e59c8082fb]:


84
85
86
87
88
89
90
91

92
93
94

95
96
97
98
99

100
101
102
103
104
105

106
107
108
109
110
111
112
84
85
86
87
88
89
90

91
92
93

94
95
96
97
98

99
100
101
102
103
104

105
106
107
108
109
110
111
112







-
+


-
+




-
+





-
+







{
	return [self initWithName: name_
			namespace: nil
		      stringValue: stringval];
}

- initWithName: (OFString*)name_
     namespace: (OFString*)ns
     namespace: (OFString*)ns_
{
	return [self initWithName: name_
			namespace: ns
			namespace: ns_
		      stringValue: nil];
}

- initWithName: (OFString*)name_
     namespace: (OFString*)ns
     namespace: (OFString*)ns_
   stringValue: (OFString*)stringval
{
	self = [super init];

	name = [name_ copy];
	namespace = [ns copy];
	ns = [ns_ copy];

	if (stringval != nil) {
		OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];;
		[self addChild:
		    [OFXMLElement elementWithCharacters: stringval]];
		[pool release];
	}
148
149
150
151
152
153
154
155

156
157
158
159
160
161
162
148
149
150
151
152
153
154

155
156
157
158
159
160
161
162







-
+







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

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

- (OFArray*)attributes
{
	return [[attributes copy] autorelease];
}

215
216
217
218
219
220
221
222
223
224


225
226
227


228
229

230
231
232
233
234
235
236
237
215
216
217
218
219
220
221



222
223
224


225
226


227

228
229
230
231
232
233
234







-
-
-
+
+

-
-
+
+
-
-
+
-







	i = 0;
	len = [name cStringLength] + 3;
	str_c = [self allocMemoryWithSize: len];

	/* Start of tag */
	str_c[i++] = '<';

	if ((namespace == nil && def_ns != nil) ||
	    (namespace != nil && def_ns == nil) ||
	    (namespace != nil && ![namespace isEqual: def_ns])) {
	if ((ns == nil && def_ns != nil) || (ns != nil && def_ns == nil) ||
	    (ns != nil && ![ns isEqual: def_ns])) {
		if ((prefix = [all_namespaces objectForKey:
		    (namespace != nil ? namespace : (OFString*)@"")]) == nil)
			@throw [OFUnboundNamespaceException
		    (ns != nil ? ns : (OFString*)@"")]) == nil)
			@throw [OFUnboundNamespaceException newWithClass: isa
			    newWithClass: isa
			       namespace: namespace];
							       namespace: ns];

		len += [prefix cStringLength] + 1;
		@try {
			str_c = [self resizeMemory: str_c
					    toSize: len];
		} @catch (OFException *e) {
			[self freeMemory: str_c];
			@throw e;
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
442
443
444
445
446
447
448
449
450

451
452
453
454
455
456
457

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
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
442
443
444
445
446

447
448
449
450
451
452
453

454
455
456
457

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







-
+










-
+








-
+




-
-
+
+


-
+



-
+


-
+


-
+











-
+






-
+



-
+

-
+

-
+

















-
+










	[self addAttribute: [OFXMLAttribute attributeWithName: name_
						    namespace: nil
						  stringValue: value]];
	[pool release];
}

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

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

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

/* TODO: Replace attribute */
/* TODO: Remove attribute */

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

	[namespaces setObject: prefix
		       forKey: ns];
		       forKey: ns_];
}

- (void)bindPrefix: (OFString*)prefix
      forNamespace: (OFString*)ns
      forNamespace: (OFString*)ns_
{
	[self setPrefix: prefix
	   forNamespace: ns];
	   forNamespace: ns_];
	[self addAttributeWithName: prefix
			 namespace: @"http://www.w3.org/2000/xmlns/"
		       stringValue: ns];
		       stringValue: ns_];
}

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

	return [[defaultNamespace retain] autorelease];
}

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

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

- (void)bindDefaultNamespace: (OFString*)ns
- (void)bindDefaultNamespace: (OFString*)ns_
{
	[self setDefaultNamespace: ns];
	[self setDefaultNamespace: ns_];
	[self addAttributeWithName: @"xmlns"
		       stringValue: ns];
		       stringValue: ns_];
}

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

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

	[children addObject: child];
}

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

	[super dealloc];
}
@end