]> err.no Git - scalable-opengroupware.org/blob - SoObjects/SOGo/SOGoDAVRendererTypes.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1088 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / SoObjects / SOGo / SOGoDAVRendererTypes.m
1 /* SOGoDAVRendererTypes.m - this file is part of SOGo
2  *
3  * Copyright (C) 2006 Inverse groupe conseil
4  *
5  * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
6  *
7  * This file is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This file is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; see the file COPYING.  If not, write to
19  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #import <Foundation/NSArray.h>
24 #import <Foundation/NSEnumerator.h>
25 #import <Foundation/NSString.h>
26
27 #import "SOGoDAVRendererTypes.h"
28
29 @implementation SOGoDAVSet
30
31 + (id) davSetWithArray: (NSArray *) newValues
32       ofValuesTaggedAs: (NSString *) newValueTag
33 {
34   id davSet;
35
36   davSet = [self new];
37   [davSet setValueTag: newValueTag];
38   [davSet setValues: newValues];
39   [davSet autorelease];
40
41   return davSet;
42 }
43
44 - (id) init
45 {
46   if ((self = [super init]))
47     {
48       valueTag = nil;
49       values = nil;
50     }
51
52   return self;
53 }
54
55 - (void) dealloc
56 {
57   if (valueTag)
58     [valueTag release];
59   if (values)
60     [values release];
61   [super dealloc];
62 }
63
64 - (void) setValueTag: (NSString *) newValueTag
65 {
66   ASSIGN (valueTag, newValueTag);
67 }
68
69 - (void) setValues: (NSArray *) newValues
70 {
71   ASSIGN (values, newValues);
72 }
73
74 - (NSString *) stringForTag: (NSString *) _key
75                     rawName: (NSString *) setTag
76                   inContext: (id) context
77                    prefixes: (NSDictionary *) prefixes
78 {
79   NSMutableString *resultString;
80   id currentValue;
81   NSString *valueString;
82   NSEnumerator *valueEnum;
83
84   resultString = [NSMutableString new];
85   [resultString autorelease];
86
87   [resultString appendFormat: @"<%@>", setTag];
88   valueEnum = [values objectEnumerator];
89   currentValue = [valueEnum nextObject];
90   while (currentValue)
91     {
92       if ([currentValue isKindOfClass: [SoWebDAVValue class]])
93         valueString
94           = [currentValue stringForTag:
95                             [NSString stringWithFormat: @"{DAV:}%@", valueTag]
96                           rawName: [NSString stringWithFormat: @"D:%@", valueTag]
97                           inContext: context
98                           prefixes: prefixes];
99       else
100         valueString = currentValue;
101
102       [resultString appendFormat: @"<%@>%@</%@>",
103                     valueTag, valueString, valueTag];
104       currentValue = [valueEnum nextObject];
105     }
106   [resultString appendFormat: @"</%@>", setTag];
107
108   NSLog(@"dav rendering for key '%@' and tag '%@':\n", _key, setTag,
109         resultString);
110
111   return resultString;
112 }
113
114 @end