]> err.no Git - sope/blob - sope-appserver/SxComponents/NSObject+SxXmlRpcValue.m
renamed packages as discussed in the developer list
[sope] / sope-appserver / SxComponents / NSObject+SxXmlRpcValue.m
1 /*
2   Copyright (C) 2000-2003 SKYRIX Software AG
3
4   This file is part of OGo
5
6   OGo 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   OGo 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 OGo; 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 // $Id$
22
23 #include "common.h"
24
25 @implementation NSObject(SxXmlRpcValue)
26
27 - (NSArray *)asXmlRpcArray {
28   if ([self respondsToSelector:@selector(objectEnumerator)]) {
29     return [[[NSArray alloc]
30                       initWithObjectsFromEnumerator:
31                         [(id)self objectEnumerator]]
32                       autorelease];
33   }
34   return nil;
35 }
36
37 - (NSDictionary *)asXmlRpcStruct {
38   return [self valuesForKeys:[[self classDescription] attributeKeys]];
39 }
40
41 - (NSString *)asXmlRpcString {
42   return [self stringValue];
43 }
44 - (int)asXmlRpcInt {
45   return [self intValue];
46 }
47
48 - (NSData *)asXmlRpcBase64 {
49   return [[self stringValue] dataUsingEncoding:NSUTF8StringEncoding];
50 }
51 - (NSDate *)asXmlRpcDateTime {
52   return [[[NSDate alloc] initWithString:[self stringValue]] autorelease];
53 }
54
55 - (id)asXmlRpcValueOfType:(NSString *)_xmlRpcValueType {
56   unsigned len;
57   
58   if ((len = [_xmlRpcValueType length]) == 0)
59     return self;
60
61   if ([_xmlRpcValueType isEqualToString:@"string"])
62     return [self asXmlRpcString];
63   if ([_xmlRpcValueType isEqualToString:@"int"])
64     return [NSNumber numberWithInt:[self asXmlRpcInt]];
65   if ([_xmlRpcValueType isEqualToString:@"array"])
66     return [self asXmlRpcArray];
67   if ([_xmlRpcValueType isEqualToString:@"struct"])
68     return [self asXmlRpcStruct];
69   if ([_xmlRpcValueType isEqualToString:@"datetime"])
70     return [self asXmlRpcDateTime];
71   if ([_xmlRpcValueType isEqualToString:@"base64"])
72     return [self asXmlRpcBase64];
73   
74   return self;
75 }
76
77 @end /* NSObject(SxXmlRpcValue) */
78
79 @implementation NSArray(SxXmlRpcValue)
80
81 - (NSArray *)asXmlRpcArray {
82   return self;
83 }
84
85 - (id)asXmlRpcValueOfType:(NSString *)_xmlRpcValueType {
86   return self;
87 }
88
89 @end /* NSArray(SxXmlRpcValue) */
90
91 @implementation NSDictionary(SxXmlRpcValue)
92
93 - (NSArray *)asXmlRpcArray {
94   return [self allValues];
95 }
96
97 - (NSDictionary *)asXmlRpcStruct {
98   return self;
99 }
100
101 @end /* NSDictionary(SxXmlRpcValue) */
102
103 @implementation NSDate(SxXmlRpcValue)
104
105 - (NSDate *)asXmlRpcDateTime {
106   return self;
107 }
108
109 @end /* NSDate(SxXmlRpcValue) */
110
111 @implementation NSData(SxXmlRpcValue)
112
113 - (NSData *)asXmlRpcBase64 {
114   return self;
115 }
116
117 @end /* NSCalendarDate(SxXmlRpcValue) */