2 * ************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2008 by Sun Microsystems, Inc.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * $RCSfile: ParameterHelper.java,v $
11 * $Revision: 1.1.2.3 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 * ***********************************************************************
35 import com
.sun
.star
.lang
.XMultiServiceFactory
;
36 import lib
.TestParameters
;
39 * This class object is more a Helper or Controller.
40 * It stores information like:
41 * - How to create a document (with a OpenOffice.org method, or with MS Word, or with OpenOffice.org as pdf)
42 * - some more infos for OpenOffice.org method
43 * - a service factory pointer
44 * - if hidden mode should use
49 * - how to handle .xml files, which in Microsoft could be Excel or Word documents
53 * create an ParameterHelper with a set of TestParameters
54 * ParameterHelper a = new ParameterHelper(params);
56 * If you wish to use pdf export instead of normal printer output, set also the reference type to 'pdf'
57 * a.setReferenceType("pdf");
61 * create a ParameterHelper and set the reference type to 'msoffice'
62 * ParameterHelper a = new ParameterHelper(params);
63 * a.setReferenceType("msoffice");
65 * within windows it's better to set also a printer name so it's simply possible to use for normal work the default printer
66 * and for such tests with ConvWatch a extra printer.
67 * a.setPrinterName("CrossOffice Printer");
71 public class ParameterHelper
75 Possible reference types are currently
80 private String m_sReferenceType
= null;
82 // private String m_sTargetFrameName = "_blank";
84 private String m_sPrinterName
= null;
86 private int m_nResolutionInDPI
= 180;
88 private boolean m_bIncludeSubdirectories
;
90 private String m_sInputPath
= null;
91 private String m_sOutputPath
= null;
92 // private String m_sReferencePath = null;
94 private TestParameters m_aCurrentParams
;
96 // private GlobalLogWriter m_aLog;
99 private ParameterHelper(){}
101 public ParameterHelper(TestParameters param
)
103 m_aCurrentParams
= param
;
105 // interpretReferenceType();
106 // interpretPrinterName();
110 protected TestParameters
getTestParameters()
112 return m_aCurrentParams
;
116 * return the input path, if given.
119 public String
getInputPath()
121 if (m_sInputPath
== null)
123 String sInputPath
= (String
)getTestParameters().get( PropertyName
.DOC_COMPARATOR_INPUT_PATH
);
124 if (sInputPath
== null || sInputPath
.length() == 0)
126 GlobalLogWriter
.println("Please set input path (path to documents) " + PropertyName
.DOC_COMPARATOR_INPUT_PATH
+ "=path.");
130 m_sInputPath
= helper
.StringHelper
.removeQuoteIfExists(sInputPath
);
136 public String
getOutputPath()
138 if (m_sOutputPath
== null)
140 String sOutputPath
= (String
)getTestParameters().get( PropertyName
.DOC_COMPARATOR_OUTPUT_PATH
);
141 if (sOutputPath
== null || sOutputPath
.length() == 0)
143 GlobalLogWriter
.println("Please set output path (path where to store document results) " + PropertyName
.DOC_COMPARATOR_OUTPUT_PATH
+ "=path.");
147 m_sOutputPath
= helper
.StringHelper
.removeQuoteIfExists(sOutputPath
);
150 return m_sOutputPath
;
153 // public String getReferencePath()
155 // if (m_sReferencePath == null)
157 // String sReferencePath = (String)getTestParameters().get( PropertyName.DOC_COMPARATOR_REFERENCE_PATH );
158 // if (sReferencePath == null || sReferencePath.length() == 0)
160 // GlobalLogWriter.println("Please set reference path (path to reference documents) " + PropertyName.DOC_COMPARATOR_REFERENCE_PATH + "=path.");
164 // m_sReferencePath = sReferencePath;
167 // return m_sReferencePath;
171 public boolean isIncludeSubDirectories()
173 m_bIncludeSubdirectories
= true;
174 String sRECURSIVE
= (String
)getTestParameters().get( PropertyName
.DOC_COMPARATOR_INCLUDE_SUBDIRS
);
175 // TODO: I need to get the boolean value with get("name") because, if it is not given getBool() returns
176 // with a default of 'false' which is not very helpful if the default should be 'true'
177 // maybe a getBoolean("name", true) could be a better choise.
178 if (sRECURSIVE
== null)
182 if (sRECURSIVE
.toLowerCase().equals("no") ||
183 sRECURSIVE
.toLowerCase().equals("false"))
185 m_bIncludeSubdirectories
= false;
187 return m_bIncludeSubdirectories
;
190 public String
getReferenceType()
192 if (m_sReferenceType
== null)
194 // REFERENCE_TYPE ----------
196 String sReferenceType
= (String
)getTestParameters().get( PropertyName
.DOC_COMPARATOR_REFERENCE_TYPE
);
197 if (sReferenceType
== null || sReferenceType
.length() == 0)
199 m_sReferenceType
= "OOo";
203 // log.println("found REFERENCE_TYPE " + sReferenceType );
204 m_sReferenceType
= sReferenceType
;
207 return m_sReferenceType
;
210 public String
getPrinterName()
212 if (m_sPrinterName
== null)
214 // PRINTER_NAME ----------
216 String sPrinterName
= (String
)getTestParameters().get( PropertyName
.DOC_COMPARATOR_PRINTER_NAME
);
217 if (sPrinterName
== null || sPrinterName
.length() == 0)
223 // log.println("found PRINTER_NAME " + sPrinterName );
224 m_sPrinterName
= sPrinterName
;
227 return m_sPrinterName
;
230 PerformanceContainer m_aPerformanceContainer
= null;
232 * helper class for performance analyser features
235 public PerformanceContainer
getPerformance()
237 if (m_aPerformanceContainer
== null)
239 m_aPerformanceContainer
= new PerformanceContainer();
241 return m_aPerformanceContainer
;
245 * Helper function to get the buildid of the current used OpenOffice.org
246 * out of the AppExecutionCommand the build ID
248 public String
getBuildID()
250 String sAPP
= (String
)m_aCurrentParams
.get(util
.PropertyName
.APP_EXECUTION_COMMAND
);
251 // return getBuildID(sAPP);
252 // TODO: here we need the getBuildID(string) method
253 String sBuildID
= BuildID
.getBuildID(sAPP
);
258 * @return integer value, which contain resolution in DPI.
260 public int getResolutionInDPI()
262 return m_nResolutionInDPI
;
265 public XMultiServiceFactory
getMultiServiceFactory()
267 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)m_aCurrentParams
.getMSF();
269 // check if MultiServiceFactory is given
270 if (getReferenceType().toLowerCase().equals("pdf") ||
271 getReferenceType().toLowerCase().equals("ooo"))
275 GlobalLogWriter
.get().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
;