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 "NGVCardAddress.h"
25 @implementation NGVCardAddress
28 return [super version] + 0 /* v0 */;
31 NSAssert2([super version] == 0,
32 @"invalid superclass (%@) version %i !",
33 NSStringFromClass([self superclass]), [super version]);
36 - (id)initWithDictionary:(NSDictionary *)_plist group:(NSString *)_group
37 types:(NSArray *)_types arguments:(NSDictionary *)_a
39 if ((self = [super initWithGroup:_group types:_types arguments:_a]) != nil) {
40 self->pobox = [[_plist objectForKey:@"pobox"] copy];
41 self->extadd = [[_plist objectForKey:@"extadd"] copy];
42 self->street = [[_plist objectForKey:@"street"] copy];
43 self->locality = [[_plist objectForKey:@"locality"] copy];
44 self->region = [[_plist objectForKey:@"region"] copy];
45 self->pcode = [[_plist objectForKey:@"pcode"] copy];
46 self->country = [[_plist objectForKey:@"country"] copy];
50 - (id)initWithPropertyList:(id)_plist group:(NSString *)_group
51 types:(NSArray *)_types arguments:(NSDictionary *)_a
53 return [self initWithDictionary:_plist
54 group:_group types:_types arguments:_a];
57 - (id)initWithGroup:(NSString *)_group types:(NSArray *)_types
58 arguments:(NSDictionary *)_a
60 return [self initWithPropertyList:nil
61 group:_group types:_types arguments:_a];
64 return [self initWithPropertyList:nil group:nil types:nil arguments:nil];
68 [self->pobox release];
69 [self->extadd release];
70 [self->street release];
71 [self->locality release];
72 [self->region release];
73 [self->pcode release];
74 [self->country release];
83 - (NSString *)extadd {
86 - (NSString *)street {
89 - (NSString *)locality {
90 return self->locality;
92 - (NSString *)region {
98 - (NSString *)country {
102 /* fake being an array */
104 - (id)objectAtIndex:(unsigned)_idx {
108 case 0: return (s = [self pobox]) ? s : (NSString *)[NSNull null];
109 case 1: return (s = [self extadd]) ? s : (NSString *)[NSNull null];
110 case 2: return (s = [self street]) ? s : (NSString *)[NSNull null];
111 case 3: return (s = [self locality]) ? s : (NSString *)[NSNull null];
112 case 4: return (s = [self region]) ? s : (NSString *)[NSNull null];
113 case 5: return (s = [self pcode]) ? s : (NSString *)[NSNull null];
114 case 6: return (s = [self country]) ? s : (NSString *)[NSNull null];
117 // TODO: throw exception
126 - (NSString *)stringValue {
127 return [self vCardString];
130 - (NSString *)xmlString {
134 ms = [[NSMutableString alloc] initWithCapacity:256];
135 [self appendXMLTag:@"pobox" value:[self pobox] to:ms];
136 [self appendXMLTag:@"extadd" value:[self extadd] to:ms];
137 [self appendXMLTag:@"street" value:[self street] to:ms];
138 [self appendXMLTag:@"locality" value:[self locality] to:ms];
139 [self appendXMLTag:@"region" value:[self region] to:ms];
140 [self appendXMLTag:@"pcode" value:[self pcode] to:ms];
141 [self appendXMLTag:@"country" value:[self country] to:ms];
142 s = [[ms copy] autorelease];
147 - (NSString *)vCardString {
151 ms = [[NSMutableString alloc] initWithCapacity:256];
152 [self appendVCardValue:[self pobox] to:ms]; [ms appendString:@";"];
153 [self appendVCardValue:[self extadd] to:ms]; [ms appendString:@";"];
154 [self appendVCardValue:[self street] to:ms]; [ms appendString:@";"];
155 [self appendVCardValue:[self locality] to:ms]; [ms appendString:@";"];
156 [self appendVCardValue:[self region] to:ms]; [ms appendString:@";"];
157 [self appendVCardValue:[self pcode] to:ms]; [ms appendString:@";"];
158 [self appendVCardValue:[self country] to:ms];
159 s = [[ms copy] autorelease];
164 - (NSDictionary *)asDictionary {
165 static NSString *keys[] = {
166 @"pobox", @"extadd", @"street", @"locality", @"region", @"pcode",
172 for (i = 0; i < [self count]; i++)
173 values[i] = [self objectAtIndex:i];
175 return [NSDictionary dictionaryWithObjects:values forKeys:keys
179 - (NSArray *)asArray {
180 id values[[self count] + 1];
183 for (i = 0; i < [self count]; i++)
184 values[i] = [self objectAtIndex:i];
186 return [NSArray arrayWithObjects:values count:[self count]];
191 - (void)encodeWithCoder:(NSCoder *)_coder {
192 [super encodeWithCoder:_coder];
194 [_coder encodeObject:self->pobox];
195 [_coder encodeObject:self->extadd];
196 [_coder encodeObject:self->street];
197 [_coder encodeObject:self->locality];
198 [_coder encodeObject:self->region];
199 [_coder encodeObject:self->pcode];
200 [_coder encodeObject:self->country];
202 - (id)initWithCoder:(NSCoder *)_coder {
203 if ((self = [super initWithCoder:_coder]) != nil) {
204 self->pobox = [[_coder decodeObject] copy];
205 self->extadd = [[_coder decodeObject] copy];
206 self->street = [[_coder decodeObject] copy];
207 self->locality = [[_coder decodeObject] copy];
208 self->region = [[_coder decodeObject] copy];
209 self->pcode = [[_coder decodeObject] copy];
210 self->country = [[_coder decodeObject] copy];
217 - (void)appendAttributesToDescription:(NSMutableString *)_ms {
218 [super appendAttributesToDescription:_ms];
219 [_ms appendFormat:@" vcard=%@", [self vCardString]];
222 @end /* NGVCardAddress */