2007-09-15 00:08:43 +02:00
|
|
|
/* SOGoAppointmentFolders.m - this file is part of SOGo
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Inverse groupe conseil
|
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2008-02-08 15:28:35 +01:00
|
|
|
#import <Foundation/NSArray.h>
|
2008-07-09 23:09:08 +02:00
|
|
|
#import <Foundation/NSEnumerator.h>
|
2007-09-15 00:08:43 +02:00
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
|
2008-07-09 18:02:42 +02:00
|
|
|
#import <NGObjWeb/WOContext.h>
|
|
|
|
#import <NGObjWeb/WORequest+So.h>
|
|
|
|
#import <NGObjWeb/NSException+HTTP.h>
|
|
|
|
|
2008-07-09 23:09:08 +02:00
|
|
|
#import <SOGo/WORequest+SOGo.h>
|
2007-09-15 00:08:43 +02:00
|
|
|
#import "SOGoAppointmentFolder.h"
|
|
|
|
|
|
|
|
#import "SOGoAppointmentFolders.h"
|
|
|
|
|
|
|
|
@implementation SOGoAppointmentFolders
|
|
|
|
|
|
|
|
+ (NSString *) gcsFolderType
|
|
|
|
{
|
|
|
|
return @"Appointment";
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (Class) subFolderClass
|
|
|
|
{
|
|
|
|
return [SOGoAppointmentFolder class];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) defaultFolderName
|
|
|
|
{
|
2008-06-23 16:23:18 +02:00
|
|
|
return [self labelForKey: @"Personal Calendar"];
|
2007-09-15 00:08:43 +02:00
|
|
|
}
|
|
|
|
|
2008-07-09 23:09:08 +02:00
|
|
|
- (NSString *) _fetchPropertyWithName: (NSString *) propertyName
|
|
|
|
inArray: (NSArray *) section
|
2008-07-09 18:02:42 +02:00
|
|
|
{
|
2008-07-09 23:09:08 +02:00
|
|
|
NSObject <DOMElement> *currentElement;
|
|
|
|
NSString *currentName, *property;
|
|
|
|
NSEnumerator *elements;
|
|
|
|
NSObject <DOMNodeList> *values;
|
2008-07-09 18:02:42 +02:00
|
|
|
|
2008-07-09 23:09:08 +02:00
|
|
|
property = nil;
|
2008-07-09 18:02:42 +02:00
|
|
|
|
2008-07-09 23:09:08 +02:00
|
|
|
elements = [section objectEnumerator];
|
|
|
|
while (!property && (currentElement = [elements nextObject]))
|
2008-07-09 18:02:42 +02:00
|
|
|
{
|
2008-07-09 23:09:08 +02:00
|
|
|
currentName = [NSString stringWithFormat: @"{%@}%@",
|
|
|
|
[currentElement namespaceURI],
|
|
|
|
[currentElement nodeName]];
|
|
|
|
if ([currentName isEqualToString: propertyName])
|
2008-07-09 18:02:42 +02:00
|
|
|
{
|
2008-07-09 23:09:08 +02:00
|
|
|
values = [currentElement childNodes];
|
|
|
|
if ([values length])
|
|
|
|
property = [[values objectAtIndex: 0] nodeValue];
|
2008-07-09 18:02:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-09 23:09:08 +02:00
|
|
|
return property;
|
2008-07-09 18:02:42 +02:00
|
|
|
}
|
|
|
|
|
2008-07-09 23:09:08 +02:00
|
|
|
#warning this method may be useful at a higher level
|
|
|
|
#warning not all values are simple strings...
|
|
|
|
- (NSException *) _applyMkCalendarProperties: (NSArray *) properties
|
|
|
|
toObject: (SOGoObject *) newFolder
|
2008-07-09 18:02:42 +02:00
|
|
|
{
|
2008-07-09 23:09:08 +02:00
|
|
|
NSEnumerator *allProperties;
|
|
|
|
NSObject <DOMElement> *currentProperty;
|
|
|
|
NSObject <DOMNodeList> *values;
|
|
|
|
NSString *value, *currentName;
|
|
|
|
SEL methodSel;
|
|
|
|
|
|
|
|
allProperties = [properties objectEnumerator];
|
|
|
|
while ((currentProperty = [allProperties nextObject]))
|
|
|
|
{
|
|
|
|
values = [currentProperty childNodes];
|
|
|
|
if ([values length])
|
|
|
|
{
|
|
|
|
value = [[values objectAtIndex: 0] nodeValue];
|
|
|
|
currentName = [NSString stringWithFormat: @"{%@}%@",
|
|
|
|
[currentProperty namespaceURI],
|
|
|
|
[currentProperty nodeName]];
|
|
|
|
methodSel = SOGoSelectorForPropertySetter (currentName);
|
|
|
|
if ([newFolder respondsToSelector: methodSel])
|
|
|
|
[newFolder performSelector: methodSel
|
|
|
|
withObject: value];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-09 18:02:42 +02:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2008-07-09 23:09:08 +02:00
|
|
|
- (NSException *) davCreateCalendarCollection: (NSString *) newName
|
|
|
|
inContext: (id) createContext
|
2008-07-09 18:02:42 +02:00
|
|
|
{
|
2008-07-09 23:09:08 +02:00
|
|
|
NSArray *subfolderNames, *setProperties;
|
|
|
|
NSString *content, *newDisplayName;
|
|
|
|
NSDictionary *properties;
|
|
|
|
NSException *error;
|
|
|
|
SOGoAppointmentFolder *newFolder;
|
|
|
|
|
|
|
|
subfolderNames = [self toManyRelationshipKeys];
|
|
|
|
if ([subfolderNames containsObject: newName])
|
|
|
|
{
|
|
|
|
content = [NSString stringWithFormat:
|
|
|
|
@"A collection named '%@' already exists.",
|
|
|
|
newName];
|
|
|
|
error = [NSException exceptionWithHTTPStatus: 403
|
|
|
|
reason: content];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
properties = [[createContext request]
|
|
|
|
davPatchedPropertiesWithTopTag: @"mkcalendar"];
|
|
|
|
setProperties = [properties objectForKey: @"set"];
|
|
|
|
newDisplayName = [self _fetchPropertyWithName: @"{DAV:}displayname"
|
|
|
|
inArray: setProperties];
|
|
|
|
if (![newDisplayName length])
|
|
|
|
newDisplayName = newName;
|
|
|
|
error
|
|
|
|
= [self newFolderWithName: newDisplayName andNameInContainer: newName];
|
|
|
|
if (!error)
|
|
|
|
{
|
|
|
|
newFolder = [self lookupName: newName
|
|
|
|
inContext: createContext
|
|
|
|
acquire: NO];
|
|
|
|
error = [self _applyMkCalendarProperties: setProperties
|
|
|
|
toObject: newFolder];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
2008-07-09 18:02:42 +02:00
|
|
|
}
|
|
|
|
|
2008-07-04 20:22:14 +02:00
|
|
|
#warning THIS CAUSES LIGHTNING TO FAIL (that is why its commented out)
|
2008-06-30 20:53:12 +02:00
|
|
|
// - (NSArray *) davComplianceClassesInContext: (id)_ctx
|
|
|
|
// {
|
|
|
|
// NSMutableArray *classes;
|
|
|
|
// NSArray *primaryClasses;
|
|
|
|
|
|
|
|
// classes = [NSMutableArray new];
|
|
|
|
// [classes autorelease];
|
|
|
|
|
|
|
|
// primaryClasses = [super davComplianceClassesInContext: _ctx];
|
|
|
|
// if (primaryClasses)
|
|
|
|
// [classes addObjectsFromArray: primaryClasses];
|
|
|
|
// [classes addObject: @"calendar-access"];
|
|
|
|
// [classes addObject: @"calendar-schedule"];
|
|
|
|
|
|
|
|
// return classes;
|
|
|
|
// }
|
|
|
|
|
2008-02-08 15:28:35 +01:00
|
|
|
// /* CalDAV support */
|
|
|
|
// - (NSArray *) davComplianceClassesInContext: (WOContext *) localContext
|
|
|
|
// {
|
|
|
|
// NSMutableArray *newClasses;
|
|
|
|
|
|
|
|
// newClasses
|
|
|
|
// = [NSMutableArray arrayWithArray:
|
|
|
|
// [super davComplianceClassesInContext: localContext]];
|
|
|
|
// [newClasses addObject: @"calendar-access"];
|
|
|
|
|
|
|
|
// return newClasses;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// - (NSArray *) davCalendarHomeSet
|
|
|
|
// {
|
|
|
|
// /*
|
|
|
|
// <C:calendar-home-set xmlns:D="DAV:"
|
|
|
|
// xmlns:C="urn:ietf:params:xml:ns:caldav">
|
|
|
|
// <D:href>http://cal.example.com/home/bernard/calendars/</D:href>
|
|
|
|
// </C:calendar-home-set>
|
|
|
|
|
|
|
|
// Note: this is the *container* for calendar collections, not the
|
|
|
|
// collections itself. So for use its the home folder, the
|
|
|
|
// public folder and the groups folder.
|
|
|
|
// */
|
|
|
|
// NSArray *tag;
|
|
|
|
|
|
|
|
// tag = [NSArray arrayWithObjects: @"href", @"DAV:", @"D",
|
|
|
|
// [self davURL], nil];
|
|
|
|
|
|
|
|
// return [NSArray arrayWithObject: tag];
|
|
|
|
// }
|
|
|
|
|
|
|
|
// - (NSArray *) davCalendarUserAddressSet
|
|
|
|
// {
|
|
|
|
// NSArray *tag, *allEmails;
|
|
|
|
// NSMutableArray *addresses;
|
|
|
|
// NSEnumerator *emails;
|
|
|
|
// NSString *currentEmail;
|
|
|
|
|
|
|
|
// addresses = [NSMutableArray array];
|
|
|
|
|
|
|
|
// allEmails = [[context activeUser] allEmails];
|
|
|
|
// emails = [allEmails objectEnumerator];
|
|
|
|
// while ((currentEmail = [emails nextObject]))
|
|
|
|
// {
|
|
|
|
// tag = [NSArray arrayWithObjects: @"href", @"DAV:", @"D",
|
|
|
|
// [NSString stringWithFormat: @"mailto:%@", currentEmail],
|
|
|
|
// nil];
|
|
|
|
// [addresses addObject: tag];
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return addresses;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// - (NSArray *) davCalendarScheduleInboxURL
|
|
|
|
// {
|
|
|
|
// NSArray *tag;
|
|
|
|
|
|
|
|
// tag = [NSArray arrayWithObjects: @"href", @"DAV:", @"D",
|
|
|
|
// [NSString stringWithFormat: @"%@personal/", [self davURL]],
|
|
|
|
// nil];
|
|
|
|
|
|
|
|
// return [NSArray arrayWithObject: tag];
|
|
|
|
// }
|
|
|
|
|
|
|
|
// - (NSString *) davCalendarScheduleOutboxURL
|
|
|
|
// {
|
|
|
|
// NSArray *tag;
|
|
|
|
|
|
|
|
// tag = [NSArray arrayWithObjects: @"href", @"DAV:", @"D",
|
|
|
|
// [NSString stringWithFormat: @"%@personal/", [self davURL]],
|
|
|
|
// nil];
|
|
|
|
|
|
|
|
// return [NSArray arrayWithObject: tag];
|
|
|
|
// }
|
|
|
|
|
|
|
|
// - (NSString *) davDropboxHomeURL
|
|
|
|
// {
|
|
|
|
// NSArray *tag;
|
|
|
|
|
|
|
|
// tag = [NSArray arrayWithObjects: @"href", @"DAV:", @"D",
|
|
|
|
// [NSString stringWithFormat: @"%@personal/", [self davURL]],
|
|
|
|
// nil];
|
|
|
|
|
|
|
|
// return [NSArray arrayWithObject: tag];
|
|
|
|
// }
|
|
|
|
|
|
|
|
// - (NSString *) davNotificationsURL
|
|
|
|
// {
|
|
|
|
// NSArray *tag;
|
|
|
|
|
|
|
|
// tag = [NSArray arrayWithObjects: @"href", @"DAV:", @"D",
|
|
|
|
// [NSString stringWithFormat: @"%@personal/", [self davURL]],
|
|
|
|
// nil];
|
|
|
|
|
|
|
|
// return [NSArray arrayWithObject: tag];
|
|
|
|
// }
|
|
|
|
|
2007-09-15 00:08:43 +02:00
|
|
|
@end
|