@@ -14,12 +14,10 @@ * file. */ #include "config.h" -#define OF_XML_PARSER_M - #include #include #import "OFXMLParser.h" @@ -335,12 +333,14 @@ if ([cache count] > 0) { void *pool = objc_autoreleasePoolPush(); OFString *characters = transform_string(cache, 0, YES, self); - [delegate parser: self - foundCharacters: characters]; + if ([delegate respondsToSelector: + @selector(parser:foundCharacters:)]) + [delegate parser: self + foundCharacters: characters]; objc_autoreleasePoolPop(pool); } [cache removeAllItems]; @@ -503,12 +503,14 @@ if (![self OF_parseXMLProcessingInstructions: pi]) @throw [OFMalformedXMLException exceptionWithClass: [self class] parser: self]; - [delegate parser: self - foundProcessingInstructions: pi]; + if ([delegate respondsToSelector: + @selector(parser:foundProcessingInstructions:)]) + [delegate parser: self + foundProcessingInstructions: pi]; objc_autoreleasePoolPop(pool); [cache removeAllItems]; @@ -562,21 +564,25 @@ if (prefix != nil && ns == nil) @throw [OFUnboundNamespaceException exceptionWithClass: [self class] prefix: prefix]; - [delegate parser: self - didStartElement: name - withPrefix: prefix - namespace: ns - attributes: nil]; + if ([delegate respondsToSelector: @selector(parser: + didStartElement:prefix:namespace:attributes:)]) + [delegate parser: self + didStartElement: name + prefix: prefix + namespace: ns + attributes: nil]; if (buffer[*i] == '/') { - [delegate parser: self - didEndElement: name - withPrefix: prefix - namespace: ns]; + if ([delegate respondsToSelector: + @selector(parser:didEndElement:prefix:namespace:)]) + [delegate parser: self + didEndElement: name + prefix: prefix + namespace: ns]; if ([previous count] == 0) finishedParsing = YES; } else [previous addObject: cacheString]; @@ -649,14 +655,16 @@ if (prefix != nil && ns == nil) @throw [OFUnboundNamespaceException exceptionWithClass: [self class] prefix: prefix]; - [delegate parser: self - didEndElement: name - withPrefix: prefix - namespace: ns]; + if ([delegate respondsToSelector: + @selector(parser:didEndElement:prefix:namespace:)]) + [delegate parser: self + didEndElement: name + prefix: prefix + namespace: ns]; objc_autoreleasePoolPop(pool); [namespaces removeLastObject]; [name release]; @@ -707,21 +715,25 @@ resolve_attribute_namespace(attributesObjects[j], namespaces, self); pool = objc_autoreleasePoolPush(); - [delegate parser: self - didStartElement: name - withPrefix: prefix - namespace: ns - attributes: attributes]; + if ([delegate respondsToSelector: + @selector(parser:didStartElement:prefix:namespace:attributes:)]) + [delegate parser: self + didStartElement: name + prefix: prefix + namespace: ns + attributes: attributes]; if (buffer[*i] == '/') { - [delegate parser: self - didEndElement: name - withPrefix: prefix - namespace: ns]; + if ([delegate respondsToSelector: + @selector(parser:didEndElement:prefix:namespace:)]) + [delegate parser: self + didEndElement: name + prefix: prefix + namespace: ns]; if ([previous count] == 0) finishedParsing = YES; [namespaces removeLastObject]; @@ -950,12 +962,13 @@ pool = objc_autoreleasePoolPush(); cache_append(cache, buffer + *last, encoding, *i - *last); CDATA = transform_string(cache, 2, NO, nil); - [delegate parser: self - foundCDATA: CDATA]; + if ([delegate respondsToSelector: @selector(parser:foundCDATA:)]) + [delegate parser: self + foundCDATA: CDATA]; objc_autoreleasePoolPop(pool); [cache removeAllItems]; @@ -1004,12 +1017,13 @@ pool = objc_autoreleasePoolPush(); cache_append(cache, buffer + *last, encoding, *i - *last); comment = transform_string(cache, 2, NO, nil); - [delegate parser: self - foundComment: comment]; + if ([delegate respondsToSelector: @selector(parser:foundComment:)]) + [delegate parser: self + foundComment: comment]; objc_autoreleasePoolPop(pool); [cache removeAllItems]; @@ -1052,52 +1066,13 @@ } - (OFString*)string: (OFString*)string containsUnknownEntityNamed: (OFString*)entity { - return [delegate parser: self - foundUnknownEntityNamed: entity]; -} -@end - -@implementation OFObject (OFXMLParserDelegate) -- (void)parser: (OFXMLParser*)parser - foundProcessingInstructions: (OFString*)pi -{ -} - -- (void)parser: (OFXMLParser*)parser - didStartElement: (OFString*)name - withPrefix: (OFString*)prefix - namespace: (OFString*)ns - attributes: (OFArray*)attributes -{ -} - -- (void)parser: (OFXMLParser*)parser - didEndElement: (OFString*)name - withPrefix: (OFString*)prefix - namespace: (OFString*)ns -{ -} - -- (void)parser: (OFXMLParser*)parser - foundCharacters: (OFString*)characters -{ -} - -- (void)parser: (OFXMLParser*)parser - foundCDATA: (OFString*)CDATA -{ -} - -- (void)parser: (OFXMLParser*)parser - foundComment: (OFString*)comment -{ -} - -- (OFString*)parser: (OFXMLParser*)parser - foundUnknownEntityNamed: (OFString*)entity -{ + if ([delegate respondsToSelector: + @selector(parser:foundUnknownEntityNamed:)]) + return [delegate parser: self + foundUnknownEntityNamed: entity]; + return nil; } @end