2007-10-03 00:03:27 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2004-2005 SKYRIX Software AG
|
|
|
|
|
2014-07-30 20:51:00 +02:00
|
|
|
This file is part of SOGo.
|
2007-10-03 00:03:27 +02:00
|
|
|
|
2014-07-30 20:51:00 +02:00
|
|
|
SOGo is free software; you can redistribute it and/or modify it under
|
2007-10-03 00:03:27 +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.
|
|
|
|
|
2014-07-30 20:51:00 +02:00
|
|
|
SOGo is distributed in the hope that it will be useful, but WITHOUT ANY
|
2007-10-03 00:03:27 +02:00
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
2009-03-24 17:33:08 +01:00
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
2007-10-03 00:03:27 +02:00
|
|
|
License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2014-07-30 20:51:00 +02:00
|
|
|
License along with SOGo; see the file COPYING. If not, write to the
|
2007-10-03 00:03:27 +02:00
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2008-12-12 18:57:23 +01:00
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSSet.h>
|
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
|
|
|
|
#import <NGExtensions/NSNull+misc.h>
|
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
|
|
|
#import <NGExtensions/NSString+misc.h>
|
|
|
|
|
|
|
|
#import <EOControl/EOQualifier.h>
|
|
|
|
|
|
|
|
#import <EOControl/EOKeyValueCoding.h>
|
|
|
|
#import <NGExtensions/NGResourceLocator.h>
|
|
|
|
|
|
|
|
#import "GCSFolderType.h"
|
|
|
|
#import "GCSFolder.h"
|
|
|
|
#import "GCSFieldInfo.h"
|
2007-10-03 00:03:27 +02:00
|
|
|
|
|
|
|
@implementation GCSFolderType
|
|
|
|
|
2009-03-24 17:33:08 +01:00
|
|
|
+ (id) folderTypeWithName: (NSString *) _typeName
|
|
|
|
{
|
|
|
|
NSString *filename, *path;
|
|
|
|
GCSFolderType *folderType;
|
|
|
|
|
|
|
|
// TODO: fix me, GCS instead of OCS
|
|
|
|
filename = [_typeName stringByAppendingPathExtension:@"ocs"];
|
|
|
|
path = [[self resourceLocator] lookupFileWithName: filename];
|
|
|
|
|
|
|
|
if (path)
|
|
|
|
{
|
|
|
|
folderType = [[self alloc] initWithContentsOfFile: path];
|
|
|
|
[folderType autorelease];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
folderType = nil;
|
|
|
|
NSLog(@"ERROR(%s): did not find model for type: '%@'",
|
|
|
|
__PRETTY_FUNCTION__, _typeName);
|
|
|
|
}
|
|
|
|
|
|
|
|
return folderType;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithPropertyList: (id) _plist
|
|
|
|
{
|
|
|
|
NSDictionary *plist = _plist;
|
|
|
|
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
blobTablePattern = [[plist objectForKey:@"blobTablePattern"] copy];
|
|
|
|
quickTablePattern = [[plist objectForKey:@"quickTablePattern"] copy];
|
|
|
|
|
|
|
|
extractorClassName =
|
|
|
|
[[plist objectForKey: @"extractorClassName"] copy];
|
|
|
|
// TODO: qualifier;
|
|
|
|
|
|
|
|
fields = [[GCSFieldInfo fieldsForPropertyList:
|
|
|
|
[plist objectForKey:@"fields"]] retain];
|
2011-10-21 16:57:57 +02:00
|
|
|
quickFields = [[GCSFieldInfo fieldsForPropertyList:
|
|
|
|
[plist objectForKey:@"quickFields"]] retain];
|
2009-03-24 17:33:08 +01:00
|
|
|
}
|
|
|
|
|
2007-10-03 00:03:27 +02:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2009-03-24 17:33:08 +01:00
|
|
|
- (id) initWithContentsOfFile: (NSString *) _path
|
|
|
|
{
|
2007-10-03 00:03:27 +02:00
|
|
|
NSDictionary *plist;
|
2009-03-24 17:33:08 +01:00
|
|
|
|
|
|
|
plist = [NSDictionary dictionaryWithContentsOfFile: _path];
|
|
|
|
if (plist)
|
|
|
|
[self initWithPropertyList: plist];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSLog(@"ERROR(%s): could not read dictionary at path %@",
|
|
|
|
__PRETTY_FUNCTION__, _path);
|
|
|
|
[self release];
|
|
|
|
self = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
2007-10-03 00:03:27 +02:00
|
|
|
}
|
|
|
|
|
2009-03-24 17:33:08 +01:00
|
|
|
+ (NGResourceLocator *) resourceLocator
|
|
|
|
{
|
2007-10-03 00:03:27 +02:00
|
|
|
NGResourceLocator *loc;
|
2009-03-24 17:33:08 +01:00
|
|
|
|
2007-10-03 00:03:27 +02:00
|
|
|
// TODO: fix me, GCS instead of OCS
|
|
|
|
loc = [NGResourceLocator resourceLocatorForGNUstepPath:
|
2008-02-14 18:31:23 +01:00
|
|
|
@"OCSTypeModels"
|
2009-03-24 17:33:08 +01:00
|
|
|
fhsPath:@"share/ocs"];
|
2007-10-03 00:03:27 +02:00
|
|
|
return loc;
|
|
|
|
}
|
|
|
|
|
2009-03-24 17:33:08 +01:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
2008-06-13 22:07:32 +02:00
|
|
|
[extractorClassName release];
|
2009-03-24 17:33:08 +01:00
|
|
|
[blobTablePattern release];
|
|
|
|
[quickTablePattern release];
|
|
|
|
[fields release];
|
2011-10-21 16:57:57 +02:00
|
|
|
[quickFields release];
|
2009-03-24 17:33:08 +01:00
|
|
|
[folderQualifier release];
|
2007-10-03 00:03:27 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* operations */
|
|
|
|
|
2009-03-24 17:33:08 +01:00
|
|
|
- (NSString *) blobTableNameForFolder: (GCSFolder *) _folder
|
|
|
|
{
|
2008-06-13 22:07:32 +02:00
|
|
|
return [blobTablePattern
|
2009-03-24 17:33:08 +01:00
|
|
|
stringByReplacingVariablesWithBindings:_folder];
|
2007-10-03 00:03:27 +02:00
|
|
|
}
|
2009-03-24 17:33:08 +01:00
|
|
|
|
|
|
|
- (NSString *) quickTableNameForFolder: (GCSFolder *) _folder
|
|
|
|
{
|
2008-06-13 22:07:32 +02:00
|
|
|
return [quickTablePattern
|
2009-03-24 17:33:08 +01:00
|
|
|
stringByReplacingVariablesWithBindings:_folder];
|
2007-10-03 00:03:27 +02:00
|
|
|
}
|
|
|
|
|
2009-03-24 17:33:08 +01:00
|
|
|
- (EOQualifier *) qualifierForFolder: (GCSFolder *) _folder
|
|
|
|
{
|
|
|
|
NSArray *keys;
|
2007-10-03 00:03:27 +02:00
|
|
|
NSDictionary *bindings;
|
2009-03-24 17:33:08 +01:00
|
|
|
|
2008-06-13 22:07:32 +02:00
|
|
|
keys = [[folderQualifier allQualifierKeys] allObjects];
|
2007-10-03 00:03:27 +02:00
|
|
|
if ([keys count] == 0)
|
2008-06-13 22:07:32 +02:00
|
|
|
return folderQualifier;
|
2007-10-03 00:03:27 +02:00
|
|
|
|
|
|
|
bindings = [_folder valuesForKeys:keys];
|
2008-06-13 22:07:32 +02:00
|
|
|
return [folderQualifier qualifierWithBindings:bindings
|
2009-03-24 17:33:08 +01:00
|
|
|
requiresAllVariables:NO];
|
2007-10-03 00:03:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* generating SQL */
|
|
|
|
|
2009-03-24 17:33:08 +01:00
|
|
|
- (NSString *) sqlQuickCreateWithTableName: (NSString *) _tabName
|
|
|
|
{
|
2007-10-03 00:03:27 +02:00
|
|
|
NSMutableString *sql;
|
|
|
|
unsigned i, count;
|
2009-03-24 17:33:08 +01:00
|
|
|
|
|
|
|
sql = [NSMutableString stringWithFormat: @"CREATE TABLE %@ (", _tabName];
|
2011-10-21 16:57:57 +02:00
|
|
|
count = [quickFields count];
|
2009-03-24 17:33:08 +01:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
if (i > 0) [sql appendString:@", "];
|
2011-10-21 16:57:57 +02:00
|
|
|
[sql appendFormat: @" %@", [[quickFields objectAtIndex:i] sqlCreateSection]];
|
2009-03-24 17:33:08 +01:00
|
|
|
}
|
2007-10-03 00:03:27 +02:00
|
|
|
[sql appendString:@"\n)"];
|
2009-03-24 17:33:08 +01:00
|
|
|
|
2007-10-03 00:03:27 +02:00
|
|
|
return sql;
|
|
|
|
}
|
|
|
|
|
2011-10-21 16:57:57 +02:00
|
|
|
- (NSArray *) quickFields
|
|
|
|
{
|
|
|
|
return quickFields;
|
|
|
|
}
|
|
|
|
|
2008-06-13 22:07:32 +02:00
|
|
|
- (NSArray *) fields
|
|
|
|
{
|
|
|
|
return fields;
|
2007-10-03 00:03:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* description */
|
|
|
|
|
2009-03-24 17:33:08 +01:00
|
|
|
- (NSString *) description
|
|
|
|
{
|
2007-10-03 00:03:27 +02:00
|
|
|
NSMutableString *ms;
|
|
|
|
|
|
|
|
ms = [NSMutableString stringWithCapacity:256];
|
|
|
|
[ms appendFormat:@"<0x%p[%@]:", self, NSStringFromClass([self class])];
|
|
|
|
|
2009-03-24 17:33:08 +01:00
|
|
|
[ms appendFormat:@" blobtable='%@'", blobTablePattern];
|
2008-06-13 22:07:32 +02:00
|
|
|
[ms appendFormat:@" quicktable='%@'", quickTablePattern];
|
2009-03-24 17:33:08 +01:00
|
|
|
[ms appendFormat:@" fields=%@", fields];
|
2011-10-21 16:57:57 +02:00
|
|
|
[ms appendFormat:@" quickFields=%@", fields];
|
2009-03-24 17:33:08 +01:00
|
|
|
[ms appendFormat:@" extractor=%@", extractorClassName];
|
|
|
|
|
2008-06-13 22:07:32 +02:00
|
|
|
if (folderQualifier)
|
|
|
|
[ms appendFormat:@" qualifier=%@", folderQualifier];
|
2009-03-24 17:33:08 +01:00
|
|
|
|
2007-10-03 00:03:27 +02:00
|
|
|
[ms appendString:@">"];
|
|
|
|
return ms;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end /* GCSFolderType */
|