1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package convwatch; 29 30 import java.io.File; 31 import java.util.ArrayList; 32 import java.io.FileWriter; 33 34 import com.sun.star.uno.UnoRuntime; 35 import com.sun.star.lang.XMultiServiceFactory; 36 import com.sun.star.document.XTypeDetection; 37 import com.sun.star.container.XNameAccess; 38 import com.sun.star.frame.XDesktop; 39 import com.sun.star.beans.XPropertySet; 40 import com.sun.star.beans.PropertyValue; 41 import com.sun.star.frame.XComponentLoader; 42 import com.sun.star.lang.XComponent; 43 import com.sun.star.frame.XStorable; 44 import com.sun.star.view.XPrintable; 45 import com.sun.star.lang.XServiceInfo; 46 import com.sun.star.frame.XModel; 47 import com.sun.star.uno.AnyConverter; 48 49 import helper.URLHelper; 50 import helper.PropertyHelper; 51 import helper.OSHelper; 52 // import convwatch.FileHelper; 53 // import convwatch.MSOfficePrint; 54 // import convwatch.GraphicalTestArguments; 55 // import convwatch.ConvWatchCancelException; 56 57 // import helper.Parameter; 58 59 /** 60 * This Object is to print a given document with OpenOffice.org / StarOffice 61 * over the normal printer driver 62 * or over it's pdf exporter 63 */ 64 public class OfficePrint { 65 66 67 // static long m_nStartTime; 68 // // static Date m_aDateCache = null; 69 // 70 // /* 71 // simple helper functions to start/stop a timer, to know how long a process need in milliseconds 72 // */ 73 // public static void startTimer() 74 // { 75 // // if (m_aDateCache == null) 76 // // { 77 // // m_aDateCache = new Date(); 78 // // } 79 // // m_nStartTime = m_aDateCache.getTime(); 80 // m_nStartTime = System.currentTimeMillis(); 81 // } 82 // public static long stopTimer() 83 // { 84 // // if (m_aDateCache == null) 85 // // { 86 // // System.out.println("Forgotten to initialise start timer."); 87 // // return 0; 88 // // } 89 // // long m_nStopTime = m_aDateCache.getTime(); 90 // if (m_nStartTime == 0) 91 // { 92 // System.out.println("Forgotten to initialise start timer."); 93 // return 0; 94 // } 95 // long m_nStopTime = System.currentTimeMillis(); 96 // return m_nStopTime - m_nStartTime; 97 // } 98 99 100 private static void showProperty(PropertyValue _aValue) 101 { 102 String sName = _aValue.Name; 103 String sValue; 104 try 105 { 106 sValue = AnyConverter.toString(_aValue.Value); 107 GlobalLogWriter.get().println("Property " + sName + ":=" + sValue); 108 } 109 catch (com.sun.star.lang.IllegalArgumentException e) 110 { 111 // GlobalLogWriter.get().println("showProperty: can't convert a object to string."); 112 GlobalLogWriter.get().println("Property " + sName + ":= a Object which can't convert by AnyConverter()"); 113 } 114 } 115 116 /** 117 * shows the FilterName and MediaType from the given XComponent 118 */ 119 static String getDocumentType( XComponent _aDoc ) 120 { 121 XModel xModel = UnoRuntime.queryInterface( XModel.class, _aDoc); 122 PropertyValue[] aArgs = xModel.getArgs(); 123 for (int i=0;i<aArgs.length;i++) 124 { 125 PropertyValue aValue = aArgs[i]; 126 // System.out.print("Property: '" + aValue.Name); 127 // System.out.println("' := '" + aValue.Value + "'"); 128 if (aValue.Name.equals("FilterName") || 129 aValue.Name.equals("MediaType")) 130 { 131 String sNameValue = "'" + aValue.Name + "' := '" + aValue.Value + "'"; 132 return sNameValue; 133 } 134 } 135 return ""; 136 } 137 138 static void showDocumentType( XComponent _aDoc ) 139 { 140 String sNameValue = getDocumentType(_aDoc); 141 GlobalLogWriter.get().println(" Property: '" + sNameValue); 142 } 143 /** 144 * load a OpenOffice.org document from a given URL (_sInputURL) 145 * the GraphicalTestArguments must contain a living MultiServiceFactory object 146 * or we crash here. 147 * Be aware, the ownership of the document gets to you, you have to close it. 148 * @param _aGTA 149 * @param _sInputURL 150 * @return 151 */ 152 public static XComponent loadFromURL(GraphicalTestArguments _aGTA, 153 String _sInputURL) 154 { 155 XComponent aDoc = null; 156 try 157 { 158 if (_aGTA.getMultiServiceFactory() == null) 159 { 160 GlobalLogWriter.get().println("MultiServiceFactory in GraphicalTestArgument not set."); 161 return null; 162 } 163 Object oDsk = _aGTA.getMultiServiceFactory().createInstance("com.sun.star.frame.Desktop"); 164 XDesktop aDesktop = UnoRuntime.queryInterface(XDesktop.class, oDsk); 165 166 if (aDesktop != null) 167 { 168 GlobalLogWriter.get().println("com.sun.star.frame.Desktop created."); 169 // String sInputURL = aCurrentParameter.sInputURL; 170 // String sOutputURL = aCurrentParameter.sOutputURL; 171 // String sPrintFileURL = aCurrentParameter.sPrintToFileURL; 172 // System.out.println(_sInputURL); 173 174 175 // set here the loadComponentFromURL() properties 176 // at the moment only 'Hidden' is set, so no window is opened at work 177 178 ArrayList<PropertyValue> aPropertyList = new ArrayList<PropertyValue>(); 179 180 // check which properties should set and count it. 181 // if (_aGTA.isHidden()) 182 // { 183 // nPropertyCount ++; 184 // } 185 // if (_aGTA.getImportFilterName() != null && _aGTA.getImportFilterName().length() > 0) 186 // { 187 // nPropertyCount ++; 188 // } 189 190 // initialize the propertyvalue 191 // int nPropertyIndex = 0; 192 // aProps = new PropertyValue[ nPropertyCount ]; 193 194 // set all property values 195 if (_aGTA.isHidden()) 196 { 197 PropertyValue Arg = new PropertyValue(); 198 Arg.Name = "Hidden"; 199 Arg.Value = Boolean.TRUE; 200 aPropertyList.add(Arg); 201 showProperty(Arg); 202 } 203 if (_aGTA.getImportFilterName() != null && _aGTA.getImportFilterName().length() > 0) 204 { 205 PropertyValue Arg = new PropertyValue(); 206 Arg.Name = "FilterName"; 207 Arg.Value = _aGTA.getImportFilterName(); 208 aPropertyList.add(Arg); 209 showProperty(Arg); 210 } 211 212 GlobalLogWriter.get().println(DateHelper.getDateTimeForHumanreadableLog() + " Load document"); 213 // GlobalLogWriter.get().flush(); 214 215 XComponentLoader aCompLoader = UnoRuntime.queryInterface( XComponentLoader.class, aDesktop); 216 217 // XComponent aDoc = null; 218 219 _aGTA.getPerformance().startTime(PerformanceContainer.Load); 220 aDoc = aCompLoader.loadComponentFromURL(_sInputURL, "_blank", 0, PropertyHelper.createPropertyValueArrayFormArrayList(aPropertyList) ); 221 _aGTA.getPerformance().stopTime(PerformanceContainer.Load); 222 if (aDoc != null) 223 { 224 GlobalLogWriter.get().println(DateHelper.getDateTimeForHumanreadableLog() + " Load document done."); 225 showDocumentType(aDoc); 226 _aGTA.setDocumentType(getDocumentType(aDoc)); 227 } 228 else 229 { 230 GlobalLogWriter.get().println(" Load document failed."); 231 if (_aGTA.getImportFilterName() != null && _aGTA.getImportFilterName().length() > 0) 232 { 233 GlobalLogWriter.get().println(" Please check FilterName := '" + _aGTA.getImportFilterName() + "'"); 234 } 235 GlobalLogWriter.get().println(""); 236 } 237 } 238 else 239 { 240 GlobalLogWriter.get().println("com.sun.star.frame.Desktop failed."); 241 } 242 } 243 catch ( com.sun.star.uno.Exception e ) 244 { 245 // Some exception occures.FAILED 246 GlobalLogWriter.get().println("UNO Exception caught."); 247 GlobalLogWriter.get().println("Message: " + e.getMessage()); 248 e.printStackTrace(); 249 aDoc = null; 250 } 251 return aDoc; 252 } 253 254 static boolean exportToPDF(XComponent _xComponent, String _sDestinationName) 255 { 256 XServiceInfo xServiceInfo = 257 UnoRuntime.queryInterface( 258 XServiceInfo.class, _xComponent 259 ); 260 261 ArrayList<PropertyValue> aPropertyList = new ArrayList<PropertyValue>(); 262 PropertyValue aFiltername = new PropertyValue(); 263 aFiltername.Name = "FilterName"; 264 aFiltername.Value = getFilterName_forPDF(xServiceInfo); 265 aPropertyList.add(aFiltername); 266 showProperty(aFiltername); 267 boolean bWorked = true; 268 269 try 270 { 271 XStorable store = 272 UnoRuntime.queryInterface( 273 XStorable.class, _xComponent 274 ); 275 store.storeToURL(_sDestinationName, PropertyHelper.createPropertyValueArrayFormArrayList(aPropertyList)); 276 } 277 catch (com.sun.star.io.IOException e) 278 { 279 GlobalLogWriter.get().println("IO Exception caught."); 280 GlobalLogWriter.get().println("Message: " + e.getMessage()); 281 bWorked = false; 282 } 283 284 return bWorked; 285 } 286 287 static String getFilterName_forPDF(XServiceInfo xServiceInfo) 288 { 289 String filterName = ""; 290 291 if (xServiceInfo.supportsService("com.sun.star.text.TextDocument")) 292 { 293 //writer 294 filterName = "writer_pdf_Export"; 295 } 296 else if ( xServiceInfo.supportsService( "com.sun.star.sheet.SpreadsheetDocument" ) ) 297 { 298 //calc 299 filterName = "calc_pdf_Export"; 300 } 301 else if ( xServiceInfo.supportsService( "com.sun.star.drawing.DrawingDocument" ) ) 302 { 303 //draw 304 filterName = "draw_pdf_Export"; 305 } 306 else if ( xServiceInfo.supportsService( "com.sun.star.presentation.PresentationDocument" ) ) 307 { 308 //impress 309 filterName = "impress_pdf_Export"; 310 } 311 else if (xServiceInfo.supportsService("com.sun.star.text.WebDocument")) 312 { 313 //html document 314 filterName = "writer_web_pdf_Export"; 315 } 316 else if ( xServiceInfo.supportsService("com.sun.star.text.GlobalDocument") ) 317 { 318 //master document 319 filterName = "writer_globaldocument_pdf_Export"; 320 } 321 else if ( xServiceInfo.supportsService( "com.sun.star.formulaFormulaProperties" ) ) 322 { 323 //math document 324 filterName = "math_pdf_Export"; 325 } 326 327 return filterName; 328 } 329 330 // ----------------------------------------------------------------------------- 331 332 public static boolean storeAsPDF(GraphicalTestArguments _aGTA, 333 String _sInputURL, 334 String _sOutputURL) 335 { 336 boolean bBack = false; 337 XComponent aDoc = loadFromURL(_aGTA, _sInputURL); 338 339 if (aDoc == null) 340 { 341 GlobalLogWriter.get().println("Can't load document."); 342 return bBack; 343 } 344 bBack = storeAsPDF(_aGTA, aDoc, _sOutputURL); 345 createInfoFile(_sOutputURL, _aGTA, "as pdf"); 346 347 GlobalLogWriter.get().println("Close document."); 348 aDoc.dispose(); 349 return bBack; 350 } 351 352 public static boolean storeAsPDF(GraphicalTestArguments _aGTA, 353 XComponent _aDoc, 354 String _sOutputURL) 355 { 356 // try { 357 boolean bBack = true; 358 _aGTA.getPerformance().startTime(PerformanceContainer.StoreAsPDF); 359 bBack = exportToPDF(_aDoc, _sOutputURL); 360 _aGTA.getPerformance().stopTime(PerformanceContainer.StoreAsPDF); 361 362 if (!bBack) 363 { 364 GlobalLogWriter.get().println("Can't store document as PDF."); 365 bBack = false; 366 } 367 return bBack; 368 } 369 370 // ----------------------------------------------------------------------------- 371 372 /** 373 * print the document found in file (_sInputURL) to as postscript to file (_sPrintFileURL) 374 * Due to the fact we use a printer to convert the file to postscript, the default printer 375 * to create such postscript format must be installed, this is not tested here. 376 * 377 * @param _aGTA 378 * @param _sInputURL 379 * @param _sOutputURL 380 * @param _sPrintFileURL 381 * @return true, if print has been done. 382 * Be careful, true means only print returns with no errors, to be sure print is really done 383 * check existance of _sPrintFileURL 384 */ 385 386 public static boolean printToFileWithOOo(GraphicalTestArguments _aGTA, 387 String _sInputURL, 388 String _sOutputURL, 389 String _sPrintFileURL) 390 { 391 // waitInSeconds(1); 392 boolean bBack = false; 393 394 XComponent aDoc = loadFromURL(_aGTA, _sInputURL); 395 if (aDoc != null) 396 { 397 if ( _sInputURL.equals(_sOutputURL) ) 398 { 399 // don't store document 400 // input and output are equal OR 401 GlobalLogWriter.get().println("Warning: Inputpath and Outputpath are equal. Document will not stored again."); 402 _aGTA.disallowStore(); 403 } 404 bBack = impl_printToFileWithOOo(_aGTA, aDoc, _sOutputURL, _sPrintFileURL); 405 406 GlobalLogWriter.get().println("Close document."); 407 aDoc.dispose(); 408 } 409 else 410 { 411 GlobalLogWriter.get().println("loadDocumentFromURL() failed with document: " + _sInputURL); 412 } 413 return bBack; 414 } 415 416 // ----------------------------------------------------------------------------- 417 public static void createInfoFile(String _sFile, GraphicalTestArguments _aGTA) 418 { 419 createInfoFile(_sFile, _aGTA, ""); 420 } 421 422 public static void createInfoFile(String _sFile, GraphicalTestArguments _aGTA, String _sSpecial) 423 { 424 String sFilename; 425 if (_sFile.startsWith("file://")) 426 { 427 sFilename = FileHelper.getSystemPathFromFileURL(_sFile); 428 GlobalLogWriter.get().println("CreateInfoFile: '" + sFilename + "'" ); 429 } 430 else 431 { 432 sFilename = _sFile; 433 } 434 String sFileDir = FileHelper.getPath(sFilename); 435 String sBasename = FileHelper.getBasename(sFilename); 436 String sNameNoSuffix = FileHelper.getNameNoSuffix(sBasename); 437 438 String fs = System.getProperty("file.separator"); 439 String ls = System.getProperty("line.separator"); 440 String sInfoFilename = sFileDir + fs + sNameNoSuffix + ".info"; 441 File aInfoFile = new File(sInfoFilename); 442 443 String sBuildID = ""; 444 445 try 446 { 447 FileWriter out = new FileWriter(aInfoFile.toString()); 448 out.write("# automatically created file by graphical compare" + ls); 449 if (_aGTA != null) 450 { 451 if (_sSpecial != null && _sSpecial.equals("msoffice")) 452 { 453 out.write("# buildid from wordloadfile" + ls); 454 sBuildID = _aGTA.getPerformance().getMSOfficeVersion(); 455 out.write("buildid=" + sBuildID + ls); 456 } 457 else 458 { 459 out.write("# buildid is read out of the bootstrap file" + ls); 460 sBuildID = _aGTA.getBuildID(); 461 out.write("buildid=" + sBuildID + ls); 462 } 463 // if (_sSpecial != null && _sSpecial.length() > 0) 464 // { 465 // out.write("special=" + _sSpecial + ls); 466 // } 467 out.write(ls); 468 out.write("# resolution given in DPI" + ls); 469 out.write("resolution=" + _aGTA.getResolutionInDPI() + ls); 470 } 471 else 472 { 473 out.write("buildid=" + _sSpecial + ls); 474 } 475 // long nTime = stopTimer(); 476 // if (nTime != 0) 477 // { 478 // out.write("# time is given in milli seconds" + ls); 479 // out.write("time=" + nTime + ls); 480 // } 481 482 out.write(ls); 483 out.write("# Values out of System.getProperty(...)" + ls); 484 out.write("os.name=" + System.getProperty("os.name") + ls); 485 out.write("os.arch=" + System.getProperty("os.arch") + ls); 486 out.write("os.version=" + System.getProperty("os.version") + ls); 487 488 if (_aGTA != null) 489 { 490 out.write(ls); 491 out.write("# Performance output, values are given in milli sec." + ls); 492 _aGTA.getPerformance().print(out); 493 } 494 495 out.flush(); 496 out.close(); 497 } 498 catch (java.io.IOException e) 499 { 500 GlobalLogWriter.get().println("can't create Info file."); 501 e.printStackTrace(); 502 } 503 504 String sExtension = FileHelper.getSuffix(_aGTA.getInputFile()); 505 if (sExtension.startsWith(".")) 506 { 507 sExtension = sExtension.substring(1); 508 } 509 510 DB.writeToDB(_aGTA.getInputFile(), 511 sNameNoSuffix, 512 sExtension, 513 sBuildID, 514 _aGTA.getReferenceType(), 515 _aGTA.getResolutionInDPI() 516 ); 517 } 518 519 520 521 // ----------------------------------------------------------------------------- 522 private static boolean impl_printToFileWithOOo(GraphicalTestArguments _aGTA, 523 XComponent _aDoc, 524 String _sOutputURL, 525 String _sPrintFileURL) 526 { 527 boolean bBack = false; 528 boolean bFailed = true; // always be a pessimist, 529 if (_aDoc == null) 530 { 531 GlobalLogWriter.get().println("No document is given."); 532 return bBack; 533 } 534 535 try 536 { 537 if (_sOutputURL != null) 538 { 539 if (_aGTA.isStoreAllowed()) 540 { 541 // store the document in an other directory 542 XStorable aStorable = UnoRuntime.queryInterface( XStorable.class, _aDoc); 543 if (aStorable != null) 544 { 545 PropertyValue [] szEmptyArgs = new PropertyValue [0]; 546 547 GlobalLogWriter.get().println(DateHelper.getDateTimeForHumanreadableLog() + " Store document."); 548 _aGTA.getPerformance().startTime(PerformanceContainer.Store); 549 aStorable.storeAsURL(_sOutputURL, szEmptyArgs); 550 _aGTA.getPerformance().stopTime(PerformanceContainer.Store); 551 552 GlobalLogWriter.get().println(DateHelper.getDateTimeForHumanreadableLog() + " Store document done."); 553 TimeHelper.waitInSeconds(2, "After store as URL to:" + _sOutputURL); 554 GlobalLogWriter.get().println("Reload stored file test."); 555 XComponent aDoc = loadFromURL(_aGTA, _sOutputURL); 556 if (aDoc == null) 557 { 558 GlobalLogWriter.get().println("Reload stored file test failed, can't reload file: " + _sOutputURL); 559 } 560 } 561 } 562 } 563 } 564 catch ( com.sun.star.uno.Exception e ) 565 { 566 // Some exception occures.FAILED 567 GlobalLogWriter.get().println("UNO Exception caught."); 568 GlobalLogWriter.get().println("Message: " + e.getMessage()); 569 570 e.printStackTrace(); 571 bBack = false; 572 } 573 574 try 575 { 576 577 // System.out.println("Document loaded."); 578 // Change Pagesettings to DIN A4 579 580 GlobalLogWriter.get().println(DateHelper.getDateTimeForHumanreadableLog() + " Print document."); 581 XPrintable aPrintable = UnoRuntime.queryInterface( XPrintable.class, _aDoc); 582 if (aPrintable != null) 583 { 584 // System.out.println(" Set PaperFormat to DIN A4"); 585 // { 586 // PropertyValue[] aPrinterProps = aPrintable.getPrinter(); 587 // System.out.println("PrinterProps size: " + String.valueOf(aPrinterProps.length)); 588 // int nPropIndex = 0; 589 // while (!"PaperFormat".equals(aPrinterProps[nPropIndex].Name)) 590 // { 591 // // System.out.println(aPrinterProps[nPropIndex].Name); 592 // nPropIndex++; 593 // } 594 // aPrinterProps[nPropIndex].Value = com.sun.star.view.PaperFormat.A4; 595 // aPrintable.setPrinter(aPrinterProps); 596 // } 597 598 // configure Office to allow to execute macos 599 600 // TODO: We need a possiblity to set the printer name also for StarOffice/OpenOffice 601 if (OSHelper.isWindows()) 602 { 603 if (_aGTA.getPrinterName() != null) 604 { 605 ArrayList<PropertyValue> aPropertyList = new ArrayList<PropertyValue>(); 606 // PropertyValue [] aPrintProps = new PropertyValue[1]; 607 PropertyValue Arg = new PropertyValue(); 608 Arg.Name = "Name"; 609 Arg.Value = _aGTA.getPrinterName(); 610 aPropertyList.add(Arg); 611 showProperty(Arg); 612 // GlobalLogWriter.get().println("Printername is not null, so set to " + _aGTA.getPrinterName()); 613 aPrintable.setPrinter(PropertyHelper.createPropertyValueArrayFormArrayList(aPropertyList)); 614 } 615 } 616 617 // set property values for XPrintable.print() 618 // more can be found at "http://api.openoffice.org/docs/common/ref/com/sun/star/view/PrintOptions.html" 619 620 // int nProperties = 1; // default for 'FileName' property 621 // if (_aGTA.printAllPages() == false) 622 // { 623 // // we don't want to print all pages, build Pages string by ourself 624 // nProperties ++; 625 // } 626 // int nPropsCount = 0; 627 628 // If we are a SpreadSheet (calc), we need to set PrintAllSheets property to 'true' 629 XServiceInfo xServiceInfo = UnoRuntime.queryInterface( XServiceInfo.class, _aDoc ); 630 if ( xServiceInfo.supportsService( "com.sun.star.sheet.SpreadsheetDocument" ) ) 631 { 632 XMultiServiceFactory xMSF = _aGTA.getMultiServiceFactory(); 633 Object aSettings = xMSF.createInstance( "com.sun.star.sheet.GlobalSheetSettings" ); 634 if (aSettings != null) 635 { 636 XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, aSettings ); 637 xPropSet.setPropertyValue( "PrintAllSheets", new Boolean( true ) ); 638 GlobalLogWriter.get().println("PrintAllSheets := true"); 639 } 640 } 641 642 ArrayList<PropertyValue> aPrintProps = new ArrayList<PropertyValue>(); 643 // GlobalLogWriter.get().println("Property FileName:=" + _sPrintFileURL); 644 645 // PropertyValue [] aPrintProps = new PropertyValue[nProperties]; 646 PropertyValue Arg = new PropertyValue(); 647 Arg.Name = "FileName"; 648 Arg.Value = _sPrintFileURL; 649 // aPrintProps[nPropsCount ++] = Arg; 650 aPrintProps.add(Arg); 651 showProperty(Arg); 652 653 if (_aGTA.printAllPages() == false) 654 { 655 String sPages = ""; 656 if (_aGTA.getMaxPages() > 0) 657 { 658 sPages = "1-" + String.valueOf(_aGTA.getMaxPages()); 659 } 660 if (_aGTA.getOnlyPages().length() != 0) 661 { 662 if (sPages.length() != 0) 663 { 664 sPages += ";"; 665 } 666 sPages += String.valueOf(_aGTA.getOnlyPages()); 667 } 668 669 Arg = new PropertyValue(); 670 Arg.Name = "Pages"; 671 Arg.Value = sPages; 672 aPrintProps.add(Arg); 673 showProperty(Arg); 674 } 675 676 // GlobalLogWriter.get().println("Start printing."); 677 678 _aGTA.getPerformance().startTime(PerformanceContainer.Print); 679 aPrintable.print(PropertyHelper.createPropertyValueArrayFormArrayList(aPrintProps)); 680 TimeHelper.waitInSeconds(1, "Start waiting for print ready."); 681 682 GlobalLogWriter.get().println("Wait until document is printed."); 683 boolean isBusy = true; 684 int nPrintCount = 0; 685 while (isBusy) 686 { 687 PropertyValue[] aPrinterProps = aPrintable.getPrinter(); 688 int nPropIndex = 0; 689 while (!"IsBusy".equals(aPrinterProps[nPropIndex].Name)) 690 { 691 // System.out.println(aPrinterProps[nPropIndex].Name); 692 nPropIndex++; 693 } 694 isBusy = (aPrinterProps[nPropIndex].Value == Boolean.TRUE) ? true : false; 695 TimeHelper.waitInSeconds(1, "is print ready?"); 696 nPrintCount++; 697 if (nPrintCount > 3600) 698 { 699 // we will never wait >1h until print is ready! 700 GlobalLogWriter.get().println("ERROR: Cancel print due to too long wait."); 701 throw new com.sun.star.uno.Exception("Convwatch exception, wait too long for printing."); 702 } 703 } 704 _aGTA.getPerformance().stopTime(PerformanceContainer.Print); 705 GlobalLogWriter.get().println(DateHelper.getDateTimeForHumanreadableLog() + " Print document done."); 706 707 // Create a .info file near the printed '.ps' or '.prn' file. 708 createInfoFile(_sPrintFileURL, _aGTA); 709 } 710 else 711 { 712 GlobalLogWriter.get().println("Can't get XPrintable interface."); 713 } 714 bFailed = false; 715 bBack = true; 716 } 717 catch ( com.sun.star.uno.Exception e ) 718 { 719 // Some exception occures.FAILED 720 GlobalLogWriter.get().println("UNO Exception caught."); 721 GlobalLogWriter.get().println("Message: " + e.getMessage()); 722 723 e.printStackTrace(); 724 bBack = false; 725 } 726 727 if (bFailed == true) 728 { 729 GlobalLogWriter.get().println("convwatch.OfficePrint: FAILED"); 730 } 731 else 732 { 733 GlobalLogWriter.get().println("convwatch.OfficePrint: OK"); 734 } 735 return bBack; 736 } 737 738 739 /** 740 * @param _aGTA 741 * @param _sAbsoluteOutputPath 742 * @param _sAbsoluteInputFile 743 * @return true, if the reference (*.prrn file) based on given output path and given input path exist. 744 * If OVERWRITE_REFERENCE is set, always return false. 745 */ 746 public static boolean isReferenceExists(GraphicalTestArguments _aGTA, 747 String _sAbsoluteOutputPath, 748 String _sAbsoluteInputFile) 749 { 750 if (! FileHelper.exists(_sAbsoluteInputFile)) 751 { 752 // throw new ConvWatchCancelException("Input file: " + _sAbsoluteInputFile + " does not exist."); 753 return false; 754 } 755 756 String fs = System.getProperty("file.separator"); 757 758 // String sInputFileURL = URLHelper.getFileURLFromSystemPath(_sAbsoluteInputFile); 759 760 String sInputFileBasename = FileHelper.getBasename(_sAbsoluteInputFile); 761 // String sOutputFileURL = null; 762 String sOutputPath; 763 if (_sAbsoluteOutputPath != null) 764 { 765 sOutputPath = _sAbsoluteOutputPath; 766 // FileHelper.makeDirectories("", sOutputPath); 767 } 768 else 769 { 770 String sInputPath = FileHelper.getPath(_sAbsoluteInputFile); 771 sOutputPath = sInputPath; 772 } 773 // sOutputFileURL = URLHelper.getFileURLFromSystemPath(sOutputPath + fs + sInputFileBasename); 774 // sOutputFileURL = null; 775 776 String sPrintFilename = FileHelper.getNameNoSuffix(sInputFileBasename); 777 // String sPrintFileURL; 778 779 String sAbsolutePrintFilename = sOutputPath + fs + sPrintFilename + ".prn"; 780 if (FileHelper.exists(sAbsolutePrintFilename) && _aGTA.getOverwrite() == false) 781 { 782 GlobalLogWriter.get().println("Reference already exist, don't overwrite. Set " + PropertyName.DOC_COMPARATOR_OVERWRITE_REFERENCE + "=true to force overwrite."); 783 return true; 784 } 785 return false; 786 } 787 788 // ----------------------------------------------------------------------------- 789 /** 790 * create a reference file 791 * _sAbsoluteInputPath contains the source file, if not exists, return with failure. 792 * _sAbsoluteOutputPath contains the destination, where the file will store after load with StarOffice/OpenOffice.org 793 * if is null, print only near the Input file path 794 * _sPrintType ".prn" Print input file with StarOffice/OpenOffice.org and the default printer as PostScript 795 * 796 * @param _aGTA 797 * @param _sAbsoluteOutputPath 798 * @param _sAbsoluteInputFile 799 * @return 800 * @throws ConvWatchCancelException 801 */ 802 public static boolean buildReference(GraphicalTestArguments _aGTA, 803 String _sAbsoluteOutputPath, 804 String _sAbsoluteInputFile) 805 throws ConvWatchCancelException 806 { 807 if (! FileHelper.exists(_sAbsoluteInputFile)) 808 { 809 throw new ConvWatchCancelException("buildReference(): Input file: " + _sAbsoluteInputFile + " does not exist."); 810 } 811 812 String fs = System.getProperty("file.separator"); 813 814 String sInputFileURL = URLHelper.getFileURLFromSystemPath(_sAbsoluteInputFile); 815 816 String sInputFileBasename = FileHelper.getBasename(_sAbsoluteInputFile); 817 String sOutputFileURL = null; 818 String sOutputPath; 819 if (_sAbsoluteOutputPath != null) 820 { 821 sOutputPath = _sAbsoluteOutputPath; 822 FileHelper.makeDirectories("", sOutputPath); 823 } 824 else 825 { 826 String sInputPath = FileHelper.getPath(_sAbsoluteInputFile); 827 sOutputPath = sInputPath; 828 } 829 // sOutputFileURL = URLHelper.getFileURLFromSystemPath(sOutputPath + fs + sInputFileBasename); 830 sOutputFileURL = null; 831 832 String sPrintFilename = FileHelper.getNameNoSuffix(sInputFileBasename); 833 String sPrintFileURL; 834 835 String sAbsolutePrintFilename = sOutputPath + fs + sPrintFilename + ".prn"; 836 if (FileHelper.exists(sAbsolutePrintFilename) && _aGTA.getOverwrite() == false) 837 { 838 GlobalLogWriter.get().println("Reference already exist, don't overwrite. Set " + PropertyName.DOC_COMPARATOR_OVERWRITE_REFERENCE + "=true to force overwrite."); 839 return true; 840 } 841 842 if (_aGTA.getReferenceType().toLowerCase().equals("msoffice")) 843 { 844 sPrintFileURL = URLHelper.getFileURLFromSystemPath(sAbsolutePrintFilename); 845 } 846 else if (_aGTA.getReferenceType().toLowerCase().equals("pdf")) 847 { 848 // TODO: If we rename the stored file to *.pdf, we have to be sure that we use *.pdf also as a available reference 849 sPrintFileURL = URLHelper.getFileURLFromSystemPath(sAbsolutePrintFilename ); 850 } 851 else if (_aGTA.getReferenceType().toLowerCase().equals("ooo")) 852 { 853 sPrintFileURL = URLHelper.getFileURLFromSystemPath(sAbsolutePrintFilename ); 854 } 855 else 856 { 857 GlobalLogWriter.get().println("OfficePrint.buildreference(): Unknown print type."); 858 return false; 859 } 860 return printToFile(_aGTA, sInputFileURL, sOutputFileURL, sPrintFileURL); 861 } 862 863 public static boolean printToFile(GraphicalTestArguments _aGTA, 864 String _sInputFileURL, 865 String _sOutputFileURL, 866 String _sPrintFileURL) throws ConvWatchCancelException 867 { 868 boolean bBack = false; 869 String sPrintFileURL = null; 870 871 // check if given file is a picture, then do nothing 872 String sDocumentSuffix = FileHelper.getSuffix(_sInputFileURL); 873 if (sDocumentSuffix.toLowerCase().endsWith(".png") || 874 sDocumentSuffix.toLowerCase().endsWith(".gif") || 875 sDocumentSuffix.toLowerCase().endsWith(".jpg") || 876 sDocumentSuffix.toLowerCase().endsWith(".bmp")) 877 { 878 return false; 879 } 880 881 882 // remember the current timer, to know how long a print process need. 883 // startTimer(); 884 885 if (_aGTA.getReferenceType().toLowerCase().equals("ooo")) 886 { 887 bBack = printToFileWithOOo(_aGTA, _sInputFileURL, _sOutputFileURL, _sPrintFileURL); 888 } 889 else if (_aGTA.getReferenceType().toLowerCase().equals("pdf")) 890 { 891 GlobalLogWriter.get().println("USE PDF AS EXPORT FORMAT."); 892 bBack = storeAsPDF(_aGTA, _sInputFileURL, _sPrintFileURL); 893 } 894 else if (_aGTA.getReferenceType().toLowerCase().equals("msoffice")) 895 { 896 if (MSOfficePrint.isMSOfficeDocumentFormat(_sInputFileURL)) 897 { 898 GlobalLogWriter.get().println("USE MSOFFICE AS EXPORT FORMAT."); 899 MSOfficePrint a = new MSOfficePrint(); 900 try 901 { 902 a.printToFileWithMSOffice(_aGTA, FileHelper.getSystemPathFromFileURL(_sInputFileURL), 903 FileHelper.getSystemPathFromFileURL(_sPrintFileURL)); 904 } 905 catch(ConvWatchCancelException e) 906 { 907 e.printStackTrace(); 908 GlobalLogWriter.get().println(e.getMessage()); 909 throw new ConvWatchCancelException("Exception caught. Problem with MSOffice printer methods."); 910 } 911 catch(java.io.IOException e) 912 { 913 GlobalLogWriter.get().println(e.getMessage()); 914 throw new ConvWatchCancelException("IOException caught. Problem with MSOffice printer methods."); 915 } 916 bBack = true; 917 } 918 else 919 { 920 GlobalLogWriter.get().println("This document type is not recognized as MSOffice format, as default fallback StarOffice/OpenOffice.org instead is used."); 921 bBack = printToFileWithOOo(_aGTA, _sInputFileURL, _sOutputFileURL, _sPrintFileURL); 922 } 923 } 924 else 925 { 926 // System.out.println(""); 927 throw new ConvWatchCancelException("OfficePrint.printToFile(): Unknown print type."); 928 } 929 return bBack; 930 } 931 932 // ----------------------------------------------------------------------------- 933 // TODO: move this away! 934 // ----------------------------------------------------------------------------- 935 static void showType(String _sInputURL, XMultiServiceFactory _xMSF) 936 { 937 if (_sInputURL.length() == 0) 938 { 939 return; 940 } 941 942 if (_xMSF == null) 943 { 944 GlobalLogWriter.get().println("MultiServiceFactory not set."); 945 return; 946 } 947 XTypeDetection aTypeDetection = null; 948 try 949 { 950 Object oObj = _xMSF.createInstance("com.sun.star.document.TypeDetection"); 951 aTypeDetection = UnoRuntime.queryInterface(XTypeDetection.class, oObj); 952 } 953 catch(com.sun.star.uno.Exception e) 954 { 955 GlobalLogWriter.get().println("Can't get com.sun.star.document.TypeDetection."); 956 return; 957 } 958 if (aTypeDetection != null) 959 { 960 String sType = aTypeDetection.queryTypeByURL(_sInputURL); 961 GlobalLogWriter.get().println("Type is: " + sType); 962 } 963 } 964 965 966 // ----------------------------------------------------------------------------- 967 public static String getInternalFilterName(String _sFilterName, XMultiServiceFactory _xMSF) 968 { 969 if (_sFilterName.length() == 0) 970 { 971 // System.out.println("No FilterName set."); 972 return null; 973 } 974 975 if (_xMSF == null) 976 { 977 GlobalLogWriter.get().println("MultiServiceFactory not set."); 978 return null; 979 } 980 // XFilterFactory aFilterFactory = null; 981 Object aObj = null; 982 try 983 { 984 aObj = _xMSF.createInstance("com.sun.star.document.FilterFactory"); 985 } 986 catch(com.sun.star.uno.Exception e) 987 { 988 GlobalLogWriter.get().println("Can't get com.sun.star.document.FilterFactory."); 989 return null; 990 } 991 if (aObj != null) 992 { 993 XNameAccess aNameAccess = UnoRuntime.queryInterface(XNameAccess.class, aObj); 994 if (aNameAccess != null) 995 { 996 997 // if (_sFilterName.toLowerCase().equals("help")) 998 // { 999 // System.out.println("Show all possible ElementNames from current version." ); 1000 // String[] aElementNames = aNameAccess.getElementNames(); 1001 // for (int i = 0; i<aElementNames.length; i++) 1002 // { 1003 // System.out.println(aElementNames[i]); 1004 // } 1005 // System.out.println("Must quit."); 1006 // System.out.exit(1); 1007 // } 1008 1009 if (! aNameAccess.hasByName(_sFilterName)) 1010 { 1011 GlobalLogWriter.get().println("FilterFactory.hasByName() says there exist no '" + _sFilterName + "'" ); 1012 return null; 1013 } 1014 1015 Object[] aElements = null; 1016 String[] aExtensions; 1017 try 1018 { 1019 aElements = (Object[]) aNameAccess.getByName(_sFilterName); 1020 if (aElements != null) 1021 { 1022 String sInternalFilterName = null; 1023 // System.out.println("getByName().length: " + String.valueOf(aElements.length)); 1024 for (int i=0;i<aElements.length; i++) 1025 { 1026 PropertyValue aPropertyValue = (PropertyValue)aElements[i]; 1027 // System.out.println("PropertyValue.Name: " + aPropertyValue.Name); 1028 if (aPropertyValue.Name.equals("Type")) 1029 { 1030 String sValue = (String)aPropertyValue.Value; 1031 // System.out.println("Type: " + sValue); 1032 sInternalFilterName = sValue; 1033 } 1034 } 1035 return sInternalFilterName; 1036 } 1037 else 1038 { 1039 GlobalLogWriter.get().println("There are no elements for FilterName '" + _sFilterName + "'"); 1040 return null; 1041 } 1042 } 1043 catch (com.sun.star.container.NoSuchElementException e) 1044 { 1045 GlobalLogWriter.get().println("NoSuchElementException caught. " + e.getMessage()); 1046 } 1047 catch (com.sun.star.lang.WrappedTargetException e) 1048 { 1049 GlobalLogWriter.get().println("WrappedTargetException caught. " + e.getMessage()); 1050 } 1051 } 1052 } 1053 return null; 1054 } 1055 1056 // ----------------------------------------------------------------------------- 1057 1058 static String getServiceNameFromFilterName(String _sFilterName, XMultiServiceFactory _xMSF) 1059 { 1060 if (_sFilterName.length() == 0) 1061 { 1062 // System.out.println("No FilterName set."); 1063 return null; 1064 } 1065 1066 if (_xMSF == null) 1067 { 1068 GlobalLogWriter.get().println("MultiServiceFactory not set."); 1069 return null; 1070 } 1071 // XFilterFactory aFilterFactory = null; 1072 Object aObj = null; 1073 try 1074 { 1075 aObj = _xMSF.createInstance("com.sun.star.document.FilterFactory"); 1076 } 1077 catch(com.sun.star.uno.Exception e) 1078 { 1079 GlobalLogWriter.get().println("Can't get com.sun.star.document.FilterFactory."); 1080 return null; 1081 } 1082 if (aObj != null) 1083 { 1084 XNameAccess aNameAccess = UnoRuntime.queryInterface(XNameAccess.class, aObj); 1085 if (aNameAccess != null) 1086 { 1087 if (! aNameAccess.hasByName(_sFilterName)) 1088 { 1089 GlobalLogWriter.get().println("FilterFactory.hasByName() says there exist no '" + _sFilterName + "'" ); 1090 return null; 1091 } 1092 1093 Object[] aElements = null; 1094 String[] aExtensions; 1095 try 1096 { 1097 aElements = (Object[]) aNameAccess.getByName(_sFilterName); 1098 if (aElements != null) 1099 { 1100 String sServiceName = null; 1101 // System.out.println("getByName().length: " + String.valueOf(aElements.length)); 1102 for (int i=0;i<aElements.length; i++) 1103 { 1104 PropertyValue aPropertyValue = (PropertyValue)aElements[i]; 1105 if (aPropertyValue.Name.equals("DocumentService")) 1106 { 1107 String sValue = (String)aPropertyValue.Value; 1108 // System.out.println("DocumentService: " + sValue); 1109 sServiceName = sValue; 1110 break; 1111 } 1112 } 1113 return sServiceName; 1114 } 1115 else 1116 { 1117 GlobalLogWriter.get().println("There are no elements for FilterName '" + _sFilterName + "'"); 1118 return null; 1119 } 1120 } 1121 catch (com.sun.star.container.NoSuchElementException e) 1122 { 1123 GlobalLogWriter.get().println("NoSuchElementException caught. " + e.getMessage()); 1124 } 1125 catch (com.sun.star.lang.WrappedTargetException e) 1126 { 1127 GlobalLogWriter.get().println("WrappedTargetException caught. " + e.getMessage()); 1128 } 1129 } 1130 } 1131 return null; 1132 } 1133 // ----------------------------------------------------------------------------- 1134 1135 public static String getFileExtension(String _sInternalFilterName, XMultiServiceFactory _xMSF) 1136 { 1137 if (_sInternalFilterName.length() == 0) 1138 { 1139 // System.out.println("No FilterName set."); 1140 return null; 1141 } 1142 1143 if (_xMSF == null) 1144 { 1145 GlobalLogWriter.get().println("MultiServiceFactory not set."); 1146 return null; 1147 } 1148 XTypeDetection aTypeDetection = null; 1149 try 1150 { 1151 Object oObj = _xMSF.createInstance("com.sun.star.document.TypeDetection"); 1152 aTypeDetection =UnoRuntime.queryInterface(XTypeDetection.class, oObj); 1153 } 1154 catch(com.sun.star.uno.Exception e) 1155 { 1156 GlobalLogWriter.get().println("Can't get com.sun.star.document.TypeDetection."); 1157 return null; 1158 } 1159 if (aTypeDetection != null) 1160 { 1161 XNameAccess aNameAccess = UnoRuntime.queryInterface(XNameAccess.class, aTypeDetection); 1162 if (aNameAccess != null) 1163 { 1164 1165 // System.out.println("Show ElementNames" ); 1166 // String[] aElementNames = aNameAccess.getElementNames(); 1167 // for (int i = 0; i<aElementNames.length; i++) 1168 // { 1169 // System.out.println(aElementNames[i]); 1170 // } 1171 1172 if (! aNameAccess.hasByName(_sInternalFilterName)) 1173 { 1174 GlobalLogWriter.get().println("TypeDetection.hasByName() says there exist no '" + _sInternalFilterName + "'" ); 1175 return null; 1176 } 1177 1178 Object[] aElements = null; 1179 String[] aExtensions; 1180 try 1181 { 1182 aElements = (Object[]) aNameAccess.getByName(_sInternalFilterName); 1183 if (aElements != null) 1184 { 1185 String sExtension = null; 1186 // System.out.println("getByName().length: " + String.valueOf(aElements.length)); 1187 for (int i=0;i<aElements.length; i++) 1188 { 1189 PropertyValue aPropertyValue = (PropertyValue)aElements[i]; 1190 // System.out.println("PropertyValue.Name: " + aPropertyValue.Name); 1191 if (aPropertyValue.Name.equals("Extensions")) 1192 { 1193 aExtensions = (String[])aPropertyValue.Value; 1194 GlobalLogWriter.get().println(" Possible extensions are: " + String.valueOf(aExtensions.length)); 1195 if (aExtensions.length > 0) 1196 { 1197 for (int j=0;j<aExtensions.length;j++) 1198 { 1199 GlobalLogWriter.get().println(" " + aExtensions[j]); 1200 } 1201 sExtension = aExtensions[0]; 1202 GlobalLogWriter.get().println(""); 1203 } 1204 } 1205 } 1206 return sExtension; 1207 } 1208 else 1209 { 1210 GlobalLogWriter.get().println("There are no elements for FilterName '" + _sInternalFilterName + "'"); 1211 return null; 1212 } 1213 } 1214 catch (com.sun.star.container.NoSuchElementException e) 1215 { 1216 GlobalLogWriter.get().println("NoSuchElementException caught. " + e.getMessage()); 1217 } 1218 catch (com.sun.star.lang.WrappedTargetException e) 1219 { 1220 GlobalLogWriter.get().println("WrappedTargetException caught. " + e.getMessage()); 1221 } 1222 } 1223 } 1224 return null; 1225 } 1226 1227 // ----------------------------------------------------------------------------- 1228 public static void convertDocument(String _sInputFile, String _sOutputPath, GraphicalTestArguments _aGTA) throws ConvWatchCancelException 1229 { 1230 XMultiServiceFactory xMSF = _aGTA.getMultiServiceFactory(); 1231 if (xMSF == null) 1232 { 1233 GlobalLogWriter.get().println("MultiServiceFactory in GraphicalTestArgument not set."); 1234 return; 1235 } 1236 1237 String sInputURL = URLHelper.getFileURLFromSystemPath(_sInputFile); 1238 // showType(sInputURL, xMSF); 1239 XComponent aDoc = loadFromURL( _aGTA, sInputURL); 1240 if (aDoc == null) 1241 { 1242 GlobalLogWriter.get().println("Can't load document '"+ sInputURL + "'"); 1243 return; 1244 } 1245 1246 if (_sOutputPath == null) 1247 { 1248 GlobalLogWriter.get().println("Outputpath not set."); 1249 return; 1250 } 1251 1252 if (! _aGTA.isStoreAllowed()) 1253 { 1254 GlobalLogWriter.get().println("It's not allowed to store, check Input/Output path."); 1255 return; 1256 } 1257 // TODO: Do we need to wait? 1258 TimeHelper.waitInSeconds(1, "wait after loadFromURL."); 1259 1260 XServiceInfo xServiceInfo = UnoRuntime.queryInterface( XServiceInfo.class, aDoc ); 1261 // String sFilter = getFilterName_forExcel(xServiceInfo); 1262 // System.out.println("Filter is " + sFilter); 1263 1264 // store the document in an other directory 1265 XStorable xStorable = UnoRuntime.queryInterface( XStorable.class, aDoc); 1266 if (xStorable == null) 1267 { 1268 GlobalLogWriter.get().println("com.sun.star.frame.XStorable is null"); 1269 return; 1270 } 1271 1272 String sFilterName = _aGTA.getExportFilterName(); 1273 1274 // check how many Properties should initialize 1275 int nPropertyCount = 0; 1276 // if (sFilterName != null && sFilterName.length() > 0) 1277 // { 1278 // nPropertyCount ++; 1279 // } 1280 1281 // initialize PropertyArray 1282 // PropertyValue [] aStoreProps = new PropertyValue[ nPropertyCount ]; 1283 // int nPropertyIndex = 0; 1284 ArrayList<PropertyValue> aPropertyList = new ArrayList<PropertyValue>(); 1285 1286 String sExtension = ""; 1287 1288 if (sFilterName != null && sFilterName.length() > 0) 1289 { 1290 String sInternalFilterName = getInternalFilterName(sFilterName, xMSF); 1291 String sServiceName = getServiceNameFromFilterName(sFilterName, xMSF); 1292 1293 GlobalLogWriter.get().println("Filter detection:"); 1294 // check if service name from file filter is the same as from the loaded document 1295 boolean bServiceFailed = false; 1296 if (sServiceName == null || sInternalFilterName == null) 1297 { 1298 GlobalLogWriter.get().println("Given FilterName '" + sFilterName + "' seems to be unknown."); 1299 bServiceFailed = true; 1300 } 1301 if (! xServiceInfo.supportsService(sServiceName)) 1302 { 1303 GlobalLogWriter.get().println("Service from FilterName '" + sServiceName + "' is not supported by loaded document."); 1304 bServiceFailed = true; 1305 } 1306 if (bServiceFailed == true) 1307 { 1308 GlobalLogWriter.get().println("Please check '" + PropertyName.DOC_CONVERTER_EXPORT_FILTER_NAME + "' in the property file."); 1309 return; 1310 } 1311 1312 if (sInternalFilterName != null && sInternalFilterName.length() > 0) 1313 { 1314 // get the FileExtension, by the filter name, if we don't get a file extension 1315 // we assume the is also no right filter name. 1316 sExtension = getFileExtension(sInternalFilterName, xMSF); 1317 if (sExtension == null) 1318 { 1319 GlobalLogWriter.get().println("Can't found an extension for filtername, take it from the source."); 1320 } 1321 } 1322 1323 PropertyValue Arg = new PropertyValue(); 1324 Arg.Name = "FilterName"; 1325 Arg.Value = sFilterName; 1326 // aStoreProps[nPropertyIndex ++] = Arg; 1327 aPropertyList.add(Arg); 1328 showProperty(Arg); 1329 GlobalLogWriter.get().println("FilterName is set to: " + sFilterName); 1330 } 1331 1332 String sOutputURL = ""; 1333 try 1334 { 1335 // create the new filename with the extension, which is ok to the file format 1336 String sInputFileBasename = FileHelper.getBasename(_sInputFile); 1337 // System.out.println("InputFileBasename " + sInputFileBasename); 1338 String sInputFileNameNoSuffix = FileHelper.getNameNoSuffix(sInputFileBasename); 1339 // System.out.println("InputFilename no suffix " + sInputFileNameNoSuffix); 1340 String fs = System.getProperty("file.separator"); 1341 String sOutputFile = _sOutputPath; 1342 if (! sOutputFile.endsWith(fs)) 1343 { 1344 sOutputFile += fs; 1345 } 1346 if (sExtension != null && sExtension.length() > 0) 1347 { 1348 sOutputFile += sInputFileNameNoSuffix + "." + sExtension; 1349 } 1350 else 1351 { 1352 sOutputFile += sInputFileBasename; 1353 } 1354 1355 if (FileHelper.exists(sOutputFile) && _aGTA.getOverwrite() == false) 1356 { 1357 GlobalLogWriter.get().println("File already exist, don't overwrite. Set " + PropertyName.DOC_COMPARATOR_OVERWRITE_REFERENCE + "=true to force overwrite."); 1358 return; 1359 } 1360 1361 sOutputURL = URLHelper.getFileURLFromSystemPath(sOutputFile); 1362 1363 GlobalLogWriter.get().println("Store document as '" + sOutputURL + "'"); 1364 xStorable.storeAsURL(sOutputURL, PropertyHelper.createPropertyValueArrayFormArrayList(aPropertyList)); 1365 GlobalLogWriter.get().println("Document stored."); 1366 } 1367 catch (com.sun.star.io.IOException e) 1368 { 1369 GlobalLogWriter.get().println("Can't store document '" + sOutputURL + "'. Message is :'" + e.getMessage() + "'"); 1370 } 1371 // TODO: Do we need to wait? 1372 TimeHelper.waitInSeconds(1, "unknown in OfficePrint.convertDocument()"); 1373 1374 } 1375 1376 } 1377 1378