2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2004 SKYRIX Software AG
|
|
|
|
|
|
|
|
This file is part of OpenGroupware.org.
|
|
|
|
|
|
|
|
OGo is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License as published by the
|
|
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
later version.
|
|
|
|
|
|
|
|
OGo 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 Lesser General Public
|
|
|
|
License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with OGo; see the file COPYING. If not, write to the
|
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2007-04-11 21:51:07 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2007-04-11 21:08:58 +02:00
|
|
|
#import <Foundation/NSException.h>
|
2008-07-04 18:06:09 +02:00
|
|
|
#import <Foundation/NSEnumerator.h>
|
2007-04-11 21:08:58 +02:00
|
|
|
#import <Foundation/NSKeyValueCoding.h>
|
2007-04-11 22:10:21 +02:00
|
|
|
#import <Foundation/NSPathUtilities.h>
|
2008-11-04 20:55:50 +01:00
|
|
|
#import <Foundation/NSString.h>
|
2007-11-06 22:24:22 +01:00
|
|
|
|
2009-07-14 19:20:49 +02:00
|
|
|
#import <Main/build.h>
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
#import <NGObjWeb/SoHTTPAuthenticator.h>
|
2007-04-11 21:08:58 +02:00
|
|
|
#import <NGObjWeb/SoObjects.h>
|
2006-07-29 00:59:11 +02:00
|
|
|
#import <NGObjWeb/WOResourceManager.h>
|
2007-04-11 21:08:58 +02:00
|
|
|
#import <NGObjWeb/WORequest.h>
|
2007-11-06 22:24:22 +01:00
|
|
|
#import <NGObjWeb/WOResponse.h>
|
2007-04-11 21:08:58 +02:00
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
|
|
|
#import <NGExtensions/NSString+misc.h>
|
|
|
|
#import <NGExtensions/NSURL+misc.h>
|
2007-11-06 22:24:22 +01:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <SOGo/NSCalendarDate+SOGo.h>
|
|
|
|
#import <SOGo/NSObject+Utilities.h>
|
|
|
|
#import <SOGo/NSString+Utilities.h>
|
|
|
|
#import <SOGo/SOGoContentObject.h>
|
|
|
|
#import <SOGo/SOGoObject.h>
|
|
|
|
#import <SOGo/SOGoPermissions.h>
|
|
|
|
#import <SOGo/SOGoSystemDefaults.h>
|
|
|
|
#import <SOGo/SOGoUser.h>
|
|
|
|
#import <SOGo/SOGoUserDefaults.h>
|
2006-10-12 18:44:40 +02:00
|
|
|
|
2007-04-11 21:08:58 +02:00
|
|
|
#import "UIxJSClose.h"
|
2006-10-03 18:16:22 +02:00
|
|
|
|
2007-11-06 22:24:22 +01:00
|
|
|
#import "UIxComponent.h"
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
@interface UIxComponent (PrivateAPI)
|
|
|
|
- (void)_parseQueryString:(NSString *)_s;
|
|
|
|
- (NSMutableDictionary *)_queryParameters;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation UIxComponent
|
|
|
|
|
|
|
|
static NSMutableArray *dayLabelKeys = nil;
|
|
|
|
static NSMutableArray *abbrDayLabelKeys = nil;
|
|
|
|
static NSMutableArray *monthLabelKeys = nil;
|
|
|
|
static NSMutableArray *abbrMonthLabelKeys = nil;
|
|
|
|
|
|
|
|
+ (int)version {
|
|
|
|
return [super version] + 0 /* v2 */;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (void)initialize {
|
|
|
|
NSAssert2([super version] == 2,
|
|
|
|
@"invalid superclass (%@) version %i !",
|
|
|
|
NSStringFromClass([self superclass]), [super version]);
|
|
|
|
|
|
|
|
if (dayLabelKeys == nil) {
|
|
|
|
dayLabelKeys = [[NSMutableArray alloc] initWithCapacity:7];
|
|
|
|
[dayLabelKeys addObject:@"Sunday"];
|
|
|
|
[dayLabelKeys addObject:@"Monday"];
|
|
|
|
[dayLabelKeys addObject:@"Tuesday"];
|
|
|
|
[dayLabelKeys addObject:@"Wednesday"];
|
|
|
|
[dayLabelKeys addObject:@"Thursday"];
|
|
|
|
[dayLabelKeys addObject:@"Friday"];
|
|
|
|
[dayLabelKeys addObject:@"Saturday"];
|
|
|
|
|
|
|
|
abbrDayLabelKeys = [[NSMutableArray alloc] initWithCapacity:7];
|
|
|
|
[abbrDayLabelKeys addObject:@"a2_Sunday"];
|
|
|
|
[abbrDayLabelKeys addObject:@"a2_Monday"];
|
|
|
|
[abbrDayLabelKeys addObject:@"a2_Tuesday"];
|
|
|
|
[abbrDayLabelKeys addObject:@"a2_Wednesday"];
|
|
|
|
[abbrDayLabelKeys addObject:@"a2_Thursday"];
|
|
|
|
[abbrDayLabelKeys addObject:@"a2_Friday"];
|
|
|
|
[abbrDayLabelKeys addObject:@"a2_Saturday"];
|
|
|
|
|
|
|
|
monthLabelKeys = [[NSMutableArray alloc] initWithCapacity:12];
|
|
|
|
[monthLabelKeys addObject:@"January"];
|
|
|
|
[monthLabelKeys addObject:@"February"];
|
|
|
|
[monthLabelKeys addObject:@"March"];
|
|
|
|
[monthLabelKeys addObject:@"April"];
|
|
|
|
[monthLabelKeys addObject:@"May"];
|
|
|
|
[monthLabelKeys addObject:@"June"];
|
|
|
|
[monthLabelKeys addObject:@"July"];
|
|
|
|
[monthLabelKeys addObject:@"August"];
|
|
|
|
[monthLabelKeys addObject:@"September"];
|
|
|
|
[monthLabelKeys addObject:@"October"];
|
|
|
|
[monthLabelKeys addObject:@"November"];
|
|
|
|
[monthLabelKeys addObject:@"December"];
|
|
|
|
|
|
|
|
abbrMonthLabelKeys = [[NSMutableArray alloc] initWithCapacity:12];
|
|
|
|
[abbrMonthLabelKeys addObject:@"a3_January"];
|
|
|
|
[abbrMonthLabelKeys addObject:@"a3_February"];
|
|
|
|
[abbrMonthLabelKeys addObject:@"a3_March"];
|
|
|
|
[abbrMonthLabelKeys addObject:@"a3_April"];
|
|
|
|
[abbrMonthLabelKeys addObject:@"a3_May"];
|
|
|
|
[abbrMonthLabelKeys addObject:@"a3_June"];
|
|
|
|
[abbrMonthLabelKeys addObject:@"a3_July"];
|
|
|
|
[abbrMonthLabelKeys addObject:@"a3_August"];
|
|
|
|
[abbrMonthLabelKeys addObject:@"a3_September"];
|
|
|
|
[abbrMonthLabelKeys addObject:@"a3_October"];
|
|
|
|
[abbrMonthLabelKeys addObject:@"a3_November"];
|
|
|
|
[abbrMonthLabelKeys addObject:@"a3_December"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-05 16:53:38 +02:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
2006-09-05 22:13:16 +02:00
|
|
|
_selectedDate = nil;
|
2008-09-02 04:53:34 +02:00
|
|
|
queryParameters = nil;
|
2006-09-05 16:53:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2007-06-27 23:25:40 +02:00
|
|
|
[queryParameters release];
|
|
|
|
[_selectedDate release];
|
2006-06-15 21:34:10 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* query parameters */
|
|
|
|
|
2006-09-19 23:09:57 +02:00
|
|
|
- (void) _parseQueryString: (NSString *) _s
|
2006-09-05 22:41:05 +02:00
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSEnumerator *e;
|
|
|
|
NSString *part;
|
2006-09-05 22:41:05 +02:00
|
|
|
NSRange r;
|
|
|
|
NSString *key, *value;
|
2006-07-11 19:43:58 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
e = [[_s componentsSeparatedByString:@"&"] objectEnumerator];
|
2009-06-04 17:08:03 +02:00
|
|
|
while ((part = [e nextObject]))
|
2006-09-05 22:41:05 +02:00
|
|
|
{
|
|
|
|
r = [part rangeOfString:@"="];
|
|
|
|
if (r.length == 0)
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
/* missing value of query parameter */
|
2009-06-04 17:08:03 +02:00
|
|
|
key = [part stringByUnescapingURL];
|
2006-09-05 22:41:05 +02:00
|
|
|
value = @"1";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-06-04 17:08:03 +02:00
|
|
|
key = [[part substringToIndex:r.location] stringByUnescapingURL];
|
2006-09-05 22:41:05 +02:00
|
|
|
value = [[part substringFromIndex:(r.location + r.length)]
|
|
|
|
stringByUnescapingURL];
|
|
|
|
}
|
2009-06-04 17:08:03 +02:00
|
|
|
if (key && value)
|
|
|
|
[queryParameters setObject:value forKey:key];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
}
|
2006-09-05 22:41:05 +02:00
|
|
|
|
|
|
|
- (void) addKeepAliveFormValuesToQueryParameters
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-09-05 22:41:05 +02:00
|
|
|
- (NSString *) queryParameterForKey: (NSString *) _key
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [[self _queryParameters] objectForKey:_key];
|
|
|
|
}
|
|
|
|
|
2006-09-05 22:41:05 +02:00
|
|
|
- (void) setQueryParameter: (NSString *) _param
|
|
|
|
forKey: (NSString *) _key
|
|
|
|
{
|
|
|
|
if (_key)
|
|
|
|
{
|
|
|
|
if (_param)
|
|
|
|
[[self _queryParameters] setObject: _param forKey: _key];
|
|
|
|
else
|
|
|
|
[[self _queryParameters] removeObjectForKey: _key];
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-09-05 22:41:05 +02:00
|
|
|
- (NSMutableDictionary *) _queryParameters
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
// TODO: this code is weird, should use WORequest methods for parsing
|
|
|
|
WORequest *req;
|
|
|
|
NSString *uri;
|
|
|
|
NSRange r;
|
2006-09-05 22:41:05 +02:00
|
|
|
NSString *qs;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-06-27 23:25:40 +02:00
|
|
|
if (queryParameters)
|
|
|
|
return queryParameters;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-06-27 23:25:40 +02:00
|
|
|
queryParameters = [[NSMutableDictionary alloc] initWithCapacity:8];
|
2006-07-11 19:43:58 +02:00
|
|
|
|
2007-08-23 18:12:16 +02:00
|
|
|
req = [context request];
|
2006-06-15 21:34:10 +02:00
|
|
|
uri = [req uri];
|
|
|
|
r = [uri rangeOfString:@"?" options:NSBackwardsSearch];
|
2006-09-05 22:41:05 +02:00
|
|
|
if (r.length > 0)
|
|
|
|
{
|
|
|
|
qs = [uri substringFromIndex:NSMaxRange(r)];
|
|
|
|
[self _parseQueryString:qs];
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
/* add form values */
|
|
|
|
[self addKeepAliveFormValuesToQueryParameters];
|
|
|
|
|
2007-06-27 23:25:40 +02:00
|
|
|
return queryParameters;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-09-05 22:41:05 +02:00
|
|
|
- (NSDictionary *) queryParameters
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
return [self _queryParameters];
|
|
|
|
}
|
|
|
|
|
2006-09-05 22:41:05 +02:00
|
|
|
- (NSDictionary *) queryParametersBySettingSelectedDate: (NSCalendarDate *) _date
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSMutableDictionary *qp;
|
|
|
|
|
|
|
|
qp = [[self queryParameters] mutableCopy];
|
|
|
|
[self setSelectedDateQueryParameter:_date inDictionary:qp];
|
|
|
|
return [qp autorelease];
|
|
|
|
}
|
|
|
|
|
2006-09-05 22:41:05 +02:00
|
|
|
- (void) setSelectedDateQueryParameter: (NSCalendarDate *) _newDate
|
|
|
|
inDictionary: (NSMutableDictionary *) _qp
|
2006-06-15 21:34:10 +02:00
|
|
|
{
|
2008-11-04 20:55:50 +01:00
|
|
|
NSString *day;
|
|
|
|
|
2006-09-05 22:41:05 +02:00
|
|
|
if (_newDate)
|
2008-11-04 20:55:50 +01:00
|
|
|
{
|
|
|
|
day = [self dateStringForDate: _newDate];
|
|
|
|
[_qp setObject: day forKey: @"day"];
|
|
|
|
[_qp setObject: [day substringToIndex: 6] forKey: @"month"];
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
else
|
2008-11-04 20:55:50 +01:00
|
|
|
{
|
|
|
|
[_qp removeObjectForKey:@"day"];
|
|
|
|
[_qp removeObjectForKey:@"month"];
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-09-05 22:41:05 +02:00
|
|
|
- (NSString *) completeHrefForMethod: (NSString *) _method
|
|
|
|
{
|
|
|
|
WOContext *ctx;
|
2006-06-15 21:34:10 +02:00
|
|
|
NSDictionary *qp;
|
2006-09-05 22:41:05 +02:00
|
|
|
NSString *qs, *qps, *href;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
qp = [self queryParameters];
|
2006-09-05 22:41:05 +02:00
|
|
|
if ([qp count] > 0)
|
|
|
|
{
|
2007-08-23 18:12:16 +02:00
|
|
|
ctx = context;
|
2006-09-05 22:41:05 +02:00
|
|
|
qps = [ctx queryPathSeparator];
|
|
|
|
[ctx setQueryPathSeparator: @"&"];
|
|
|
|
qs = [ctx queryStringFromDictionary: qp];
|
|
|
|
[ctx setQueryPathSeparator: qps];
|
|
|
|
href = [_method stringByAppendingFormat:@"?%@", qs];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
href = _method;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-09-05 22:41:05 +02:00
|
|
|
return href;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-09-05 22:41:05 +02:00
|
|
|
- (NSString *) ownMethodName
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSString *uri;
|
|
|
|
NSRange r;
|
|
|
|
|
2007-08-23 18:12:16 +02:00
|
|
|
uri = [[context request] uri];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
/* first: cut off query parameters */
|
|
|
|
|
|
|
|
r = [uri rangeOfString:@"?" options:NSBackwardsSearch];
|
|
|
|
if (r.length > 0)
|
|
|
|
uri = [uri substringToIndex:r.location];
|
|
|
|
|
|
|
|
/* next: strip trailing slash */
|
2007-03-18 16:13:57 +01:00
|
|
|
|
2006-09-05 22:41:05 +02:00
|
|
|
if ([uri hasSuffix: @"/"])
|
|
|
|
uri = [uri substringToIndex: ([uri length] - 1)];
|
|
|
|
r = [uri rangeOfString:@"/" options: NSBackwardsSearch];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
/* then: cut of last path component */
|
|
|
|
|
|
|
|
if (r.length == 0) // no slash? are we at root?
|
|
|
|
return @"/";
|
|
|
|
|
2006-09-05 22:41:05 +02:00
|
|
|
return [uri substringFromIndex: (r.location + 1)];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-09-07 16:13:03 +02:00
|
|
|
- (NSString *) userFolderPath
|
2006-07-29 00:59:11 +02:00
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
WOContext *ctx;
|
2006-09-07 16:13:03 +02:00
|
|
|
NSEnumerator *objects;
|
|
|
|
SOGoObject *currentObject;
|
|
|
|
BOOL found;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-08-23 18:12:16 +02:00
|
|
|
ctx = context;
|
2006-09-07 16:13:03 +02:00
|
|
|
objects = [[ctx objectTraversalStack] objectEnumerator];
|
|
|
|
currentObject = [objects nextObject];
|
|
|
|
found = NO;
|
|
|
|
while (currentObject
|
|
|
|
&& !found)
|
|
|
|
if ([currentObject isKindOfClass: [SOGoUserFolder class]])
|
|
|
|
found = YES;
|
|
|
|
else
|
|
|
|
currentObject = [objects nextObject];
|
|
|
|
|
2007-02-09 17:53:05 +01:00
|
|
|
return [[currentObject baseURLInContext:ctx] hostlessURL];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (NSString *) applicationPath
|
2009-11-10 22:39:40 +01:00
|
|
|
{
|
|
|
|
NSString *appName;
|
|
|
|
|
|
|
|
appName = [[context request] applicationName];
|
|
|
|
|
|
|
|
return [NSString stringWithFormat: @"/%@", appName];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) modulePath
|
2006-07-29 00:59:11 +02:00
|
|
|
{
|
2006-09-07 00:25:46 +02:00
|
|
|
SOGoObject *currentClient, *parent;
|
|
|
|
BOOL found;
|
2008-05-03 00:51:49 +02:00
|
|
|
Class objectClass, userFolderClass;
|
|
|
|
// , groupFolderClass
|
2006-09-07 00:25:46 +02:00
|
|
|
|
|
|
|
currentClient = [self clientObject];
|
2007-09-07 00:16:30 +02:00
|
|
|
if (currentClient
|
|
|
|
&& [currentClient isKindOfClass: [SOGoObject class]])
|
2006-09-07 00:25:46 +02:00
|
|
|
{
|
2008-05-03 00:51:49 +02:00
|
|
|
// groupFolderClass = [SOGoCustomGroupFolder class];
|
2007-09-07 00:16:30 +02:00
|
|
|
userFolderClass = [SOGoUserFolder class];
|
|
|
|
|
|
|
|
objectClass = [currentClient class];
|
2008-05-03 00:51:49 +02:00
|
|
|
// found = (objectClass == groupFolderClass || objectClass == userFolderClass);
|
|
|
|
found = (objectClass == userFolderClass);
|
2007-09-07 00:16:30 +02:00
|
|
|
while (!found && currentClient)
|
|
|
|
{
|
|
|
|
parent = [currentClient container];
|
|
|
|
objectClass = [parent class];
|
2008-05-03 00:51:49 +02:00
|
|
|
if (// objectClass == groupFolderClass
|
|
|
|
// ||
|
|
|
|
objectClass == userFolderClass)
|
2007-09-07 00:16:30 +02:00
|
|
|
found = YES;
|
|
|
|
else
|
|
|
|
currentClient = parent;
|
|
|
|
}
|
2006-09-07 00:25:46 +02:00
|
|
|
}
|
2007-09-07 00:16:30 +02:00
|
|
|
else
|
|
|
|
currentClient = [WOApplication application];
|
2006-09-07 00:25:46 +02:00
|
|
|
|
2007-09-07 00:16:30 +02:00
|
|
|
return [[currentClient baseURLInContext: context] hostlessURL];
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) resourcesPath
|
|
|
|
{
|
|
|
|
WOResourceManager *rm;
|
|
|
|
|
|
|
|
if ((rm = [self resourceManager]) == nil)
|
|
|
|
rm = [[WOApplication application] resourceManager];
|
|
|
|
|
|
|
|
return [rm webServerResourcesPath];
|
|
|
|
}
|
|
|
|
|
2006-09-05 22:41:05 +02:00
|
|
|
- (NSString *) ownPath
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSString *uri;
|
|
|
|
NSRange r;
|
|
|
|
|
2007-08-23 18:12:16 +02:00
|
|
|
uri = [[context request] uri];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
/* first: cut off query parameters */
|
|
|
|
|
|
|
|
r = [uri rangeOfString:@"?" options:NSBackwardsSearch];
|
|
|
|
if (r.length > 0)
|
|
|
|
uri = [uri substringToIndex:r.location];
|
2006-09-05 22:41:05 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return uri;
|
|
|
|
}
|
|
|
|
|
2006-09-05 22:41:05 +02:00
|
|
|
- (NSString *) relativePathToUserFolderSubPath: (NSString *) _sub
|
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
NSString *dst, *rel;
|
|
|
|
|
2007-04-11 21:51:07 +02:00
|
|
|
dst = [[self userFolderPath] stringByAppendingPathComponent: _sub];
|
2006-06-15 21:34:10 +02:00
|
|
|
rel = [dst urlPathRelativeToPath:[self ownPath]];
|
2006-09-05 22:41:05 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
return rel;
|
|
|
|
}
|
2006-09-07 16:13:03 +02:00
|
|
|
|
2006-10-04 21:21:45 +02:00
|
|
|
- (NSCalendarDate *) selectedDate
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoUserDefaults *ud;
|
2007-04-11 21:08:58 +02:00
|
|
|
|
2006-10-04 21:21:45 +02:00
|
|
|
if (!_selectedDate)
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
ud = [[context activeUser] userDefaults];
|
2006-10-04 21:21:45 +02:00
|
|
|
_selectedDate
|
2006-10-05 01:13:09 +02:00
|
|
|
= [NSCalendarDate
|
|
|
|
dateFromShortDateString: [self queryParameterForKey: @"day"]
|
|
|
|
andShortTimeString: [self queryParameterForKey: @"hm"]
|
2009-11-29 05:19:32 +01:00
|
|
|
inTimeZone: [ud timeZone]];
|
2006-09-05 22:13:16 +02:00
|
|
|
[_selectedDate retain];
|
2006-09-05 20:42:18 +02:00
|
|
|
}
|
|
|
|
|
2006-09-05 22:13:16 +02:00
|
|
|
return _selectedDate;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-09-19 23:09:57 +02:00
|
|
|
- (NSString *) dateStringForDate: (NSCalendarDate *) _date
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoUserDefaults *ud;
|
2007-04-11 21:08:58 +02:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
ud = [[context activeUser] userDefaults];
|
|
|
|
[_date setTimeZone: [ud timeZone]];
|
2006-09-19 23:09:57 +02:00
|
|
|
|
2007-09-11 21:32:52 +02:00
|
|
|
return [_date descriptionWithCalendarFormat: @"%Y%m%d"];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (BOOL) hideFrame
|
|
|
|
{
|
|
|
|
return ([[self queryParameterForKey: @"noframe"] boolValue]);
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-10-12 18:44:40 +02:00
|
|
|
- (UIxComponent *) jsCloseWithRefreshMethod: (NSString *) methodName
|
|
|
|
{
|
|
|
|
UIxJSClose *jsClose;
|
|
|
|
|
|
|
|
jsClose = [UIxJSClose new];
|
|
|
|
[jsClose autorelease];
|
|
|
|
[jsClose setRefreshMethod: methodName];
|
|
|
|
|
|
|
|
return jsClose;
|
|
|
|
}
|
|
|
|
|
2007-11-09 17:40:15 +01:00
|
|
|
/* common conditions */
|
|
|
|
- (BOOL) canCreateOrModify
|
|
|
|
{
|
|
|
|
SoSecurityManager *sm;
|
|
|
|
|
|
|
|
sm = [SoSecurityManager sharedSecurityManager];
|
|
|
|
|
|
|
|
return (![sm validatePermission: SoPerm_ChangeImagesAndFiles
|
|
|
|
onObject: [self clientObject]
|
|
|
|
inContext: context]);
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* SoUser */
|
|
|
|
|
2006-09-05 22:41:05 +02:00
|
|
|
- (NSString *) shortUserNameForDisplay
|
|
|
|
{
|
2007-09-05 16:55:58 +02:00
|
|
|
return [[context activeUser] login];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* labels */
|
|
|
|
|
2006-09-05 22:41:05 +02:00
|
|
|
- (NSString *) labelForKey: (NSString *) _str
|
2006-08-15 22:56:38 +02:00
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
WOResourceManager *rm;
|
2006-09-05 22:41:05 +02:00
|
|
|
NSArray *languages;
|
|
|
|
NSString *lKey, *lTable, *lVal;
|
2006-06-15 21:34:10 +02:00
|
|
|
NSRange r;
|
|
|
|
|
|
|
|
if ([_str length] == 0)
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
/* lookup languages */
|
|
|
|
|
2007-08-23 18:12:16 +02:00
|
|
|
languages = [context resourceLookupLanguages];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
/* find resource manager */
|
|
|
|
|
2006-08-22 00:23:47 +02:00
|
|
|
if ((rm = [self pageResourceManager]) == nil)
|
2006-06-15 21:34:10 +02:00
|
|
|
rm = [[WOApplication application] resourceManager];
|
|
|
|
if (rm == nil)
|
|
|
|
[self warnWithFormat:@"missing resource manager!"];
|
|
|
|
|
|
|
|
/* get parameters */
|
|
|
|
|
|
|
|
r = [_str rangeOfString:@"/"];
|
|
|
|
if (r.length > 0) {
|
|
|
|
lTable = [_str substringToIndex:r.location];
|
|
|
|
lKey = [_str substringFromIndex:(r.location + r.length)];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lTable = nil;
|
|
|
|
lKey = _str;
|
|
|
|
}
|
|
|
|
lVal = lKey;
|
|
|
|
|
|
|
|
if ([lKey hasPrefix:@"$"])
|
|
|
|
lKey = [self valueForKeyPath:[lKey substringFromIndex:1]];
|
|
|
|
|
|
|
|
if ([lTable hasPrefix:@"$"])
|
|
|
|
lTable = [self valueForKeyPath:[lTable substringFromIndex:1]];
|
|
|
|
|
|
|
|
/* lookup string */
|
2006-08-15 22:56:38 +02:00
|
|
|
return [rm stringForKey: lKey
|
|
|
|
inTableNamed: lTable
|
|
|
|
withDefaultValue: lVal
|
|
|
|
languages: languages];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2008-03-10 16:04:01 +01:00
|
|
|
- (NSString *) localizedNameForDayOfWeek: (unsigned) dayOfWeek
|
|
|
|
{
|
|
|
|
return [self labelForKey: [dayLabelKeys objectAtIndex: dayOfWeek % 7]];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2008-03-10 16:04:01 +01:00
|
|
|
- (NSString *) localizedAbbreviatedNameForDayOfWeek: (unsigned) dayOfWeek
|
|
|
|
{
|
|
|
|
return [self labelForKey: [abbrDayLabelKeys objectAtIndex: dayOfWeek % 7]];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2008-03-10 16:04:01 +01:00
|
|
|
- (NSString *) localizedNameForMonthOfYear: (unsigned) monthOfYear
|
|
|
|
{
|
|
|
|
return [self labelForKey: [monthLabelKeys objectAtIndex: (monthOfYear - 1) % 12]];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2008-03-10 16:04:01 +01:00
|
|
|
- (NSString *) localizedAbbreviatedNameForMonthOfYear: (unsigned) monthOfYear
|
|
|
|
{
|
|
|
|
return [self labelForKey: [abbrMonthLabelKeys objectAtIndex: (monthOfYear - 1) % 12]];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* HTTP method safety */
|
|
|
|
|
|
|
|
- (BOOL)isInvokedBySafeMethod {
|
|
|
|
// TODO: move to WORequest?
|
|
|
|
NSString *m;
|
|
|
|
|
2007-08-23 18:12:16 +02:00
|
|
|
m = [[context request] method];
|
2006-06-15 21:34:10 +02:00
|
|
|
if ([m isEqualToString:@"GET"]) return YES;
|
|
|
|
if ([m isEqualToString:@"HEAD"]) return YES;
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* locale */
|
|
|
|
|
|
|
|
- (NSDictionary *)locale {
|
|
|
|
/* we need no fallback here, as locale is guaranteed to be set by sogod */
|
2007-06-11 23:26:11 +02:00
|
|
|
return [context valueForKey: @"locale"];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
- (WOResourceManager *) pageResourceManager
|
|
|
|
{
|
|
|
|
WOResourceManager *rm;
|
|
|
|
|
2007-08-23 18:12:16 +02:00
|
|
|
if ((rm = [[context page] resourceManager]) == nil)
|
2006-07-29 00:59:11 +02:00
|
|
|
rm = [[WOApplication application] resourceManager];
|
|
|
|
|
|
|
|
return rm;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) urlForResourceFilename: (NSString *) filename
|
|
|
|
{
|
|
|
|
static NSMutableDictionary *pageToURL = nil;
|
|
|
|
NSString *url;
|
|
|
|
WOComponent *page;
|
|
|
|
WOResourceManager *rm;
|
|
|
|
NSBundle *pageBundle;
|
|
|
|
|
2006-08-01 21:18:06 +02:00
|
|
|
if (filename)
|
2006-07-29 00:59:11 +02:00
|
|
|
{
|
2006-08-01 21:18:06 +02:00
|
|
|
if (!pageToURL)
|
|
|
|
pageToURL = [[NSMutableDictionary alloc] initWithCapacity: 32];
|
|
|
|
|
|
|
|
url = [pageToURL objectForKey: filename];
|
2006-07-29 00:59:11 +02:00
|
|
|
if (!url)
|
2006-08-01 21:18:06 +02:00
|
|
|
{
|
|
|
|
rm = [self pageResourceManager];
|
2007-08-23 18:12:16 +02:00
|
|
|
page = [context page];
|
2006-08-01 21:18:06 +02:00
|
|
|
pageBundle = [NSBundle bundleForClass: [page class]];
|
|
|
|
url = [rm urlForResourceNamed: filename
|
|
|
|
inFramework: [pageBundle bundlePath]
|
|
|
|
languages: nil
|
2007-08-23 18:12:16 +02:00
|
|
|
request: [context request]];
|
2006-08-01 21:18:06 +02:00
|
|
|
if (!url)
|
|
|
|
url = @"";
|
|
|
|
else
|
|
|
|
if ([url hasPrefix: @"http"])
|
|
|
|
url = [url hostlessURL];
|
|
|
|
[pageToURL setObject: url forKey: filename];
|
|
|
|
}
|
2006-07-29 00:59:11 +02:00
|
|
|
|
|
|
|
// NSLog (@"url for '%@': '%@'", filename, url);
|
2006-08-01 21:18:06 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
url = @"";
|
2006-07-29 00:59:11 +02:00
|
|
|
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
2007-12-13 20:25:01 +01:00
|
|
|
- (WOResponse *) responseWithStatus: (unsigned int) status
|
2007-09-11 21:32:52 +02:00
|
|
|
{
|
|
|
|
WOResponse *response;
|
|
|
|
|
|
|
|
response = [context response];
|
2007-12-13 20:25:01 +01:00
|
|
|
[response setStatus: status];
|
2009-07-19 19:11:37 +02:00
|
|
|
[response setHeader: @"text/plain; charset=utf-8"
|
|
|
|
forKey: @"content-type"];
|
2007-12-13 20:25:01 +01:00
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) responseWithStatus: (unsigned int) status
|
|
|
|
andString: (NSString *) contentString
|
|
|
|
{
|
|
|
|
WOResponse *response;
|
|
|
|
|
|
|
|
response = [self responseWithStatus: status];
|
|
|
|
[response appendContentString: contentString];
|
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) responseWithStatus: (unsigned int) status
|
|
|
|
andJSONRepresentation: (NSObject *) contentObject;
|
|
|
|
{
|
|
|
|
return [self responseWithStatus: status
|
|
|
|
andString: [contentObject jsonRepresentation]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) responseWith204
|
|
|
|
{
|
|
|
|
return [self responseWithStatus: 204];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) redirectToLocation: (NSString *) newLocation
|
|
|
|
{
|
|
|
|
WOResponse *response;
|
|
|
|
|
|
|
|
response = [self responseWithStatus: 302];
|
|
|
|
[response setHeader: newLocation forKey: @"location"];
|
2007-09-11 21:32:52 +02:00
|
|
|
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* debugging */
|
|
|
|
|
2009-07-14 19:20:49 +02:00
|
|
|
- (NSString *) buildDate
|
|
|
|
{
|
|
|
|
return SOGoBuildDate;
|
|
|
|
}
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
- (BOOL) isUIxDebugEnabled
|
2009-07-14 19:20:49 +02:00
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoSystemDefaults *sd;
|
|
|
|
|
|
|
|
sd = [SOGoSystemDefaults sharedSystemDefaults];
|
|
|
|
|
|
|
|
return [sd uixDebugEnabled];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@end /* UIxComponent */
|