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
28 - (id)initWithGroup:(NSString *)_group types:(NSArray *)_types
29 arguments:(NSDictionary *)_a
31 if ((self = [super init]) != nil) {
32 self->group = [_group copy];
33 self->types = [_types copy];
34 self->arguments = [_a copy];
39 return [self initWithGroup:nil types:nil arguments:nil];
43 [self->group release];
44 [self->types release];
45 [self->arguments release];
57 - (NSDictionary *)arguments {
58 return self->arguments;
61 return [self->types containsObject:@"PREF"];
66 - (NSString *)stringValue {
67 [self logWithFormat:@"ERROR(%s): subclasses should override this method!",
73 return [self stringValue];
76 - (NSString *)xmlString {
77 return [[self stringValue] stringByEscapingXMLString];
80 - (NSString *)vCardString {
81 // TODO: apply proper escaping
82 return [self stringValue];
85 /* misc support methods */
87 - (void)appendXMLTag:(NSString *)_tag value:(NSString *)_val
88 to:(NSMutableString *)_ms
90 [_ms appendString:@"<"];
91 [_ms appendString:_tag];
92 [_ms appendString:@">"];
93 if ([_val isNotNull]) [_ms appendString:[_val stringByEscapingXMLString]];
94 [_ms appendString:@"</"];
95 [_ms appendString:_tag];
96 [_ms appendString:@">"];
99 - (void)appendVCardValue:(NSString *)_val to:(NSMutableString *)_ms {
100 // TODO: properly escape!
101 if ([_val isNotNull]) [_ms appendString:_val];
106 - (id)copyWithZone:(NSZone *)_zone {
107 /* values are considered immutable */
108 return [self retain];
113 - (void)encodeWithCoder:(NSCoder *)_coder {
114 [_coder encodeObject:self->group];
115 [_coder encodeObject:self->types];
116 [_coder encodeObject:self->arguments];
118 - (id)initWithCoder:(NSCoder *)_coder {
119 self->group = [[_coder decodeObject] copy];
120 self->types = [[_coder decodeObject] copy];
121 self->arguments = [[_coder decodeObject] copy];
127 - (void)appendDictionary:(NSDictionary *)_d compactTo:(NSMutableString *)_s {
131 keys = [_d keyEnumerator];
132 while ((k = [keys nextObject]) != nil) {
135 v = [_d objectForKey:k];
136 [_s appendFormat:@"%@='%@';", k, v];
140 - (void)appendAttributesToDescription:(NSMutableString *)_ms {
141 if (self->group != nil) [_ms appendFormat:@" group='%@'", self->group];
142 if ([self->types count] > 0) {
143 [_ms appendFormat:@" types=%@",
144 [self->types componentsJoinedByString:@","]];
146 if ([self->arguments count] > 0) {
147 [_ms appendString:@" args="];
148 [self appendDictionary:self->arguments compactTo:_ms];
152 - (NSString *)description {
153 NSMutableString *str = nil;
155 str = [NSMutableString stringWithCapacity:64];
156 [str appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
157 [self appendAttributesToDescription:str];
158 [str appendString:@">"];
162 @end /* NGVCardValue */