2 Copyright (C) 2004-2005 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "GCSFolderType.h"
23 #include "GCSFolder.h"
24 #include "GCSFieldInfo.h"
25 #include "GCSFieldExtractor.h"
27 #include <EOControl/EOKeyValueCoding.h>
28 #include <NGExtensions/NGResourceLocator.h>
30 @implementation GCSFolderType
32 - (id)initWithPropertyList:(id)_plist {
33 if ((self = [super init])) {
34 self->blobTablePattern = [[_plist objectForKey:@"blobTablePattern"] copy];
35 self->quickTablePattern = [[_plist objectForKey:@"quickTablePattern"]copy];
37 self->extractorClassName =
38 [[_plist objectForKey:@"extractorClassName"] copy];
41 self->fields = [[GCSFieldInfo fieldsForPropertyList:
42 [_plist objectForKey:@"fields"]] retain];
47 - (id)initWithContentsOfFile:(NSString *)_path {
50 plist = [NSDictionary dictionaryWithContentsOfFile:_path];
52 NSLog(@"ERROR(%s): could not read dictionary at path %@",
53 __PRETTY_FUNCTION__, _path);
57 return [self initWithPropertyList:plist];
60 + (NGResourceLocator *)resourceLocator {
61 NGResourceLocator *loc;
63 // TODO: fix me, GCS instead of OCS
64 loc = [NGResourceLocator resourceLocatorForGNUstepPath:
65 @"Library/OCSTypeModels"
66 fhsPath:@"share/ocs"];
70 + (id)folderTypeWithName:(NSString *)_typeName {
71 NSString *filename, *path;
73 // TODO: fix me, GCS instead of OCS
74 filename = [_typeName stringByAppendingPathExtension:@"ocs"];
75 path = [[self resourceLocator] lookupFileWithName:filename];
78 return [[self alloc] initWithContentsOfFile:path];
80 NSLog(@"ERROR(%s): did not find model for type: '%@'",
81 __PRETTY_FUNCTION__, _typeName);
85 - (id)initWithFolderTypeName:(NSString *)_typeName {
88 return [[GCSFolderType folderTypeWithName:_typeName] retain];
92 [self->extractor release];
93 [self->extractorClassName release];
94 [self->blobTablePattern release];
95 [self->quickTablePattern release];
96 [self->fields release];
97 [self->fieldDict release];
98 [self->folderQualifier release];
104 - (NSString *)blobTableNameForFolder:(GCSFolder *)_folder {
105 return [self->blobTablePattern
106 stringByReplacingVariablesWithBindings:_folder];
108 - (NSString *)quickTableNameForFolder:(GCSFolder *)_folder {
109 return [self->quickTablePattern
110 stringByReplacingVariablesWithBindings:_folder];
113 - (EOQualifier *)qualifierForFolder:(GCSFolder *)_folder {
115 NSDictionary *bindings;
117 keys = [[self->folderQualifier allQualifierKeys] allObjects];
118 if ([keys count] == 0)
119 return self->folderQualifier;
121 bindings = [_folder valuesForKeys:keys];
122 return [self->folderQualifier qualifierWithBindings:bindings
123 requiresAllVariables:NO];
128 - (NSString *)sqlQuickCreateWithTableName:(NSString *)_tabName {
129 NSMutableString *sql;
132 sql = [NSMutableString stringWithCapacity:512];
133 [sql appendString:@"CREATE TABLE "];
134 [sql appendString:_tabName];
135 [sql appendString:@" (\n"];
137 count = [self->fields count];
138 for (i = 0; i < count; i++) {
139 if (i > 0) [sql appendString:@",\n"];
141 [sql appendString:@" "];
142 [sql appendString:[[self->fields objectAtIndex:i] sqlCreateSection]];
145 [sql appendString:@"\n)"];
152 - (GCSFieldExtractor *)quickExtractor {
156 return [self->extractor isNotNull] ? self->extractor : nil;
158 clazz = self->extractorClassName
159 ? NSClassFromString(self->extractorClassName)
160 : [GCSFieldExtractor class];
162 [self logWithFormat:@"ERROR: did not find field extractor class!"];
166 if ((self->extractor = [[clazz alloc] init]) == nil) {
167 [self logWithFormat:@"ERROR: could not create field extractor of class %@",
171 return self->extractor;
176 - (NSString *)description {
179 ms = [NSMutableString stringWithCapacity:256];
180 [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
182 [ms appendFormat:@" blobtable='%@'", self->blobTablePattern];
183 [ms appendFormat:@" quicktable='%@'", self->quickTablePattern];
184 [ms appendFormat:@" fields=%@", self->fields];
185 [ms appendFormat:@" extractor=%@", self->extractorClassName];
187 if (self->folderQualifier)
188 [ms appendFormat:@" qualifier=%@", self->folderQualifier];
190 [ms appendString:@">"];
194 @end /* GCSFolderType */