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