2 * ************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 * ***********************************************************************
32 import com
.sun
.star
.lang
.XMultiServiceFactory
;
33 import lib
.TestParameters
;
36 * This class object is more a Helper or Controller.
37 * It stores information like:
38 * - How to create a document (with a OpenOffice.org method, or with MS Word, or with OpenOffice.org as pdf)
39 * - some more infos for OpenOffice.org method
40 * - a service factory pointer
41 * - if hidden mode should use
46 * - how to handle .xml files, which in Microsoft could be Excel or Word documents
50 * create an ParameterHelper with a set of TestParameters
51 * ParameterHelper a = new ParameterHelper(params);
53 * If you wish to use pdf export instead of normal printer output, set also the reference type to 'pdf'
54 * a.setReferenceType("pdf");
58 * create a ParameterHelper and set the reference type to 'msoffice'
59 * ParameterHelper a = new ParameterHelper(params);
60 * a.setReferenceType("msoffice");
62 * within windows it's better to set also a printer name so it's simply possible to use for normal work the default printer
63 * and for such tests with ConvWatch a extra printer.
64 * a.setPrinterName("CrossOffice Printer");
68 public class ParameterHelper
72 Possible reference types are currently
77 private String m_sReferenceType
= null;
79 // private String m_sTargetFrameName = "_blank";
81 private String m_sPrinterName
= null;
83 private int m_nResolutionInDPI
= 180;
85 private boolean m_bIncludeSubdirectories
;
87 private String m_sInputPath
= null;
88 private String m_sOutputPath
= null;
89 // private String m_sReferencePath = null;
91 private TestParameters m_aCurrentParams
;
93 // private GlobalLogWriter m_aLog;
96 private ParameterHelper(){}
98 public ParameterHelper(TestParameters param
)
100 m_aCurrentParams
= param
;
102 // interpretReferenceType();
103 // interpretPrinterName();
107 protected TestParameters
getTestParameters()
109 return m_aCurrentParams
;
113 * return the input path, if given.
116 public String
getInputPath()
118 if (m_sInputPath
== null)
120 String sInputPath
= (String
)getTestParameters().get( PropertyName
.DOC_COMPARATOR_INPUT_PATH
);
121 if (sInputPath
== null || sInputPath
.length() == 0)
123 GlobalLogWriter
.println("Please set input path (path to documents) " + PropertyName
.DOC_COMPARATOR_INPUT_PATH
+ "=path.");
127 m_sInputPath
= helper
.StringHelper
.removeQuoteIfExists(sInputPath
);
133 public String
getOutputPath()
135 if (m_sOutputPath
== null)
137 String sOutputPath
= (String
)getTestParameters().get( PropertyName
.DOC_COMPARATOR_OUTPUT_PATH
);
138 if (sOutputPath
== null || sOutputPath
.length() == 0)
140 GlobalLogWriter
.println("Please set output path (path where to store document results) " + PropertyName
.DOC_COMPARATOR_OUTPUT_PATH
+ "=path.");
144 m_sOutputPath
= helper
.StringHelper
.removeQuoteIfExists(sOutputPath
);
147 return m_sOutputPath
;
150 // public String getReferencePath()
152 // if (m_sReferencePath == null)
154 // String sReferencePath = (String)getTestParameters().get( PropertyName.DOC_COMPARATOR_REFERENCE_PATH );
155 // if (sReferencePath == null || sReferencePath.length() == 0)
157 // GlobalLogWriter.println("Please set reference path (path to reference documents) " + PropertyName.DOC_COMPARATOR_REFERENCE_PATH + "=path.");
161 // m_sReferencePath = sReferencePath;
164 // return m_sReferencePath;
168 public boolean isIncludeSubDirectories()
170 m_bIncludeSubdirectories
= true;
171 String sRECURSIVE
= (String
)getTestParameters().get( PropertyName
.DOC_COMPARATOR_INCLUDE_SUBDIRS
);
172 // TODO: I need to get the boolean value with get("name") because, if it is not given getBool() returns
173 // with a default of 'false' which is not very helpful if the default should be 'true'
174 // maybe a getBoolean("name", true) could be a better choise.
175 if (sRECURSIVE
== null)
179 if (sRECURSIVE
.toLowerCase().equals("no") ||
180 sRECURSIVE
.toLowerCase().equals("false"))
182 m_bIncludeSubdirectories
= false;
184 return m_bIncludeSubdirectories
;
187 public String
getReferenceType()
189 if (m_sReferenceType
== null)
191 // REFERENCE_TYPE ----------
193 String sReferenceType
= (String
)getTestParameters().get( PropertyName
.DOC_COMPARATOR_REFERENCE_TYPE
);
194 if (sReferenceType
== null || sReferenceType
.length() == 0)
196 m_sReferenceType
= "ps";
200 // log.println("found REFERENCE_TYPE " + sReferenceType );
201 m_sReferenceType
= sReferenceType
;
204 return m_sReferenceType
;
207 public String
getPrinterName()
209 if (m_sPrinterName
== null)
211 // PRINTER_NAME ----------
213 String sPrinterName
= (String
)getTestParameters().get( PropertyName
.DOC_COMPARATOR_PRINTER_NAME
);
214 if (sPrinterName
== null || sPrinterName
.length() == 0)
220 // log.println("found PRINTER_NAME " + sPrinterName );
221 m_sPrinterName
= sPrinterName
;
224 return m_sPrinterName
;
227 PerformanceContainer m_aPerformanceContainer
= null;
229 * helper class for performance analyser features
232 public PerformanceContainer
getPerformance()
234 if (m_aPerformanceContainer
== null)
236 m_aPerformanceContainer
= new PerformanceContainer();
238 return m_aPerformanceContainer
;
242 * Helper function to get the buildid of the current used OpenOffice.org
243 * out of the AppExecutionCommand the build ID
246 public String
getBuildID()
248 String sAPP
= (String
)m_aCurrentParams
.get(util
.PropertyName
.APP_EXECUTION_COMMAND
);
249 // return getBuildID(sAPP);
250 // TODO: here we need the getBuildID(string) method
251 String sBuildID
= BuildID
.getBuildID(sAPP
);
256 * @return integer value, which contain resolution in DPI.
258 public int getResolutionInDPI()
260 return m_nResolutionInDPI
;
263 public XMultiServiceFactory
getMultiServiceFactory()
265 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)m_aCurrentParams
.getMSF();
267 // check if MultiServiceFactory is given
268 if (getReferenceType().toLowerCase().equals("pdf") ||
269 getReferenceType().toLowerCase().equals("ps") ||
270 getReferenceType().toLowerCase().equals("ooo") ||
271 getReferenceType().toLowerCase().equals("o3") )
275 GlobalLogWriter
.println("ERROR! MultiServiceFactory not given.");
281 // Hidden = true hiddes a used OpenOffice.org, all code is executed in the background
282 // This parameter is not used for RefType: msoffice
283 // boolean m_bHidden = true;
286 public boolean isHidden()
290 String sOfficeViewable
= (String
)m_aCurrentParams
.get(PropertyName
.OFFICE_VIEWABLE
);
291 if (sOfficeViewable
!= null)
293 if (sOfficeViewable
.toLowerCase().equals("yes") ||
294 sOfficeViewable
.toLowerCase().equals("true"))
296 return false; // setViewable();
300 return true; // setHidden();
303 return true; /* default: hidden */
306 // get/set for FilterName
307 // get the right Filtername (internal Name) from
308 // http://framework.openoffice.org/files/documents/25/897/filter_description.html
310 String m_sImportFilterName
= "";
311 String m_sExportFilterName
= "";
312 public void setImportFilterName(String _sImportFilterName
)
314 m_sImportFilterName
= _sImportFilterName
;
316 public String
getImportFilterName()
318 return m_sImportFilterName
;
320 public void setExportFilterName(String _sExportFilterName
)
322 m_sExportFilterName
= _sExportFilterName
;
324 public String
getExportFilterName()
326 return m_sExportFilterName
;
328 String m_sDocumentType
= "";
329 public void setDocumentType(String _sName
)
331 m_sDocumentType
= _sName
;
333 public String
getDocumentType()
335 return m_sDocumentType
;
339 // String m_sDefaultXMLFormatApplication = null;
340 // public String getDefaultXMLFormatApp()
342 // if (m_sDefaultXMLFormatApplication == null)
344 // // DEFAULT_XML_FORMAT_APP ------
346 // String sDefaultXMLFormatApp = (String)m_aCurrentParams.get( PropertyName.DOC_COMPARATOR_DEFAULT_XML_FORMAT_APP );
347 // if (sDefaultXMLFormatApp == null || sDefaultXMLFormatApp.length() == 0)
349 // m_sDefaultXMLFormatApplication = "word";
353 // m_sDefaultXMLFormatApplication = sDefaultXMLFormatApp;
356 // return m_sDefaultXMLFormatApplication;
360 // Pages -------------------------------------------------------------------
363 * @return the number of pages to be print
365 public int getMaxPages()
367 // default is 0 (print all pages)
368 int nMaxPages
= m_aCurrentParams
.getInt( PropertyName
.DOC_COMPARATOR_PRINT_MAX_PAGE
);
373 * @return as string, which pages should be print, e.g. '1-4;6' here, page 1 to 4 and page 6.
375 public String
getOnlyPages()
377 // default is null, there is no page which we want to print only.
378 String sOnlyPage
= (String
)m_aCurrentParams
.get(PropertyName
.DOC_COMPARATOR_PRINT_ONLY_PAGE
);
379 if (sOnlyPage
== null)
387 * @return true, if there should not print all pages at all, use getMaxPages() and or getOnlyPages() to get which pages to print
389 public boolean printAllPages()
391 if ( (getMaxPages() > 0) ||
392 (getOnlyPages().length() != 0))
399 public boolean getOverwrite()
401 boolean bOverwrite
= m_aCurrentParams
.getBool( PropertyName
.DOC_COMPARATOR_OVERWRITE_REFERENCE
);
405 private String m_sHTMLPrefix
= null;
406 public String
getHTMLPrefix()
408 if (m_sHTMLPrefix
== null)
410 String sPrefix
= (String
)getTestParameters().get( PropertyName
.DOC_COMPARATOR_HTML_OUTPUT_PREFIX
);
411 if (sPrefix
== null || sPrefix
.length() == 0)
413 GlobalLogWriter
.println("Please set html prefix " + PropertyName
.DOC_COMPARATOR_HTML_OUTPUT_PREFIX
+ "=prefix.");
417 m_sHTMLPrefix
= sPrefix
;
420 return m_sHTMLPrefix
;
423 public boolean createSmallPictures()
425 // boolean bCreateSmallPictures = true;
426 boolean bNoSmallPictures
= m_aCurrentParams
.getBool( PropertyName
.NO_SMALL_PICTURES
);
427 if (bNoSmallPictures
== true)