diff options
author | Robert Antoni Buj i Gelonch <robert.buj@gmail.com> | 2014-10-13 13:20:47 +0200 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2014-10-14 07:15:41 +0000 |
commit | a2c481457cd2d03263054a5fefe80da316e09a44 (patch) | |
tree | 5b8717ae1fdfd55b5c3c56410408acd92a94ef42 | |
parent | fa6ac05beaaf1160c205e40099b99f0ed0efb131 (diff) |
runner: finally block to ensure that a resource is closed (Prior to Java SE 7)
http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
Change-Id: I5ecefd3e5bf84fea2a8735a44236ed4c86b440c4
Reviewed-on: https://gerrit.libreoffice.org/11950
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
Tested-by: Noel Grandin <noelgrandin@gmail.com>
-rw-r--r-- | qadevOOo/runner/convwatch/DB.java | 78 | ||||
-rw-r--r-- | qadevOOo/runner/convwatch/DBHelper.java | 18 | ||||
-rw-r--r-- | qadevOOo/runner/convwatch/FileHelper.java | 30 | ||||
-rw-r--r-- | qadevOOo/runner/convwatch/MSOfficePrint.java | 710 | ||||
-rw-r--r-- | qadevOOo/runner/convwatch/OfficePrint.java | 66 | ||||
-rw-r--r-- | qadevOOo/runner/graphical/MSOfficePostscriptCreator.java | 476 | ||||
-rw-r--r-- | qadevOOo/runner/helper/FileTools.java | 28 | ||||
-rw-r--r-- | qadevOOo/runner/stats/FileLogWriter.java | 13 | ||||
-rw-r--r-- | qadevOOo/runner/stats/SQLExecution.java | 86 | ||||
-rw-r--r-- | qadevOOo/runner/stats/SimpleFileOutProducer.java | 64 | ||||
-rw-r--r-- | qadevOOo/runner/util/DBTools.java | 32 |
11 files changed, 873 insertions, 728 deletions
diff --git a/qadevOOo/runner/convwatch/DB.java b/qadevOOo/runner/convwatch/DB.java index 70a25597af89..8b4c4ff006cf 100644 --- a/qadevOOo/runner/convwatch/DB.java +++ b/qadevOOo/runner/convwatch/DB.java @@ -215,49 +215,65 @@ public class DB extends DBHelper ArrayList<String> aResultList = new ArrayList<String>(); try { - oStmt = _aCon.createStatement(); - - java.sql.ResultSet aResultSet = oStmt.executeQuery(_sSQL); - java.sql.ResultSetMetaData aResultSetMetaData = aResultSet.getMetaData(); - - int nColumnCount = aResultSetMetaData.getColumnCount(); // java sql starts with '1' - - while( aResultSet.next() ) + try { - StringBuffer aResult = new StringBuffer(); + oStmt = _aCon.createStatement(); + java.sql.ResultSet aResultSet = null; try { - aResult.append("sqlresult: "); - for (int i=1;i<=nColumnCount;i++) + aResultSet = oStmt.executeQuery(_sSQL); + java.sql.ResultSetMetaData aResultSetMetaData = aResultSet.getMetaData(); + + int nColumnCount = aResultSetMetaData.getColumnCount(); // java sql starts with '1' + + while( aResultSet.next() ) { - String sColumnName = aResultSetMetaData.getColumnName(i); - aResult.append(sColumnName).append("="); - String sValue; - int nSQLType = aResultSetMetaData.getColumnType(i); - switch(nSQLType) + StringBuffer aResult = new StringBuffer(); + try { - case java.sql.Types.VARCHAR: - sValue = "'" + aResultSet.getString(i) + "'"; - break; - case java.sql.Types.INTEGER: - { - int nValue = aResultSet.getInt(i); - sValue = String.valueOf(nValue); - break; + aResult.append("sqlresult: "); + for (int i=1;i<=nColumnCount;i++) + { + String sColumnName = aResultSetMetaData.getColumnName(i); + aResult.append(sColumnName).append("="); + String sValue; + int nSQLType = aResultSetMetaData.getColumnType(i); + switch(nSQLType) + { + case java.sql.Types.VARCHAR: + sValue = "'" + aResultSet.getString(i) + "'"; + break; + case java.sql.Types.INTEGER: + { + int nValue = aResultSet.getInt(i); + sValue = String.valueOf(nValue); + break; + } + + default: + sValue = "UNSUPPORTED TYPE"; + } + aResult.append(sValue).append(", "); + } + String sResult = aResult.toString(); + aResultList.add(sResult); } - - default: - sValue = "UNSUPPORTED TYPE"; + catch (java.sql.SQLException e) + { } - aResult.append(sValue).append(", "); } - String sResult = aResult.toString(); - aResultList.add(sResult); } - catch (java.sql.SQLException e) + finally { + if (aResultSet != null) + aResultSet.close(); } } + finally + { + if (oStmt != null) + oStmt.close(); + } } catch (java.sql.SQLException e) { diff --git a/qadevOOo/runner/convwatch/DBHelper.java b/qadevOOo/runner/convwatch/DBHelper.java index aaf6497bcd75..03128eafa0ba 100644 --- a/qadevOOo/runner/convwatch/DBHelper.java +++ b/qadevOOo/runner/convwatch/DBHelper.java @@ -69,11 +69,19 @@ class ShareConnection try { - oStmt = m_aCon.createStatement(); - - GlobalLogWriter.get().println("DB: " + m_sSQL); - /* ResultSet oResult = */ - oStmt.executeUpdate(m_sSQL); + try + { + oStmt = m_aCon.createStatement(); + + GlobalLogWriter.get().println("DB: " + m_sSQL); + /* ResultSet oResult = */ + oStmt.executeUpdate(m_sSQL); + } + finally + { + if (oStmt != null) + oStmt.close(); + } } catch(Exception e) { diff --git a/qadevOOo/runner/convwatch/FileHelper.java b/qadevOOo/runner/convwatch/FileHelper.java index ba4e4c3f46a1..dab33c32e1f5 100644 --- a/qadevOOo/runner/convwatch/FileHelper.java +++ b/qadevOOo/runner/convwatch/FileHelper.java @@ -267,15 +267,31 @@ public class FileHelper File inputFile = new File(_sSource); File outputFile = new File(_sDestination); - java.io.FileReader in = new java.io.FileReader(inputFile); - java.io.FileWriter out = new java.io.FileWriter(outputFile); - int c; + java.io.FileReader in = null; + java.io.FileWriter out = null; + try + { + in = new java.io.FileReader(inputFile); + try + { + out = new java.io.FileWriter(outputFile); + int c; - while ((c = in.read()) != -1) - out.write(c); + while ((c = in.read()) != -1) + out.write(c); - in.close(); - out.close(); + } + finally + { + if (out != null) + out.close(); + } + } + finally + { + if (in != null) + in.close(); + } } catch (java.io.IOException e) { diff --git a/qadevOOo/runner/convwatch/MSOfficePrint.java b/qadevOOo/runner/convwatch/MSOfficePrint.java index 4436d8397cbf..ba65b5bcf80e 100644 --- a/qadevOOo/runner/convwatch/MSOfficePrint.java +++ b/qadevOOo/runner/convwatch/MSOfficePrint.java @@ -275,86 +275,93 @@ public class MSOfficePrint String sName = sTmpPath + fs + sPrintViaWord; File aFile = new File(sName); - FileWriter out = new FileWriter(aFile.toString()); - - - out.write( "eval 'exec perl -wS $0 ${1+\"$@\"}' " + ls ); - out.write( " if 0; " + ls ); - out.write( "use strict; " + ls ); - out.write( "use Time::HiRes; " + ls ); - out.write( "if ( $^O ne \"MSWin32\") " + ls ); - out.write( "{ " + ls ); - out.write( " print 'Windows only.\\n'; " + ls ); - out.write( " print_usage(); " + ls ); - out.write( " exit(1); " + ls ); - out.write( "} " + ls ); - out.write( " " + ls ); - out.write( "use Win32::OLE; " + ls ); - out.write( "use Win32::OLE::Const 'Microsoft Word'; " + ls ); - out.write( " " + ls ); - out.write( "# ------ usage ------ " + ls ); - out.write( "sub print_usage() " + ls ); - out.write( "{ " + ls ); - out.write( " print STDERR \"Usage: word_print.pl <Word file> <name of printer> <output file> .\\n " + ls ); - out.write( " Please use the same string for the name of the printer as you can find \\n " + ls ); - out.write( " under Start-Control Panel-Printer and Faxes \\n " + ls ); - out.write( " The name could look like the following line: \\n " + ls ); - out.write( " Apple LaserWriter II NT v47.0 \\n " + ls ); - out.write( " Sample command line: \\n " + ls ); - out.write( " execl_print.pl c:\\book1.doc Apple LaserWriter II NT v47.0 c:\\output\\book1.ps \\n\"; " + ls ); - out.write( "} " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( "if ($#ARGV != 2) " + ls ); - out.write( "{ " + ls ); - out.write( " print 'Too less arguments.\\n'; " + ls ); - out.write( " print_usage(); " + ls ); - out.write( " exit(1); " + ls ); - out.write( "} " + ls ); - out.write( " " + ls ); - out.write( "my $startWordTime = Time::HiRes::time(); " + ls ); - out.write( "my $Word = Win32::OLE->new('Word.Application'); " + ls ); - out.write( "my $stopWordTime = Time::HiRes::time() - $startWordTime; " + ls ); - out.write( "# $Word->{'Visible'} = 1; # if you want to see what's going on " + ls ); - out.write( "# , ReadOnly => 1})" + ls ); - out.write(ls); - out.write( "my $startLoadWordTime = Time::HiRes::time(); " + ls ); - out.write( "$Word->Documents->Open({Filename => $ARGV[0]}) " + ls ); - out.write( " || die('Unable to open document ', Win32::OLE->LastError()); " + ls ); - out.write( "my $stopLoadWordTime = Time::HiRes::time() - $startLoadWordTime; " + ls ); - out.write(ls); - out.write( "my $startPrintWordTime = Time::HiRes::time(); " + ls); - out.write( "my $oldActivePrinte = $Word->{ActivePrinter} ; " + ls ); - out.write( "$Word->{ActivePrinter} = $ARGV[1]; " + ls ); - out.write( "$Word->ActiveDocument->PrintOut({ " + ls ); - out.write( " Background => 0, " + ls ); - out.write( " Append => 0, " + ls ); - out.write( " Range => wdPrintAllDocument, " + ls ); - out.write( " Item => wdPrintDocumentContent, " + ls ); - out.write( " Copies => 1, " + ls ); - out.write( " PageType => wdPrintAllPages, " + ls ); - out.write( " PrintToFile => 1, " + ls ); - out.write( " OutputFileName => $ARGV[2] " + ls ); - out.write( " }); " + ls ); - out.write( "$Word->{ActivePrinter} = $oldActivePrinte; " + ls ); - out.write( "my $stopPrintWordTime = Time::HiRes::time() - $startPrintWordTime;" + ls); - - out.write( "# ActiveDocument.Close(SaveChanges:=WdSaveOptions.wdDoNotSaveChanges)" + ls ); - out.write( "my $sVersion = $Word->Application->Version();"+ls); - out.write( "$Word->ActiveDocument->Close({SaveChanges => 0}); " + ls ); - out.write( "$Word->Quit(); " + ls ); - - out.write( "local *FILE;" + ls); - out.write( "if (open(FILE, \">$ENV{HOME}/msofficeloadtimes.txt\"))" + ls); - out.write( "{" + ls); - out.write( " print FILE \"name=$ARGV[0]\\n\";" + ls); - out.write( " print FILE \"WordVersion=$sVersion\\n\";" + ls); - out.write( " print FILE \"WordStartTime=$stopWordTime\\n\";" + ls); - out.write( " print FILE \"WordLoadTime=$stopLoadWordTime\\n\";" + ls); - out.write( " print FILE \"WordPrintTime=$stopPrintWordTime\\n\";" + ls); - out.write( " close(FILE);" + ls); - out.write( "}" + ls); - out.close(); + FileWriter out = null; + try + { + out = new FileWriter(aFile.toString()); + + out.write( "eval 'exec perl -wS $0 ${1+\"$@\"}' " + ls ); + out.write( " if 0; " + ls ); + out.write( "use strict; " + ls ); + out.write( "use Time::HiRes; " + ls ); + out.write( "if ( $^O ne \"MSWin32\") " + ls ); + out.write( "{ " + ls ); + out.write( " print 'Windows only.\\n'; " + ls ); + out.write( " print_usage(); " + ls ); + out.write( " exit(1); " + ls ); + out.write( "} " + ls ); + out.write( " " + ls ); + out.write( "use Win32::OLE; " + ls ); + out.write( "use Win32::OLE::Const 'Microsoft Word'; " + ls ); + out.write( " " + ls ); + out.write( "# ------ usage ------ " + ls ); + out.write( "sub print_usage() " + ls ); + out.write( "{ " + ls ); + out.write( " print STDERR \"Usage: word_print.pl <Word file> <name of printer> <output file> .\\n " + ls ); + out.write( " Please use the same string for the name of the printer as you can find \\n " + ls ); + out.write( " under Start-Control Panel-Printer and Faxes \\n " + ls ); + out.write( " The name could look like the following line: \\n " + ls ); + out.write( " Apple LaserWriter II NT v47.0 \\n " + ls ); + out.write( " Sample command line: \\n " + ls ); + out.write( " execl_print.pl c:\\book1.doc Apple LaserWriter II NT v47.0 c:\\output\\book1.ps \\n\"; " + ls ); + out.write( "} " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( "if ($#ARGV != 2) " + ls ); + out.write( "{ " + ls ); + out.write( " print 'Too less arguments.\\n'; " + ls ); + out.write( " print_usage(); " + ls ); + out.write( " exit(1); " + ls ); + out.write( "} " + ls ); + out.write( " " + ls ); + out.write( "my $startWordTime = Time::HiRes::time(); " + ls ); + out.write( "my $Word = Win32::OLE->new('Word.Application'); " + ls ); + out.write( "my $stopWordTime = Time::HiRes::time() - $startWordTime; " + ls ); + out.write( "# $Word->{'Visible'} = 1; # if you want to see what's going on " + ls ); + out.write( "# , ReadOnly => 1})" + ls ); + out.write(ls); + out.write( "my $startLoadWordTime = Time::HiRes::time(); " + ls ); + out.write( "$Word->Documents->Open({Filename => $ARGV[0]}) " + ls ); + out.write( " || die('Unable to open document ', Win32::OLE->LastError()); " + ls ); + out.write( "my $stopLoadWordTime = Time::HiRes::time() - $startLoadWordTime; " + ls ); + out.write(ls); + out.write( "my $startPrintWordTime = Time::HiRes::time(); " + ls); + out.write( "my $oldActivePrinte = $Word->{ActivePrinter} ; " + ls ); + out.write( "$Word->{ActivePrinter} = $ARGV[1]; " + ls ); + out.write( "$Word->ActiveDocument->PrintOut({ " + ls ); + out.write( " Background => 0, " + ls ); + out.write( " Append => 0, " + ls ); + out.write( " Range => wdPrintAllDocument, " + ls ); + out.write( " Item => wdPrintDocumentContent, " + ls ); + out.write( " Copies => 1, " + ls ); + out.write( " PageType => wdPrintAllPages, " + ls ); + out.write( " PrintToFile => 1, " + ls ); + out.write( " OutputFileName => $ARGV[2] " + ls ); + out.write( " }); " + ls ); + out.write( "$Word->{ActivePrinter} = $oldActivePrinte; " + ls ); + out.write( "my $stopPrintWordTime = Time::HiRes::time() - $startPrintWordTime;" + ls); + + out.write( "# ActiveDocument.Close(SaveChanges:=WdSaveOptions.wdDoNotSaveChanges)" + ls ); + out.write( "my $sVersion = $Word->Application->Version();"+ls); + out.write( "$Word->ActiveDocument->Close({SaveChanges => 0}); " + ls ); + out.write( "$Word->Quit(); " + ls ); + + out.write( "local *FILE;" + ls); + out.write( "if (open(FILE, \">$ENV{HOME}/msofficeloadtimes.txt\"))" + ls); + out.write( "{" + ls); + out.write( " print FILE \"name=$ARGV[0]\\n\";" + ls); + out.write( " print FILE \"WordVersion=$sVersion\\n\";" + ls); + out.write( " print FILE \"WordStartTime=$stopWordTime\\n\";" + ls); + out.write( " print FILE \"WordLoadTime=$stopLoadWordTime\\n\";" + ls); + out.write( " print FILE \"WordPrintTime=$stopPrintWordTime\\n\";" + ls); + out.write( " close(FILE);" + ls); + out.write( "}" + ls); + } + finally + { + if (out != null) + out.close(); + } aList.add("perl"); aList.add(sName); @@ -412,59 +419,67 @@ public class MSOfficePrint } File aFile = new File(sName); - FileWriter out = new FileWriter(aFile.toString()); - - out.write( "eval 'exec perl -wS $0 ${1+\"$@\"}' " + ls ); - out.write( " if 0; " + ls ); - out.write( "use strict; " + ls ); - out.write( " " + ls ); - out.write( "if ( $^O ne \"MSWin32\") " + ls ); - out.write( "{ " + ls ); - out.write( " print 'Windows only.\\n'; " + ls ); - out.write( " print_usage(); " + ls ); - out.write( " exit(1); " + ls ); - out.write( "} " + ls ); - out.write( " " + ls ); - out.write( "use Win32::OLE; " + ls ); - out.write( "use Win32::OLE::Const 'Microsoft Word'; " + ls ); - out.write( " " + ls ); - out.write( "# ------ usage ------ " + ls ); - out.write( "sub print_usage() " + ls ); - out.write( "{ " + ls ); - out.write( " print STDERR \"Usage: storeViaWord.pl <Word file> <output filer> <output file> \\n\" " + ls ); - out.write( "} " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( "if ($#ARGV != 2) " + ls ); - out.write( "{ " + ls ); - out.write( " print 'Too less arguments.\\n'; " + ls ); - out.write( " print_usage(); " + ls ); - out.write( " exit(1); " + ls ); - out.write( "} " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( "my $Word = Win32::OLE->new('Word.Application'); " + ls ); - out.write( "# $Word->{'Visible'} = 1; # if you want to see what's going on " + ls ); - out.write( "my $Book = $Word->Documents->Open($ARGV[0]) " + ls ); - out.write( " || die('Unable to open document ', Win32::OLE->LastError()); " + ls ); - out.write( "# my $oldActivePrinte = $Word->{ActivePrinter} ; " + ls ); - out.write( "# $Word->{ActivePrinter} = $ARGV[1]; " + ls ); - out.write( "# $Word->ActiveDocument->PrintOut({ " + ls ); - out.write( "# Background => 0, " + ls ); - out.write( "# Append => 0, " + ls ); - out.write( "# Range => wdPrintAllDocument, " + ls ); - out.write( "# Item => wdPrintDocumentContent, " + ls ); - out.write( "# Copies => 1, " + ls ); - out.write( "# PageType => wdPrintAllPages, " + ls ); - out.write( "# PrintToFile => 1, " + ls ); - out.write( "# OutputFileName => $ARGV[2] " + ls ); - out.write( "# }); " + ls ); - out.write( "# $Word->{ActivePrinter} = $oldActivePrinte; " + ls ); - out.write( "$Book->savaAs($ARGV[2], $ARGV[1]); " + ls ); - out.write( "# ActiveDocument.Close(SaveChanges:=WdSaveOptions.wdDoNotSaveChanges)" + ls ); - out.write( "$Book->Close({SaveChanges => 0}); " + ls ); - out.write( "$Word->Quit(); " + ls ); - out.close(); + FileWriter out = null; + try + { + out = new FileWriter(aFile.toString()); + + out.write( "eval 'exec perl -wS $0 ${1+\"$@\"}' " + ls ); + out.write( " if 0; " + ls ); + out.write( "use strict; " + ls ); + out.write( " " + ls ); + out.write( "if ( $^O ne \"MSWin32\") " + ls ); + out.write( "{ " + ls ); + out.write( " print 'Windows only.\\n'; " + ls ); + out.write( " print_usage(); " + ls ); + out.write( " exit(1); " + ls ); + out.write( "} " + ls ); + out.write( " " + ls ); + out.write( "use Win32::OLE; " + ls ); + out.write( "use Win32::OLE::Const 'Microsoft Word'; " + ls ); + out.write( " " + ls ); + out.write( "# ------ usage ------ " + ls ); + out.write( "sub print_usage() " + ls ); + out.write( "{ " + ls ); + out.write( " print STDERR \"Usage: storeViaWord.pl <Word file> <output filer> <output file> \\n\" " + ls ); + out.write( "} " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( "if ($#ARGV != 2) " + ls ); + out.write( "{ " + ls ); + out.write( " print 'Too less arguments.\\n'; " + ls ); + out.write( " print_usage(); " + ls ); + out.write( " exit(1); " + ls ); + out.write( "} " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( "my $Word = Win32::OLE->new('Word.Application'); " + ls ); + out.write( "# $Word->{'Visible'} = 1; # if you want to see what's going on " + ls ); + out.write( "my $Book = $Word->Documents->Open($ARGV[0]) " + ls ); + out.write( " || die('Unable to open document ', Win32::OLE->LastError()); " + ls ); + out.write( "# my $oldActivePrinte = $Word->{ActivePrinter} ; " + ls ); + out.write( "# $Word->{ActivePrinter} = $ARGV[1]; " + ls ); + out.write( "# $Word->ActiveDocument->PrintOut({ " + ls ); + out.write( "# Background => 0, " + ls ); + out.write( "# Append => 0, " + ls ); + out.write( "# Range => wdPrintAllDocument, " + ls ); + out.write( "# Item => wdPrintDocumentContent, " + ls ); + out.write( "# Copies => 1, " + ls ); + out.write( "# PageType => wdPrintAllPages, " + ls ); + out.write( "# PrintToFile => 1, " + ls ); + out.write( "# OutputFileName => $ARGV[2] " + ls ); + out.write( "# }); " + ls ); + out.write( "# $Word->{ActivePrinter} = $oldActivePrinte; " + ls ); + out.write( "$Book->savaAs($ARGV[2], $ARGV[1]); " + ls ); + out.write( "# ActiveDocument.Close(SaveChanges:=WdSaveOptions.wdDoNotSaveChanges)" + ls ); + out.write( "$Book->Close({SaveChanges => 0}); " + ls ); + out.write( "$Word->Quit(); " + ls ); + } + finally + { + if (out != null) + out.close(); + } aList.add("perl"); aList.add(sName); @@ -493,74 +508,82 @@ public class MSOfficePrint } File aFile = new File(sName); - FileWriter out = new FileWriter(aFile.toString()); - - out.write( "eval 'exec perl -wS $0 ${1+\"$@\"}' " + ls ); - out.write( " if 0; " + ls ); - out.write( "use strict; " + ls ); - out.write( " " + ls ); - out.write( "if ( $^O ne \"MSWin32\") " + ls ); - out.write( "{ " + ls ); - out.write( " print \"Windows only.\\n\"; " + ls ); - out.write( " print_usage(); " + ls ); - out.write( " exit(1); " + ls ); - out.write( "} " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( "use Win32::OLE qw(in with); " + ls ); - out.write( "use Win32::OLE::Const 'Microsoft Excel'; " + ls ); - out.write( " " + ls ); - out.write( "# ------ usage ------ " + ls ); - out.write( "sub print_usage() " + ls ); - out.write( "{ " + ls ); - out.write( " print STDERR \"Usage: printViaExcel.pl <Excel file> <name of printer> <output file> .\\n " + ls ); - out.write( " Please use the same string for the name of the printer as you can find \\n " + ls ); - out.write( " under Start-Control Panel-Printer and Faxes \\n " + ls ); - out.write( " The name could look like the following line: \\n " + ls ); - out.write( " Apple LaserWriter II NT v47.0 \\n " + ls ); - out.write( " Sample command line: \\n " + ls ); - out.write( " execl_print.pl c:\\book1.xls Apple LaserWriter II NT v47.0 c:\\output\\book1.ps \\n\"; " + ls ); - out.write( "} " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( "$Win32::OLE::Warn = 3; # die on errors... " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( "if ($#ARGV != 2) " + ls ); - out.write( "{ " + ls ); - out.write( " print STDERR \"Too less arguments.\\n\"; " + ls ); - out.write( " print STDERR \"ARGV[0] $ARGV[0]\\n\"; " + ls ); - out.write( " print STDERR \"ARGV[1] $ARGV[1]\\n\"; " + ls ); - out.write( " print STDERR \"ARGV[2] $ARGV[2]\\n\"; " + ls ); - out.write( " print_usage(); " + ls ); - out.write( " exit(1); " + ls ); - out.write( "} " + ls ); - out.write( " " + ls ); - out.write( "my $Excel = Win32::OLE->GetActiveObject('Excel.Application') " + ls ); - out.write( " || Win32::OLE->new('Excel.Application', 'Quit'); # get already active Excel " + ls ); - out.write( " # application or open new " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( "my $Book = $Excel->Workbooks->Open( $ARGV[0] ); " + ls ); - out.write( " $Book->PrintOut({Copies => 1, " + ls ); - out.write( " ActivePrinter => $ARGV[1], " + ls ); - out.write( " PrToFileName => $ARGV[2], " + ls ); - out.write( " Collate => 1 " + ls ); - out.write( " }); " + ls ); - out.write( "# Close worksheets without store changes" + ls ); - out.write( "# $Book->Close({SaveChanges => 0}); " + ls ); - out.write( "my $sVersion = $Excel->Application->Version();"+ls); - out.write( "$Excel->Quit(); " + ls ); - out.write( "local *FILE;" + ls); - out.write( "if (open(FILE, \">$ENV{HOME}/msofficeloadtimes.txt\"))" + ls); - out.write( "{" + ls); - out.write( " print FILE \"name=$ARGV[0]\\n\";" + ls); - out.write( " print FILE \"ExcelVersion=$sVersion\\n\";" + ls); - out.write( " close(FILE);" + ls); - out.write( "}" + ls); - out.close(); + FileWriter out = null; + try + { + out = new FileWriter(aFile.toString()); + + out.write( "eval 'exec perl -wS $0 ${1+\"$@\"}' " + ls ); + out.write( " if 0; " + ls ); + out.write( "use strict; " + ls ); + out.write( " " + ls ); + out.write( "if ( $^O ne \"MSWin32\") " + ls ); + out.write( "{ " + ls ); + out.write( " print \"Windows only.\\n\"; " + ls ); + out.write( " print_usage(); " + ls ); + out.write( " exit(1); " + ls ); + out.write( "} " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( "use Win32::OLE qw(in with); " + ls ); + out.write( "use Win32::OLE::Const 'Microsoft Excel'; " + ls ); + out.write( " " + ls ); + out.write( "# ------ usage ------ " + ls ); + out.write( "sub print_usage() " + ls ); + out.write( "{ " + ls ); + out.write( " print STDERR \"Usage: printViaExcel.pl <Excel file> <name of printer> <output file> .\\n " + ls ); + out.write( " Please use the same string for the name of the printer as you can find \\n " + ls ); + out.write( " under Start-Control Panel-Printer and Faxes \\n " + ls ); + out.write( " The name could look like the following line: \\n " + ls ); + out.write( " Apple LaserWriter II NT v47.0 \\n " + ls ); + out.write( " Sample command line: \\n " + ls ); + out.write( " execl_print.pl c:\\book1.xls Apple LaserWriter II NT v47.0 c:\\output\\book1.ps \\n\"; " + ls ); + out.write( "} " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( "$Win32::OLE::Warn = 3; # die on errors... " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( "if ($#ARGV != 2) " + ls ); + out.write( "{ " + ls ); + out.write( " print STDERR \"Too less arguments.\\n\"; " + ls ); + out.write( " print STDERR \"ARGV[0] $ARGV[0]\\n\"; " + ls ); + out.write( " print STDERR \"ARGV[1] $ARGV[1]\\n\"; " + ls ); + out.write( " print STDERR \"ARGV[2] $ARGV[2]\\n\"; " + ls ); + out.write( " print_usage(); " + ls ); + out.write( " exit(1); " + ls ); + out.write( "} " + ls ); + out.write( " " + ls ); + out.write( "my $Excel = Win32::OLE->GetActiveObject('Excel.Application') " + ls ); + out.write( " || Win32::OLE->new('Excel.Application', 'Quit'); # get already active Excel " + ls ); + out.write( " # application or open new " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( "my $Book = $Excel->Workbooks->Open( $ARGV[0] ); " + ls ); + out.write( " $Book->PrintOut({Copies => 1, " + ls ); + out.write( " ActivePrinter => $ARGV[1], " + ls ); + out.write( " PrToFileName => $ARGV[2], " + ls ); + out.write( " Collate => 1 " + ls ); + out.write( " }); " + ls ); + out.write( "# Close worksheets without store changes" + ls ); + out.write( "# $Book->Close({SaveChanges => 0}); " + ls ); + out.write( "my $sVersion = $Excel->Application->Version();"+ls); + out.write( "$Excel->Quit(); " + ls ); + out.write( "local *FILE;" + ls); + out.write( "if (open(FILE, \">$ENV{HOME}/msofficeloadtimes.txt\"))" + ls); + out.write( "{" + ls); + out.write( " print FILE \"name=$ARGV[0]\\n\";" + ls); + out.write( " print FILE \"ExcelVersion=$sVersion\\n\";" + ls); + out.write( " close(FILE);" + ls); + out.write( "}" + ls); + } + finally + { + if (out != null) + out.close(); + } aList.add("perl"); aList.add(sName); @@ -588,69 +611,77 @@ public class MSOfficePrint } File aFile = new File(sName); - FileWriter out = new FileWriter(aFile.toString()); - - out.write( "eval 'exec perl -wS $0 ${1+\"$@\"}' " + ls ); - out.write( " if 0; " + ls ); - out.write( "use strict; " + ls ); - out.write( "# This script is automatically created. " + ls ); - out.write( " " + ls ); - out.write( "use Win32::OLE qw(in with); " + ls ); - out.write( "use Win32::OLE::Const 'Microsoft Excel'; " + ls ); - out.write( " " + ls ); - out.write( "# ------ usage ------ " + ls ); - out.write( "sub print_usage() " + ls ); - out.write( "{ " + ls ); - out.write( " print STDERR \"Usage: savaViaExcel.pl <Excel file> <filefilter> <output file> .\\n " + ls ); - out.write( " execl_print.pl c:\\book1.xls Apple LaserWriter II NT v47.0 c:\\output\\book1.ps \\n\"; " + ls ); - out.write( "} " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( "$Win32::OLE::Warn = 3; # die on errors... " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( "if ($#ARGV != 2) " + ls ); - out.write( "{ " + ls ); - out.write( " print \"Too less arguments.\\n\"; " + ls ); - out.write( " print_usage(); " + ls ); - out.write( " exit(1); " + ls ); - out.write( "} " + ls ); - out.write( " " + ls ); - out.write( "my $Excel = Win32::OLE->GetActiveObject('Excel.Application') " + ls ); - out.write( " || Win32::OLE->new('Excel.Application', 'Quit'); # get already active Excel " + ls ); - out.write( " # application or open new " + ls ); - out.write( "my $sFilterParameter = $ARGV[1]; " + ls ); - out.write( "my $sFilterName = xlHTML; " + ls ); - out.write( "if ($sFilterParameter eq 'xlXMLSpreadsheet') " + ls ); - out.write( "{ " + ls ); - out.write( " $sFilterName = xlXMLSpreadsheet; " + ls ); - out.write( "} " + ls ); - out.write( "elsif ($sFilterParameter eq 'xlHTML') " + ls ); - out.write( "{ " + ls ); - out.write( " $sFilterName = xlHTML; " + ls ); - out.write( "} " + ls ); - out.write( "else " + ls ); - out.write( "{ " + ls ); - out.write( " my $undefined; " + ls); - out.write( " $sFilterName = $undefined; " + ls ); - out.write( "} " + ls ); - out.write( " " + ls ); - out.write( "my $Book = $Excel->Workbooks->Open( $ARGV[0] ); " + ls ); - out.write( "$Excel->{DisplayAlerts} = 0; " + ls ); - out.write( "$Book->saveAs($ARGV[2], " + ls ); - out.write( " $sFilterName, " + ls ); - out.write( " '', " + ls ); - out.write( " '', " + ls ); - out.write( " 0, " + ls ); - out.write( " 0, " + ls ); - out.write( " xlNoChange, " + ls ); - out.write( " xlLocalSessionChanges, " + ls ); - out.write( " 1); " + ls ); - out.write( "# Close worksheets without store changes" + ls ); - out.write( "# $Book->Close({SaveChanges => 0}); " + ls ); - out.write( "$Excel->Quit(); " + ls ); - out.close(); + FileWriter out = null; + try + { + out = new FileWriter(aFile.toString()); + + out.write( "eval 'exec perl -wS $0 ${1+\"$@\"}' " + ls ); + out.write( " if 0; " + ls ); + out.write( "use strict; " + ls ); + out.write( "# This script is automatically created. " + ls ); + out.write( " " + ls ); + out.write( "use Win32::OLE qw(in with); " + ls ); + out.write( "use Win32::OLE::Const 'Microsoft Excel'; " + ls ); + out.write( " " + ls ); + out.write( "# ------ usage ------ " + ls ); + out.write( "sub print_usage() " + ls ); + out.write( "{ " + ls ); + out.write( " print STDERR \"Usage: savaViaExcel.pl <Excel file> <filefilter> <output file> .\\n " + ls ); + out.write( " execl_print.pl c:\\book1.xls Apple LaserWriter II NT v47.0 c:\\output\\book1.ps \\n\"; " + ls ); + out.write( "} " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( "$Win32::OLE::Warn = 3; # die on errors... " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( "if ($#ARGV != 2) " + ls ); + out.write( "{ " + ls ); + out.write( " print \"Too less arguments.\\n\"; " + ls ); + out.write( " print_usage(); " + ls ); + out.write( " exit(1); " + ls ); + out.write( "} " + ls ); + out.write( " " + ls ); + out.write( "my $Excel = Win32::OLE->GetActiveObject('Excel.Application') " + ls ); + out.write( " || Win32::OLE->new('Excel.Application', 'Quit'); # get already active Excel " + ls ); + out.write( " # application or open new " + ls ); + out.write( "my $sFilterParameter = $ARGV[1]; " + ls ); + out.write( "my $sFilterName = xlHTML; " + ls ); + out.write( "if ($sFilterParameter eq 'xlXMLSpreadsheet') " + ls ); + out.write( "{ " + ls ); + out.write( " $sFilterName = xlXMLSpreadsheet; " + ls ); + out.write( "} " + ls ); + out.write( "elsif ($sFilterParameter eq 'xlHTML') " + ls ); + out.write( "{ " + ls ); + out.write( " $sFilterName = xlHTML; " + ls ); + out.write( "} " + ls ); + out.write( "else " + ls ); + out.write( "{ " + ls ); + out.write( " my $undefined; " + ls); + out.write( " $sFilterName = $undefined; " + ls ); + out.write( "} " + ls ); + out.write( " " + ls ); + out.write( "my $Book = $Excel->Workbooks->Open( $ARGV[0] ); " + ls ); + out.write( "$Excel->{DisplayAlerts} = 0; " + ls ); + out.write( "$Book->saveAs($ARGV[2], " + ls ); + out.write( " $sFilterName, " + ls ); + out.write( " '', " + ls ); + out.write( " '', " + ls ); + out.write( " 0, " + ls ); + out.write( " 0, " + ls ); + out.write( " xlNoChange, " + ls ); + out.write( " xlLocalSessionChanges, " + ls ); + out.write( " 1); " + ls ); + out.write( "# Close worksheets without store changes" + ls ); + out.write( "# $Book->Close({SaveChanges => 0}); " + ls ); + out.write( "$Excel->Quit(); " + ls ); + } + finally + { + if (out != null) + out.close(); + } aList.add("perl"); aList.add(sName); @@ -678,78 +709,85 @@ public class MSOfficePrint } File aFile = new File(sName); - FileWriter out = new FileWriter(aFile.toString()); - - - out.write( "eval 'exec perl -wS $0 $1 $2 ' " + ls ); - out.write( " if 0; " + ls ); - out.write( "use strict; " + ls ); - out.write( " " + ls ); - out.write( "if ( $^O ne \"MSWin32\") " + ls ); - out.write( "{ " + ls ); - out.write( " print \"Windows only.\\n\"; " + ls ); - out.write( " print_usage(); " + ls ); - out.write( " exit(1); " + ls ); - out.write( "} " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( "use Win32::OLE qw(in with); " + ls ); - out.write( "use Win32::OLE::Const 'Microsoft PowerPoint'; " + ls ); - out.write( " " + ls ); - out.write( "# ------ usage ------ " + ls ); - out.write( "sub print_usage() " + ls ); - out.write( "{ " + ls ); - out.write( " print STDERR \"Usage: powerpoint_print.pl <PowerPoint file> <name of printer> <output file> .\\n " + ls ); - out.write( " Please use the same string for the name of the printer as you can find \\n " + ls ); - out.write( " under Start-Control Panel-Printer and Faxes \\n " + ls ); - out.write( " The name could look like the following line: \\n " + ls ); - out.write( " Apple LaserWriter II NT v47.0 \\n " + ls ); - out.write( " Sample command line: \\n " + ls ); - out.write( " powerpoint_print.pl c:\\book.ppt Apple LaserWriter II NT v47.0 c:\\output\\book.ps \\n\"; " + ls ); - out.write( "} " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( "$Win32::OLE::Warn = 3; # die on errors... " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( "if ($#ARGV < 2) " + ls ); - out.write( "{ " + ls ); - out.write( " print \"Too less arguments.\\n\"; " + ls ); - out.write( " print_usage(); " + ls ); - out.write( " exit(1); " + ls ); - out.write( "} " + ls ); - out.write( " " + ls ); - out.write( "my $PowerPoint = Win32::OLE->GetActiveObject('PowerPoint.Application') " + ls ); - out.write( " || Win32::OLE->new('PowerPoint.Application', 'Quit'); # get already active Excel " + ls ); - out.write( " # application or open new " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( " $PowerPoint->{'Visible'} = 1; " + ls ); - out.write( " my $Presentation = $PowerPoint->Presentations->Add; " + ls ); - out.write( " my $Presentation = $PowerPoint->Presentations->Open( $ARGV[0] ); " + ls ); - out.write( "# we can't change active printer in powerpoint " + ls ); - out.write( "# $Presentation->PrintOptions->{ActivePrinter} = $ARGV[1]; " + ls ); - out.write( " print \"Active printer is: \" . $Presentation->PrintOptions->{ActivePrinter} . \"\\n\"; " + ls ); - out.write( " $Presentation->PrintOptions->{PrintInBackground} = 0; " + ls ); - out.write( " # PrintColorType = 1 means print in color and PrintColorType = 2 means print in gray " + ls ); - out.write( " $Presentation->PrintOptions->{PrintColorType} = 1; " + ls ); - out.write( " " + ls ); - out.write( " $Presentation->PrintOut({PrintToFile => $ARGV[2]}); " + ls ); - out.write( " sleep 5; " + ls ); - out.write( " print \"Presentation has been printed\\n\"; " + ls ); - out.write( "my $sVersion = $Presentation->Application->Version();"+ls); - out.write( " $PowerPoint->Quit(); " + ls ); - - out.write( "local *FILE;" + ls); - out.write( "if (open(FILE, \">$ENV{HOME}/msofficeloadtimes.txt\"))" + ls); - out.write( "{" + ls); - out.write( " print FILE \"name=$ARGV[0]\\n\";" + ls); - out.write( " print FILE \"PowerPointVersion=$sVersion\\n\";" + ls); - out.write( " close(FILE);" + ls); - out.write( "}" + ls); - out.close(); + FileWriter out = null; + try + { + out = new FileWriter(aFile.toString()); + + out.write( "eval 'exec perl -wS $0 $1 $2 ' " + ls ); + out.write( " if 0; " + ls ); + out.write( "use strict; " + ls ); + out.write( " " + ls ); + out.write( "if ( $^O ne \"MSWin32\") " + ls ); + out.write( "{ " + ls ); + out.write( " print \"Windows only.\\n\"; " + ls ); + out.write( " print_usage(); " + ls ); + out.write( " exit(1); " + ls ); + out.write( "} " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( "use Win32::OLE qw(in with); " + ls ); + out.write( "use Win32::OLE::Const 'Microsoft PowerPoint'; " + ls ); + out.write( " " + ls ); + out.write( "# ------ usage ------ " + ls ); + out.write( "sub print_usage() " + ls ); + out.write( "{ " + ls ); + out.write( " print STDERR \"Usage: powerpoint_print.pl <PowerPoint file> <name of printer> <output file> .\\n " + ls ); + out.write( " Please use the same string for the name of the printer as you can find \\n " + ls ); + out.write( " under Start-Control Panel-Printer and Faxes \\n " + ls ); + out.write( " The name could look like the following line: \\n " + ls ); + out.write( " Apple LaserWriter II NT v47.0 \\n " + ls ); + out.write( " Sample command line: \\n " + ls ); + out.write( " powerpoint_print.pl c:\\book.ppt Apple LaserWriter II NT v47.0 c:\\output\\book.ps \\n\"; " + ls ); + out.write( "} " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( "$Win32::OLE::Warn = 3; # die on errors... " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( "if ($#ARGV < 2) " + ls ); + out.write( "{ " + ls ); + out.write( " print \"Too less arguments.\\n\"; " + ls ); + out.write( " print_usage(); " + ls ); + out.write( " exit(1); " + ls ); + out.write( "} " + ls ); + out.write( " " + ls ); + out.write( "my $PowerPoint = Win32::OLE->GetActiveObject('PowerPoint.Application') " + ls ); + out.write( " || Win32::OLE->new('PowerPoint.Application', 'Quit'); # get already active Excel " + ls ); + out.write( " # application or open new " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( " $PowerPoint->{'Visible'} = 1; " + ls ); + out.write( " my $Presentation = $PowerPoint->Presentations->Add; " + ls ); + out.write( " my $Presentation = $PowerPoint->Presentations->Open( $ARGV[0] ); " + ls ); + out.write( "# we can't change active printer in powerpoint " + ls ); + out.write( "# $Presentation->PrintOptions->{ActivePrinter} = $ARGV[1]; " + ls ); + out.write( " print \"Active printer is: \" . $Presentation->PrintOptions->{ActivePrinter} . \"\\n\"; " + ls ); + out.write( " $Presentation->PrintOptions->{PrintInBackground} = 0; " + ls ); + out.write( " # PrintColorType = 1 means print in color and PrintColorType = 2 means print in gray " + ls ); + out.write( " $Presentation->PrintOptions->{PrintColorType} = 1; " + ls ); + out.write( " " + ls ); + out.write( " $Presentation->PrintOut({PrintToFile => $ARGV[2]}); " + ls ); + out.write( " sleep 5; " + ls ); + out.write( " print \"Presentation has been printed\\n\"; " + ls ); + out.write( "my $sVersion = $Presentation->Application->Version();"+ls); + out.write( " $PowerPoint->Quit(); " + ls ); + + out.write( "local *FILE;" + ls); + out.write( "if (open(FILE, \">$ENV{HOME}/msofficeloadtimes.txt\"))" + ls); + out.write( "{" + ls); + out.write( " print FILE \"name=$ARGV[0]\\n\";" + ls); + out.write( " print FILE \"PowerPointVersion=$sVersion\\n\";" + ls); + out.write( " close(FILE);" + ls); + out.write( "}" + ls); + } + finally + { + if (out != null) + out.close(); + } aList.add("perl"); aList.add(sName); diff --git a/qadevOOo/runner/convwatch/OfficePrint.java b/qadevOOo/runner/convwatch/OfficePrint.java index 24eb0b047483..cc7867db015e 100644 --- a/qadevOOo/runner/convwatch/OfficePrint.java +++ b/qadevOOo/runner/convwatch/OfficePrint.java @@ -362,48 +362,56 @@ public class OfficePrint { String sBuildID = ""; + FileWriter out = null; try { - FileWriter out = new FileWriter(aInfoFile.toString()); - out.write("# automatically created file by graphical compare" + ls); - if (_aGTA != null) + try { - if (_sSpecial != null && _sSpecial.equals("msoffice")) + out = new FileWriter(aInfoFile.toString()); + out.write("# automatically created file by graphical compare" + ls); + if (_aGTA != null) { - out.write("# buildid from wordloadfile" + ls); - sBuildID = _aGTA.getPerformance().getMSOfficeVersion(); - out.write("buildid=" + sBuildID + ls); + if (_sSpecial != null && _sSpecial.equals("msoffice")) + { + out.write("# buildid from wordloadfile" + ls); + sBuildID = _aGTA.getPerformance().getMSOfficeVersion(); + out.write("buildid=" + sBuildID + ls); + } + else + { + out.write("# buildid is read out of the bootstrap file" + ls); + sBuildID = _aGTA.getBuildID(); + out.write("buildid=" + sBuildID + ls); + } + out.write(ls); + out.write("# resolution given in DPI" + ls); + out.write("resolution=" + _aGTA.getResolutionInDPI() + ls); } else { - out.write("# buildid is read out of the bootstrap file" + ls); - sBuildID = _aGTA.getBuildID(); - out.write("buildid=" + sBuildID + ls); + out.write("buildid=" + _sSpecial + ls); } + out.write(ls); - out.write("# resolution given in DPI" + ls); - out.write("resolution=" + _aGTA.getResolutionInDPI() + ls); - } - else - { - out.write("buildid=" + _sSpecial + ls); - } + out.write("# Values out of System.getProperty(...)" + ls); + out.write("os.name=" + System.getProperty("os.name") + ls); + out.write("os.arch=" + System.getProperty("os.arch") + ls); + out.write("os.version=" + System.getProperty("os.version") + ls); - out.write(ls); - out.write("# Values out of System.getProperty(...)" + ls); - out.write("os.name=" + System.getProperty("os.name") + ls); - out.write("os.arch=" + System.getProperty("os.arch") + ls); - out.write("os.version=" + System.getProperty("os.version") + ls); + if (_aGTA != null) + { + out.write(ls); + out.write("# Performance output, values are given in milli sec." + ls); + _aGTA.getPerformance().print(out); + } - if (_aGTA != null) + out.flush(); + } + finally { - out.write(ls); - out.write("# Performance output, values are given in milli sec." + ls); - _aGTA.getPerformance().print(out); + if (out != null) + out.close(); } - - out.flush(); - out.close(); } catch (java.io.IOException e) { diff --git a/qadevOOo/runner/graphical/MSOfficePostscriptCreator.java b/qadevOOo/runner/graphical/MSOfficePostscriptCreator.java index 5a940ca79b3e..6133094ece6d 100644 --- a/qadevOOo/runner/graphical/MSOfficePostscriptCreator.java +++ b/qadevOOo/runner/graphical/MSOfficePostscriptCreator.java @@ -285,86 +285,93 @@ public class MSOfficePostscriptCreator implements IOffice String sFileName = FileHelper.appendPath(sTmpPath, sPrintViaWord); File aFile = new File(sFileName); - FileWriter out = new FileWriter(aFile); - - - out.write( "eval 'exec perl -wS $0 ${1+\"$@\"}' " + ls ); - out.write( " if 0; " + ls ); - out.write( "use strict; " + ls ); - out.write( "use Time::HiRes; " + ls ); - out.write( "if ( $^O ne \"MSWin32\") " + ls ); - out.write( "{ " + ls ); - out.write( " print 'Windows only.\\n'; " + ls ); - out.write( " print_usage(); " + ls ); - out.write( " exit(1); " + ls ); - out.write( "} " + ls ); - out.write( " " + ls ); - out.write( "use Win32::OLE; " + ls ); - out.write( "use Win32::OLE::Const 'Microsoft Word'; " + ls ); - out.write( " " + ls ); - out.write( "# ------ usage ------ " + ls ); - out.write( "sub print_usage() " + ls ); - out.write( "{ " + ls ); - out.write( " print STDERR \"Usage: word_print.pl <Word file> <name of printer> <output file> .\\n " + ls ); - out.write( " Please use the same string for the name of the printer as you can find \\n " + ls ); - out.write( " under Start-Control Panel-Printer and Faxes \\n " + ls ); - out.write( " The name could look like the following line: \\n " + ls ); - out.write( " Apple LaserWriter II NT v47.0 \\n " + ls ); - out.write( " Sample command line: \\n " + ls ); - out.write( " execl_print.pl c:\\book1.doc Apple LaserWriter II NT v47.0 c:\\output\\book1.ps \\n\"; " + ls ); - out.write( "} " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( "if ($#ARGV != 2) " + ls ); - out.write( "{ " + ls ); - out.write( " print 'Too less arguments.\\n'; " + ls ); - out.write( " print_usage(); " + ls ); - out.write( " exit(1); " + ls ); - out.write( "} " + ls ); - out.write( " " + ls ); - out.write( "my $startWordTime = Time::HiRes::time(); " + ls ); - out.write( "my $Word = Win32::OLE->new('Word.Application'); " + ls ); - out.write( "my $stopWordTime = Time::HiRes::time() - $startWordTime; " + ls ); - out.write( "# $Word->{'Visible'} = 1; # if you want to see what's going on " + ls ); - out.write( "# , ReadOnly => 1})" + ls ); - out.write(ls); - out.write( "my $startLoadWordTime = Time::HiRes::time(); " + ls ); - out.write( "$Word->Documents->Open({Filename => $ARGV[0]}) " + ls ); - out.write( " || die('Unable to open document ', Win32::OLE->LastError()); " + ls ); - out.write( "my $stopLoadWordTime = Time::HiRes::time() - $startLoadWordTime; " + ls ); - out.write(ls); - out.write( "my $startPrintWordTime = Time::HiRes::time(); " + ls); - out.write( "my $oldActivePrinte = $Word->{ActivePrinter} ; " + ls ); - out.write( "$Word->{ActivePrinter} = $ARGV[1]; " + ls ); - out.write( "$Word->ActiveDocument->PrintOut({ " + ls ); - out.write( " Background => 0, " + ls ); - out.write( " Append => 0, " + ls ); - out.write( " Range => wdPrintAllDocument, " + ls ); - out.write( " Item => wdPrintDocumentContent, " + ls ); - out.write( " Copies => 1, " + ls ); - out.write( " PageType => wdPrintAllPages, " + ls ); - out.write( " PrintToFile => 1, " + ls ); - out.write( " OutputFileName => $ARGV[2] " + ls ); - out.write( " }); " + ls ); - out.write( "$Word->{ActivePrinter} = $oldActivePrinte; " + ls ); - out.write( "my $stopPrintWordTime = Time::HiRes::time() - $startPrintWordTime;" + ls); - - out.write( "# ActiveDocument.Close(SaveChanges:=WdSaveOptions.wdDoNotSaveChanges)" + ls ); - out.write( "my $sVersion = $Word->Application->Version();"+ls); - out.write( "$Word->ActiveDocument->Close({SaveChanges => 0}); " + ls ); - out.write( "$Word->Quit(); " + ls ); - - out.write( "local *FILE;" + ls); - out.write( "if (open(FILE, \">$ENV{HOME}/msofficeloadtimes.txt\"))" + ls); - out.write( "{" + ls); - out.write( " print FILE \"name=$ARGV[0]\\n\";" + ls); - out.write( " print FILE \"WordVersion=$sVersion\\n\";" + ls); - out.write( " print FILE \"WordStartTime=$stopWordTime\\n\";" + ls); - out.write( " print FILE \"WordLoadTime=$stopLoadWordTime\\n\";" + ls); - out.write( " print FILE \"WordPrintTime=$stopPrintWordTime\\n\";" + ls); - out.write( " close(FILE);" + ls); - out.write( "}" + ls); - out.close(); + FileWriter out = null; + try + { + out = new FileWriter(aFile); + + out.write( "eval 'exec perl -wS $0 ${1+\"$@\"}' " + ls ); + out.write( " if 0; " + ls ); + out.write( "use strict; " + ls ); + out.write( "use Time::HiRes; " + ls ); + out.write( "if ( $^O ne \"MSWin32\") " + ls ); + out.write( "{ " + ls ); + out.write( " print 'Windows only.\\n'; " + ls ); + out.write( " print_usage(); " + ls ); + out.write( " exit(1); " + ls ); + out.write( "} " + ls ); + out.write( " " + ls ); + out.write( "use Win32::OLE; " + ls ); + out.write( "use Win32::OLE::Const 'Microsoft Word'; " + ls ); + out.write( " " + ls ); + out.write( "# ------ usage ------ " + ls ); + out.write( "sub print_usage() " + ls ); + out.write( "{ " + ls ); + out.write( " print STDERR \"Usage: word_print.pl <Word file> <name of printer> <output file> .\\n " + ls ); + out.write( " Please use the same string for the name of the printer as you can find \\n " + ls ); + out.write( " under Start-Control Panel-Printer and Faxes \\n " + ls ); + out.write( " The name could look like the following line: \\n " + ls ); + out.write( " Apple LaserWriter II NT v47.0 \\n " + ls ); + out.write( " Sample command line: \\n " + ls ); + out.write( " execl_print.pl c:\\book1.doc Apple LaserWriter II NT v47.0 c:\\output\\book1.ps \\n\"; " + ls ); + out.write( "} " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( "if ($#ARGV != 2) " + ls ); + out.write( "{ " + ls ); + out.write( " print 'Too less arguments.\\n'; " + ls ); + out.write( " print_usage(); " + ls ); + out.write( " exit(1); " + ls ); + out.write( "} " + ls ); + out.write( " " + ls ); + out.write( "my $startWordTime = Time::HiRes::time(); " + ls ); + out.write( "my $Word = Win32::OLE->new('Word.Application'); " + ls ); + out.write( "my $stopWordTime = Time::HiRes::time() - $startWordTime; " + ls ); + out.write( "# $Word->{'Visible'} = 1; # if you want to see what's going on " + ls ); + out.write( "# , ReadOnly => 1})" + ls ); + out.write(ls); + out.write( "my $startLoadWordTime = Time::HiRes::time(); " + ls ); + out.write( "$Word->Documents->Open({Filename => $ARGV[0]}) " + ls ); + out.write( " || die('Unable to open document ', Win32::OLE->LastError()); " + ls ); + out.write( "my $stopLoadWordTime = Time::HiRes::time() - $startLoadWordTime; " + ls ); + out.write(ls); + out.write( "my $startPrintWordTime = Time::HiRes::time(); " + ls); + out.write( "my $oldActivePrinte = $Word->{ActivePrinter} ; " + ls ); + out.write( "$Word->{ActivePrinter} = $ARGV[1]; " + ls ); + out.write( "$Word->ActiveDocument->PrintOut({ " + ls ); + out.write( " Background => 0, " + ls ); + out.write( " Append => 0, " + ls ); + out.write( " Range => wdPrintAllDocument, " + ls ); + out.write( " Item => wdPrintDocumentContent, " + ls ); + out.write( " Copies => 1, " + ls ); + out.write( " PageType => wdPrintAllPages, " + ls ); + out.write( " PrintToFile => 1, " + ls ); + out.write( " OutputFileName => $ARGV[2] " + ls ); + out.write( " }); " + ls ); + out.write( "$Word->{ActivePrinter} = $oldActivePrinte; " + ls ); + out.write( "my $stopPrintWordTime = Time::HiRes::time() - $startPrintWordTime;" + ls); + + out.write( "# ActiveDocument.Close(SaveChanges:=WdSaveOptions.wdDoNotSaveChanges)" + ls ); + out.write( "my $sVersion = $Word->Application->Version();"+ls); + out.write( "$Word->ActiveDocument->Close({SaveChanges => 0}); " + ls ); + out.write( "$Word->Quit(); " + ls ); + + out.write( "local *FILE;" + ls); + out.write( "if (open(FILE, \">$ENV{HOME}/msofficeloadtimes.txt\"))" + ls); + out.write( "{" + ls); + out.write( " print FILE \"name=$ARGV[0]\\n\";" + ls); + out.write( " print FILE \"WordVersion=$sVersion\\n\";" + ls); + out.write( " print FILE \"WordStartTime=$stopWordTime\\n\";" + ls); + out.write( " print FILE \"WordLoadTime=$stopLoadWordTime\\n\";" + ls); + out.write( " print FILE \"WordPrintTime=$stopPrintWordTime\\n\";" + ls); + out.write( " close(FILE);" + ls); + out.write( "}" + ls); + } + finally + { + if (out != null) + out.close(); + } aList.add(getPerlExe()); aList.add(sFileName); @@ -420,78 +427,86 @@ public class MSOfficePostscriptCreator implements IOffice } File aFile = new File(sName); - FileWriter out = new FileWriter(aFile); - - out.write("#BEGIN" + ls); - out.write("#{" + ls); - out.write("#" + ls); - out.write("# # insert HACK" + ls); - out.write("# unshift(@INC, '');" + ls); - out.write("#}" + ls); - out.write( "use strict; " + ls ); - out.write( " " + ls ); - out.write( "if ( $^O ne \"MSWin32\") " + ls ); - out.write( "{ " + ls ); - out.write( " print \"Windows only.\\n\"; " + ls ); - out.write( " print_usage(); " + ls ); - out.write( " exit(1); " + ls ); - out.write( "} " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( "use Win32::OLE qw(in with); " + ls ); - out.write( "use Win32::OLE::Const 'Microsoft Excel'; " + ls ); - out.write( " " + ls ); - out.write( "# ------ usage ------ " + ls ); - out.write( "sub print_usage() " + ls ); - out.write( "{ " + ls ); - out.write( " print STDERR \"Usage: printViaExcel.pl <Excel file> <name of printer> <output file> .\\n " + ls ); - out.write( " Please use the same string for the name of the printer as you can find \\n " + ls ); - out.write( " under Start-Control Panel-Printer and Faxes \\n " + ls ); - out.write( " The name could look like the following line: \\n " + ls ); - out.write( " Apple LaserWriter II NT v47.0 \\n " + ls ); - out.write( " Sample command line: \\n " + ls ); - out.write( " execl_print.pl c:\\book1.xls Apple LaserWriter II NT v47.0 c:\\output\\book1.ps \\n\"; " + ls ); - out.write( "} " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( "$Win32::OLE::Warn = 3; # die on errors... " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( "if ($#ARGV != 2) " + ls ); - out.write( "{ " + ls ); - out.write( " print STDERR \"Too less arguments.\\n\"; " + ls ); - out.write( " print STDERR \"ARGV[0] $ARGV[0]\\n\"; " + ls ); - out.write( " print STDERR \"ARGV[1] $ARGV[1]\\n\"; " + ls ); - out.write( " print STDERR \"ARGV[2] $ARGV[2]\\n\"; " + ls ); - out.write( " print_usage(); " + ls ); - out.write( " exit(1); " + ls ); - out.write( "} " + ls ); - out.write( " " + ls ); - out.write( "my $Excel = Win32::OLE->GetActiveObject('Excel.Application') " + ls ); - out.write( " || Win32::OLE->new('Excel.Application', 'Quit'); # get already active Excel " + ls ); - out.write( " # application or open new " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( "my $Book = $Excel->Workbooks->Open( $ARGV[0] ); " + ls ); - out.write( " $Book->PrintOut({Copies => 1, " + ls ); - out.write( " ActivePrinter => $ARGV[1], " + ls ); - out.write( " PrToFileName => $ARGV[2], " + ls ); - out.write( " Collate => 1 " + ls ); - out.write( " }); " + ls ); - out.write( "# Close worksheets without store changes" + ls ); - out.write( "# $Book->Close({SaveChanges => 0}); " + ls ); - out.write( "my $sVersion = $Excel->Application->Version();"+ls); - out.write( "$Excel->Quit(); " + ls ); - out.write( "local *FILE;" + ls); - out.write( "if (open(FILE, \">$ENV{HOME}/msofficeloadtimes.txt\"))" + ls); - out.write( "{" + ls); - out.write( " print FILE \"name=$ARGV[0]\\n\";" + ls); - out.write( " print FILE \"ExcelVersion=$sVersion\\n\";" + ls); - out.write( " close(FILE);" + ls); - out.write( "}" + ls); - out.close(); + FileWriter out = null; + try + { + out = new FileWriter(aFile); + + out.write("#BEGIN" + ls); + out.write("#{" + ls); + out.write("#" + ls); + out.write("# # insert HACK" + ls); + out.write("# unshift(@INC, '');" + ls); + out.write("#}" + ls); + out.write( "use strict; " + ls ); + out.write( " " + ls ); + out.write( "if ( $^O ne \"MSWin32\") " + ls ); + out.write( "{ " + ls ); + out.write( " print \"Windows only.\\n\"; " + ls ); + out.write( " print_usage(); " + ls ); + out.write( " exit(1); " + ls ); + out.write( "} " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( "use Win32::OLE qw(in with); " + ls ); + out.write( "use Win32::OLE::Const 'Microsoft Excel'; " + ls ); + out.write( " " + ls ); + out.write( "# ------ usage ------ " + ls ); + out.write( "sub print_usage() " + ls ); + out.write( "{ " + ls ); + out.write( " print STDERR \"Usage: printViaExcel.pl <Excel file> <name of printer> <output file> .\\n " + ls ); + out.write( " Please use the same string for the name of the printer as you can find \\n " + ls ); + out.write( " under Start-Control Panel-Printer and Faxes \\n " + ls ); + out.write( " The name could look like the following line: \\n " + ls ); + out.write( " Apple LaserWriter II NT v47.0 \\n " + ls ); + out.write( " Sample command line: \\n " + ls ); + out.write( " execl_print.pl c:\\book1.xls Apple LaserWriter II NT v47.0 c:\\output\\book1.ps \\n\"; " + ls ); + out.write( "} " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( "$Win32::OLE::Warn = 3; # die on errors... " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( "if ($#ARGV != 2) " + ls ); + out.write( "{ " + ls ); + out.write( " print STDERR \"Too less arguments.\\n\"; " + ls ); + out.write( " print STDERR \"ARGV[0] $ARGV[0]\\n\"; " + ls ); + out.write( " print STDERR \"ARGV[1] $ARGV[1]\\n\"; " + ls ); + out.write( " print STDERR \"ARGV[2] $ARGV[2]\\n\"; " + ls ); + out.write( " print_usage(); " + ls ); + out.write( " exit(1); " + ls ); + out.write( "} " + ls ); + out.write( " " + ls ); + out.write( "my $Excel = Win32::OLE->GetActiveObject('Excel.Application') " + ls ); + out.write( " || Win32::OLE->new('Excel.Application', 'Quit'); # get already active Excel " + ls ); + out.write( " # application or open new " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( "my $Book = $Excel->Workbooks->Open( $ARGV[0] ); " + ls ); + out.write( " $Book->PrintOut({Copies => 1, " + ls ); + out.write( " ActivePrinter => $ARGV[1], " + ls ); + out.write( " PrToFileName => $ARGV[2], " + ls ); + out.write( " Collate => 1 " + ls ); + out.write( " }); " + ls ); + out.write( "# Close worksheets without store changes" + ls ); + out.write( "# $Book->Close({SaveChanges => 0}); " + ls ); + out.write( "my $sVersion = $Excel->Application->Version();"+ls); + out.write( "$Excel->Quit(); " + ls ); + out.write( "local *FILE;" + ls); + out.write( "if (open(FILE, \">$ENV{HOME}/msofficeloadtimes.txt\"))" + ls); + out.write( "{" + ls); + out.write( " print FILE \"name=$ARGV[0]\\n\";" + ls); + out.write( " print FILE \"ExcelVersion=$sVersion\\n\";" + ls); + out.write( " close(FILE);" + ls); + out.write( "}" + ls); + } + finally + { + if (out != null) + out.close(); + } aList.add(getPerlExe()); aList.add(sName); @@ -518,81 +533,88 @@ public class MSOfficePostscriptCreator implements IOffice } File aFile = new File(sName); - FileWriter out = new FileWriter(aFile); - - - out.write( "eval 'exec perl -wS $0 $1 $2 ' " + ls ); - out.write( " if 0; " + ls ); - out.write( "use strict; " + ls ); - out.write( " " + ls ); - out.write( "if ( $^O ne \"MSWin32\") " + ls ); - out.write( "{ " + ls ); - out.write( " print \"Windows only.\\n\"; " + ls ); - out.write( " print_usage(); " + ls ); - out.write( " exit(1); " + ls ); - out.write( "} " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( "use Win32::OLE qw(in with); " + ls ); - out.write( "use Win32::OLE::Const 'Microsoft PowerPoint'; " + ls ); - out.write( " " + ls ); - out.write( "# ------ usage ------ " + ls ); - out.write( "sub print_usage() " + ls ); - out.write( "{ " + ls ); - out.write( " print STDERR \"Usage: powerpoint_print.pl <PowerPoint file> <name of printer> <output file> .\\n " + ls ); - out.write( " Please use the same string for the name of the printer as you can find \\n " + ls ); - out.write( " under Start-Control Panel-Printer and Faxes \\n " + ls ); - out.write( " The name could look like the following line: \\n " + ls ); - out.write( " Apple LaserWriter II NT v47.0 \\n " + ls ); - out.write( " Sample command line: \\n " + ls ); - out.write( " powerpoint_print.pl c:\\book.ppt Apple LaserWriter II NT v47.0 c:\\output\\book.ps \\n\"; " + ls ); - out.write( "} " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( "$Win32::OLE::Warn = 3; # die on errors... " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( "if ($#ARGV < 2) " + ls ); - out.write( "{ " + ls ); - out.write( " print \"Too less arguments.\\n\"; " + ls ); - out.write( " print_usage(); " + ls ); - out.write( " exit(1); " + ls ); - out.write( "} " + ls ); - out.write( " " + ls ); - out.write( "my $PowerPoint = Win32::OLE->GetActiveObject('PowerPoint.Application') " + ls ); - out.write( " || Win32::OLE->new('PowerPoint.Application', 'Quit'); # get already active Excel " + ls ); - out.write( " # application or open new " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( " " + ls ); - out.write( " $PowerPoint->{'Visible'} = 1; " + ls ); - out.write( " my $Presentation = $PowerPoint->Presentations->Add; " + ls ); - out.write( " my $Presentation = $PowerPoint->Presentations->Open( $ARGV[0] ); " + ls ); - out.write( "# we can't change active printer in powerpoint " + ls ); - out.write( "# $Presentation->PrintOptions->{ActivePrinter} = $ARGV[1]; " + ls ); - out.write( " print \"Active printer is: \" . $Presentation->PrintOptions->{ActivePrinter} . \"\\n\"; " + ls ); - out.write( " $Presentation->PrintOptions->{PrintInBackground} = 0; " + ls ); - out.write( " # PrintColorType = 1 means print in color and PrintColorType = 2 means print in gray " + ls ); - out.write( " $Presentation->PrintOptions->{PrintColorType} = 1; " + ls ); - out.write( " " + ls ); - out.write( " $Presentation->PrintOut({PrintToFile => $ARGV[2]}); " + ls ); - out.write( " sleep 5; " + ls ); - out.write( " print \"Presentation has been printed\\n\"; " + ls ); - out.write( "my $sVersion = $Presentation->Application->Version();"+ls); - out.write( " $PowerPoint->Quit(); " + ls ); - - out.write( "local *FILE;" + ls); - out.write( "if (open(FILE, \">$ENV{HOME}/msofficeloadtimes.txt\"))" + ls); - out.write( "{" + ls); - out.write( " print FILE \"name=$ARGV[0]\\n\";" + ls); - out.write( " print FILE \"PowerPointVersion=$sVersion\\n\";" + ls); -// out.write( " print FILE \"WordStartTime=$stopWordTime\\n\";" + ls); -// out.write( " print FILE \"WordLoadTime=$stopLoadWordTime\\n\";" + ls); -// out.write( " print FILE \"WordPrintTime=$stopPrintWordTime\\n\";" + ls); - out.write( " close(FILE);" + ls); - out.write( "}" + ls); - out.close(); + FileWriter out = null; + try + { + out = new FileWriter(aFile); + + out.write( "eval 'exec perl -wS $0 $1 $2 ' " + ls ); + out.write( " if 0; " + ls ); + out.write( "use strict; " + ls ); + out.write( " " + ls ); + out.write( "if ( $^O ne \"MSWin32\") " + ls ); + out.write( "{ " + ls ); + out.write( " print \"Windows only.\\n\"; " + ls ); + out.write( " print_usage(); " + ls ); + out.write( " exit(1); " + ls ); + out.write( "} " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( "use Win32::OLE qw(in with); " + ls ); + out.write( "use Win32::OLE::Const 'Microsoft PowerPoint'; " + ls ); + out.write( " " + ls ); + out.write( "# ------ usage ------ " + ls ); + out.write( "sub print_usage() " + ls ); + out.write( "{ " + ls ); + out.write( " print STDERR \"Usage: powerpoint_print.pl <PowerPoint file> <name of printer> <output file> .\\n " + ls ); + out.write( " Please use the same string for the name of the printer as you can find \\n " + ls ); + out.write( " under Start-Control Panel-Printer and Faxes \\n " + ls ); + out.write( " The name could look like the following line: \\n " + ls ); + out.write( " Apple LaserWriter II NT v47.0 \\n " + ls ); + out.write( " Sample command line: \\n " + ls ); + out.write( " powerpoint_print.pl c:\\book.ppt Apple LaserWriter II NT v47.0 c:\\output\\book.ps \\n\"; " + ls ); + out.write( "} " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( "$Win32::OLE::Warn = 3; # die on errors... " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( "if ($#ARGV < 2) " + ls ); + out.write( "{ " + ls ); + out.write( " print \"Too less arguments.\\n\"; " + ls ); + out.write( " print_usage(); " + ls ); + out.write( " exit(1); " + ls ); + out.write( "} " + ls ); + out.write( " " + ls ); + out.write( "my $PowerPoint = Win32::OLE->GetActiveObject('PowerPoint.Application') " + ls ); + out.write( " || Win32::OLE->new('PowerPoint.Application', 'Quit'); # get already active Excel " + ls ); + out.write( " # application or open new " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( " " + ls ); + out.write( " $PowerPoint->{'Visible'} = 1; " + ls ); + out.write( " my $Presentation = $PowerPoint->Presentations->Add; " + ls ); + out.write( " my $Presentation = $PowerPoint->Presentations->Open( $ARGV[0] ); " + ls ); + out.write( "# we can't change active printer in powerpoint " + ls ); + out.write( "# $Presentation->PrintOptions->{ActivePrinter} = $ARGV[1]; " + ls ); + out.write( " print \"Active printer is: \" . $Presentation->PrintOptions->{ActivePrinter} . \"\\n\"; " + ls ); + out.write( " $Presentation->PrintOptions->{PrintInBackground} = 0; " + ls ); + out.write( " # PrintColorType = 1 means print in color and PrintColorType = 2 means print in gray " + ls ); + out.write( " $Presentation->PrintOptions->{PrintColorType} = 1; " + ls ); + out.write( " " + ls ); + out.write( " $Presentation->PrintOut({PrintToFile => $ARGV[2]}); " + ls ); + out.write( " sleep 5; " + ls ); + out.write( " print \"Presentation has been printed\\n\"; " + ls ); + out.write( "my $sVersion = $Presentation->Application->Version();"+ls); + out.write( " $PowerPoint->Quit(); " + ls ); + + out.write( "local *FILE;" + ls); + out.write( "if (open(FILE, \">$ENV{HOME}/msofficeloadtimes.txt\"))" + ls); + out.write( "{" + ls); + out.write( " print FILE \"name=$ARGV[0]\\n\";" + ls); + out.write( " print FILE \"PowerPointVersion=$sVersion\\n\";" + ls); +// out.write( " print FILE \"WordStartTime=$stopWordTime\\n\";" + ls); +// out.write( " print FILE \"WordLoadTime=$stopLoadWordTime\\n\";" + ls); +// out.write( " print FILE \"WordPrintTime=$stopPrintWordTime\\n\";" + ls); + out.write( " close(FILE);" + ls); + out.write( "}" + ls); + } + finally + { + if (out!= null) + out.close(); + } aList.add(getPerlExe()); aList.add(sName); diff --git a/qadevOOo/runner/helper/FileTools.java b/qadevOOo/runner/helper/FileTools.java index cede7c46059d..4bcee70a52ce 100644 --- a/qadevOOo/runner/helper/FileTools.java +++ b/qadevOOo/runner/helper/FileTools.java @@ -80,17 +80,27 @@ public class FileTools { * @throws java.io.IOException throws java.io.IOException if something failes */ public static void copyFile(File src, File dst) throws java.io.IOException { - InputStream in = new FileInputStream(src); - OutputStream out = new FileOutputStream(dst); + InputStream in = null; + OutputStream out = null; + try { + in = new FileInputStream(src); + try { + out = new FileOutputStream(dst); - // Transfer bytes from in to out - byte[] buf = new byte[1024]; - int len; - while ((len = in.read(buf)) > 0) { - out.write(buf, 0, len); + // Transfer bytes from in to out + byte[] buf = new byte[1024]; + int len; + while ((len = in.read(buf)) > 0) { + out.write(buf, 0, len); + } + } finally { + if (out != null) + out.close(); + } + } finally { + if (in != null) + in.close(); } - in.close(); - out.close(); } diff --git a/qadevOOo/runner/stats/FileLogWriter.java b/qadevOOo/runner/stats/FileLogWriter.java index 22d538df988b..aebcb0fbf868 100644 --- a/qadevOOo/runner/stats/FileLogWriter.java +++ b/qadevOOo/runner/stats/FileLogWriter.java @@ -59,10 +59,17 @@ public class FileLogWriter extends PrintWriter implements LogWriter { public void addFileLog(String filePath){ + FileWriter fileWriter = null; try{ - if(mFileWriters == null) - mFileWriters = new HashMap<String, FileWriter>(); - mFileWriters.put(filePath, new FileWriter(filePath)); + try{ + if(mFileWriters == null) + mFileWriters = new HashMap<String, FileWriter>(); + fileWriter = new FileWriter(filePath); + mFileWriters.put(filePath, fileWriter); + }finally{ + if (fileWriter != null) + fileWriter.close(); + } }catch(IOException e ){ e.printStackTrace(this); } diff --git a/qadevOOo/runner/stats/SQLExecution.java b/qadevOOo/runner/stats/SQLExecution.java index 9c6dca8a69c9..bb50dce7b1a5 100644 --- a/qadevOOo/runner/stats/SQLExecution.java +++ b/qadevOOo/runner/stats/SQLExecution.java @@ -255,54 +255,60 @@ public class SQLExecution { private void execute(String command, HashMap<String, String[]> output, boolean update) { if (m_bDebug) System.out.println("Debug - SQLExecution - execute Command: " + command); + + ResultSet sqlResult = null; try { - if (update) { - // make an update - mStatement.executeUpdate(command); - } - else { - // make a select: collect the result - ResultSet sqlResult = mStatement.executeQuery(command); - ResultSetMetaData sqlRSMeta = sqlResult.getMetaData(); - int columnCount = sqlRSMeta.getColumnCount(); - String[] columnNames = new String[columnCount]; - int countRows = 0; - boolean goThroughRowsTheFirstTime = true; - for(int i=1; i<=columnCount; i++) { - columnNames[i-1] = sqlRSMeta.getColumnName(i); - // initialize output - ArrayList<String> v = new ArrayList<String>(); + try { + if (update) { + // make an update + mStatement.executeUpdate(command); + } + else { + // make a select: collect the result + sqlResult = mStatement.executeQuery(command); + ResultSetMetaData sqlRSMeta = sqlResult.getMetaData(); + int columnCount = sqlRSMeta.getColumnCount(); + String[] columnNames = new String[columnCount]; + int countRows = 0; + boolean goThroughRowsTheFirstTime = true; + for(int i=1; i<=columnCount; i++) { + columnNames[i-1] = sqlRSMeta.getColumnName(i); + // initialize output + ArrayList<String> v = new ArrayList<String>(); - sqlResult.beforeFirst(); - while (sqlResult.next()) { - String value = sqlResult.getString(i); - v.add(value); - // the first time: count rows + sqlResult.beforeFirst(); + while (sqlResult.next()) { + String value = sqlResult.getString(i); + v.add(value); + // the first time: count rows + if (goThroughRowsTheFirstTime) + countRows++; + } + // rows are counted if (goThroughRowsTheFirstTime) - countRows++; - } - // rows are counted - if (goThroughRowsTheFirstTime) - goThroughRowsTheFirstTime = false; + goThroughRowsTheFirstTime = false; - // put result in output HashMap - String[]s = new String[countRows]; - s = v.toArray(s); - output.put(columnNames[i-1], s); - if (m_bDebug) { - if (i == 1) { - System.out.print("Debug - SQLExecution - Command returns: "); - System.out.print("row: " + columnNames[i-1] + " vals: "); + // put result in output HashMap + String[]s = new String[countRows]; + s = v.toArray(s); + output.put(columnNames[i-1], s); + if (m_bDebug) { + if (i == 1) { + System.out.print("Debug - SQLExecution - Command returns: "); + System.out.print("row: " + columnNames[i-1] + " vals: "); + } + for (int j=0; j<s.length; j++) + System.out.print(s[j] + " "); + if (i == columnCount - 1) + System.out.println(); } - for (int j=0; j<s.length; j++) - System.out.print(s[j] + " "); - if (i == columnCount - 1) - System.out.println(); } } + } finally { + if (sqlResult != null) + sqlResult.close(); } - } - catch (java.sql.SQLException e) { + } catch (java.sql.SQLException e) { e.printStackTrace(); } } diff --git a/qadevOOo/runner/stats/SimpleFileOutProducer.java b/qadevOOo/runner/stats/SimpleFileOutProducer.java index 2a0dbf6096e5..e8d572ecb657 100644 --- a/qadevOOo/runner/stats/SimpleFileOutProducer.java +++ b/qadevOOo/runner/stats/SimpleFileOutProducer.java @@ -42,39 +42,43 @@ public class SimpleFileOutProducer implements LogWriter { * the information, maybe write them to a db */ public boolean summary(share.DescEntry entry) { + FileWriter out = null; try { - String outpath = (String) entry.UserDefinedParams.get("OutputPath"); - if (outpath==null) { - System.out.println("## Parameter OutputPath isn't defined using default"); - return summary_default(entry); + try { + String outpath = (String) entry.UserDefinedParams.get("OutputPath"); + if (outpath==null) { + System.out.println("## Parameter OutputPath isn't defined using default"); + return summary_default(entry); + } + String FileName = entry.longName + ".out"; + if (!entry.EntryType.equals("component")) { + FileName = entry.longName.substring(0, + entry.longName.indexOf(':')) + ".out"; + } + util.utils.make_Directories("",outpath); + File outputFile = new File(outpath, FileName); + out = new FileWriter(outputFile.toString(),true); + String ls = System.getProperty("line.separator"); + String date = new java.util.Date().toString(); + String header = "***** State for "+entry.longName+"( "+ date +" ) ******"; + out.write(header+ls); + if (entry.hasErrorMsg) { + out.write(entry.ErrorMsg+ls); + out.write("Whole "+entry.EntryType+": "+entry.State+ls); + } else { + out.write("Whole "+entry.EntryType+": "+entry.State+ls); + } + String bottom=""; + for (int i=0;i<header.length();i++) { + bottom += "*"; + } + out.write(bottom+ls); + out.write(""+ls); + } finally { + if (out != null) + out.close(); } - String FileName = entry.longName + ".out"; - if (!entry.EntryType.equals("component")) { - FileName = entry.longName.substring(0, - entry.longName.indexOf(':')) + ".out"; - } - util.utils.make_Directories("",outpath); - File outputFile = new File(outpath, FileName); - FileWriter out = new FileWriter(outputFile.toString(),true); - String ls = System.getProperty("line.separator"); - String date = new java.util.Date().toString(); - String header = "***** State for "+entry.longName+"( "+ date +" ) ******"; - out.write(header+ls); - if (entry.hasErrorMsg) { - out.write(entry.ErrorMsg+ls); - out.write("Whole "+entry.EntryType+": "+entry.State+ls); - } else { - out.write("Whole "+entry.EntryType+": "+entry.State+ls); - } - String bottom=""; - for (int i=0;i<header.length();i++) { - bottom += "*"; - } - out.write(bottom+ls); - out.write(""+ls); - out.close(); } catch (java.io.IOException e) { - } return true; } diff --git a/qadevOOo/runner/util/DBTools.java b/qadevOOo/runner/util/DBTools.java index 7960a8dac488..f6e7c815bc81 100644 --- a/qadevOOo/runner/util/DBTools.java +++ b/qadevOOo/runner/util/DBTools.java @@ -326,6 +326,7 @@ public class DBTools { public void initTestTableUsingJDBC(String tbl_name, DataSourceInfo dsi) throws java.sql.SQLException, ClassNotFoundException { + //register jdbc driver if ( dsi.Info[0].Name.equals("JavaDriverClass") ) { Class.forName((String)dsi.Info[0].Value); @@ -333,21 +334,30 @@ public class DBTools { Class.forName(TST_JDBC_DRIVER); } - //getting connection Connection connection = null; + Statement statement = null; + try { + //getting connection + connection = DriverManager.getConnection(dsi.URL, dsi.User, dsi.Password); + try { + statement = connection.createStatement(); - connection = DriverManager.getConnection( - dsi.URL, dsi.User, dsi.Password); - Statement statement = connection.createStatement(); - - //drop table - dropMySQLTable(statement, tbl_name); + //drop table + dropMySQLTable(statement, tbl_name); - //create table - createMySQLTable(statement, tbl_name); + //create table + createMySQLTable(statement, tbl_name); - //insert some content - insertContentMySQLTable(statement, tbl_name); + //insert some content + insertContentMySQLTable(statement, tbl_name); + } finally { + if (statement != null) + statement.close(); + } + } finally { + if (connection != null) + connection.close(); + } } /** |