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 package convwatch; 23 24 import com.sun.star.lang.XMultiServiceFactory; 25 import lib.TestParameters; 26 import java.io.File; 27 28 import com.sun.star.container.XNameAccess; 29 import com.sun.star.uno.UnoRuntime; 30 31 /** 32 * This class object is more a Helper or Controller. 33 * It stores information like: 34 * - How to create a document (with a OpenOffice method, or with MS Word, or with OpenOffice as pdf) 35 * - some more info for OpenOffice method 36 * - a service factory pointer 37 * - if hidden mode should use 38 * - target name 39 * 40 * - printer name 41 * 42 * - how to handle .xml files, which in Microsoft could be Excel or Word documents 43 * 44 * HOWTO USE: 45 * For AOO, 46 * create an GraphicalTestArguments with a set of TestParameters 47 * GraphicalTestArguments a = new GraphicalTestArguments(params); 48 * 49 * If you wish to use pdf export instead of normal printer output, set also the reference type to 'pdf' 50 * a.setReferenceType("pdf"); 51 * 52 * 53 * For MS Office: 54 * create an GraphicalTestArguments and set the reference type to 'msoffice' 55 * GraphicalTestArguments a = new GraphicalTestArguments(params); 56 * a.setReferenceType("msoffice"); 57 * 58 * within windows it's better to set also a printer name so it's simply possible to use for normal work the default printer 59 * and for such tests with ConvWatch a extra printer. 60 * a.setPrinterName("CrossOffice Printer"); 61 * 62 */ 63 64 public class GraphicalTestArguments 65 { 66 /** 67 2DO: 68 Possible reference types are currently 69 // ooo 70 // pdf 71 // msoffice 72 */ 73 String m_sReferenceType = "OOo"; 74 75 String m_sTargetFrameName = "_blank"; 76 77 String m_sPrinterName = null; 78 79 // Hidden = true hides a used OpenOffice, all code is executed in the background 80 // This parameter is not used for RefType: msoffice 81 boolean m_bHidden = true; 82 83 String m_sDefaultXMLFormatApplication = null; 84 85 boolean m_bIncludeSubdirectories; 86 87 TestParameters m_aCurrentParams; 88 89 int m_nMaxPages = 0; // default is 0 (print all pages) 90 String m_sOnlyPage = ""; // default is "", there is no page which we want to print only. 91 92 int m_nResolutionInDPI = 0; 93 94 boolean m_bStoreFile = true; 95 boolean m_bResuseOffice = false; 96 97 boolean m_bDebugMode = false; 98 99 String m_sLeaveOutNames = null; 100 101 String m_sDistinct = null; 102 103 boolean m_bCreateDefaultReference = false; 104 105 // CONSTRUCTOR 106 private GraphicalTestArguments(){} 107 108 public GraphicalTestArguments(TestParameters param) 109 { 110 m_aCurrentParams = param; 111 // collect interesting information from the ComplexTestCase 112 // .... 113 114 // REFERENCE_TYPE ---------- 115 String sReferenceType = (String)param.get( PropertyName.DOC_COMPARATOR_REFERENCE_TYPE ); 116 if (sReferenceType == null || sReferenceType.length() == 0) 117 { 118 } 119 else 120 { 121 // log.println("found REFERENCE_TYPE " + sReferenceType ); 122 setReferenceType(sReferenceType); 123 } 124 125 // PRINTER_NAME ---------- 126 String sPrinterName = (String)param.get( PropertyName.DOC_COMPARATOR_PRINTER_NAME ); 127 if (sPrinterName == null || sPrinterName.length() == 0) 128 { 129 } 130 else 131 { 132 // log.println("found PRINTER_NAME " + sPrinterName ); 133 setPrinterName(sPrinterName); 134 } 135 // DEFAULT_XML_FORMAT_APP ------ 136 String sDefaultXMLFormatApp = (String)param.get( PropertyName.DOC_COMPARATOR_DEFAULT_XML_FORMAT_APP ); 137 if (sDefaultXMLFormatApp == null || sDefaultXMLFormatApp.length() == 0) 138 { 139 } 140 else 141 { 142 setDefaultXMLFormatApp(sDefaultXMLFormatApp); 143 } 144 145 m_bIncludeSubdirectories = true; 146 String sRECURSIVE = (String)param.get( PropertyName.DOC_COMPARATOR_INCLUDE_SUBDIRS ); 147 // TODO: I need to get the boolean value with get("name") because, if it is not given getBool() returns 148 // with a default of 'false' which is not very helpful if the default should be 'true' 149 // maybe a getBoolean("name", true) could be a better choice. 150 if (sRECURSIVE == null) 151 { 152 sRECURSIVE = "true"; 153 } 154 if (sRECURSIVE.toLowerCase().equals("no") || 155 sRECURSIVE.toLowerCase().equals("false")) 156 { 157 m_bIncludeSubdirectories = false; 158 } 159 160 // ---------------------------------------- 161 m_nMaxPages = param.getInt( PropertyName.DOC_COMPARATOR_PRINT_MAX_PAGE ); 162 m_sOnlyPage = (String)param.get(PropertyName.DOC_COMPARATOR_PRINT_ONLY_PAGE); 163 164 m_nResolutionInDPI = param.getInt( PropertyName.DOC_COMPARATOR_GFX_OUTPUT_DPI_RESOLUTION ); 165 if (m_nResolutionInDPI == 0) 166 { 167 // 212 DPI is 1754 x 2474 pixel for DIN A4 168 m_nResolutionInDPI = 212; 169 } 170 171 // ---------------------------------------- 172 String sImportFilterName = (String)param.get(PropertyName.DOC_CONVERTER_IMPORT_FILTER_NAME); 173 if (sImportFilterName != null && sImportFilterName.length() > 0) 174 { 175 // System.out.println("found " + PropertyName.DOC_CONVERTER_IMPORT_FILTER_NAME + " " + sImportFilterName ); 176 m_sImportFilterName = sImportFilterName; 177 178 if (sImportFilterName.toLowerCase().equals("help")) 179 { 180 showInternalFilterName(sImportFilterName, getMultiServiceFactory() ); 181 GlobalLogWriter.get().println("Must quit."); 182 } 183 } 184 // ---------------------------------------- 185 String sExportFilterName = (String)param.get(PropertyName.DOC_CONVERTER_EXPORT_FILTER_NAME); 186 if (sExportFilterName != null && sExportFilterName.length() > 0) 187 { 188 // System.out.println("found " + PropertyName.DOC_CONVERTER_EXPORT_FILTER_NAME + " " + sExportFilterName ); 189 m_sExportFilterName = sExportFilterName; 190 if (sExportFilterName.toLowerCase().equals("help")) 191 { 192 showInternalFilterName(sExportFilterName, getMultiServiceFactory() ); 193 GlobalLogWriter.get().println("Must quit."); 194 } 195 } 196 197 // ---------------------------------------- 198 String sOfficeProgram = (String)param.get(PropertyName.DOC_CONVERTER_OFFICE_PROGRAM); 199 if (sOfficeProgram != null && sOfficeProgram.length() > 0) 200 { 201 m_sOfficeProgram = sOfficeProgram; 202 } 203 // ---------------------------------------- 204 String sREUSE_OFFICE = (String)param.get( PropertyName.DOC_CONVERTER_REUSE_OFFICE); 205 if (sREUSE_OFFICE == null) 206 { 207 sREUSE_OFFICE = "false"; 208 } 209 if (sREUSE_OFFICE.toLowerCase().equals("yes") || 210 sREUSE_OFFICE.toLowerCase().equals("true")) 211 { 212 m_bResuseOffice = true; 213 } 214 else 215 { 216 m_bResuseOffice = false; 217 } 218 219 220 String sHTMLOutputPrefix = (String)param.get( PropertyName.DOC_COMPARATOR_HTML_OUTPUT_PREFIX); 221 if (sHTMLOutputPrefix == null) 222 { 223 m_sHTMLOutputPrefix = ""; 224 } 225 else 226 { 227 m_sHTMLOutputPrefix = sHTMLOutputPrefix; 228 } 229 230 String sWithBorderMove = (String)param.get( PropertyName.DOC_COMPARATOR_GFXCMP_WITH_BORDERMOVE); 231 if (sWithBorderMove == null) 232 { 233 sWithBorderMove = ""; 234 // m_tWithBorderMove = TriState.UNSET; 235 m_tWithBorderMove = TriState.FALSE; 236 } 237 if (sWithBorderMove.toLowerCase().equals("yes") || 238 sWithBorderMove.toLowerCase().equals("true")) 239 { 240 m_tWithBorderMove = TriState.TRUE; 241 } 242 else if (sWithBorderMove.toLowerCase().equals("no") || 243 sWithBorderMove.toLowerCase().equals("false")) 244 { 245 m_tWithBorderMove = TriState.FALSE; 246 } 247 else 248 { 249 m_tWithBorderMove = TriState.FALSE; 250 // m_tWithBorderMove = TriState.UNSET; 251 } 252 253 String sLeaveOutNames = (String)param.get(PropertyName.DOC_COMPARATOR_LEAVE_OUT_FILES); 254 if (sLeaveOutNames != null) 255 { 256 m_sLeaveOutNames = sLeaveOutNames; 257 } 258 259 String sDBInfoString = (String)param.get(PropertyName.DOC_COMPARATOR_DB_INFO_STRING); 260 if (sDBInfoString != null) 261 { 262 m_sDBInfoString = sDBInfoString; 263 } 264 265 // DISTINCT ---------- 266 String sDistinct = (String)param.get( "DISTINCT" ); 267 if (sDistinct == null || sDistinct.length() == 0) 268 { 269 sDistinct = ""; 270 } 271 else 272 { 273 m_sDistinct = sDistinct; 274 } 275 // HIDDEN 276 String sOfficeViewable = (String)param.get(PropertyName.OFFICE_VIEWABLE); 277 if (sOfficeViewable != null) 278 { 279 if (sOfficeViewable.toLowerCase().equals("yes") || 280 sOfficeViewable.toLowerCase().equals("true")) 281 { 282 setViewable(); 283 } 284 else 285 { 286 setHidden(); 287 } 288 } 289 // CREATE_DEFAULT 290 String sCreateDefault = (String)param.get(PropertyName.CREATE_DEFAULT); 291 if (sCreateDefault != null) 292 { 293 if (sCreateDefault.toLowerCase().equals("yes") || 294 sCreateDefault.toLowerCase().equals("true")) 295 { 296 m_bCreateDefaultReference = true; 297 } 298 else 299 { 300 m_bCreateDefaultReference = false; 301 } 302 } 303 304 } 305 306 public boolean checkIfUsableDocumentType(String _sName) 307 { 308 // @todo 309 // check if the name is in the leave out list and then return 'false' 310 if (_sName.toLowerCase().endsWith(".jpg") || 311 _sName.toLowerCase().endsWith(".png") || 312 _sName.toLowerCase().endsWith(".gif") || 313 _sName.toLowerCase().endsWith(".bmp") || 314 _sName.toLowerCase().endsWith(".prn") || 315 _sName.toLowerCase().endsWith(".ps")) 316 { 317 return false; 318 } 319 320 return true; 321 } 322 323 static void showInternalFilterName(String _sFilterName, XMultiServiceFactory _xMSF) 324 { 325 if (_sFilterName.length() == 0) 326 { 327 // System.out.println("No FilterName set."); 328 return; 329 } 330 331 if (_xMSF == null) 332 { 333 GlobalLogWriter.get().println("MultiServiceFactory not set."); 334 return; 335 } 336 // XFilterFactory aFilterFactory = null; 337 Object aObj = null; 338 try 339 { 340 aObj = _xMSF.createInstance("com.sun.star.document.FilterFactory"); 341 } 342 catch(com.sun.star.uno.Exception e) 343 { 344 GlobalLogWriter.get().println("Can't get com.sun.star.document.FilterFactory."); 345 return; 346 } 347 if (aObj != null) 348 { 349 XNameAccess aNameAccess = (XNameAccess)UnoRuntime.queryInterface(XNameAccess.class, aObj); 350 if (aNameAccess != null) 351 { 352 353 if (_sFilterName.toLowerCase().equals("help")) 354 { 355 GlobalLogWriter.get().println("Show all possible ElementNames from current version." ); 356 String[] aElementNames = aNameAccess.getElementNames(); 357 for (int i = 0; i<aElementNames.length; i++) 358 { 359 GlobalLogWriter.get().println(aElementNames[i]); 360 } 361 } 362 } 363 } 364 } 365 366 /* 367 public GraphicalTestArguments(TestParameters param, Log xxx) 368 { 369 // collect interesting information from the ComplexTestCase 370 // .... 371 } 372 */ 373 374 // set methods 375 public void setReferenceType(String _sType) 376 { 377 // special casse, null is not allowed, set to default. 378 if (_sType == null) 379 { 380 m_sReferenceType = "OOo"; 381 } 382 else 383 { 384 m_sReferenceType = _sType; 385 } 386 } 387 public void setTargetFrameName(String _sTargetFrameName) {m_sTargetFrameName = _sTargetFrameName;} 388 public void setPrinterName(String _sName) {m_sPrinterName = _sName;} 389 public void setHidden() { m_bHidden = true;} 390 public void setViewable() {m_bHidden = false;} 391 public void setDefaultXMLFormatApp(String _sNameOfApp) {m_sDefaultXMLFormatApplication = _sNameOfApp;} 392 393 // get methods 394 public XMultiServiceFactory getMultiServiceFactory() 395 { 396 XMultiServiceFactory xMSF = (XMultiServiceFactory)m_aCurrentParams.getMSF(); 397 398 // check if MultiServiceFactory is given 399 if (getReferenceType().toLowerCase().equals("pdf") || 400 getReferenceType().toLowerCase().equals("ooo")) 401 { 402 if (xMSF == null) 403 { 404 GlobalLogWriter.get().println("ERROR! MultiServiceFactory not given."); 405 } 406 } 407 return xMSF; 408 } 409 410 public String getReferenceType() {return m_sReferenceType;} 411 public String getTargetFrameName() {return m_sTargetFrameName;} 412 public String getPrinterName() {return m_sPrinterName;} 413 public boolean isHidden() {return m_bHidden;} 414 public String getDefaultXMLFormatApp() {return m_sDefaultXMLFormatApplication;} 415 416 417 /** 418 * @return true, if subdirectories should run through 419 */ 420 public boolean includeSubDirectories() {return m_bIncludeSubdirectories;} 421 422 /** 423 * @return the number of pages to be print 424 */ 425 public int getMaxPages() {return m_nMaxPages;} 426 427 /** 428 * @return as string, which pages should be print, e.g. '1-4;6' here, page 1 to 4 and page 6. 429 */ 430 public String getOnlyPages() 431 { 432 if (m_sOnlyPage == null) 433 { 434 return ""; 435 } 436 return m_sOnlyPage; 437 } 438 439 /** 440 * @return true, if there should not print all pages at all, use getMaxPages() and or getOnlyPages() to get which pages to print 441 */ 442 public boolean printAllPages() 443 { 444 if ( (getMaxPages() > 0) || 445 (getOnlyPages().length() != 0)) 446 { 447 return false; 448 } 449 return true; 450 } 451 452 /** 453 * @return integer value, which contain resolution in DPI. 454 */ 455 public int getResolutionInDPI() {return m_nResolutionInDPI;} 456 457 public static void checkIfMSWindowsConformPath(String _sPath) 458 { 459 if (_sPath != null && _sPath.length() > 1) 460 { 461 if (_sPath.charAt(1) == ':') 462 { 463 if (_sPath.charAt(2) != '\\') 464 { 465 GlobalLogWriter.get().println("This is not a Microsoft Windows conform path: '" + _sPath + "' please fix."); 466 System.exit(1); 467 } 468 } 469 } 470 } 471 472 473 /** 474 * @return the INPUT_PATH out of the TestParameters 475 */ 476 public String getInputPath() 477 { 478 String sInputPath; 479 sInputPath = (String)m_aCurrentParams.get(PropertyName.DOC_COMPARATOR_INPUT_PATH); 480 checkIfMSWindowsConformPath(sInputPath); 481 return sInputPath; 482 } 483 /** 484 * @return the OUTPUT_PATH out of the TestParameters 485 */ 486 public String getOutputPath() 487 { 488 String sOutputPath; 489 sOutputPath = (String)m_aCurrentParams.get(PropertyName.DOC_COMPARATOR_OUTPUT_PATH); 490 checkIfMSWindowsConformPath(sOutputPath); 491 return sOutputPath; 492 } 493 /** 494 * @return the REFERENCE_PATH out of the TestParameters 495 */ 496 public String getReferencePath() 497 { 498 String sReferencePath; 499 sReferencePath = (String)m_aCurrentParams.get(PropertyName.DOC_COMPARATOR_REFERENCE_PATH); 500 checkIfMSWindowsConformPath(sReferencePath); 501 return sReferencePath; 502 } 503 /** 504 * @return the DIFF_PATH out of the TestParameters 505 */ 506 public String getDiffPath() 507 { 508 String sDiffPath; 509 sDiffPath = (String)m_aCurrentParams.get(PropertyName.DOC_COMPARATOR_DIFF_PATH); 510 checkIfMSWindowsConformPath(sDiffPath); 511 return sDiffPath; 512 } 513 514 public boolean getOverwrite() 515 { 516 boolean bOverwrite = m_aCurrentParams.getBool( PropertyName.DOC_COMPARATOR_OVERWRITE_REFERENCE); 517 return bOverwrite; 518 } 519 public String getReferenceInputPath() 520 { 521 String sReferenceInputPath; 522 sReferenceInputPath = (String)m_aCurrentParams.get(PropertyName.DOC_COMPARATOR_REFERENCE_INPUT_PATH); 523 return sReferenceInputPath; 524 } 525 526 /** 527 * Helper function to get the buildid of the current used OpenOffice 528 * out of the AppExecutionCommand the build ID 529 */ 530 public String getBuildID() 531 { 532 String sAPP = (String)m_aCurrentParams.get(util.PropertyName.APP_EXECUTION_COMMAND); 533 // return getBuildID(sAPP); 534 // TODO: here we need the getBuildID(string) method 535 String sBuildID = convwatch.BuildID.getBuildID(sAPP); 536 return sBuildID; 537 } 538 539 public boolean shouldOfficeStart() 540 { 541 String sNoOffice = (String)m_aCurrentParams.get( "NoOffice" ); 542 if (sNoOffice != null) 543 { 544 if (sNoOffice.toLowerCase().startsWith("t") || sNoOffice.toLowerCase().startsWith("y")) 545 { 546 return false; 547 } 548 } 549 return true; 550 } 551 552 // Handle for Reference Build ID, is set in ConvWatch.createPostscriptStartCheck() 553 private String m_sRefBuildID; 554 555 public void setRefBuildID(String _sRef) 556 { 557 m_sRefBuildID = _sRef; 558 } 559 public String getRefBuildID() 560 { 561 return m_sRefBuildID; 562 } 563 564 public void disallowStore() 565 { 566 m_bStoreFile = false; 567 } 568 public void allowStore() 569 { 570 m_bStoreFile = true; 571 } 572 public boolean isStoreAllowed() 573 { 574 return m_bStoreFile; 575 } 576 public boolean createDefaultReference() 577 { 578 return m_bCreateDefaultReference; 579 } 580 581 582 // get/set for FilterName 583 // get the right Filtername (internal Name) from 584 // http://framework.openoffice.org/files/documents/25/897/filter_description.html 585 586 String m_sImportFilterName = ""; 587 String m_sExportFilterName = ""; 588 public void setImportFilterName(String _sImportFilterName) 589 { 590 m_sImportFilterName = _sImportFilterName; 591 } 592 public String getImportFilterName() 593 { 594 return m_sImportFilterName; 595 } 596 public void setExportFilterName(String _sExportFilterName) 597 { 598 m_sExportFilterName = _sExportFilterName; 599 } 600 public String getExportFilterName() 601 { 602 return m_sExportFilterName; 603 } 604 605 String m_sOfficeProgram = ""; 606 public void setOfficeProgram(String _sName) 607 { 608 m_sOfficeProgram = _sName; 609 } 610 public String getOfficeProgram() 611 { 612 return m_sOfficeProgram; 613 } 614 615 public boolean restartOffice() 616 { 617 if (m_bResuseOffice == false) 618 { 619 return true; 620 } 621 return false; 622 } 623 624 String m_sHTMLOutputPrefix = ""; 625 public String getHTMLOutputPrefix() 626 { 627 return m_sHTMLOutputPrefix; 628 } 629 630 TriState m_tWithBorderMove = TriState.UNSET; 631 // public TriState isBorderMove() 632 // { 633 // return m_tWithBorderMove; 634 // } 635 public TriState getBorderMove() 636 { 637 return m_tWithBorderMove; 638 } 639 public void setBorderMove(TriState _tBorderMove) 640 { 641 m_tWithBorderMove = _tBorderMove; 642 } 643 644 String m_sDocumentType = ""; 645 public void setDocumentType(String _sName) 646 { 647 m_sDocumentType = _sName; 648 } 649 public String getDocumentType() 650 { 651 return m_sDocumentType; 652 } 653 654 /* 655 helper class for performance analyzer features 656 */ 657 PerformanceContainer m_aPerformanceContainer = null; 658 public PerformanceContainer getPerformance() 659 { 660 if (m_aPerformanceContainer == null) 661 { 662 m_aPerformanceContainer = new PerformanceContainer(); 663 } 664 return m_aPerformanceContainer; 665 } 666 667 private String m_aInputFile; 668 public void setInputFile(String _sInputFile) 669 { 670 m_aInputFile = _sInputFile; 671 } 672 public String getInputFile() 673 { 674 return m_aInputFile; 675 } 676 677 private String m_sDBInfoString; 678 public String getDBInfoString() 679 { 680 if (m_sDBInfoString != null) 681 { 682 if (m_sDBInfoString.length() == 0) 683 { 684 return null; 685 } 686 } 687 688 return m_sDBInfoString; 689 } 690 691 public boolean cancelRequest() 692 { 693 File aCancelFile = null; 694 String fs; 695 fs = System.getProperty("file.separator"); 696 String sTempPath = (String)m_aCurrentParams.get( PropertyName.TEMPPATH ); 697 if (sTempPath != null) 698 { 699 String sGDC_Dir = sTempPath; 700 701 if (m_sDistinct.length() > 0) 702 { 703 sGDC_Dir = sGDC_Dir + fs + m_sDistinct; 704 } 705 706 String sCancelFile = sGDC_Dir + fs + "cancel_compare.txt"; 707 aCancelFile = new File(sCancelFile); 708 709 if (aCancelFile.exists()) 710 { 711 GlobalLogWriter.get().println("ATTENTION: Found file: '" + sCancelFile + "'."); 712 GlobalLogWriter.get().println("User has canceled the program flow."); 713 return true; 714 } 715 } 716 return false; 717 } 718 719 } 720 721 722 /* 723 public class MSGraphicalTestArguments extends GraphicalTestArguments 724 { 725 MSGraphicalTestArguments() 726 { 727 setReferenceType("msoffice"); 728 } 729 } 730 731 public class OOoGraphicalTestArguments extends GraphicalTestArguments 732 { 733 OOoGraphicalTestArguments(XMultiServiceFactory _aFactory) 734 { 735 setMultiServiceFactory(_aFactory); 736 } 737 } 738 */ 739