]> err.no Git - sope/blob - sope-xml/SaxObjC/SaxDefaultHandler+NSXML.m
use Version file for install locations
[sope] / sope-xml / SaxObjC / SaxDefaultHandler+NSXML.m
1 /*
2   Copyright (C) 2000-2003 SKYRIX Software AG
3
4   This file is part of OGo
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #include "SaxDefaultHandler.h"
24 #include "SaxException.h"
25
26 @implementation SaxDefaultHandler(NSXML)
27
28 static BOOL doDebug = NO;
29
30 - (void)parserDidStartDocument:(id)_parser {
31   if (doDebug) NSLog(@"parser: startdoc %@", _parser);
32   [self startDocument];
33 }
34 - (void)parserDidEndDocument:(id)_parser {
35   if (doDebug) NSLog(@"parser: endoc    %@", _parser);
36   [self endDocument];
37 }
38
39 - (id<NSObject,SaxAttributes>)_wrapAttributes:(NSDictionary *)_attrs {
40   // TODO: implement ..
41   return [[SaxAttributes alloc] initWithDictionary:_attrs];
42 }
43
44 - (void)parser:(id)_parser 
45   didStartElement:(NSString *)_tag 
46   namespaceURI:(NSString *)_nsuri 
47   qualifiedName:(NSString *)_rawName 
48   attributes:(NSDictionary *)_attrs
49 {
50   id<NSObject,SaxAttributes> attrs;
51
52   if ([_rawName length] == 0) _rawName = _tag;
53   if (doDebug) 
54     NSLog(@"parser: start %@ raw %@ uri %@", _tag, _rawName, _nsuri);
55   
56   attrs = [self _wrapAttributes:_attrs];
57   [self startElement:_tag namespace:_nsuri rawName:_rawName
58         attributes:attrs];
59   [attrs release];
60 }
61
62 - (void)parser:(id)_parser 
63   didEndElement:(NSString *)_tag 
64   namespaceURI:(NSString *)_nsuri
65   qualifiedName:(NSString *)_rawName
66 {
67   if ([_rawName length] == 0) _rawName = _tag;
68   if (doDebug) 
69     NSLog(@"parser: end %@ raw %@ uri %@", _tag, _rawName, _nsuri);
70   [self endElement:_tag namespace:_nsuri rawName:_rawName];
71 }
72
73 - (void)parser:(id)_parser 
74   didStartMappingPrefix:(NSString *)_prefix 
75   toURI:(NSString *)_uri
76 {
77   [self startPrefixMapping:_prefix uri:_uri];
78 }
79 - (void)parser:(id)_parser didEndMappingPrefix:(NSString *)_prefix {
80   [self endPrefixMapping:_prefix];
81 }
82
83 - (void)parser:(id)_parser foundCharacters:(NSString *)_string {
84   /* Note: expensive ..., decompose string into chars */
85   int     len;
86   unichar *buf = NULL;
87   
88   if ((len = [_string length]) > 0) {
89     buf = calloc(len + 2, sizeof(unichar));
90     [_string getCharacters:buf];
91   }
92   [self characters:buf length:len];
93   if (buf) free(buf);
94 }
95 - (void)parser:(id)_parser foundIgnorableWhitespace:(NSString *)_ws {
96   /* Note: expensive ..., decompose string into chars */
97   int     len;
98   unichar *buf = NULL;
99   
100   if ((len = [_ws length]) > 0) {
101     buf = calloc(len + 2, sizeof(unichar));
102     [_ws getCharacters:buf];
103   }
104   [self ignorableWhitespace:buf length:len];
105   if (buf) free(buf);
106 }
107
108 - (void)parser:(id)_parser foundCDATA:(NSData *)_data {
109   /* TODO: what about that? */
110   NSLog(@"ERROR(%s): CDATA section ignored!", __PRETTY_FUNCTION__);
111 }
112
113 #if 0 /* TODO: implement */
114 - (void)parser:(id)_parser foundComment:(NSString *)comment {
115 }
116 #endif
117
118 - (void)parser:(id)_parser 
119   foundProcessingInstructionWithTarget:(NSString *)_target 
120   data:(NSString *)_data
121 {
122   [self processingInstruction:_target data:_data];
123 }
124
125 /* entity resolver */
126
127 - (NSData *)parser:(id)_parser 
128   resolveExternalEntityName:(NSString *)_name 
129   systemID:(NSString *)_sysId
130 {
131   return [self resolveEntityWithPublicId:_name systemId:_sysId];
132 }
133
134 /* handle errors */
135
136 - (SaxParseException *)_wrapErrorIntoException:(NSError *)_error {
137   // TODO: perform proper wrapping or conversion
138   return (id)_error;
139 }
140
141 - (void)parser:(id)_parser parseErrorOccurred:(NSError *)_error {
142   if (doDebug) NSLog(@"parser: error %@", _error);
143   [self error:[self _wrapErrorIntoException:_error]];
144 }
145 - (void)parser:(id)_parser validationErrorOccurred:(NSError *)_error {
146   if (doDebug) NSLog(@"parser: validation error %@", _error);
147   [self error:[self _wrapErrorIntoException:_error]];
148 }
149
150 /* DTD processing */
151
152 - (void)parser:(id)_parser 
153   foundNotationDeclarationWithName:(NSString *)_name 
154   publicID:(NSString *)_pubId systemID:(NSString *)_sysId
155 {
156   [self notationDeclaration:_name publicId:_pubId systemId:_sysId];
157 }
158
159 - (void)parser:(id)_parser 
160   foundUnparsedEntityDeclarationWithName:(NSString *)_name 
161   publicID:(NSString *)_pubId systemID:(NSString *)_sysId
162   notationName:(NSString *)_notName
163 {
164   [self unparsedEntityDeclaration:_name
165         publicId:_pubId systemId:_sysId
166         notationName:_notName];
167 }
168
169 #if 0 /* TODO: DTD processing ... */
170
171 - (void)parser:(id)_parser 
172   foundAttributeDeclarationWithName:(NSString *)attributeName 
173   forElement:(NSString *)_tag type:(NSString *)type 
174   defaultValue:(NSString *)defaultValue;
175
176 - (void)parser:(id)_parser 
177   foundElementDeclarationWithName:(NSString *)_tag model:(NSString *)model;
178
179 - (void)parser:(id)_parser 
180   foundInternalEntityDeclarationWithName:(NSString *)name 
181   value:(NSString *)value;
182
183 - (void)parser:(id)_parser 
184   foundExternalEntityDeclarationWithName:(NSString *)name 
185   publicID:(NSString *)publicID systemID:(NSString *)systemID;
186
187 #endif
188
189 @end /* SaxDefaultHandler(NSXML) */