/*! @header FTExport @abstract Module of FT @availability OS X, GNUstep @copyright 2004, 2005, 2006 Free Software Foundation, Inc. This library 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.1 of the License, or (at your option) any later version. This library 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 this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  -------------------------------------------------------------------------
  Modification history

  14.02.06 ola     initial version
  23.08.06 ola     license changed
  -------------------------------------------------------------------------
  
*/ #include #include #include @implementation FTExport + (ECLogger *) log { return [ECLogging loggerForContext: @"FTExport"]; } - init { self = [super init]; self->output = [[ECStandardOutput alloc] init]; self->fileEncoding = NSUTF8StringEncoding; self->login = nil; self->passwd = nil; return self; } - (void) dealloc { [self->output release]; [super dealloc]; } - (BOOL) cmdLineArgumentsOK { BOOL gotGraphIdString = NO; BOOL gotExportDir = NO; BOOL gotBaseExportFilename = NO; BOOL gotLogin = NO; BOOL gotPasswd = NO; EC_AUTORELEASEPOOL_BEGIN NSString *arg; NSEnumerator *arguments = [[[NSProcessInfo processInfo] arguments] objectEnumerator]; while( (arg = [arguments nextObject]) ) { if( [arg isEqualToString: @"-graphId"] ) { self->graphIdString = [arguments nextObject]; gotGraphIdString = nil != self->graphIdString; continue; } else if( [arg isEqualToString: @"-exportDir"] ) { NSFileManager *fileMgr = [NSFileManager defaultManager]; self->exportDir = [arguments nextObject]; BOOL isDir; if( nil == self->exportDir ) { /* incorrect usage, so: */ break; } if( ![fileMgr fileExistsAtPath: self->exportDir isDirectory: &isDir] ) { [self->output writeString: [NSString stringWithFormat: @"Directory \"%@\" for export does not exist!\n", self->exportDir]]; break; } if( !isDir) { [self->output writeString: [NSString stringWithFormat: @"Given export directory \"%@\" is not a "\ "directory!\n", self->exportDir]]; break; } if( ![fileMgr isWritableFileAtPath: self->exportDir] ) { [self->output writeString: [NSString stringWithFormat: @"Have no permissions to write into directory "\ "\"%@\"\n", self->exportDir]]; break; } gotExportDir = YES; } else if( [arg isEqualToString: @"-baseExportFilename"] ) { self->baseExportFilename = [arguments nextObject]; gotBaseExportFilename = nil != self->baseExportFilename; continue; } else if( [arg isEqualToString: @"-login"] ) { self->login = [arguments nextObject]; gotLogin = YES; continue; } else if( [arg isEqualToString: @"-password"] ) { self->passwd = [arguments nextObject]; gotPasswd = YES; } } EC_AUTORELEASEPOOL_END return gotGraphIdString && gotExportDir && gotBaseExportFilename && gotLogin && gotPasswd; } #define _argumentsOverview \ @"\nCommand line parameters:\n"\ "\t-configFile \n\t\tFT configuration file\n"\ "\t-graphId \n\t\tspecifies a graph. Assumes that the "\ "graph identifier is of type string\n\n"\ "\t-exportDir \n\t\t"\ "Specifies the directory where the output files have to be written to\n\n"\ "\t-baseExportFilename \n"\ "\t\tSpecifies the base filename for all generated files\n"\ "\t-login \n\t\tlogin account for an admin user\n"\ "\t-password \n\t\tpassword of the specified login" - cmdLineArgumentsOverview { [self->output writeString: _argumentsOverview]; return self; } - (int) fileEncoding { return self->fileEncoding; } - (ECLogger *) log { return [FTExport log]; } - run { EC_AUTORELEASEPOOL_BEGIN FTGraphVisitor *visitor; [self startServerUsingLogin: self->login usingPassword: self->passwd]; if( ![[self session] conformsToProtocol: @protocol(FTAdministrationSession)] ) { [self->output writeString: @"Specified login session does not have "\ "administrative rights!"]; EC_AUTORELEASEPOOL_RELEASE; return self; } visitor = [[[FTGraphVisitor alloc] initForSession: ( id ) [self session] graphId: self->graphIdString exportDirectory: self->exportDir baseFilename: self->baseExportFilename encoding: self->fileEncoding] autorelease]; [visitor exportContent]; EC_AUTORELEASEPOOL_END return self; } @end int main( int argc, char *argv[] ) { EC_AUTORELEASEPOOL_BEGIN FTExport *exportTool; NSLog( @"FTExport Version %@", FTEXPORT_VERSION ); exportTool = [[[FTExport alloc] init] autorelease]; [FTAbstractTool startTool: exportTool]; EC_AUTORELEASEPOOL_END exit( 0 ); }