︙ | | | ︙ | |
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
[super dealloc];
}
@end
@implementation OFXMLElement
@synthesize name = _name, namespace = _namespace;
@synthesize defaultNamespace = _defaultNamespace;
+ (instancetype)elementWithName: (OFString *)name
{
return [[[self alloc] initWithName: name] autorelease];
}
+ (instancetype)elementWithName: (OFString *)name
|
<
|
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
[super dealloc];
}
@end
@implementation OFXMLElement
@synthesize name = _name, namespace = _namespace;
+ (instancetype)elementWithName: (OFString *)name
{
return [[[self alloc] initWithName: name] autorelease];
}
+ (instancetype)elementWithName: (OFString *)name
|
︙ | | | ︙ | |
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
stringValue: (OFString *)stringValue
{
return [[[self alloc] initWithName: name
namespace: namespace
stringValue: stringValue] autorelease];
}
+ (instancetype)elementWithElement: (OFXMLElement *)element
{
return [[[self alloc] initWithElement: element] autorelease];
}
+ (instancetype)elementWithXMLString: (OFString *)string
{
return [[[self alloc] initWithXMLString: string] autorelease];
}
+ (instancetype)elementWithStream: (OFStream *)stream
{
|
<
<
<
<
<
|
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
stringValue: (OFString *)stringValue
{
return [[[self alloc] initWithName: name
namespace: namespace
stringValue: stringValue] autorelease];
}
+ (instancetype)elementWithXMLString: (OFString *)string
{
return [[[self alloc] initWithXMLString: string] autorelease];
}
+ (instancetype)elementWithStream: (OFStream *)stream
{
|
︙ | | | ︙ | |
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
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
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
namespace: nil
stringValue: stringValue];
}
- (instancetype)initWithName: (OFString *)name
namespace: (OFString *)namespace
{
return [self initWithName: name namespace: namespace stringValue: nil];
}
- (instancetype)initWithName: (OFString *)name
namespace: (OFString *)namespace
stringValue: (OFString *)stringValue
{
self = [super of_init];
@try {
if (name == nil)
@throw [OFInvalidArgumentException exception];
_name = [name copy];
_namespace = [namespace copy];
_namespaces = [[OFMutableDictionary alloc]
initWithKeysAndObjects:
@"http://www.w3.org/XML/1998/namespace", @"xml",
@"http://www.w3.org/2000/xmlns/", @"xmlns", nil];
if (stringValue != nil)
self.stringValue = stringValue;
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (instancetype)initWithElement: (OFXMLElement *)element
{
self = [super of_init];
@try {
if (element == nil ||
![element isKindOfClass: [OFXMLElement class]])
@throw [OFInvalidArgumentException exception];
_name = [element->_name copy];
_namespace = [element->_namespace 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;
}
- (instancetype)initWithXMLString: (OFString *)string
{
void *pool;
OFXMLParser *parser;
OFXMLElementBuilder *builder;
OFXMLElementElementBuilderDelegate *delegate;
[self release];
if (string == nil)
@throw [OFInvalidArgumentException exception];
pool = objc_autoreleasePoolPush();
parser = [OFXMLParser parser];
builder = [OFXMLElementBuilder builder];
delegate = [[[OFXMLElementElementBuilderDelegate alloc] init]
autorelease];
parser.delegate = builder;
builder.delegate = delegate;
[parser parseString: string];
if (!parser.hasFinishedParsing)
@throw [OFMalformedXMLException exceptionWithParser: parser];
self = [delegate->_element retain];
objc_autoreleasePoolPop(pool);
return self;
}
- (instancetype)initWithStream: (OFStream *)stream
{
void *pool;
OFXMLParser *parser;
OFXMLElementBuilder *builder;
OFXMLElementElementBuilderDelegate *delegate;
[self release];
pool = objc_autoreleasePoolPush();
parser = [OFXMLParser parser];
builder = [OFXMLElementBuilder builder];
delegate = [[[OFXMLElementElementBuilderDelegate alloc] init]
autorelease];
parser.delegate = builder;
builder.delegate = delegate;
[parser parseStream: stream];
if (!parser.hasFinishedParsing)
@throw [OFMalformedXMLException exceptionWithParser: parser];
self = [delegate->_element retain];
objc_autoreleasePoolPop(pool);
return self;
}
- (instancetype)initWithSerialization: (OFXMLElement *)element
{
self = [super of_init];
@try {
void *pool = objc_autoreleasePoolPush();
OFXMLElement *attributesElement, *namespacesElement;
OFXMLElement *childrenElement;
OFEnumerator *keyEnumerator, *objectEnumerator;
OFString *key, *object;
if (![element.name isEqual: self.className] ||
![element.namespace isEqual: OFSerializationNS])
@throw [OFInvalidArgumentException exception];
_name = [[element attributeForName: @"name"].stringValue copy];
_namespace = [[element attributeForName: @"namespace"]
.stringValue copy];
_defaultNamespace = [[element attributeForName:
@"defaultNamespace"].stringValue copy];
attributesElement = [[element
elementForName: @"attributes"
namespace: OFSerializationNS] elementsForNamespace:
OFSerializationNS].firstObject;
namespacesElement = [[element
elementForName: @"namespaces"
namespace: OFSerializationNS] elementsForNamespace:
OFSerializationNS].firstObject;
childrenElement = [[element
elementForName: @"children"
namespace: OFSerializationNS] elementsForNamespace:
OFSerializationNS].firstObject;
_attributes = [attributesElement.objectByDeserializing
mutableCopy];
_namespaces = [namespacesElement.objectByDeserializing
mutableCopy];
_children = [childrenElement.objectByDeserializing
mutableCopy];
/* Sanity checks */
if ((_attributes != nil && ![_attributes isKindOfClass:
[OFMutableArray class]]) || (_namespaces != nil &&
![_namespaces isKindOfClass:
|
<
<
<
<
<
<
<
<
<
<
|
>
>
|
|
<
<
|
<
<
<
<
<
<
>
>
>
|
|
|
<
<
|
|
|
|
|
|
|
|
|
|
|
|
>
|
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
|
|
|
<
<
|
|
|
|
|
|
|
|
|
|
>
|
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
|
>
|
<
<
<
<
|
>
|
>
>
>
>
|
>
|
>
|
>
>
>
|
|
|
|
|
|
>
>
>
>
>
>
>
>
|
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
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
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
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
|
namespace: nil
stringValue: stringValue];
}
- (instancetype)initWithName: (OFString *)name
namespace: (OFString *)namespace
{
self = [super of_init];
@try {
if (name == nil)
@throw [OFInvalidArgumentException exception];
_name = [name copy];
_namespace = [namespace copy];
_namespaces = [[OFMutableDictionary alloc]
initWithKeysAndObjects:
@"http://www.w3.org/XML/1998/namespace", @"xml",
@"http://www.w3.org/2000/xmlns/", @"xmlns", nil];
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (instancetype)initWithName: (OFString *)name
namespace: (OFString *)namespace
stringValue: (OFString *)stringValue
{
self = [self initWithName: name namespace: namespace];
@try {
if (stringValue != nil)
self.stringValue = stringValue;
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (instancetype)initWithXMLString: (OFString *)string
{
void *pool;
OFXMLElement *element;
@try {
OFXMLParser *parser;
OFXMLElementBuilder *builder;
OFXMLElementElementBuilderDelegate *delegate;
if (string == nil)
@throw [OFInvalidArgumentException exception];
pool = objc_autoreleasePoolPush();
parser = [OFXMLParser parser];
builder = [OFXMLElementBuilder builder];
delegate = [[[OFXMLElementElementBuilderDelegate alloc] init]
autorelease];
parser.delegate = builder;
builder.delegate = delegate;
[parser parseString: string];
if (!parser.hasFinishedParsing)
@throw [OFMalformedXMLException
exceptionWithParser: parser];
element = delegate->_element;
} @catch (id e) {
[self release];
@throw e;
}
self = [self initWithName: element->_name
namespace: element->_namespace];
@try {
[_attributes release];
_attributes = [element->_attributes retain];
[_namespaces release];
_namespaces = [element->_namespaces retain];
[_children release];
_children = [element->_children retain];
objc_autoreleasePoolPop(pool);
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (instancetype)initWithStream: (OFStream *)stream
{
void *pool;
OFXMLElement *element;
@try {
OFXMLParser *parser;
OFXMLElementBuilder *builder;
OFXMLElementElementBuilderDelegate *delegate;
pool = objc_autoreleasePoolPush();
parser = [OFXMLParser parser];
builder = [OFXMLElementBuilder builder];
delegate = [[[OFXMLElementElementBuilderDelegate alloc] init]
autorelease];
parser.delegate = builder;
builder.delegate = delegate;
[parser parseStream: stream];
if (!parser.hasFinishedParsing)
@throw [OFMalformedXMLException
exceptionWithParser: parser];
element = delegate->_element;
} @catch (id e) {
[self release];
@throw e;
}
self = [self initWithName: element->_name
namespace: element->_namespace];
@try {
[_attributes release];
_attributes = [element->_attributes retain];
[_namespaces release];
_namespaces = [element->_namespaces retain];
[_children release];
_children = [element->_children retain];
objc_autoreleasePoolPop(pool);
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (instancetype)initWithSerialization: (OFXMLElement *)element
{
void *pool;
OFString *name, *namespace;
@try {
pool = objc_autoreleasePoolPush();
if (![element.name isEqual: self.className] ||
![element.namespace isEqual: OFSerializationNS])
@throw [OFInvalidArgumentException exception];
name = [element attributeForName: @"name"].stringValue;
namespace =
[element attributeForName: @"namespace"].stringValue;
} @catch (id e) {
[self release];
@throw e;
}
self = [self initWithName: name namespace: namespace];
@try {
OFXMLElement *attributesElement, *namespacesElement;
OFXMLElement *childrenElement;
OFEnumerator *keyEnumerator, *objectEnumerator;
OFString *key, *object;
attributesElement = [[element
elementForName: @"attributes"
namespace: OFSerializationNS]
elementsForNamespace: OFSerializationNS].firstObject;
namespacesElement = [[element
elementForName: @"namespaces"
namespace: OFSerializationNS]
elementsForNamespace: OFSerializationNS].firstObject;
childrenElement = [[element
elementForName: @"children"
namespace: OFSerializationNS]
elementsForNamespace: OFSerializationNS].firstObject;
[_attributes release];
_attributes = nil;
_attributes = [attributesElement.objectByDeserializing
mutableCopy];
[_namespaces release];
_namespaces = nil;
_namespaces = [namespacesElement.objectByDeserializing
mutableCopy];
[_children release];
_children = nil;
_children = [childrenElement.objectByDeserializing
mutableCopy];
/* Sanity checks */
if ((_attributes != nil && ![_attributes isKindOfClass:
[OFMutableArray class]]) || (_namespaces != nil &&
![_namespaces isKindOfClass:
|
︙ | | | ︙ | |
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
358
|
[_namespaces
setObject: @"xml"
forKey: @"http://www.w3.org/XML/1998/namespace"];
[_namespaces setObject: @"xmlns"
forKey: @"http://www.w3.org/2000/xmlns/"];
if (_name == nil)
@throw [OFInvalidArgumentException exception];
objc_autoreleasePoolPop(pool);
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)dealloc
{
[_name release];
[_namespace release];
[_defaultNamespace release];
[_attributes release];
[_namespaces release];
[_children release];
[super dealloc];
}
|
<
<
<
<
|
363
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
|
[_namespaces
setObject: @"xml"
forKey: @"http://www.w3.org/XML/1998/namespace"];
[_namespaces setObject: @"xmlns"
forKey: @"http://www.w3.org/2000/xmlns/"];
objc_autoreleasePoolPop(pool);
} @catch (id e) {
[self release];
@throw e;
}
return self;
}
- (void)dealloc
{
[_name release];
[_namespace release];
[_attributes release];
[_namespaces release];
[_children release];
[super dealloc];
}
|
︙ | | | ︙ | |
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
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
|
}
[ret makeImmutable];
return ret;
}
- (OFString *)of_XMLStringWithParent: (OFXMLElement *)parent
namespaces: (OFDictionary *)allNS
indentation: (unsigned int)indentation
level: (unsigned int)level OF_DIRECT
{
void *pool;
char *cString;
size_t length, i;
OFString *prefix, *parentPrefix;
OFString *ret;
OFString *defaultNS;
pool = objc_autoreleasePoolPush();
parentPrefix = [allNS objectForKey:
(parent != nil && parent->_namespace != nil
? parent->_namespace : (OFString *)@"")];
/* Add the namespaces of the current element */
if (allNS != nil) {
OFEnumerator *keyEnumerator = [_namespaces keyEnumerator];
OFEnumerator *objectEnumerator = [_namespaces objectEnumerator];
OFMutableDictionary *tmp;
OFString *key, *object;
tmp = [[allNS mutableCopy] autorelease];
while ((key = [keyEnumerator nextObject]) != nil &&
(object = [objectEnumerator nextObject]) != nil)
[tmp setObject: object forKey: key];
allNS = tmp;
} else
allNS = _namespaces;
prefix = [allNS objectForKey:
(_namespace != nil ? _namespace : (OFString *)@"")];
if (parent != nil && parent->_namespace != nil && parentPrefix == nil)
defaultNS = parent->_namespace;
else if (parent != nil && parent->_defaultNamespace != nil)
defaultNS = parent->_defaultNamespace;
else
defaultNS = _defaultNamespace;
i = 0;
length = _name.UTF8StringLength + 3 + (level * indentation);
cString = OFAllocMemory(length, 1);
@try {
memset(cString + i, ' ', level * indentation);
i += level * indentation;
/* Start of tag */
cString[i++] = '<';
if (prefix != nil && ![_namespace isEqual: defaultNS]) {
length += prefix.UTF8StringLength + 1;
cString = OFResizeMemory(cString, length, 1);
memcpy(cString + i, prefix.UTF8String,
prefix.UTF8StringLength);
i += prefix.UTF8StringLength;
cString[i++] = ':';
}
memcpy(cString + i, _name.UTF8String, _name.UTF8StringLength);
i += _name.UTF8StringLength;
/* xmlns if necessary */
if (prefix == nil && ((_namespace != nil &&
![_namespace isEqual: defaultNS]) ||
(_namespace == nil && defaultNS != nil))) {
length += _namespace.UTF8StringLength + 9;
cString = OFResizeMemory(cString, length, 1);
memcpy(cString + i, " xmlns='", 8);
i += 8;
memcpy(cString + i, _namespace.UTF8String,
_namespace.UTF8StringLength);
i += _namespace.UTF8StringLength;
cString[i++] = '\'';
}
/* Attributes */
for (OFXMLAttribute *attribute in _attributes) {
void *pool2 = objc_autoreleasePoolPush();
const char *attributeNameCString =
attribute->_name.UTF8String;
size_t attributeNameLength =
attribute->_name.UTF8StringLength;
OFString *attributePrefix = nil;
OFString *tmp =
attribute.stringValue.stringByXMLEscaping;
char delimiter = (attribute->_useDoubleQuotes
? '"' : '\'');
if (attribute->_namespace != nil &&
(attributePrefix = [allNS objectForKey:
attribute->_namespace]) == nil)
@throw [OFUnboundNamespaceException
exceptionWithNamespace: attribute.namespace
element: self];
length += attributeNameLength + (attributePrefix != nil
? attributePrefix.UTF8StringLength + 1 : 0) +
tmp.UTF8StringLength + 4;
|
|
|
|
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
|
<
>
>
|
|
|
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
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
|
}
[ret makeImmutable];
return ret;
}
- (OFString *)of_XMLStringWithDefaultNS: (OFString *)defaultNS
namespaces: (OFDictionary *)allNS
indentation: (unsigned int)indentation
level: (unsigned int)level OF_DIRECT
{
void *pool;
char *cString;
size_t length, i;
OFString *prefix, *ret;
pool = objc_autoreleasePoolPush();
/* Add the namespaces of the current element */
if (allNS != nil) {
OFEnumerator *keyEnumerator = [_namespaces keyEnumerator];
OFEnumerator *objectEnumerator = [_namespaces objectEnumerator];
OFMutableDictionary *tmp;
OFString *key, *object;
tmp = [[allNS mutableCopy] autorelease];
while ((key = [keyEnumerator nextObject]) != nil &&
(object = [objectEnumerator nextObject]) != nil)
[tmp setObject: object forKey: key];
allNS = tmp;
} else
allNS = _namespaces;
prefix = [allNS objectForKey:
(_namespace != nil ? _namespace : (OFString *)@"")];
i = 0;
length = _name.UTF8StringLength + 3 + (level * indentation);
cString = OFAllocMemory(length, 1);
@try {
memset(cString + i, ' ', level * indentation);
i += level * indentation;
/* Start of tag */
cString[i++] = '<';
if (prefix.length > 0) {
length += prefix.UTF8StringLength + 1;
cString = OFResizeMemory(cString, length, 1);
memcpy(cString + i, prefix.UTF8String,
prefix.UTF8StringLength);
i += prefix.UTF8StringLength;
cString[i++] = ':';
}
memcpy(cString + i, _name.UTF8String, _name.UTF8StringLength);
i += _name.UTF8StringLength;
/* xmlns if necessary */
if (prefix.length == 0 && defaultNS != _namespace &&
![defaultNS isEqual: _namespace]) {
length += _namespace.UTF8StringLength + 9;
cString = OFResizeMemory(cString, length, 1);
memcpy(cString + i, " xmlns='", 8);
i += 8;
memcpy(cString + i, _namespace.UTF8String,
_namespace.UTF8StringLength);
i += _namespace.UTF8StringLength;
cString[i++] = '\'';
defaultNS = _namespace;
}
/* Attributes */
for (OFXMLAttribute *attribute in _attributes) {
void *pool2 = objc_autoreleasePoolPush();
const char *attributeNameCString =
attribute->_name.UTF8String;
size_t attributeNameLength =
attribute->_name.UTF8StringLength;
OFString *attributePrefix = nil;
OFString *tmp =
attribute.stringValue.stringByXMLEscaping;
char delimiter = (attribute->_useDoubleQuotes
? '"' : '\'');
if (attribute->_namespace != nil &&
[(attributePrefix = [allNS objectForKey:
attribute->_namespace]) length] == 0)
@throw [OFUnboundNamespaceException
exceptionWithNamespace: attribute.namespace
element: self];
length += attributeNameLength + (attributePrefix != nil
? attributePrefix.UTF8StringLength + 1 : 0) +
tmp.UTF8StringLength + 4;
|
︙ | | | ︙ | |
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
|
unsigned int ind = (indent ? indentation : 0);
if (ind)
[tmp addItem: "\n"];
if ([child isKindOfClass: [OFXMLElement class]])
childString = [(OFXMLElement *)child
of_XMLStringWithParent: self
namespaces: allNS
indentation: ind
level: level + 1];
else
childString = [child
XMLStringWithIndentation: ind
level: level +
1];
[tmp addItems: childString.UTF8String
count: childString.UTF8StringLength];
}
if (indent)
[tmp addItem: "\n"];
|
|
|
|
|
>
|
|
<
>
|
|
>
|
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
|
unsigned int ind = (indent ? indentation : 0);
if (ind)
[tmp addItem: "\n"];
if ([child isKindOfClass: [OFXMLElement class]])
childString = [(OFXMLElement *)child
of_XMLStringWithDefaultNS: defaultNS
namespaces: allNS
indentation: ind
level: level +
1];
else {
childString = child.XMLString;
for (unsigned int j = 0;
j < ind * (level + 1); j++)
[tmp addItem: " "];
}
[tmp addItems: childString.UTF8String
count: childString.UTF8StringLength];
}
if (indent)
[tmp addItem: "\n"];
|
︙ | | | ︙ | |
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
|
if (indent) {
memset(cString + i, ' ', level * indentation);
i += level * indentation;
}
cString[i++] = '<';
cString[i++] = '/';
if (prefix != nil) {
length += prefix.UTF8StringLength + 1;
cString = OFResizeMemory(cString, length, 1);
memcpy(cString + i, prefix.UTF8String,
prefix.UTF8StringLength);
i += prefix.UTF8StringLength;
cString[i++] = ':';
|
|
|
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
|
if (indent) {
memset(cString + i, ' ', level * indentation);
i += level * indentation;
}
cString[i++] = '<';
cString[i++] = '/';
if (prefix.length > 0) {
length += prefix.UTF8StringLength + 1;
cString = OFResizeMemory(cString, length, 1);
memcpy(cString + i, prefix.UTF8String,
prefix.UTF8StringLength);
i += prefix.UTF8StringLength;
cString[i++] = ':';
|
︙ | | | ︙ | |
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
|
OFFreeMemory(cString);
}
return ret;
}
- (OFString *)XMLString
{
return [self of_XMLStringWithParent: nil
namespaces: nil
indentation: 0
level: 0];
}
- (OFString *)XMLStringWithIndentation: (unsigned int)indentation
{
return [self of_XMLStringWithParent: nil
namespaces: nil
indentation: indentation
level: 0];
}
- (OFString *)XMLStringWithIndentation: (unsigned int)indentation
level: (unsigned int)level
{
return [self of_XMLStringWithParent: nil
namespaces: nil
indentation: indentation
level: level];
}
- (OFXMLElement *)XMLElementBySerializing
{
void *pool = objc_autoreleasePoolPush();
OFXMLElement *element;
element = [OFXMLElement elementWithName: self.className
namespace: OFSerializationNS];
if (_name != nil)
[element addAttributeWithName: @"name" stringValue: _name];
if (_namespace != nil)
[element addAttributeWithName: @"namespace"
stringValue: _namespace];
if (_defaultNamespace != nil)
[element addAttributeWithName: @"defaultNamespace"
stringValue: _defaultNamespace];
if (_attributes != nil) {
OFXMLElement *attributesElement;
attributesElement =
[OFXMLElement elementWithName: @"attributes"
namespace: OFSerializationNS];
[attributesElement addChild:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<
<
<
<
|
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
|
OFFreeMemory(cString);
}
return ret;
}
- (OFString *)XMLString
{
return [self of_XMLStringWithDefaultNS: nil
namespaces: nil
indentation: 0
level: 0];
}
- (OFString *)XMLStringWithIndentation: (unsigned int)indentation
{
return [self of_XMLStringWithDefaultNS: nil
namespaces: nil
indentation: indentation
level: 0];
}
- (OFString *)XMLStringWithDefaultNamespace: (OFString *)defaultNS
indentation: (unsigned int)indentation
{
return [self of_XMLStringWithDefaultNS: defaultNS
namespaces: nil
indentation: indentation
level: 0];
}
- (OFXMLElement *)XMLElementBySerializing
{
void *pool = objc_autoreleasePoolPush();
OFXMLElement *element;
element = [OFXMLElement elementWithName: self.className
namespace: OFSerializationNS];
if (_name != nil)
[element addAttributeWithName: @"name" stringValue: _name];
if (_namespace != nil)
[element addAttributeWithName: @"namespace"
stringValue: _namespace];
if (_attributes != nil) {
OFXMLElement *attributesElement;
attributesElement =
[OFXMLElement elementWithName: @"attributes"
namespace: OFSerializationNS];
[attributesElement addChild:
|
︙ | | | ︙ | |
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
|
}
}
- (void)setPrefix: (OFString *)prefix forNamespace: (OFString *)namespace
{
if (prefix.length == 0)
@throw [OFInvalidArgumentException exception];
if (namespace == nil)
namespace = @"";
[_namespaces setObject: prefix forKey: namespace];
}
- (void)bindPrefix: (OFString *)prefix forNamespace: (OFString *)namespace
{
[self setPrefix: prefix forNamespace: namespace];
|
<
<
|
829
830
831
832
833
834
835
836
837
838
839
840
841
842
|
}
}
- (void)setPrefix: (OFString *)prefix forNamespace: (OFString *)namespace
{
if (prefix.length == 0)
@throw [OFInvalidArgumentException exception];
[_namespaces setObject: prefix forKey: namespace];
}
- (void)bindPrefix: (OFString *)prefix forNamespace: (OFString *)namespace
{
[self setPrefix: prefix forNamespace: namespace];
|
︙ | | | ︙ | |
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
|
element = object;
if (element->_name != _name && ![element->_name isEqual: _name])
return false;
if (element->_namespace != _namespace &&
![element->_namespace isEqual: _namespace])
return false;
if (element->_defaultNamespace != _defaultNamespace &&
![element->_defaultNamespace isEqual: _defaultNamespace])
return false;
if (element->_attributes != _attributes &&
![element->_attributes isEqual: _attributes])
return false;
if (element->_namespaces != _namespaces &&
![element->_namespaces isEqual: _namespaces])
return false;
if (element->_children != _children &&
|
<
<
<
|
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
|
element = object;
if (element->_name != _name && ![element->_name isEqual: _name])
return false;
if (element->_namespace != _namespace &&
![element->_namespace isEqual: _namespace])
return false;
if (element->_attributes != _attributes &&
![element->_attributes isEqual: _attributes])
return false;
if (element->_namespaces != _namespaces &&
![element->_namespaces isEqual: _namespaces])
return false;
if (element->_children != _children &&
|
︙ | | | ︙ | |
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
|
{
unsigned long hash;
OFHashInit(&hash);
OFHashAddHash(&hash, _name.hash);
OFHashAddHash(&hash, _namespace.hash);
OFHashAddHash(&hash, _defaultNamespace.hash);
OFHashAddHash(&hash, _attributes.hash);
OFHashAddHash(&hash, _namespaces.hash);
OFHashAddHash(&hash, _children.hash);
OFHashFinalize(&hash);
return hash;
}
- (id)copy
{
return [[[self class] alloc] initWithElement: self];
}
@end
|
<
>
>
>
>
>
>
>
>
>
>
>
|
>
|
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
|
{
unsigned long hash;
OFHashInit(&hash);
OFHashAddHash(&hash, _name.hash);
OFHashAddHash(&hash, _namespace.hash);
OFHashAddHash(&hash, _attributes.hash);
OFHashAddHash(&hash, _namespaces.hash);
OFHashAddHash(&hash, _children.hash);
OFHashFinalize(&hash);
return hash;
}
- (id)copy
{
OFXMLElement *copy = [[OFXMLElement alloc] of_init];
@try {
copy->_name = [_name copy];
copy->_namespace = [_namespace copy];
copy->_attributes = [_attributes mutableCopy];
copy->_namespaces = [_namespaces mutableCopy];
copy->_children = [_children mutableCopy];
} @catch (id e) {
[copy release];
@throw e;
}
return copy;
}
@end
|