Index: src/OFXMLElementBuilder.m ================================================================== --- src/OFXMLElementBuilder.m +++ src/OFXMLElementBuilder.m @@ -179,8 +179,9 @@ - (void)elementBuilder: (OFXMLElementBuilder*)builder didNotExpectCloseTag: (OFString*)name withPrefix: (OFString*)prefix namespace: (OFString*)ns { - @throw [OFMalformedXMLException newWithClass: [builder class]]; + @throw [OFMalformedXMLException newWithClass: [builder class] + parser: nil]; } @end Index: src/OFXMLParser.m ================================================================== --- src/OFXMLParser.m +++ src/OFXMLParser.m @@ -278,11 +278,12 @@ { size_t len; if (finishedParsing && buf[*i] != ' ' && buf[*i] != '\t' && buf[*i] != '\n' && buf[*i] != '\r' && buf[*i] != '<') - @throw [OFMalformedXMLException newWithClass: isa]; + @throw [OFMalformedXMLException newWithClass: isa + parser: self]; if (buf[*i] != '<') return; if ((len = *i - *last) > 0) @@ -317,11 +318,12 @@ - (void)_parseTagOpenedWithBuffer: (const char*)buf i: (size_t*)i last: (size_t*)last { if (finishedParsing && buf[*i] != '!') - @throw [OFMalformedXMLException newWithClass: isa]; + @throw [OFMalformedXMLException newWithClass: isa + parser: self]; switch (buf[*i]) { case '?': *last = *i + 1; state = OF_XMLPARSER_IN_PROCESSING_INSTRUCTIONS; @@ -503,11 +505,12 @@ name = [cache copy]; prefix = nil; } if (![[previous lastObject] isEqual: cache]) - @throw [OFMalformedXMLException newWithClass: isa]; + @throw [OFMalformedXMLException newWithClass: isa + parser: self]; [previous removeNObjects: 1]; [cache setToCString: ""]; @@ -670,11 +673,12 @@ if (buf[*i] == ' ' || buf[*i] == '\t' || buf[*i] == '\n' || buf[*i] == '\r') return; if (buf[*i] != '\'' && buf[*i] != '"') - @throw [OFMalformedXMLException newWithClass: isa]; + @throw [OFMalformedXMLException newWithClass: isa + parser: self]; delim = buf[*i]; state = OF_XMLPARSER_IN_ATTR_VALUE; } @@ -729,11 +733,12 @@ { if (buf[*i] == '>') { *last = *i + 1; state = OF_XMLPARSER_OUTSIDE_TAG; } else - @throw [OFMalformedXMLException newWithClass: isa]; + @throw [OFMalformedXMLException newWithClass: isa + parser: self]; } /* Expecting closing '>' or space */ - (void)_parseExpectSpaceOrCloseWithBuffer: (const char*)buf i: (size_t*)i @@ -742,20 +747,22 @@ if (buf[*i] == '>') { *last = *i + 1; state = OF_XMLPARSER_OUTSIDE_TAG; } else if (buf[*i] != ' ' && buf[*i] != '\t' && buf[*i] != '\n' && buf[*i] != '\r') - @throw [OFMalformedXMLException newWithClass: isa]; + @throw [OFMalformedXMLException newWithClass: isa + parser: self]; } /* In ') - @throw [OFMalformedXMLException newWithClass: isa]; + @throw [OFMalformedXMLException newWithClass: isa + parser: self]; pool = [[OFAutoreleasePool alloc] init]; [cache appendCStringWithoutUTF8Checking: buf + *last length: *i - *last]; @@ -922,11 +933,12 @@ last: (size_t*)last { if ((level < 6 && buf[*i] != "OCTYPE"[level]) || (level == 6 && buf[*i] != ' ' && buf[*i] != '\t' && buf[*i] != '\n' && buf[*i] != '\r')) - @throw [OFMalformedXMLException newWithClass: isa]; + @throw [OFMalformedXMLException newWithClass: isa + parser: self]; if (level < 7 || buf[*i] == '<') level++; if (buf[*i] == '>') { Index: src/exceptions/OFMalformedXMLException.h ================================================================== --- src/exceptions/OFMalformedXMLException.h +++ src/exceptions/OFMalformedXMLException.h @@ -14,11 +14,40 @@ * file. */ #import "OFException.h" +@class OFXMLParser; + /** - * \brief An exception indicating that a parser encountered malformed or - * invalid XML. + * \brief An exception indicating that a parser encountered malformed XML. */ @interface OFMalformedXMLException: OFException +{ + OFXMLParser *parser; +} + +#ifdef OF_HAVE_PROPERTIES +@property (readonly, nonatomic) OFXMLParser *parser; +#endif + +/** + * \param parser The parser which encountered malformed XML + * \return A new malformed XML exception + */ ++ newWithClass: (Class)class_ + parser: (OFXMLParser*)parser; + +/** + * Initializes an already allocated malformed XML exception. + * + * \param parser The parser which encountered malformed XML + * \return An initialized malformed XML exception + */ +- initWithClass: (Class)class_ + parser: (OFXMLParser*)parser; + +/** + * \return The parser which encountered malformed XML + */ +- (OFXMLParser*)parser; @end Index: src/exceptions/OFMalformedXMLException.m ================================================================== --- src/exceptions/OFMalformedXMLException.m +++ src/exceptions/OFMalformedXMLException.m @@ -16,12 +16,51 @@ #include "config.h" #import "OFMalformedXMLException.h" #import "OFString.h" + +#import "OFNotImplementedException.h" @implementation OFMalformedXMLException ++ newWithClass: (Class)class_ + parser: (OFXMLParser*)parser +{ + return [[self alloc] initWithClass: class_ + parser: parser]; +} + +- initWithClass: (Class)class_ +{ + Class c = isa; + [self release]; + @throw [OFNotImplementedException newWithClass: c + selector: _cmd]; +} + +- initWithClass: (Class)class_ + parser: (OFXMLParser*)parser_ +{ + self = [super initWithClass: class_]; + + @try { + parser = [parser_ retain]; + } @catch (id e) { + [self release]; + @throw e; + } + + return self; +} + +- (void)dealloc +{ + [parser release]; + + [super dealloc]; +} + - (OFString*)description { if (description != nil) return description; @@ -28,6 +67,11 @@ description = [[OFString alloc] initWithFormat: @"The parser in class %@ encountered malformed XML!", inClass]; return description; } + +- (OFXMLParser*)parser +{ + return parser; +} @end