2 Copyright (C) 2005 Helge Hess
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 "NGVCardSaxHandler.h"
25 @implementation NGVCardSaxHandler
28 if (self->content != NULL) free(self->content);
29 [self->vCards release];
30 [self->vCard release];
31 [self->currentGroup release];
37 - (void)resetExceptResult {
38 [self->currentGroup release]; self->currentGroup = nil;
39 [self->vCard release]; self->vCard = nil;
41 if (self->content != NULL) {
46 self->vcs.isInVCardSet = 0;
47 self->vcs.isInVCard = 0;
49 self->vcs.isInGroup = 0;
50 self->vcs.collectContent = 0;
54 [self resetExceptResult];
55 [self->vCards removeAllObjects];
60 - (void)startDocument {
62 if (self->vCards == nil)
63 self->vCards = [[NSMutableArray alloc] initWithCapacity:16];
66 [self resetExceptResult];
71 - (void)startGroup:(NSString *)_name {
72 self->vcs.isInGroup = 1;
73 ASSIGNCOPY(self->currentGroup, _name);
76 self->vcs.isInGroup = 0;
77 [self->currentGroup release]; self->currentGroup = nil;
87 - (void)startVCard:(id<SaxAttributes>)_attrs {
88 self->vcs.isInVCard = 1;
91 self->vcs.isInVCard = 0;
94 - (void)startVCardSet:(id<SaxAttributes>)_attrs {
95 self->vcs.isInVCardSet = 1;
98 self->vcs.isInVCardSet = 0;
103 - (void)startElement:(NSString *)_localName
104 namespace:(NSString *)_ns
105 rawName:(NSString *)_rawName
106 attributes:(id<SaxAttributes>)_attrs
108 if ([_localName isEqualToString:@"group"])
109 [self startGroup:[_attrs valueForName:@"name" uri:_ns]];
110 else if ([_localName isEqualToString:@"n"])
112 else if ([_localName isEqualToString:@"tel"])
114 else if ([_localName isEqualToString:@"vCard"])
115 [self startVCard:_attrs];
116 else if ([_localName isEqualToString:@"vCardSet"])
117 [self startVCardSet:_attrs];
119 if (self->vcs.isInN) {
123 - (void)endElement:(NSString *)_localName
124 namespace:(NSString *)_ns
125 rawName:(NSString *)_rawName
127 if (self->vcs.isInN) {
130 if ([_localName isEqualToString:@"group"])
132 else if ([_localName isEqualToString:@"n"])
134 else if ([_localName isEqualToString:@"tel"])
136 else if ([_localName isEqualToString:@"vCard"])
138 else if ([_localName isEqualToString:@"vCardSet"])
144 - (void)startCollectingContent {
145 if (self->content != NULL) {
147 self->content = NULL;
149 self->vcs.collectContent = 1;
152 - (NSString *)finishCollectingContent {
155 self->vcs.collectContent = 0;
157 if (self->content == NULL)
160 if (self->contentLength == 0)
163 s = [NSString stringWithCharacters:self->content length:self->contentLength];
164 if (self->content != NULL) {
166 self->content = NULL;
171 - (void)characters:(unichar *)_chars length:(int)_len {
172 if (_len == 0 || _chars == NULL)
175 if (self->content == NULL) {
177 self->contentLength = _len;
178 self->content = calloc(_len + 1, sizeof(unichar));
179 memcpy(self->content, _chars, (_len * sizeof(unichar)));
182 /* increase content */
184 realloc(self->content, (self->contentLength + _len+2) * sizeof(unichar));
185 memcpy(&(self->content[self->contentLength]), _chars,
186 (_len * sizeof(unichar)));
187 self->contentLength += _len;
189 self->content[self->contentLength] = 0;
192 @end /* NGVCardSaxHandler */