2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
6 OGo 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 OGo 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 OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include "SaxDefaultHandler.h"
24 #include "SaxException.h"
26 @implementation SaxDefaultHandler(NSXML)
28 static BOOL doDebug = NO;
30 - (void)parserDidStartDocument:(id)_parser {
31 if (doDebug) NSLog(@"parser: startdoc %@", _parser);
34 - (void)parserDidEndDocument:(id)_parser {
35 if (doDebug) NSLog(@"parser: endoc %@", _parser);
39 - (id<NSObject,SaxAttributes>)_wrapAttributes:(NSDictionary *)_attrs {
41 return [[SaxAttributes alloc] initWithDictionary:_attrs];
44 - (void)parser:(id)_parser
45 didStartElement:(NSString *)_tag
46 namespaceURI:(NSString *)_nsuri
47 qualifiedName:(NSString *)_rawName
48 attributes:(NSDictionary *)_attrs
50 id<NSObject,SaxAttributes> attrs;
52 if ([_rawName length] == 0) _rawName = _tag;
54 NSLog(@"parser: start %@ raw %@ uri %@", _tag, _rawName, _nsuri);
56 attrs = [self _wrapAttributes:_attrs];
57 [self startElement:_tag namespace:_nsuri rawName:_rawName
62 - (void)parser:(id)_parser
63 didEndElement:(NSString *)_tag
64 namespaceURI:(NSString *)_nsuri
65 qualifiedName:(NSString *)_rawName
67 if ([_rawName length] == 0) _rawName = _tag;
69 NSLog(@"parser: end %@ raw %@ uri %@", _tag, _rawName, _nsuri);
70 [self endElement:_tag namespace:_nsuri rawName:_rawName];
73 - (void)parser:(id)_parser
74 didStartMappingPrefix:(NSString *)_prefix
75 toURI:(NSString *)_uri
77 [self startPrefixMapping:_prefix uri:_uri];
79 - (void)parser:(id)_parser didEndMappingPrefix:(NSString *)_prefix {
80 [self endPrefixMapping:_prefix];
83 - (void)parser:(id)_parser foundCharacters:(NSString *)_string {
84 /* Note: expensive ..., decompose string into chars */
88 if ((len = [_string length]) > 0) {
89 buf = calloc(len + 2, sizeof(unichar));
90 [_string getCharacters:buf];
92 [self characters:buf length:len];
95 - (void)parser:(id)_parser foundIgnorableWhitespace:(NSString *)_ws {
96 /* Note: expensive ..., decompose string into chars */
100 if ((len = [_ws length]) > 0) {
101 buf = calloc(len + 2, sizeof(unichar));
102 [_ws getCharacters:buf];
104 [self ignorableWhitespace:buf length:len];
108 - (void)parser:(id)_parser foundCDATA:(NSData *)_data {
109 /* TODO: what about that? */
110 NSLog(@"ERROR(%s): CDATA section ignored!", __PRETTY_FUNCTION__);
113 #if 0 /* TODO: implement */
114 - (void)parser:(id)_parser foundComment:(NSString *)comment {
118 - (void)parser:(id)_parser
119 foundProcessingInstructionWithTarget:(NSString *)_target
120 data:(NSString *)_data
122 [self processingInstruction:_target data:_data];
125 /* entity resolver */
127 - (NSData *)parser:(id)_parser
128 resolveExternalEntityName:(NSString *)_name
129 systemID:(NSString *)_sysId
131 return [self resolveEntityWithPublicId:_name systemId:_sysId];
136 - (SaxParseException *)_wrapErrorIntoException:(NSError *)_error {
137 // TODO: perform proper wrapping or conversion
141 - (void)parser:(id)_parser parseErrorOccurred:(NSError *)_error {
142 if (doDebug) NSLog(@"parser: error %@", _error);
143 [self error:[self _wrapErrorIntoException:_error]];
145 - (void)parser:(id)_parser validationErrorOccurred:(NSError *)_error {
146 if (doDebug) NSLog(@"parser: validation error %@", _error);
147 [self error:[self _wrapErrorIntoException:_error]];
152 - (void)parser:(id)_parser
153 foundNotationDeclarationWithName:(NSString *)_name
154 publicID:(NSString *)_pubId systemID:(NSString *)_sysId
156 [self notationDeclaration:_name publicId:_pubId systemId:_sysId];
159 - (void)parser:(id)_parser
160 foundUnparsedEntityDeclarationWithName:(NSString *)_name
161 publicID:(NSString *)_pubId systemID:(NSString *)_sysId
162 notationName:(NSString *)_notName
164 [self unparsedEntityDeclaration:_name
165 publicId:_pubId systemId:_sysId
166 notationName:_notName];
169 #if 0 /* TODO: DTD processing ... */
171 - (void)parser:(id)_parser
172 foundAttributeDeclarationWithName:(NSString *)attributeName
173 forElement:(NSString *)_tag type:(NSString *)type
174 defaultValue:(NSString *)defaultValue;
176 - (void)parser:(id)_parser
177 foundElementDeclarationWithName:(NSString *)_tag model:(NSString *)model;
179 - (void)parser:(id)_parser
180 foundInternalEntityDeclarationWithName:(NSString *)name
181 value:(NSString *)value;
183 - (void)parser:(id)_parser
184 foundExternalEntityDeclarationWithName:(NSString *)name
185 publicID:(NSString *)publicID systemID:(NSString *)systemID;
189 @end /* SaxDefaultHandler(NSXML) */