2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
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
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.
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
25 @implementation NSObject(SxXmlRpcValue)
27 - (NSArray *)asXmlRpcArray {
28 if ([self respondsToSelector:@selector(objectEnumerator)]) {
29 return [[[NSArray alloc]
30 initWithObjectsFromEnumerator:
31 [(id)self objectEnumerator]]
37 - (NSDictionary *)asXmlRpcStruct {
38 return [self valuesForKeys:[[self classDescription] attributeKeys]];
41 - (NSString *)asXmlRpcString {
42 return [self stringValue];
45 return [self intValue];
48 - (NSData *)asXmlRpcBase64 {
49 return [[self stringValue] dataUsingEncoding:NSUTF8StringEncoding];
51 - (NSDate *)asXmlRpcDateTime {
52 return [[[NSDate alloc] initWithString:[self stringValue]] autorelease];
55 - (id)asXmlRpcValueOfType:(NSString *)_xmlRpcValueType {
58 if ((len = [_xmlRpcValueType length]) == 0)
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];
77 @end /* NSObject(SxXmlRpcValue) */
79 @implementation NSArray(SxXmlRpcValue)
81 - (NSArray *)asXmlRpcArray {
85 - (id)asXmlRpcValueOfType:(NSString *)_xmlRpcValueType {
89 @end /* NSArray(SxXmlRpcValue) */
91 @implementation NSDictionary(SxXmlRpcValue)
93 - (NSArray *)asXmlRpcArray {
94 return [self allValues];
97 - (NSDictionary *)asXmlRpcStruct {
101 @end /* NSDictionary(SxXmlRpcValue) */
103 @implementation NSDate(SxXmlRpcValue)
105 - (NSDate *)asXmlRpcDateTime {
109 @end /* NSDate(SxXmlRpcValue) */
111 @implementation NSData(SxXmlRpcValue)
113 - (NSData *)asXmlRpcBase64 {
117 @end /* NSCalendarDate(SxXmlRpcValue) */