2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "SaxDefaultHandler.h"
23 #include "SaxException.h"
25 @implementation SaxDefaultHandler(NSXML)
27 static BOOL doDebug = NO;
29 - (void)parserDidStartDocument:(id)_parser {
30 if (doDebug) NSLog(@"parser: startdoc %@", _parser);
33 - (void)parserDidEndDocument:(id)_parser {
34 if (doDebug) NSLog(@"parser: endoc %@", _parser);
38 - (id<NSObject,SaxAttributes>)_wrapAttributes:(NSDictionary *)_attrs {
40 return [[SaxAttributes alloc] initWithDictionary:_attrs];
43 - (void)parser:(id)_parser
44 didStartElement:(NSString *)_tag
45 namespaceURI:(NSString *)_nsuri
46 qualifiedName:(NSString *)_rawName
47 attributes:(NSDictionary *)_attrs
49 id<NSObject,SaxAttributes> attrs;
51 if ([_rawName length] == 0) _rawName = _tag;
53 NSLog(@"parser: start %@ raw %@ uri %@", _tag, _rawName, _nsuri);
55 attrs = [self _wrapAttributes:_attrs];
56 [self startElement:_tag namespace:_nsuri rawName:_rawName
61 - (void)parser:(id)_parser
62 didEndElement:(NSString *)_tag
63 namespaceURI:(NSString *)_nsuri
64 qualifiedName:(NSString *)_rawName
66 if ([_rawName length] == 0) _rawName = _tag;
68 NSLog(@"parser: end %@ raw %@ uri %@", _tag, _rawName, _nsuri);
69 [self endElement:_tag namespace:_nsuri rawName:_rawName];
72 - (void)parser:(id)_parser
73 didStartMappingPrefix:(NSString *)_prefix
74 toURI:(NSString *)_uri
76 [self startPrefixMapping:_prefix uri:_uri];
78 - (void)parser:(id)_parser didEndMappingPrefix:(NSString *)_prefix {
79 [self endPrefixMapping:_prefix];
82 - (void)parser:(id)_parser foundCharacters:(NSString *)_string {
83 /* Note: expensive ..., decompose string into chars */
87 if ((len = [_string length]) > 0) {
88 buf = calloc(len + 2, sizeof(unichar));
89 [_string getCharacters:buf];
91 [self characters:buf length:len];
94 - (void)parser:(id)_parser foundIgnorableWhitespace:(NSString *)_ws {
95 /* Note: expensive ..., decompose string into chars */
99 if ((len = [_ws length]) > 0) {
100 buf = calloc(len + 2, sizeof(unichar));
101 [_ws getCharacters:buf];
103 [self ignorableWhitespace:buf length:len];
107 - (void)parser:(id)_parser foundCDATA:(NSData *)_data {
108 /* TODO: what about that? */
109 NSLog(@"ERROR(%s): CDATA section ignored!", __PRETTY_FUNCTION__);
112 #if 0 /* TODO: implement */
113 - (void)parser:(id)_parser foundComment:(NSString *)comment {
117 - (void)parser:(id)_parser
118 foundProcessingInstructionWithTarget:(NSString *)_target
119 data:(NSString *)_data
121 [self processingInstruction:_target data:_data];
124 /* entity resolver */
126 - (NSData *)parser:(id)_parser
127 resolveExternalEntityName:(NSString *)_name
128 systemID:(NSString *)_sysId
130 return [self resolveEntityWithPublicId:_name systemId:_sysId];
135 - (SaxParseException *)_wrapErrorIntoException:(NSError *)_error {
136 // TODO: perform proper wrapping or conversion
140 - (void)parser:(id)_parser parseErrorOccurred:(NSError *)_error {
141 if (doDebug) NSLog(@"parser: error %@", _error);
142 [self error:[self _wrapErrorIntoException:_error]];
144 - (void)parser:(id)_parser validationErrorOccurred:(NSError *)_error {
145 if (doDebug) NSLog(@"parser: validation error %@", _error);
146 [self error:[self _wrapErrorIntoException:_error]];
151 - (void)parser:(id)_parser
152 foundNotationDeclarationWithName:(NSString *)_name
153 publicID:(NSString *)_pubId systemID:(NSString *)_sysId
155 [self notationDeclaration:_name publicId:_pubId systemId:_sysId];
158 - (void)parser:(id)_parser
159 foundUnparsedEntityDeclarationWithName:(NSString *)_name
160 publicID:(NSString *)_pubId systemID:(NSString *)_sysId
161 notationName:(NSString *)_notName
163 [self unparsedEntityDeclaration:_name
164 publicId:_pubId systemId:_sysId
165 notationName:_notName];
168 #if 0 /* TODO: DTD processing ... */
170 - (void)parser:(id)_parser
171 foundAttributeDeclarationWithName:(NSString *)attributeName
172 forElement:(NSString *)_tag type:(NSString *)type
173 defaultValue:(NSString *)defaultValue;
175 - (void)parser:(id)_parser
176 foundElementDeclarationWithName:(NSString *)_tag model:(NSString *)model;
178 - (void)parser:(id)_parser
179 foundInternalEntityDeclarationWithName:(NSString *)name
180 value:(NSString *)value;
182 - (void)parser:(id)_parser
183 foundExternalEntityDeclarationWithName:(NSString *)name
184 publicID:(NSString *)publicID systemID:(NSString *)systemID;
188 @end /* SaxDefaultHandler(NSXML) */