merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / runner / convwatch / GraphicalTestArguments.java
blobf9857b9316d231562cbd11bdcd6c003a6c751545
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: GraphicalTestArguments.java,v $
10 * $Revision: 1.13.8.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package convwatch;
33 import com.sun.star.lang.XMultiServiceFactory;
34 import lib.TestParameters;
35 import java.io.File;
37 import com.sun.star.container.XNameAccess;
38 import com.sun.star.uno.UnoRuntime;
40 /**
41 * This class object is more a Helper or Controller.
42 * It stores information like:
43 * - How to create a document (with a OpenOffice.org method, or with MS Word, or with OpenOffice.org as pdf)
44 * - some more infos for OpenOffice.org method
45 * - a service factory pointer
46 * - if hidden mode should use
47 * - target name
49 * - printer name
51 * - how to handle .xml files, which in Microsoft could be Excel or Word documents
53 * HOWTO USE:
54 * For OOo,
55 * create an GraphicalTestArguments with a set of TestParameters
56 * GraphicalTestArguments a = new GraphicalTestArguments(params);
58 * If you wish to use pdf export instead of normal printer output, set also the reference type to 'pdf'
59 * a.setReferenceType("pdf");
62 * For MS Office:
63 * create an GraphicalTestArguments and set the reference type to 'msoffice'
64 * GraphicalTestArguments a = new GraphicalTestArguments(params);
65 * a.setReferenceType("msoffice");
67 * within windows it's better to set also a printer name so it's simply possible to use for normal work the default printer
68 * and for such tests with ConvWatch a extra printer.
69 * a.setPrinterName("CrossOffice Printer");
73 public class GraphicalTestArguments
75 /**
76 2DO:
77 Possible reference types are currently
78 // ooo
79 // pdf
80 // msoffice
82 String m_sReferenceType = "OOo";
84 String m_sTargetFrameName = "_blank";
86 String m_sPrinterName = null;
88 // Hidden = true hiddes a used OpenOffice.org, all code is executed in the background
89 // This parameter is not used for RefType: msoffice
90 boolean m_bHidden = true;
92 String m_sDefaultXMLFormatApplication = null;
94 boolean m_bIncludeSubdirectories;
96 TestParameters m_aCurrentParams;
98 int m_nMaxPages = 0; // default is 0 (print all pages)
99 String m_sOnlyPage = ""; // default is "", there is no page which we want to print only.
101 int m_nResolutionInDPI = 0;
103 boolean m_bStoreFile = true;
104 boolean m_bResuseOffice = false;
106 boolean m_bDebugMode = false;
108 String m_sLeaveOutNames = null;
110 String m_sDistinct = null;
112 boolean m_bCreateDefaultReference = false;
114 // CONSTRUCTOR
115 private GraphicalTestArguments(){}
117 public GraphicalTestArguments(TestParameters param)
119 m_aCurrentParams = param;
120 // collect interesting information from the ComplexTestCase
121 // ....
123 // REFERENCE_TYPE ----------
124 String sReferenceType = (String)param.get( PropertyName.DOC_COMPARATOR_REFERENCE_TYPE );
125 if (sReferenceType == null || sReferenceType.length() == 0)
128 else
130 // log.println("found REFERENCE_TYPE " + sReferenceType );
131 setReferenceType(sReferenceType);
134 // PRINTER_NAME ----------
135 String sPrinterName = (String)param.get( PropertyName.DOC_COMPARATOR_PRINTER_NAME );
136 if (sPrinterName == null || sPrinterName.length() == 0)
139 else
141 // log.println("found PRINTER_NAME " + sPrinterName );
142 setPrinterName(sPrinterName);
144 // DEFAULT_XML_FORMAT_APP ------
145 String sDefaultXMLFormatApp = (String)param.get( PropertyName.DOC_COMPARATOR_DEFAULT_XML_FORMAT_APP );
146 if (sDefaultXMLFormatApp == null || sDefaultXMLFormatApp.length() == 0)
149 else
151 setDefaultXMLFormatApp(sDefaultXMLFormatApp);
154 m_bIncludeSubdirectories = true;
155 String sRECURSIVE = (String)param.get( PropertyName.DOC_COMPARATOR_INCLUDE_SUBDIRS );
156 // TODO: I need to get the boolean value with get("name") because, if it is not given getBool() returns
157 // with a default of 'false' which is not very helpful if the default should be 'true'
158 // maybe a getBoolean("name", true) could be a better choise.
159 if (sRECURSIVE == null)
161 sRECURSIVE = "true";
163 if (sRECURSIVE.toLowerCase().equals("no") ||
164 sRECURSIVE.toLowerCase().equals("false"))
166 m_bIncludeSubdirectories = false;
169 // ----------------------------------------
170 m_nMaxPages = param.getInt( PropertyName.DOC_COMPARATOR_PRINT_MAX_PAGE );
171 m_sOnlyPage = (String)param.get(PropertyName.DOC_COMPARATOR_PRINT_ONLY_PAGE);
173 m_nResolutionInDPI = param.getInt( PropertyName.DOC_COMPARATOR_GFX_OUTPUT_DPI_RESOLUTION );
174 if (m_nResolutionInDPI == 0)
176 // 212 DPI is 1754 x 2474 pixel for DIN A4
177 m_nResolutionInDPI = 212;
180 // ----------------------------------------
181 String sImportFilterName = (String)param.get(PropertyName.DOC_CONVERTER_IMPORT_FILTER_NAME);
182 if (sImportFilterName != null && sImportFilterName.length() > 0)
184 // System.out.println("found " + PropertyName.DOC_CONVERTER_IMPORT_FILTER_NAME + " " + sImportFilterName );
185 m_sImportFilterName = sImportFilterName;
187 if (sImportFilterName.toLowerCase().equals("help"))
189 showInternalFilterName(sImportFilterName, getMultiServiceFactory() );
190 GlobalLogWriter.get().println("Must quit.");
193 // ----------------------------------------
194 String sExportFilterName = (String)param.get(PropertyName.DOC_CONVERTER_EXPORT_FILTER_NAME);
195 if (sExportFilterName != null && sExportFilterName.length() > 0)
197 // System.out.println("found " + PropertyName.DOC_CONVERTER_EXPORT_FILTER_NAME + " " + sExportFilterName );
198 m_sExportFilterName = sExportFilterName;
199 if (sExportFilterName.toLowerCase().equals("help"))
201 showInternalFilterName(sExportFilterName, getMultiServiceFactory() );
202 GlobalLogWriter.get().println("Must quit.");
206 // ----------------------------------------
207 String sOfficeProgram = (String)param.get(PropertyName.DOC_CONVERTER_OFFICE_PROGRAM);
208 if (sOfficeProgram != null && sOfficeProgram.length() > 0)
210 m_sOfficeProgram = sOfficeProgram;
212 // ----------------------------------------
213 String sREUSE_OFFICE = (String)param.get( PropertyName.DOC_CONVERTER_REUSE_OFFICE);
214 if (sREUSE_OFFICE == null)
216 sREUSE_OFFICE = "false";
218 if (sREUSE_OFFICE.toLowerCase().equals("yes") ||
219 sREUSE_OFFICE.toLowerCase().equals("true"))
221 m_bResuseOffice = true;
223 else
225 m_bResuseOffice = false;
229 String sHTMLOutputPrefix = (String)param.get( PropertyName.DOC_COMPARATOR_HTML_OUTPUT_PREFIX);
230 if (sHTMLOutputPrefix == null)
232 m_sHTMLOutputPrefix = "";
234 else
236 m_sHTMLOutputPrefix = sHTMLOutputPrefix;
239 String sWithBorderMove = (String)param.get( PropertyName.DOC_COMPARATOR_GFXCMP_WITH_BORDERMOVE);
240 if (sWithBorderMove == null)
242 sWithBorderMove = "";
243 // m_tWithBorderMove = TriState.UNSET;
244 m_tWithBorderMove = TriState.FALSE;
246 if (sWithBorderMove.toLowerCase().equals("yes") ||
247 sWithBorderMove.toLowerCase().equals("true"))
249 m_tWithBorderMove = TriState.TRUE;
251 else if (sWithBorderMove.toLowerCase().equals("no") ||
252 sWithBorderMove.toLowerCase().equals("false"))
254 m_tWithBorderMove = TriState.FALSE;
256 else
258 m_tWithBorderMove = TriState.FALSE;
259 // m_tWithBorderMove = TriState.UNSET;
262 String sLeaveOutNames = (String)param.get(PropertyName.DOC_COMPARATOR_LEAVE_OUT_FILES);
263 if (sLeaveOutNames != null)
265 m_sLeaveOutNames = sLeaveOutNames;
268 String sDBInfoString = (String)param.get(PropertyName.DOC_COMPARATOR_DB_INFO_STRING);
269 if (sDBInfoString != null)
271 m_sDBInfoString = sDBInfoString;
274 // DISTINCT ----------
275 String sDistinct = (String)param.get( "DISTINCT" );
276 if (sDistinct == null || sDistinct.length() == 0)
278 sDistinct = "";
280 else
282 m_sDistinct = sDistinct;
284 // HIDDEN
285 String sOfficeViewable = (String)param.get(PropertyName.OFFICE_VIEWABLE);
286 if (sOfficeViewable != null)
288 if (sOfficeViewable.toLowerCase().equals("yes") ||
289 sOfficeViewable.toLowerCase().equals("true"))
291 setViewable();
293 else
295 setHidden();
298 // CREATE_DEFAULT
299 String sCreateDefault = (String)param.get(PropertyName.CREATE_DEFAULT);
300 if (sCreateDefault != null)
302 if (sCreateDefault.toLowerCase().equals("yes") ||
303 sCreateDefault.toLowerCase().equals("true"))
305 m_bCreateDefaultReference = true;
307 else
309 m_bCreateDefaultReference = false;
315 public boolean checkIfUsableDocumentType(String _sName)
317 // @todo
318 // check if the name is in the leave out list and then return 'false'
319 if (_sName.toLowerCase().endsWith(".jpg") ||
320 _sName.toLowerCase().endsWith(".png") ||
321 _sName.toLowerCase().endsWith(".gif") ||
322 _sName.toLowerCase().endsWith(".bmp") ||
323 _sName.toLowerCase().endsWith(".prn") ||
324 _sName.toLowerCase().endsWith(".ps"))
326 return false;
329 return true;
332 static void showInternalFilterName(String _sFilterName, XMultiServiceFactory _xMSF)
334 if (_sFilterName.length() == 0)
336 // System.out.println("No FilterName set.");
337 return;
340 if (_xMSF == null)
342 GlobalLogWriter.get().println("MultiServiceFactory not set.");
343 return;
345 // XFilterFactory aFilterFactory = null;
346 Object aObj = null;
349 aObj = _xMSF.createInstance("com.sun.star.document.FilterFactory");
351 catch(com.sun.star.uno.Exception e)
353 GlobalLogWriter.get().println("Can't get com.sun.star.document.FilterFactory.");
354 return;
356 if (aObj != null)
358 XNameAccess aNameAccess = (XNameAccess)UnoRuntime.queryInterface(XNameAccess.class, aObj);
359 if (aNameAccess != null)
362 if (_sFilterName.toLowerCase().equals("help"))
364 GlobalLogWriter.get().println("Show all possible ElementNames from current version." );
365 String[] aElementNames = aNameAccess.getElementNames();
366 for (int i = 0; i<aElementNames.length; i++)
368 GlobalLogWriter.get().println(aElementNames[i]);
376 public GraphicalTestArguments(TestParameters param, Log xxx)
378 // collect interesting information from the ComplexTestCase
379 // ....
383 // set methods
384 public void setReferenceType(String _sType)
386 // special casse, null is not allowed, set to default.
387 if (_sType == null)
389 m_sReferenceType = "OOo";
391 else
393 m_sReferenceType = _sType;
396 public void setTargetFrameName(String _sTargetFrameName) {m_sTargetFrameName = _sTargetFrameName;}
397 public void setPrinterName(String _sName) {m_sPrinterName = _sName;}
398 public void setHidden() { m_bHidden = true;}
399 public void setViewable() {m_bHidden = false;}
400 public void setDefaultXMLFormatApp(String _sNameOfApp) {m_sDefaultXMLFormatApplication = _sNameOfApp;}
402 // get methods
403 public XMultiServiceFactory getMultiServiceFactory()
405 XMultiServiceFactory xMSF = (XMultiServiceFactory)m_aCurrentParams.getMSF();
407 // check if MultiServiceFactory is given
408 if (getReferenceType().toLowerCase().equals("pdf") ||
409 getReferenceType().toLowerCase().equals("ooo"))
411 if (xMSF == null)
413 GlobalLogWriter.get().println("ERROR! MultiServiceFactory not given.");
416 return xMSF;
419 public String getReferenceType() {return m_sReferenceType;}
420 public String getTargetFrameName() {return m_sTargetFrameName;}
421 public String getPrinterName() {return m_sPrinterName;}
422 public boolean isHidden() {return m_bHidden;}
423 public String getDefaultXMLFormatApp() {return m_sDefaultXMLFormatApplication;}
427 * @return true, if subdirectories should run through
429 public boolean includeSubDirectories() {return m_bIncludeSubdirectories;}
432 * @return the number of pages to be print
434 public int getMaxPages() {return m_nMaxPages;}
437 * @return as string, which pages should be print, e.g. '1-4;6' here, page 1 to 4 and page 6.
439 public String getOnlyPages()
441 if (m_sOnlyPage == null)
443 return "";
445 return m_sOnlyPage;
449 * @return true, if there should not print all pages at all, use getMaxPages() and or getOnlyPages() to get which pages to print
451 public boolean printAllPages()
453 if ( (getMaxPages() > 0) ||
454 (getOnlyPages().length() != 0))
456 return false;
458 return true;
462 * @return integer value, which contain resolution in DPI.
464 public int getResolutionInDPI() {return m_nResolutionInDPI;}
466 public static void checkIfMSWindowsConformPath(String _sPath)
468 if (_sPath != null && _sPath.length() > 1)
470 if (_sPath.charAt(1) == ':')
472 if (_sPath.charAt(2) != '\\')
474 GlobalLogWriter.get().println("This is not a Microsoft Windows conform path: '" + _sPath + "' please fix.");
475 System.exit(1);
483 * @return the INPUT_PATH out of the TestParameters
485 public String getInputPath()
487 String sInputPath;
488 sInputPath = (String)m_aCurrentParams.get(PropertyName.DOC_COMPARATOR_INPUT_PATH);
489 checkIfMSWindowsConformPath(sInputPath);
490 return sInputPath;
493 * @return the OUTPUT_PATH out of the TestParameters
495 public String getOutputPath()
497 String sOutputPath;
498 sOutputPath = (String)m_aCurrentParams.get(PropertyName.DOC_COMPARATOR_OUTPUT_PATH);
499 checkIfMSWindowsConformPath(sOutputPath);
500 return sOutputPath;
503 * @return the REFERENCE_PATH out of the TestParameters
505 public String getReferencePath()
507 String sReferencePath;
508 sReferencePath = (String)m_aCurrentParams.get(PropertyName.DOC_COMPARATOR_REFERENCE_PATH);
509 checkIfMSWindowsConformPath(sReferencePath);
510 return sReferencePath;
513 * @return the DIFF_PATH out of the TestParameters
515 public String getDiffPath()
517 String sDiffPath;
518 sDiffPath = (String)m_aCurrentParams.get(PropertyName.DOC_COMPARATOR_DIFF_PATH);
519 checkIfMSWindowsConformPath(sDiffPath);
520 return sDiffPath;
523 public boolean getOverwrite()
525 boolean bOverwrite = m_aCurrentParams.getBool( PropertyName.DOC_COMPARATOR_OVERWRITE_REFERENCE);
526 return bOverwrite;
528 public String getReferenceInputPath()
530 String sReferenceInputPath;
531 sReferenceInputPath = (String)m_aCurrentParams.get(PropertyName.DOC_COMPARATOR_REFERENCE_INPUT_PATH);
532 return sReferenceInputPath;
536 * Helper function to get the buildid of the current used OpenOffice.org
537 * out of the AppExecutionCommand the build ID
539 public String getBuildID()
541 String sAPP = (String)m_aCurrentParams.get(util.PropertyName.APP_EXECUTION_COMMAND);
542 // return getBuildID(sAPP);
543 // TODO: here we need the getBuildID(string) method
544 String sBuildID = convwatch.BuildID.getBuildID(sAPP);
545 return sBuildID;
548 public boolean shouldOfficeStart()
550 String sNoOffice = (String)m_aCurrentParams.get( "NoOffice" );
551 if (sNoOffice != null)
553 if (sNoOffice.toLowerCase().startsWith("t") || sNoOffice.toLowerCase().startsWith("y"))
555 return false;
558 return true;
561 // Handle for Reference Build ID, is set in ConvWatch.createPostscriptStartCheck()
562 private String m_sRefBuildID;
564 public void setRefBuildID(String _sRef)
566 m_sRefBuildID = _sRef;
568 public String getRefBuildID()
570 return m_sRefBuildID;
573 public void disallowStore()
575 m_bStoreFile = false;
577 public void allowStore()
579 m_bStoreFile = true;
581 public boolean isStoreAllowed()
583 return m_bStoreFile;
585 public boolean createDefaultReference()
587 return m_bCreateDefaultReference;
591 // get/set for FilterName
592 // get the right Filtername (internal Name) from
593 // http://framework.openoffice.org/files/documents/25/897/filter_description.html
595 String m_sImportFilterName = "";
596 String m_sExportFilterName = "";
597 public void setImportFilterName(String _sImportFilterName)
599 m_sImportFilterName = _sImportFilterName;
601 public String getImportFilterName()
603 return m_sImportFilterName;
605 public void setExportFilterName(String _sExportFilterName)
607 m_sExportFilterName = _sExportFilterName;
609 public String getExportFilterName()
611 return m_sExportFilterName;
614 String m_sOfficeProgram = "";
615 public void setOfficeProgram(String _sName)
617 m_sOfficeProgram = _sName;
619 public String getOfficeProgram()
621 return m_sOfficeProgram;
624 public boolean restartOffice()
626 if (m_bResuseOffice == false)
628 return true;
630 return false;
633 String m_sHTMLOutputPrefix = "";
634 public String getHTMLOutputPrefix()
636 return m_sHTMLOutputPrefix;
639 TriState m_tWithBorderMove = TriState.UNSET;
640 // public TriState isBorderMove()
641 // {
642 // return m_tWithBorderMove;
643 // }
644 public TriState getBorderMove()
646 return m_tWithBorderMove;
648 public void setBorderMove(TriState _tBorderMove)
650 m_tWithBorderMove = _tBorderMove;
653 String m_sDocumentType = "";
654 public void setDocumentType(String _sName)
656 m_sDocumentType = _sName;
658 public String getDocumentType()
660 return m_sDocumentType;
664 helper class for performance analyser features
666 PerformanceContainer m_aPerformanceContainer = null;
667 public PerformanceContainer getPerformance()
669 if (m_aPerformanceContainer == null)
671 m_aPerformanceContainer = new PerformanceContainer();
673 return m_aPerformanceContainer;
676 private String m_aInputFile;
677 public void setInputFile(String _sInputFile)
679 m_aInputFile = _sInputFile;
681 public String getInputFile()
683 return m_aInputFile;
686 private String m_sDBInfoString;
687 public String getDBInfoString()
689 if (m_sDBInfoString != null)
691 if (m_sDBInfoString.length() == 0)
693 return null;
697 return m_sDBInfoString;
700 public boolean cancelRequest()
702 File aCancelFile = null;
703 String fs;
704 fs = System.getProperty("file.separator");
705 String sTempPath = (String)m_aCurrentParams.get( PropertyName.TEMPPATH );
706 if (sTempPath != null)
708 String sGDC_Dir = sTempPath;
710 if (m_sDistinct.length() > 0)
712 sGDC_Dir = sGDC_Dir + fs + m_sDistinct;
715 String sCancelFile = sGDC_Dir + fs + "cancel_compare.txt";
716 aCancelFile = new File(sCancelFile);
718 if (aCancelFile.exists())
720 GlobalLogWriter.get().println("ATTENTION: Found file: '" + sCancelFile + "'.");
721 GlobalLogWriter.get().println("User has canceled the program flow.");
722 return true;
725 return false;
732 public class MSGraphicalTestArguments extends GraphicalTestArguments
734 MSGraphicalTestArguments()
736 setReferenceType("msoffice");
740 public class OOoGraphicalTestArguments extends GraphicalTestArguments
742 OOoGraphicalTestArguments(XMultiServiceFactory _aFactory)
744 setMultiServiceFactory(_aFactory);