]> err.no Git - sope/blob - sope-ical/NGiCal/NGVCardStrArrayValue.m
synced with latest gstep-make process
[sope] / sope-ical / NGiCal / NGVCardStrArrayValue.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 "NGVCardStrArrayValue.h"
23 #include "common.h"
24
25 @implementation NGVCardStrArrayValue
26
27 + (int)version {
28   return [super version] + 0 /* v0 */;
29 }
30 + (void)initialize {
31   NSAssert2([super version] == 0,
32             @"invalid superclass (%@) version %i !",
33             NSStringFromClass([self superclass]), [super version]);
34 }
35
36 - (id)initWithArray:(NSArray *)_plist group:(NSString *)_group 
37   types:(NSArray *)_types arguments:(NSDictionary *)_a
38 {
39   if ((self = [super initWithGroup:_group types:_types arguments:_a]) != nil) {
40     self->values = [_plist copy];
41   }
42   return self;
43 }
44
45 - (id)initWithString:(NSString *)_plist group:(NSString *)_group 
46   types:(NSArray *)_types arguments:(NSDictionary *)_a
47 {
48   // TODO: unescaping of commas?
49   return [self initWithArray:[_plist componentsSeparatedByString:@","]
50                group:_group types:_types arguments:_a];
51 }
52
53 - (id)initWithPropertyList:(id)_plist group:(NSString *)_group 
54   types:(NSArray *)_types arguments:(NSDictionary *)_a
55 {
56   if ([_plist isKindOfClass:[NSString class]]) {
57     return [self initWithString:_plist
58                  group:_group types:_types arguments:_a];
59   }
60   if ([_plist isKindOfClass:[NSArray class]]) {
61     return [self initWithArray:_plist
62                  group:_group types:_types arguments:_a];
63   }
64
65   [self logWithFormat:@"ERROR: unexpected property list type: %@",
66           [_plist class]];
67   [self release];
68   return nil;
69 }
70 - (id)initWithPropertyList:(id)_plist {
71   return [self initWithPropertyList:_plist group:nil types:nil arguments:nil];
72 }
73
74 - (id)initWithGroup:(NSString *)_group types:(NSArray *)_types
75   arguments:(NSDictionary *)_a
76 {
77   return [self initWithArray:nil 
78                group:_group types:_types arguments:_a];
79 }
80 - (id)init {
81   return [self initWithPropertyList:nil group:nil types:nil arguments:nil];
82 }
83
84 - (void)dealloc {
85   [self->values release];
86   [super dealloc];
87 }
88
89 /* accessors */
90
91 - (NSArray *)values {
92   return self->values;
93 }
94
95 /* values */
96
97 - (NSString *)stringValue {
98   return [self vCardString];
99 }
100
101 - (NSString *)xmlString {
102   return [[self stringValue] stringByEscapingXMLString];
103 }
104
105 - (NSString *)vCardString {
106   return [[self values] componentsJoinedByString:@","];
107 }
108
109 - (id)propertyList {
110   return [self values];
111 }
112
113 - (NSArray *)asArray {
114   return self->values;
115 }
116
117 /* fake being an array */
118
119 - (id)objectAtIndex:(unsigned)_idx {
120   return [self->values objectAtIndex:_idx];
121 }
122 - (unsigned)count {
123   return [self->values count];
124 }
125
126 /* fake being a string */
127
128 - (unichar)characterAtIndex:(unsigned)_idx {
129   return [[self stringValue] characterAtIndex:_idx];
130 }
131 - (unsigned)length {
132   return [[self stringValue] length];
133 }
134
135 /* NSCoding */
136
137 - (void)encodeWithCoder:(NSCoder *)_coder {
138   [super encodeWithCoder:_coder];
139   [_coder encodeObject:self->values];
140 }
141 - (id)initWithCoder:(NSCoder *)_coder {
142   if ((self = [super initWithCoder:_coder]) != nil) {
143     self->values = [[_coder decodeObject] copy];
144   }
145   return self;
146 }
147
148 /* description */
149
150 - (void)appendAttributesToDescription:(NSMutableString *)_ms {
151   [super appendAttributesToDescription:_ms];
152   [_ms appendFormat:@" vcard=%@", [self vCardString]];
153 }
154
155 @end /* NGVCardStrArrayValue */