]> err.no Git - sope/blob - sope-ical/NGiCal/NGVCardValue.m
dd4457b9383a5aa5093a2003fc8c0faf89905952
[sope] / sope-ical / NGiCal / NGVCardValue.m
1 /*
2   Copyright (C) 2005 Helge Hess
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 "NGVCardValue.h"
23 #include <NGExtensions/NSString+misc.h>
24 #include "common.h"
25
26 @implementation NGVCardValue
27
28 - (void)dealloc {
29   [self->group     release];
30   [self->types     release];
31   [self->arguments release];
32   [super dealloc];
33 }
34
35 /* accessors */
36
37 - (NSString *)group {
38   return self->group;
39 }
40 - (NSArray *)types {
41   return self->types;
42 }
43 - (NSDictionary *)arguments {
44   return self->arguments;
45 }
46 - (BOOL)isPreferred {
47   return [self->types containsObject:@"PREF"];
48 }
49
50 /* values */
51
52 - (NSString *)stringValue {
53   [self logWithFormat:@"ERROR(%s): subclasses should override this method!",
54         __PRETTY_FUNCTION__];
55   return nil;
56 }
57
58 - (id)propertyList {
59   return [self stringValue];
60 }
61
62 - (NSString *)xmlString {
63   return [[self stringValue] stringByEscapingXMLString];
64 }
65
66 - (NSString *)vCardString {
67   // TODO: apply proper escaping
68   return [self stringValue];
69 }
70
71 /* misc support methods */
72
73 - (void)appendXMLTag:(NSString *)_tag value:(NSString *)_val
74   to:(NSMutableString *)_ms
75 {
76   [_ms appendString:@"<"];
77   [_ms appendString:_tag];
78   [_ms appendString:@">"];
79   if ([_val isNotNull]) [_ms appendString:[_val stringByEscapingXMLString]];
80   [_ms appendString:@"</"];
81   [_ms appendString:_tag];
82   [_ms appendString:@">"];
83 }
84
85 - (void)appendVCardValue:(NSString *)_val to:(NSMutableString *)_ms {
86   // TODO: properly escape!
87   if ([_val isNotNull]) [_ms appendString:_val];
88 }
89
90 /* NSCopying */
91
92 - (id)copyWithZone:(NSZone *)_zone {
93   /* values are considered immutable */
94   return [self retain];
95 }
96
97 /* NSCoding */
98
99 - (void)encodeWithCoder:(NSCoder *)_coder {
100   [_coder encodeObject:self->group];
101   [_coder encodeObject:self->types];
102   [_coder encodeObject:self->arguments];
103 }
104 - (id)initWithCoder:(NSCoder *)_coder {
105   self->group     = [[_coder decodeObject] copy];
106   self->types     = [[_coder decodeObject] copy];
107   self->arguments = [[_coder decodeObject] copy];
108   return self;
109 }
110
111 @end /* NGVCardValue */