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 "NGVCardValue.h"
23 #include <NGExtensions/NSString+misc.h>
26 @implementation NGVCardValue
29 return [super version] + 0 /* v0 */;
32 - (id)initWithGroup:(NSString *)_group types:(NSArray *)_types
33 arguments:(NSDictionary *)_a
35 if ((self = [super init]) != nil) {
36 self->group = [_group copy];
37 self->types = [_types copy];
38 self->arguments = [_a copy];
43 return [self initWithGroup:nil types:nil arguments:nil];
47 [self->group release];
48 [self->types release];
49 [self->arguments release];
61 - (NSDictionary *)arguments {
62 return self->arguments;
65 return [self->types containsObject:@"PREF"];
70 - (NSString *)stringValue {
71 [self logWithFormat:@"ERROR(%s): subclasses should override this method!",
77 return [self stringValue];
80 - (NSString *)xmlString {
81 return [[self stringValue] stringByEscapingXMLString];
84 - (NSString *)vCardString {
85 // TODO: apply proper escaping
86 return [self stringValue];
89 /* misc support methods */
91 - (void)appendXMLTag:(NSString *)_tag value:(NSString *)_val
92 to:(NSMutableString *)_ms
94 [_ms appendString:@"<"];
95 [_ms appendString:_tag];
96 [_ms appendString:@">"];
97 if ([_val isNotNull]) [_ms appendString:[_val stringByEscapingXMLString]];
98 [_ms appendString:@"</"];
99 [_ms appendString:_tag];
100 [_ms appendString:@">"];
103 - (void)appendVCardValue:(NSString *)_val to:(NSMutableString *)_ms {
104 // TODO: properly escape!
105 if ([_val isNotNull]) [_ms appendString:_val];
110 - (id)copyWithZone:(NSZone *)_zone {
111 /* values are considered immutable */
112 return [self retain];
117 - (void)encodeWithCoder:(NSCoder *)_coder {
118 [_coder encodeObject:self->group];
119 [_coder encodeObject:self->types];
120 [_coder encodeObject:self->arguments];
122 - (id)initWithCoder:(NSCoder *)_coder {
123 self->group = [[_coder decodeObject] copy];
124 self->types = [[_coder decodeObject] copy];
125 self->arguments = [[_coder decodeObject] copy];
131 - (void)appendDictionary:(NSDictionary *)_d compactTo:(NSMutableString *)_s {
135 keys = [_d keyEnumerator];
136 while ((k = [keys nextObject]) != nil) {
139 v = [_d objectForKey:k];
140 [_s appendFormat:@"%@='%@';", k, v];
144 - (void)appendAttributesToDescription:(NSMutableString *)_ms {
145 if (self->group != nil) [_ms appendFormat:@" group='%@'", self->group];
146 if ([self->types count] > 0) {
147 [_ms appendFormat:@" types=%@",
148 [self->types componentsJoinedByString:@","]];
150 if ([self->arguments count] > 0) {
151 [_ms appendString:@" args="];
152 [self appendDictionary:self->arguments compactTo:_ms];
156 - (NSString *)description {
157 NSMutableString *str = nil;
159 str = [NSMutableString stringWithCapacity:64];
160 [str appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
161 [self appendAttributesToDescription:str];
162 [str appendString:@">"];
166 @end /* NGVCardValue */