2006-06-15 21:34:10 +02:00
|
|
|
/*
|
2015-06-10 15:08:10 +02:00
|
|
|
Copyright (C) 2007-2015 Inverse inc.
|
2006-06-15 21:34:10 +02:00
|
|
|
Copyright (C) 2004 SKYRIX Software AG
|
|
|
|
|
2011-04-25 12:31:08 +02:00
|
|
|
This file is part of SOGo
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2011-04-25 12:31:08 +02:00
|
|
|
SOGo is free software; you can redistribute it and/or modify it under
|
2006-06-15 21:34:10 +02:00
|
|
|
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.
|
|
|
|
|
2011-04-25 12:31:08 +02:00
|
|
|
SOGo is distributed in the hope that it will be useful, but WITHOUT ANY
|
2006-06-15 21:34:10 +02:00
|
|
|
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>
|
2012-09-22 03:48:39 +02:00
|
|
|
#import <Foundation/NSUserDefaults.h> /* for locale strings */
|
2008-11-04 20:55:50 +01:00
|
|
|
#import <Foundation/NSString.h>
|
2007-11-06 22:24:22 +01:00
|
|
|
|
2006-07-29 00:59:11 +02:00
|
|
|
#import <NGObjWeb/SoHTTPAuthenticator.h>
|
2007-04-11 21:08:58 +02:00
|
|
|
#import <NGObjWeb/SoObjects.h>
|
2012-09-22 03:48:39 +02:00
|
|
|
#import <NGObjWeb/SoProduct.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>
|
2015-03-26 13:52:48 +01:00
|
|
|
#import <SOGo/NSDictionary+Utilities.h>
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <SOGo/NSObject+Utilities.h>
|
|
|
|
#import <SOGo/NSString+Utilities.h>
|
2010-02-18 23:08:48 +01:00
|
|
|
#import <SOGo/SOGoBuild.h>
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <SOGo/SOGoContentObject.h>
|
|
|
|
#import <SOGo/SOGoObject.h>
|
|
|
|
#import <SOGo/SOGoPermissions.h>
|
|
|
|
#import <SOGo/SOGoSystemDefaults.h>
|
|
|
|
#import <SOGo/SOGoUser.h>
|
2012-10-22 16:09:13 +02:00
|
|
|
#import <SOGo/SOGoUserFolder.h>
|
2009-11-29 05:19:32 +01:00
|
|
|
#import <SOGo/SOGoUserDefaults.h>
|
2014-08-06 22:01:05 +02:00
|
|
|
#import <SOGo/WOContext+SOGo.h>
|
2012-10-22 16:09:13 +02:00
|
|
|
#import <SOGo/WOResourceManager+SOGo.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;
|
2012-09-22 03:48:39 +02:00
|
|
|
static SoProduct *commonProduct = nil;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
+ (void)initialize {
|
|
|
|
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];
|
2012-09-22 03:48:39 +02:00
|
|
|
[abbrMonthLabelKeys addObject:@"Jan"];
|
|
|
|
[abbrMonthLabelKeys addObject:@"Feb"];
|
|
|
|
[abbrMonthLabelKeys addObject:@"Mar"];
|
|
|
|
[abbrMonthLabelKeys addObject:@"Apr"];
|
|
|
|
[abbrMonthLabelKeys addObject:@"May"];
|
|
|
|
[abbrMonthLabelKeys addObject:@"Jun"];
|
|
|
|
[abbrMonthLabelKeys addObject:@"Jul"];
|
|
|
|
[abbrMonthLabelKeys addObject:@"Aug"];
|
|
|
|
[abbrMonthLabelKeys addObject:@"Sep"];
|
|
|
|
[abbrMonthLabelKeys addObject:@"Oct"];
|
|
|
|
[abbrMonthLabelKeys addObject:@"Nov"];
|
|
|
|
[abbrMonthLabelKeys addObject:@"Dec"];
|
|
|
|
|
|
|
|
// @see commonLabelForKey:
|
|
|
|
commonProduct = [[SoProduct alloc] initWithBundle:
|
|
|
|
[NSBundle bundleForClass: NSClassFromString(@"CommonUIProduct")]];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-22 03:48:39 +02:00
|
|
|
+ (NSArray *) abbrDayLabelKeys
|
|
|
|
{
|
|
|
|
return (NSArray *) abbrDayLabelKeys;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSArray *) monthLabelKeys
|
|
|
|
{
|
|
|
|
return (NSArray *) monthLabelKeys;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSArray *) abbrMonthLabelKeys
|
|
|
|
{
|
|
|
|
return (NSArray *) abbrMonthLabelKeys;
|
|
|
|
}
|
|
|
|
|
2006-09-05 16:53:38 +02:00
|
|
|
- (id) init
|
|
|
|
{
|
2012-09-22 03:48:39 +02:00
|
|
|
NSString *language;
|
|
|
|
|
2006-09-05 16:53:38 +02:00
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
2006-09-05 22:13:16 +02:00
|
|
|
_selectedDate = nil;
|
2008-09-02 04:53:34 +02:00
|
|
|
queryParameters = nil;
|
2012-09-22 03:48:39 +02:00
|
|
|
ASSIGN (userDefaults, [[context activeUser] userDefaults]);
|
2012-11-01 15:27:27 +01:00
|
|
|
if (!userDefaults)
|
|
|
|
ASSIGN (userDefaults, [SOGoSystemDefaults sharedSystemDefaults]);
|
2012-09-22 03:48:39 +02:00
|
|
|
language = [userDefaults language];
|
2014-08-06 22:01:05 +02:00
|
|
|
ASSIGN (languages, [context resourceLookupLanguages]);
|
2012-10-22 16:09:13 +02:00
|
|
|
ASSIGN (locale,
|
|
|
|
[[self resourceManager] localeForLanguageNamed: language]);
|
2006-09-05 16:53:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2007-06-27 23:25:40 +02:00
|
|
|
[queryParameters release];
|
|
|
|
[_selectedDate release];
|
2012-09-22 03:48:39 +02:00
|
|
|
[locale release];
|
|
|
|
[userDefaults 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;
|
2014-03-04 19:23:55 +01:00
|
|
|
NSString *hostLessURL;
|
2008-05-03 00:51:49 +02:00
|
|
|
Class objectClass, userFolderClass;
|
2015-09-19 02:30:35 +02:00
|
|
|
|
|
|
|
if ([[self parent] respondsToSelector: @selector(modulePath)])
|
|
|
|
return [NSString stringWithFormat: @"%@/%@", [[self clientObject] baseURLInContext: context], [[self parent] modulePath]];
|
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
|
|
|
{
|
2007-09-07 00:16:30 +02:00
|
|
|
userFolderClass = [SOGoUserFolder class];
|
|
|
|
|
|
|
|
objectClass = [currentClient class];
|
2008-05-03 00:51:49 +02:00
|
|
|
found = (objectClass == userFolderClass);
|
2007-09-07 00:16:30 +02:00
|
|
|
while (!found && currentClient)
|
|
|
|
{
|
|
|
|
parent = [currentClient container];
|
|
|
|
objectClass = [parent class];
|
2015-09-19 02:30:35 +02:00
|
|
|
if (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];
|
2014-03-04 19:23:55 +01:00
|
|
|
|
|
|
|
hostLessURL = [[currentClient baseURLInContext: context] hostlessURL];
|
2006-09-07 00:25:46 +02:00
|
|
|
|
2014-03-04 19:23:55 +01:00
|
|
|
return [hostLessURL substringToIndex: [hostLessURL length] - 1];
|
2006-07-29 00:59:11 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
2014-11-14 20:50:13 +01:00
|
|
|
NSString *dst, *rel, *theme;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
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
|
|
|
|
2014-11-14 20:50:13 +01:00
|
|
|
theme = [[context request] formValueForKey: @"theme"];
|
|
|
|
if ([theme length])
|
|
|
|
rel = [NSString stringWithFormat: @"%@?theme=%@", rel, theme];
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
if (!_selectedDate)
|
|
|
|
{
|
|
|
|
_selectedDate
|
2006-10-05 01:13:09 +02:00
|
|
|
= [NSCalendarDate
|
|
|
|
dateFromShortDateString: [self queryParameterForKey: @"day"]
|
|
|
|
andShortTimeString: [self queryParameterForKey: @"hm"]
|
2012-09-22 03:48:39 +02:00
|
|
|
inTimeZone: [userDefaults 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
|
|
|
}
|
|
|
|
|
2015-03-26 13:52:48 +01:00
|
|
|
- (NSString *) currentDayDescription
|
|
|
|
{
|
2015-04-01 14:51:48 +02:00
|
|
|
NSDictionary *currentDay;
|
|
|
|
SOGoUser *user;
|
|
|
|
|
|
|
|
user = [context activeUser];
|
|
|
|
if (user)
|
|
|
|
currentDay = [user currentDay];
|
|
|
|
else
|
|
|
|
currentDay = [NSDictionary dictionary];
|
|
|
|
|
|
|
|
return [currentDay jsonRepresentation];
|
2015-03-26 13:52:48 +01:00
|
|
|
}
|
|
|
|
|
2006-09-19 23:09:57 +02:00
|
|
|
- (NSString *) dateStringForDate: (NSCalendarDate *) _date
|
|
|
|
{
|
2012-09-22 03:48:39 +02:00
|
|
|
[_date setTimeZone: [userDefaults 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];
|
2015-06-10 15:08:10 +02:00
|
|
|
[jsClose setRefreshMethod: [methodName doubleQuotedString]];
|
2006-10-12 18:44:40 +02:00
|
|
|
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
2011-12-02 08:22:47 +01:00
|
|
|
- (BOOL) singleWindowModeEnabled
|
|
|
|
{
|
|
|
|
//WEClientCapabilities *cc;
|
|
|
|
NSString *value;
|
|
|
|
BOOL result;
|
|
|
|
|
|
|
|
//cc = [[context request] clientCapabilities];
|
|
|
|
|
|
|
|
//NSLog(@"User agent = %@, Type = %@, OS = %@, CPU = %@, Browser major version = %i", [cc userAgent], [cc userAgentType], [cc os], [cc cpu], [cc majorVersion]);
|
|
|
|
|
|
|
|
value = [[context request] cookieValueForKey: @"SOGoWindowMode"];
|
|
|
|
result = ([value isEqualToString: @"single"]);
|
|
|
|
|
2011-12-09 17:34:11 +01:00
|
|
|
//NSLog(@"Single window mode %@", result?@"enabled":@"disabled");
|
2011-12-02 08:22:47 +01:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-12-09 15:53:44 +01:00
|
|
|
- (BOOL) userHasCalendarAccess
|
|
|
|
{
|
|
|
|
SOGoUser *user;
|
|
|
|
|
|
|
|
user = [context activeUser];
|
|
|
|
|
|
|
|
return [user canAccessModule: @"Calendar"];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) userHasMailAccess
|
|
|
|
{
|
|
|
|
SOGoUser *user;
|
|
|
|
|
|
|
|
user = [context activeUser];
|
|
|
|
|
|
|
|
return [user canAccessModule: @"Mail"];
|
|
|
|
}
|
|
|
|
|
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;
|
2012-09-22 03:48:39 +02:00
|
|
|
/* find resource manager */
|
|
|
|
|
|
|
|
rm = [self pageResourceManager];
|
|
|
|
|
|
|
|
return [self labelForKey: _str withResourceManager: rm];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) commonLabelForKey: (NSString *) _str
|
|
|
|
{
|
|
|
|
WOResourceManager *rm;
|
|
|
|
|
|
|
|
rm = [commonProduct resourceManager];
|
|
|
|
|
|
|
|
return [self labelForKey: _str withResourceManager: rm];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) labelForKey: (NSString *) _str
|
|
|
|
withResourceManager: (WOResourceManager *) rm
|
|
|
|
{
|
2006-09-05 22:41:05 +02:00
|
|
|
NSString *lKey, *lTable, *lVal;
|
2006-06-15 21:34:10 +02:00
|
|
|
NSRange r;
|
|
|
|
|
|
|
|
if ([_str length] == 0)
|
|
|
|
return nil;
|
2012-09-22 03:48:39 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
if (rm == nil)
|
|
|
|
[self warnWithFormat:@"missing resource manager!"];
|
2012-09-22 03:48:39 +02:00
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* 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
|
|
|
|
{
|
2012-09-22 03:48:39 +02:00
|
|
|
return [[locale objectForKey: NSWeekDayNameArray] objectAtIndex: dayOfWeek % 7];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2008-03-10 16:04:01 +01:00
|
|
|
- (NSString *) localizedAbbreviatedNameForDayOfWeek: (unsigned) dayOfWeek
|
|
|
|
{
|
2012-09-22 03:48:39 +02:00
|
|
|
// Defined in Common bundle
|
|
|
|
return [self commonLabelForKey: [abbrDayLabelKeys objectAtIndex: dayOfWeek % 7]];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2008-03-10 16:04:01 +01:00
|
|
|
- (NSString *) localizedNameForMonthOfYear: (unsigned) monthOfYear
|
|
|
|
{
|
2012-09-22 03:48:39 +02:00
|
|
|
// Defined in Locale
|
|
|
|
return [[locale objectForKey: NSMonthNameArray] objectAtIndex: (monthOfYear - 1) % 12];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2008-03-10 16:04:01 +01:00
|
|
|
- (NSString *) localizedAbbreviatedNameForMonthOfYear: (unsigned) monthOfYear
|
|
|
|
{
|
2012-09-22 03:48:39 +02:00
|
|
|
// Defined in Locale
|
|
|
|
return [[locale objectForKey: NSShortMonthNameArray] 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;
|
|
|
|
{
|
2010-03-09 21:29:17 +01:00
|
|
|
WOResponse *response;
|
|
|
|
|
|
|
|
response = [self responseWithStatus: status
|
|
|
|
andString: [contentObject jsonRepresentation]];
|
|
|
|
[response setHeader: @"application/json" forKey: @"content-type"];
|
|
|
|
|
|
|
|
return response;
|
2007-12-13 20:25:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) responseWith204
|
|
|
|
{
|
|
|
|
return [self responseWithStatus: 204];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (WOResponse *) redirectToLocation: (NSString *) newLocation
|
|
|
|
{
|
|
|
|
WOResponse *response;
|
2014-08-06 22:01:05 +02:00
|
|
|
NSURL *url;
|
|
|
|
NSMutableString *location;
|
|
|
|
NSString *theme, *query;
|
|
|
|
|
|
|
|
location = [NSMutableString stringWithString: newLocation];
|
|
|
|
theme = [[context request] formValueForKey: @"theme"];
|
|
|
|
if ([theme length])
|
|
|
|
{
|
|
|
|
url = [NSURL URLWithString: newLocation];
|
|
|
|
query = [url query];
|
|
|
|
if ([query length])
|
|
|
|
{
|
|
|
|
if ([query rangeOfString: @"theme="].length == 0)
|
|
|
|
[location appendFormat: @"&theme=%@", theme];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
[location appendFormat: @"?theme=%@", theme];
|
|
|
|
}
|
2007-12-13 20:25:01 +01:00
|
|
|
|
|
|
|
response = [self responseWithStatus: 302];
|
2014-08-06 22:01:05 +02:00
|
|
|
[response setHeader: location 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 */
|