2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import com
.sun
.star
.lang
.XMultiServiceFactory
;
22 import lib
.TestParameters
;
25 import com
.sun
.star
.container
.XNameAccess
;
26 import com
.sun
.star
.uno
.UnoRuntime
;
29 * This class object is more a Helper or Controller.
30 * It stores information like:
31 * - How to create a document (with a OpenOffice.org method, or with MS Word, or with OpenOffice.org as pdf)
32 * - some more infos for OpenOffice.org method
33 * - a service factory pointer
34 * - if hidden mode should use
39 * - how to handle .xml files, which in Microsoft could be Excel or Word documents
43 * create an GraphicalTestArguments with a set of TestParameters
44 * GraphicalTestArguments a = new GraphicalTestArguments(params);
46 * If you wish to use pdf export instead of normal printer output, set also the reference type to 'pdf'
47 * a.setReferenceType("pdf");
51 * create an GraphicalTestArguments and set the reference type to 'msoffice'
52 * GraphicalTestArguments a = new GraphicalTestArguments(params);
53 * a.setReferenceType("msoffice");
55 * within windows it's better to set also a printer name so it's simply possible to use for normal work the default printer
56 * and for such tests with ConvWatch a extra printer.
57 * a.setPrinterName("CrossOffice Printer");
61 public class GraphicalTestArguments
65 Possible reference types are currently
70 String m_sReferenceType
= "OOo";
72 String m_sTargetFrameName
= "_blank";
74 String m_sPrinterName
= null;
76 // Hidden = true hiddes a used OpenOffice.org, all code is executed in the background
77 // This parameter is not used for RefType: msoffice
78 boolean m_bHidden
= true;
80 String m_sDefaultXMLFormatApplication
= null;
82 boolean m_bIncludeSubdirectories
;
84 TestParameters m_aCurrentParams
;
86 int m_nMaxPages
= 0; // default is 0 (print all pages)
87 String m_sOnlyPage
= ""; // default is "", there is no page which we want to print only.
89 int m_nResolutionInDPI
= 0;
91 boolean m_bStoreFile
= true;
92 boolean m_bResuseOffice
= false;
94 boolean m_bDebugMode
= false;
96 String m_sLeaveOutNames
= null;
98 String m_sDistinct
= null;
100 boolean m_bCreateDefaultReference
= false;
102 public GraphicalTestArguments(TestParameters param
)
104 m_aCurrentParams
= param
;
105 // collect interesting information from the ComplexTestCase
108 // REFERENCE_TYPE ----------
109 String sReferenceType
= (String
)param
.get( PropertyName
.DOC_COMPARATOR_REFERENCE_TYPE
);
110 if (sReferenceType
== null || sReferenceType
.length() == 0)
115 // log.println("found REFERENCE_TYPE " + sReferenceType );
116 setReferenceType(sReferenceType
);
119 // PRINTER_NAME ----------
120 String sPrinterName
= (String
)param
.get( PropertyName
.DOC_COMPARATOR_PRINTER_NAME
);
121 if (sPrinterName
== null || sPrinterName
.length() == 0)
126 // log.println("found PRINTER_NAME " + sPrinterName );
127 setPrinterName(sPrinterName
);
129 // DEFAULT_XML_FORMAT_APP ------
130 String sDefaultXMLFormatApp
= (String
)param
.get( PropertyName
.DOC_COMPARATOR_DEFAULT_XML_FORMAT_APP
);
131 if (sDefaultXMLFormatApp
== null || sDefaultXMLFormatApp
.length() == 0)
136 setDefaultXMLFormatApp(sDefaultXMLFormatApp
);
139 m_bIncludeSubdirectories
= true;
140 String sRECURSIVE
= (String
)param
.get( PropertyName
.DOC_COMPARATOR_INCLUDE_SUBDIRS
);
141 // TODO: I need to get the boolean value with get("name") because, if it is not given getBool() returns
142 // with a default of 'false' which is not very helpful if the default should be 'true'
143 // maybe a getBoolean("name", true) could be a better choise.
144 if (sRECURSIVE
== null)
148 if (sRECURSIVE
.toLowerCase().equals("no") ||
149 sRECURSIVE
.toLowerCase().equals("false"))
151 m_bIncludeSubdirectories
= false;
154 // ----------------------------------------
155 m_nMaxPages
= param
.getInt( PropertyName
.DOC_COMPARATOR_PRINT_MAX_PAGE
);
156 m_sOnlyPage
= (String
)param
.get(PropertyName
.DOC_COMPARATOR_PRINT_ONLY_PAGE
);
158 m_nResolutionInDPI
= param
.getInt( PropertyName
.DOC_COMPARATOR_GFX_OUTPUT_DPI_RESOLUTION
);
159 if (m_nResolutionInDPI
== 0)
161 // 212 DPI is 1754 x 2474 pixel for DIN A4
162 m_nResolutionInDPI
= 212;
165 // ----------------------------------------
166 String sImportFilterName
= (String
)param
.get(PropertyName
.DOC_CONVERTER_IMPORT_FILTER_NAME
);
167 if (sImportFilterName
!= null && sImportFilterName
.length() > 0)
169 // System.out.println("found " + PropertyName.DOC_CONVERTER_IMPORT_FILTER_NAME + " " + sImportFilterName );
170 m_sImportFilterName
= sImportFilterName
;
172 if (sImportFilterName
.toLowerCase().equals("help"))
174 showInternalFilterName(sImportFilterName
, getMultiServiceFactory() );
175 GlobalLogWriter
.get().println("Must quit.");
178 // ----------------------------------------
179 String sExportFilterName
= (String
)param
.get(PropertyName
.DOC_CONVERTER_EXPORT_FILTER_NAME
);
180 if (sExportFilterName
!= null && sExportFilterName
.length() > 0)
182 // System.out.println("found " + PropertyName.DOC_CONVERTER_EXPORT_FILTER_NAME + " " + sExportFilterName );
183 m_sExportFilterName
= sExportFilterName
;
184 if (sExportFilterName
.toLowerCase().equals("help"))
186 showInternalFilterName(sExportFilterName
, getMultiServiceFactory() );
187 GlobalLogWriter
.get().println("Must quit.");
191 // ----------------------------------------
192 String sOfficeProgram
= (String
)param
.get(PropertyName
.DOC_CONVERTER_OFFICE_PROGRAM
);
193 if (sOfficeProgram
!= null && sOfficeProgram
.length() > 0)
195 m_sOfficeProgram
= sOfficeProgram
;
197 // ----------------------------------------
198 String sREUSE_OFFICE
= (String
)param
.get( PropertyName
.DOC_CONVERTER_REUSE_OFFICE
);
199 if (sREUSE_OFFICE
== null)
201 sREUSE_OFFICE
= "false";
203 if (sREUSE_OFFICE
.toLowerCase().equals("yes") ||
204 sREUSE_OFFICE
.toLowerCase().equals("true"))
206 m_bResuseOffice
= true;
210 m_bResuseOffice
= false;
214 String sHTMLOutputPrefix
= (String
)param
.get( PropertyName
.DOC_COMPARATOR_HTML_OUTPUT_PREFIX
);
215 if (sHTMLOutputPrefix
== null)
217 m_sHTMLOutputPrefix
= "";
221 m_sHTMLOutputPrefix
= sHTMLOutputPrefix
;
224 String sWithBorderMove
= (String
)param
.get( PropertyName
.DOC_COMPARATOR_GFXCMP_WITH_BORDERMOVE
);
225 if (sWithBorderMove
== null)
227 sWithBorderMove
= "";
228 // m_tWithBorderMove = TriState.UNSET;
229 m_tWithBorderMove
= TriState
.FALSE
;
231 if (sWithBorderMove
.toLowerCase().equals("yes") ||
232 sWithBorderMove
.toLowerCase().equals("true"))
234 m_tWithBorderMove
= TriState
.TRUE
;
236 else if (sWithBorderMove
.toLowerCase().equals("no") ||
237 sWithBorderMove
.toLowerCase().equals("false"))
239 m_tWithBorderMove
= TriState
.FALSE
;
243 m_tWithBorderMove
= TriState
.FALSE
;
244 // m_tWithBorderMove = TriState.UNSET;
247 String sLeaveOutNames
= (String
)param
.get(PropertyName
.DOC_COMPARATOR_LEAVE_OUT_FILES
);
248 if (sLeaveOutNames
!= null)
250 m_sLeaveOutNames
= sLeaveOutNames
;
253 String sDBInfoString
= (String
)param
.get(PropertyName
.DOC_COMPARATOR_DB_INFO_STRING
);
254 if (sDBInfoString
!= null)
256 m_sDBInfoString
= sDBInfoString
;
259 // DISTINCT ----------
260 String sDistinct
= (String
)param
.get( "DISTINCT" );
261 if (sDistinct
== null || sDistinct
.length() == 0)
267 m_sDistinct
= sDistinct
;
270 String sOfficeViewable
= (String
)param
.get(PropertyName
.OFFICE_VIEWABLE
);
271 if (sOfficeViewable
!= null)
273 if (sOfficeViewable
.toLowerCase().equals("yes") ||
274 sOfficeViewable
.toLowerCase().equals("true"))
284 String sCreateDefault
= (String
)param
.get(PropertyName
.CREATE_DEFAULT
);
285 if (sCreateDefault
!= null)
287 if (sCreateDefault
.toLowerCase().equals("yes") ||
288 sCreateDefault
.toLowerCase().equals("true"))
290 m_bCreateDefaultReference
= true;
294 m_bCreateDefaultReference
= false;
300 public boolean checkIfUsableDocumentType(String _sName
)
303 // check if the name is in the leave out list and then return 'false'
304 if (_sName
.toLowerCase().endsWith(".jpg") ||
305 _sName
.toLowerCase().endsWith(".png") ||
306 _sName
.toLowerCase().endsWith(".gif") ||
307 _sName
.toLowerCase().endsWith(".bmp") ||
308 _sName
.toLowerCase().endsWith(".prn") ||
309 _sName
.toLowerCase().endsWith(".ps"))
317 static void showInternalFilterName(String _sFilterName
, XMultiServiceFactory _xMSF
)
319 if (_sFilterName
.length() == 0)
321 // System.out.println("No FilterName set.");
327 GlobalLogWriter
.get().println("MultiServiceFactory not set.");
330 // XFilterFactory aFilterFactory = null;
334 aObj
= _xMSF
.createInstance("com.sun.star.document.FilterFactory");
336 catch(com
.sun
.star
.uno
.Exception e
)
338 GlobalLogWriter
.get().println("Can't get com.sun.star.document.FilterFactory.");
343 XNameAccess aNameAccess
= UnoRuntime
.queryInterface(XNameAccess
.class, aObj
);
344 if (aNameAccess
!= null)
347 if (_sFilterName
.toLowerCase().equals("help"))
349 GlobalLogWriter
.get().println("Show all possible ElementNames from current version." );
350 String
[] aElementNames
= aNameAccess
.getElementNames();
351 for (int i
= 0; i
<aElementNames
.length
; i
++)
353 GlobalLogWriter
.get().println(aElementNames
[i
]);
361 public GraphicalTestArguments(TestParameters param, Log xxx)
363 // collect interesting information from the ComplexTestCase
369 public void setReferenceType(String _sType
)
371 // special casse, null is not allowed, set to default.
374 m_sReferenceType
= "OOo";
378 m_sReferenceType
= _sType
;
381 public void setTargetFrameName(String _sTargetFrameName
) {m_sTargetFrameName
= _sTargetFrameName
;}
382 public void setPrinterName(String _sName
) {m_sPrinterName
= _sName
;}
383 public void setHidden() { m_bHidden
= true;}
384 public void setViewable() {m_bHidden
= false;}
385 public void setDefaultXMLFormatApp(String _sNameOfApp
) {m_sDefaultXMLFormatApplication
= _sNameOfApp
;}
388 public XMultiServiceFactory
getMultiServiceFactory()
390 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)m_aCurrentParams
.getMSF();
392 // check if MultiServiceFactory is given
393 if (getReferenceType().toLowerCase().equals("pdf") ||
394 getReferenceType().toLowerCase().equals("ooo"))
398 GlobalLogWriter
.get().println("ERROR! MultiServiceFactory not given.");
404 public String
getReferenceType() {return m_sReferenceType
;}
405 public String
getTargetFrameName() {return m_sTargetFrameName
;}
406 public String
getPrinterName() {return m_sPrinterName
;}
407 public boolean isHidden() {return m_bHidden
;}
408 public String
getDefaultXMLFormatApp() {return m_sDefaultXMLFormatApplication
;}
412 * @return true, if subdirectories should run through
414 public boolean includeSubDirectories() {return m_bIncludeSubdirectories
;}
417 * @return the number of pages to be print
419 public int getMaxPages() {return m_nMaxPages
;}
422 * @return as string, which pages should be print, e.g. '1-4;6' here, page 1 to 4 and page 6.
424 public String
getOnlyPages()
426 if (m_sOnlyPage
== null)
434 * @return true, if there should not print all pages at all, use getMaxPages() and or getOnlyPages() to get which pages to print
436 public boolean printAllPages()
438 if ( (getMaxPages() > 0) ||
439 (getOnlyPages().length() != 0))
447 * @return integer value, which contain resolution in DPI.
449 public int getResolutionInDPI() {return m_nResolutionInDPI
;}
451 public static void checkIfMSWindowsConformPath(String _sPath
)
453 if (_sPath
!= null && _sPath
.length() > 1)
455 if (_sPath
.charAt(1) == ':')
457 if (_sPath
.charAt(2) != '\\')
459 GlobalLogWriter
.get().println("This is not a Microsoft Windows conform path: '" + _sPath
+ "' please fix.");
468 * @return the INPUT_PATH out of the TestParameters
470 public String
getInputPath()
473 sInputPath
= (String
)m_aCurrentParams
.get(PropertyName
.DOC_COMPARATOR_INPUT_PATH
);
474 checkIfMSWindowsConformPath(sInputPath
);
478 * @return the OUTPUT_PATH out of the TestParameters
480 public String
getOutputPath()
483 sOutputPath
= (String
)m_aCurrentParams
.get(PropertyName
.DOC_COMPARATOR_OUTPUT_PATH
);
484 checkIfMSWindowsConformPath(sOutputPath
);
488 * @return the REFERENCE_PATH out of the TestParameters
490 public String
getReferencePath()
492 String sReferencePath
;
493 sReferencePath
= (String
)m_aCurrentParams
.get(PropertyName
.DOC_COMPARATOR_REFERENCE_PATH
);
494 checkIfMSWindowsConformPath(sReferencePath
);
495 return sReferencePath
;
498 * @return the DIFF_PATH out of the TestParameters
500 public String
getDiffPath()
503 sDiffPath
= (String
)m_aCurrentParams
.get(PropertyName
.DOC_COMPARATOR_DIFF_PATH
);
504 checkIfMSWindowsConformPath(sDiffPath
);
508 public boolean getOverwrite()
510 boolean bOverwrite
= m_aCurrentParams
.getBool( PropertyName
.DOC_COMPARATOR_OVERWRITE_REFERENCE
);
513 public String
getReferenceInputPath()
515 String sReferenceInputPath
;
516 sReferenceInputPath
= (String
)m_aCurrentParams
.get(PropertyName
.DOC_COMPARATOR_REFERENCE_INPUT_PATH
);
517 return sReferenceInputPath
;
521 * Helper function to get the buildid of the current used OpenOffice.org
522 * out of the AppExecutionCommand the build ID
524 public String
getBuildID()
526 String sAPP
= (String
)m_aCurrentParams
.get(util
.PropertyName
.APP_EXECUTION_COMMAND
);
527 // return getBuildID(sAPP);
528 // TODO: here we need the getBuildID(string) method
529 String sBuildID
= convwatch
.BuildID
.getBuildID(sAPP
);
533 public boolean shouldOfficeStart()
535 String sNoOffice
= (String
)m_aCurrentParams
.get( "NoOffice" );
536 if (sNoOffice
!= null)
538 if (sNoOffice
.toLowerCase().startsWith("t") || sNoOffice
.toLowerCase().startsWith("y"))
546 // Handle for Reference Build ID, is set in ConvWatch.createPostscriptStartCheck()
547 private String m_sRefBuildID
;
549 public void setRefBuildID(String _sRef
)
551 m_sRefBuildID
= _sRef
;
553 public String
getRefBuildID()
555 return m_sRefBuildID
;
558 public void disallowStore()
560 m_bStoreFile
= false;
562 public void allowStore()
566 public boolean isStoreAllowed()
570 public boolean createDefaultReference()
572 return m_bCreateDefaultReference
;
576 // get/set for FilterName
577 // get the right Filtername (internal Name) from
578 // http://framework.openoffice.org/files/documents/25/897/filter_description.html
580 String m_sImportFilterName
= "";
581 String m_sExportFilterName
= "";
582 public void setImportFilterName(String _sImportFilterName
)
584 m_sImportFilterName
= _sImportFilterName
;
586 public String
getImportFilterName()
588 return m_sImportFilterName
;
590 public void setExportFilterName(String _sExportFilterName
)
592 m_sExportFilterName
= _sExportFilterName
;
594 public String
getExportFilterName()
596 return m_sExportFilterName
;
599 String m_sOfficeProgram
= "";
600 public void setOfficeProgram(String _sName
)
602 m_sOfficeProgram
= _sName
;
604 public String
getOfficeProgram()
606 return m_sOfficeProgram
;
609 public boolean restartOffice()
611 if (m_bResuseOffice
== false)
618 String m_sHTMLOutputPrefix
= "";
619 public String
getHTMLOutputPrefix()
621 return m_sHTMLOutputPrefix
;
624 TriState m_tWithBorderMove
= TriState
.UNSET
;
625 // public TriState isBorderMove()
627 // return m_tWithBorderMove;
629 public TriState
getBorderMove()
631 return m_tWithBorderMove
;
633 public void setBorderMove(TriState _tBorderMove
)
635 m_tWithBorderMove
= _tBorderMove
;
638 String m_sDocumentType
= "";
639 public void setDocumentType(String _sName
)
641 m_sDocumentType
= _sName
;
643 public String
getDocumentType()
645 return m_sDocumentType
;
649 helper class for performance analyser features
651 PerformanceContainer m_aPerformanceContainer
= null;
652 public PerformanceContainer
getPerformance()
654 if (m_aPerformanceContainer
== null)
656 m_aPerformanceContainer
= new PerformanceContainer();
658 return m_aPerformanceContainer
;
661 private String m_aInputFile
;
662 public void setInputFile(String _sInputFile
)
664 m_aInputFile
= _sInputFile
;
666 public String
getInputFile()
671 private String m_sDBInfoString
;
672 public String
getDBInfoString()
674 if (m_sDBInfoString
!= null)
676 if (m_sDBInfoString
.length() == 0)
682 return m_sDBInfoString
;
685 public boolean cancelRequest()
687 File aCancelFile
= null;
689 fs
= System
.getProperty("file.separator");
690 String sTempPath
= (String
)m_aCurrentParams
.get( PropertyName
.TEMPPATH
);
691 if (sTempPath
!= null)
693 String sGDC_Dir
= sTempPath
;
695 if (m_sDistinct
.length() > 0)
697 sGDC_Dir
= sGDC_Dir
+ fs
+ m_sDistinct
;
700 String sCancelFile
= sGDC_Dir
+ fs
+ "cancel_compare.txt";
701 aCancelFile
= new File(sCancelFile
);
703 if (aCancelFile
.exists())
705 GlobalLogWriter
.get().println("ATTENTION: Found file: '" + sCancelFile
+ "'.");
706 GlobalLogWriter
.get().println("User has canceled the program flow.");
717 public class MSGraphicalTestArguments extends GraphicalTestArguments
719 MSGraphicalTestArguments()
721 setReferenceType("msoffice");
725 public class OOoGraphicalTestArguments extends GraphicalTestArguments
727 OOoGraphicalTestArguments(XMultiServiceFactory _aFactory)
729 setMultiServiceFactory(_aFactory);