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