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