diff --git a/ChangeLog b/ChangeLog index 9a0b1b5eb..c6ffd8341 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2006-07-11 Wolfgang Sourdeau + * UI/Common/NSDictionary+URL.m ([NSDictionary -asURLParameters]): + returns a parameter string to add to a base URL. + + * UI/Common/NSString+URL.m ([NSString + -composeURLWithAction:parameters:andHash:useHash]): new method to + compose a complete URL from an object URL with parameters and an + optional '#' character. + * UI/Common/UIxPageFrame.h: separated interface from UIxPageFrame.m. diff --git a/UI/Common/NSDictionary+URL.h b/UI/Common/NSDictionary+URL.h new file mode 100644 index 000000000..1568b042c --- /dev/null +++ b/UI/Common/NSDictionary+URL.h @@ -0,0 +1,36 @@ +/* NSDictionary+URL.h - this file is part of SOGo + * + * Copyright (C) 2006 Inverse groupe conseil + * + * Author: Wolfgang Sourdeau + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef NSDICTIONARY_URL_H +#define NSDICTIONARY_URL_H + +#import + +@class NSString; + +@interface NSDictionary (SOGoURLExtension) + +- (NSString *) asURLParameters; + +@end + +#endif /* NSDICTIONARY_URL_H */ diff --git a/UI/Common/NSDictionary+URL.m b/UI/Common/NSDictionary+URL.m new file mode 100644 index 000000000..e283b7176 --- /dev/null +++ b/UI/Common/NSDictionary+URL.m @@ -0,0 +1,60 @@ +/* NSDictionary+URL.m - this file is part of SOGo + * + * Copyright (C) 2006 Inverse groupe conseil + * + * Author: Wolfgang Sourdeau + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#import +#import + +#import "NSDictionary+URL.h" + +@implementation NSDictionary (SOGoURLExtension) + +- (NSString *) asURLParameters +{ + NSMutableString *urlParameters; + NSArray *keys; + NSEnumerator *keysEnum; + NSString *currentKey; + BOOL isFirst; + + urlParameters = [NSMutableString new]; + [urlParameters autorelease]; + + keys = [self allKeys]; + if ([keys count] > 0) + { + isFirst = YES; + keysEnum = [keys objectEnumerator]; + currentKey = [keysEnum nextObject]; + while (currentKey) + { + [urlParameters appendFormat: @"%@%@=%@", + ((isFirst) ? @"?" : @"&"), + currentKey, [self objectForKey: currentKey]]; + isFirst = NO; + currentKey = [keysEnum nextObject]; + } + } + + return urlParameters; +} + +@end diff --git a/UI/Common/NSString+URL.h b/UI/Common/NSString+URL.h new file mode 100644 index 000000000..13926c254 --- /dev/null +++ b/UI/Common/NSString+URL.h @@ -0,0 +1,37 @@ +/* NSString+URL.h - this file is part of SOGo + * + * Copyright (C) 2006 Inverse groupe conseil + * + * Author: Wolfgang Sourdeau + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef NSSTRING_URL_H +#define NSSTRING_URL_H + +#import + +@class NSDictionary; + +@interface NSString (SOGoURLExtension) + +- (NSString *) composeURLWithAction: (NSString *) action + parameters: (NSDictionary *) urlParameters + andHash: (BOOL) useHash; +@end + +#endif /* NSSTRING_URL_H */ diff --git a/UI/Common/NSString+URL.m b/UI/Common/NSString+URL.m new file mode 100644 index 000000000..ca5728f76 --- /dev/null +++ b/UI/Common/NSString+URL.m @@ -0,0 +1,26 @@ +#import "NSString+URL.h" +#import "NSDictionary+URL.h" + +@implementation NSString (SOGoURLExtension) + +- (NSString *) composeURLWithAction: (NSString *) action + parameters: (NSDictionary *) urlParameters + andHash: (BOOL) useHash +{ + NSMutableString *completeURL; + + completeURL = [NSMutableString new]; + [completeURL autorelease]; + + [completeURL appendString: self]; + if (![completeURL hasSuffix: @"/"]) + [completeURL appendString: @"/"]; + [completeURL appendString: action]; + [completeURL appendString: [urlParameters asURLParameters]]; + if (useHash) + [completeURL appendString: @"#"]; + + return completeURL; +} + +@end