From 3755c18f7b0c572c2205011d7a1d519c36fa2ef0 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Fri, 30 Jul 2010 18:16:38 +0000 Subject: Replace redundant code with newly established methods. --- Source/SPExportInitializer.h | 2 +- Source/SPExportInitializer.m | 60 ++++++++------------------------------------ 2 files changed, 11 insertions(+), 51 deletions(-) (limited to 'Source') diff --git a/Source/SPExportInitializer.h b/Source/SPExportInitializer.h index d42429ee..cc80e15c 100644 --- a/Source/SPExportInitializer.h +++ b/Source/SPExportInitializer.h @@ -44,6 +44,6 @@ - (SPXMLExporter *)initializeXMLExporterForTable:(NSString *)table orDataArray:(NSArray *)dataArray; - (void)writeXMLHeaderToFileHandle:(SPFileHandle *)fileHandle; -- (SPFileHandle *)getFileHandleForFilePath:(NSString *)path; +- (SPFileHandle *)fileHandleForFilePath:(NSString *)path; @end diff --git a/Source/SPExportInitializer.m b/Source/SPExportInitializer.m index 0ba5037f..ee14b388 100644 --- a/Source/SPExportInitializer.m +++ b/Source/SPExportInitializer.m @@ -167,29 +167,9 @@ // export, create the single file now and assign it to all subsequently created exporters. if ((![self exportToMultipleFiles]) || (exportSource == SPFilteredExport) || (exportSource == SPQueryExport)) { - // Create custom filename if required - if (createCustomFilename) { - [exportFilename setString:[self expandCustomFilenameFormatFromString:[exportCustomFilenameTokenField stringValue] usingTableName:nil]]; - } - else { - // Determine what the file name should be - switch (exportSource) - { - case SPFilteredExport: - [exportFilename setString:[NSString stringWithFormat:@"%@_view", [tableDocumentInstance table]]]; - break; - case SPQueryExport: - [exportFilename setString:@"query_result"]; - break; - case SPTableExport: - [exportFilename setString:[tableDocumentInstance database]]; - break; - } - } + [exportFilename setString:(createCustomFilename) ? [self expandCustomFilenameFormatFromString:[exportCustomFilenameTokenField stringValue] usingTableName:nil] : [self generateDefaultExportFilename]]; - [exportFilename setString:[exportFilename stringByAppendingPathExtension:[self currentDefaultExportFileExtension]]]; - - singleFileHandle = [self getFileHandleForFilePath:[[exportPathField stringValue] stringByAppendingPathComponent:exportFilename]]; + singleFileHandle = [self fileHandleForFilePath:[[exportPathField stringValue] stringByAppendingPathComponent:exportFilename]]; } // Start the export process depending on the data source @@ -287,7 +267,7 @@ [exportFilename setString:[exportFilename stringByAppendingPathExtension:[self currentDefaultExportFileExtension]]]; - SPFileHandle *fileHandle = [self getFileHandleForFilePath:[[exportPathField stringValue] stringByAppendingPathComponent:exportFilename]]; + SPFileHandle *fileHandle = [self fileHandleForFilePath:[[exportPathField stringValue] stringByAppendingPathComponent:exportFilename]]; [sqlExporter setExportOutputFileHandle:fileHandle]; @@ -304,29 +284,9 @@ // export, create the single file now and assign it to all subsequently created exporters. if ((![self exportToMultipleFiles]) || (exportSource == SPFilteredExport) || (exportSource == SPQueryExport)) { - // Create custom filename if required - if (createCustomFilename) { - [exportFilename setString:[self expandCustomFilenameFormatFromString:[exportCustomFilenameTokenField stringValue] usingTableName:nil]]; - } - else { - // Determine what the file name should be - switch (exportSource) - { - case SPFilteredExport: - [exportFilename setString:[NSString stringWithFormat:@"%@_view", [tableDocumentInstance table]]]; - break; - case SPQueryExport: - [exportFilename setString:@"query_result"]; - break; - case SPTableExport: - [exportFilename setString:[tableDocumentInstance database]]; - break; - } - } - - [exportFilename setString:[exportFilename stringByAppendingPathExtension:[self currentDefaultExportFileExtension]]]; - - singleFileHandle = [self getFileHandleForFilePath:[[exportPathField stringValue] stringByAppendingPathComponent:exportFilename]]; + [exportFilename setString:(createCustomFilename) ? [self expandCustomFilenameFormatFromString:[exportCustomFilenameTokenField stringValue] usingTableName:nil] : [self generateDefaultExportFilename]]; + + singleFileHandle = [self fileHandleForFilePath:[[exportPathField stringValue] stringByAppendingPathComponent:exportFilename]]; } // Start the export process depending on the data source @@ -395,7 +355,7 @@ [exportFilename setString:[exportFilename stringByAppendingPathExtension:[self currentDefaultExportFileExtension]]]; - SPFileHandle *fileHandle = [self getFileHandleForFilePath:[[exportPathField stringValue] stringByAppendingPathComponent:exportFilename]]; + SPFileHandle *fileHandle = [self fileHandleForFilePath:[[exportPathField stringValue] stringByAppendingPathComponent:exportFilename]]; [dotExporter setExportOutputFileHandle:fileHandle]; @@ -468,7 +428,7 @@ [exportFilename setString:[exportFilename stringByAppendingPathExtension:[self currentDefaultExportFileExtension]]]; - fileHandle = [self getFileHandleForFilePath:[[exportPathField stringValue] stringByAppendingPathComponent:exportFilename]]; + fileHandle = [self fileHandleForFilePath:[[exportPathField stringValue] stringByAppendingPathComponent:exportFilename]]; [csvExporter setExportOutputFileHandle:fileHandle]; } @@ -504,7 +464,7 @@ [exportFilename setString:[[exportPathField stringValue] stringByAppendingPathComponent:table]]; [exportFilename setString:[exportFilename stringByAppendingPathExtension:[self currentDefaultExportFileExtension]]]; - fileHandle = [self getFileHandleForFilePath:exportFilename]; + fileHandle = [self fileHandleForFilePath:exportFilename]; // Write the file header [self writeXMLHeaderToFileHandle:fileHandle]; @@ -542,7 +502,7 @@ /** * Returns a file handle for writing at the supplied path. */ -- (SPFileHandle *)getFileHandleForFilePath:(NSString *)path +- (SPFileHandle *)fileHandleForFilePath:(NSString *)path { SPFileHandle *fileHandle = nil; NSFileManager *fileManager = [NSFileManager defaultManager]; -- cgit v1.2.3