1 /* 2 * ************************************************************************ 3 * 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * Copyright 2000, 2010 Oracle and/or its affiliates. 7 * 8 * OpenOffice.org - a multi-platform office productivity suite 9 * 10 * This file is part of OpenOffice.org. 11 * 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. 15 * 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). 21 * 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. 26 * 27 * *********************************************************************** 28 */ 29 30 package graphical; 31 32 import com.sun.star.lang.XMultiServiceFactory; 33 import lib.TestParameters; 34 35 /** 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 42 * - target name 43 * 44 * - printer name 45 * 46 * - how to handle .xml files, which in Microsoft could be Excel or Word documents 47 * 48 * HOWTO USE: 49 * For OOo, 50 * create an ParameterHelper with a set of TestParameters 51 * ParameterHelper a = new ParameterHelper(params); 52 * 53 * If you wish to use pdf export instead of normal printer output, set also the reference type to 'pdf' 54 * a.setReferenceType("pdf"); 55 * 56 * 57 * For MS Office: 58 * create a ParameterHelper and set the reference type to 'msoffice' 59 * ParameterHelper a = new ParameterHelper(params); 60 * a.setReferenceType("msoffice"); 61 * 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"); 65 * 66 */ 67 68 public class ParameterHelper 69 { 70 /* 71 TODO: 72 Possible reference types are currently 73 // ooo 74 // pdf 75 // msoffice 76 */ 77 private String m_sReferenceType = null; 78 79 // private String m_sTargetFrameName = "_blank"; 80 81 private String m_sPrinterName = null; 82 83 private int m_nResolutionInDPI = 180; 84 85 private boolean m_bIncludeSubdirectories; 86 87 private String m_sInputPath = null; 88 private String m_sOutputPath = null; 89 // private String m_sReferencePath = null; 90 91 private TestParameters m_aCurrentParams; 92 93 // private GlobalLogWriter m_aLog; 94 95 // CONSTRUCTOR 96 private ParameterHelper(){} 97 98 public ParameterHelper(TestParameters param) 99 { 100 m_aCurrentParams = param; 101 // m_aLog = log; 102 // interpretReferenceType(); 103 // interpretPrinterName(); 104 } 105 106 107 protected TestParameters getTestParameters() 108 { 109 return m_aCurrentParams; 110 } 111 112 /** 113 * return the input path, if given. 114 * @return 115 */ 116 public String getInputPath() 117 { 118 if (m_sInputPath == null) 119 { 120 String sInputPath = (String)getTestParameters().get( PropertyName.DOC_COMPARATOR_INPUT_PATH ); 121 if (sInputPath == null || sInputPath.length() == 0) 122 { 123 GlobalLogWriter.println("Please set input path (path to documents) " + PropertyName.DOC_COMPARATOR_INPUT_PATH + "=path."); 124 } 125 else 126 { 127 m_sInputPath = helper.StringHelper.removeQuoteIfExists(sInputPath); 128 } 129 } 130 return m_sInputPath; 131 } 132 133 public String getOutputPath() 134 { 135 if (m_sOutputPath == null) 136 { 137 String sOutputPath = (String)getTestParameters().get( PropertyName.DOC_COMPARATOR_OUTPUT_PATH ); 138 if (sOutputPath == null || sOutputPath.length() == 0) 139 { 140 GlobalLogWriter.println("Please set output path (path where to store document results) " + PropertyName.DOC_COMPARATOR_OUTPUT_PATH + "=path."); 141 } 142 else 143 { 144 m_sOutputPath = helper.StringHelper.removeQuoteIfExists(sOutputPath); 145 } 146 } 147 return m_sOutputPath; 148 } 149 150 // public String getReferencePath() 151 // { 152 // if (m_sReferencePath == null) 153 // { 154 // String sReferencePath = (String)getTestParameters().get( PropertyName.DOC_COMPARATOR_REFERENCE_PATH ); 155 // if (sReferencePath == null || sReferencePath.length() == 0) 156 // { 157 // GlobalLogWriter.println("Please set reference path (path to reference documents) " + PropertyName.DOC_COMPARATOR_REFERENCE_PATH + "=path."); 158 // } 159 // else 160 // { 161 // m_sReferencePath = sReferencePath; 162 // } 163 // } 164 // return m_sReferencePath; 165 // } 166 167 168 public boolean isIncludeSubDirectories() 169 { 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) 176 { 177 sRECURSIVE = "true"; 178 } 179 if (sRECURSIVE.toLowerCase().equals("no") || 180 sRECURSIVE.toLowerCase().equals("false")) 181 { 182 m_bIncludeSubdirectories = false; 183 } 184 return m_bIncludeSubdirectories; 185 } 186 187 public String getReferenceType() 188 { 189 if (m_sReferenceType == null) 190 { 191 // REFERENCE_TYPE ---------- 192 193 String sReferenceType = (String)getTestParameters().get( PropertyName.DOC_COMPARATOR_REFERENCE_TYPE ); 194 if (sReferenceType == null || sReferenceType.length() == 0) 195 { 196 m_sReferenceType = "ps"; 197 } 198 else 199 { 200 // log.println("found REFERENCE_TYPE " + sReferenceType ); 201 m_sReferenceType = sReferenceType; 202 } 203 } 204 return m_sReferenceType; 205 } 206 207 public String getPrinterName() 208 { 209 if (m_sPrinterName == null) 210 { 211 // PRINTER_NAME ---------- 212 213 String sPrinterName = (String)getTestParameters().get( PropertyName.DOC_COMPARATOR_PRINTER_NAME ); 214 if (sPrinterName == null || sPrinterName.length() == 0) 215 { 216 m_sPrinterName = ""; 217 } 218 else 219 { 220 // log.println("found PRINTER_NAME " + sPrinterName ); 221 m_sPrinterName = sPrinterName; 222 } 223 } 224 return m_sPrinterName; 225 } 226 227 PerformanceContainer m_aPerformanceContainer = null; 228 /** 229 * helper class for performance analyser features 230 * @return 231 */ 232 public PerformanceContainer getPerformance() 233 { 234 if (m_aPerformanceContainer == null) 235 { 236 m_aPerformanceContainer = new PerformanceContainer(); 237 } 238 return m_aPerformanceContainer; 239 } 240 241 /** 242 * Helper function to get the buildid of the current used OpenOffice.org 243 * out of the AppExecutionCommand the build ID 244 * @return 245 */ 246 public String getBuildID() 247 { 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); 252 return sBuildID; 253 } 254 255 /** 256 * @return integer value, which contain resolution in DPI. 257 */ 258 public int getResolutionInDPI() 259 { 260 return m_nResolutionInDPI; 261 } 262 // get methods 263 public XMultiServiceFactory getMultiServiceFactory() 264 { 265 XMultiServiceFactory xMSF = (XMultiServiceFactory)m_aCurrentParams.getMSF(); 266 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") ) 272 { 273 if (xMSF == null) 274 { 275 GlobalLogWriter.println("ERROR! MultiServiceFactory not given."); 276 } 277 } 278 return xMSF; 279 } 280 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; 284 285 286 public boolean isHidden() 287 { 288 // HIDDEN 289 290 String sOfficeViewable = (String)m_aCurrentParams.get(PropertyName.OFFICE_VIEWABLE); 291 if (sOfficeViewable != null) 292 { 293 if (sOfficeViewable.toLowerCase().equals("yes") || 294 sOfficeViewable.toLowerCase().equals("true")) 295 { 296 return false; // setViewable(); 297 } 298 else 299 { 300 return true; // setHidden(); 301 } 302 } 303 return true; /* default: hidden */ 304 } 305 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 309 310 String m_sImportFilterName = ""; 311 String m_sExportFilterName = ""; 312 public void setImportFilterName(String _sImportFilterName) 313 { 314 m_sImportFilterName = _sImportFilterName; 315 } 316 public String getImportFilterName() 317 { 318 return m_sImportFilterName; 319 } 320 public void setExportFilterName(String _sExportFilterName) 321 { 322 m_sExportFilterName = _sExportFilterName; 323 } 324 public String getExportFilterName() 325 { 326 return m_sExportFilterName; 327 } 328 String m_sDocumentType = ""; 329 public void setDocumentType(String _sName) 330 { 331 m_sDocumentType = _sName; 332 } 333 public String getDocumentType() 334 { 335 return m_sDocumentType; 336 } 337 338 339 // String m_sDefaultXMLFormatApplication = null; 340 // public String getDefaultXMLFormatApp() 341 // { 342 // if (m_sDefaultXMLFormatApplication == null) 343 // { 344 // // DEFAULT_XML_FORMAT_APP ------ 345 // 346 // String sDefaultXMLFormatApp = (String)m_aCurrentParams.get( PropertyName.DOC_COMPARATOR_DEFAULT_XML_FORMAT_APP ); 347 // if (sDefaultXMLFormatApp == null || sDefaultXMLFormatApp.length() == 0) 348 // { 349 // m_sDefaultXMLFormatApplication = "word"; 350 // } 351 // else 352 // { 353 // m_sDefaultXMLFormatApplication = sDefaultXMLFormatApp; 354 // } 355 // } 356 // return m_sDefaultXMLFormatApplication; 357 // } 358 359 360 // Pages ------------------------------------------------------------------- 361 362 /** 363 * @return the number of pages to be print 364 */ 365 public int getMaxPages() 366 { 367 // default is 0 (print all pages) 368 int nMaxPages = m_aCurrentParams.getInt( PropertyName.DOC_COMPARATOR_PRINT_MAX_PAGE ); 369 return nMaxPages; 370 } 371 372 /** 373 * @return as string, which pages should be print, e.g. '1-4;6' here, page 1 to 4 and page 6. 374 */ 375 public String getOnlyPages() 376 { 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) 380 { 381 sOnlyPage = ""; 382 } 383 return sOnlyPage; 384 } 385 386 /** 387 * @return true, if there should not print all pages at all, use getMaxPages() and or getOnlyPages() to get which pages to print 388 */ 389 public boolean printAllPages() 390 { 391 if ( (getMaxPages() > 0) || 392 (getOnlyPages().length() != 0)) 393 { 394 return false; 395 } 396 return true; 397 } 398 399 public boolean getOverwrite() 400 { 401 boolean bOverwrite = m_aCurrentParams.getBool( PropertyName.DOC_COMPARATOR_OVERWRITE_REFERENCE); 402 return bOverwrite; 403 } 404 405 private String m_sHTMLPrefix = null; 406 public String getHTMLPrefix() 407 { 408 if (m_sHTMLPrefix == null) 409 { 410 String sPrefix = (String)getTestParameters().get( PropertyName.DOC_COMPARATOR_HTML_OUTPUT_PREFIX ); 411 if (sPrefix == null || sPrefix.length() == 0) 412 { 413 GlobalLogWriter.println("Please set html prefix " + PropertyName.DOC_COMPARATOR_HTML_OUTPUT_PREFIX + "=prefix."); 414 } 415 else 416 { 417 m_sHTMLPrefix = sPrefix; 418 } 419 } 420 return m_sHTMLPrefix; 421 } 422 423 public boolean createSmallPictures() 424 { 425 // boolean bCreateSmallPictures = true; 426 boolean bNoSmallPictures = m_aCurrentParams.getBool( PropertyName.NO_SMALL_PICTURES); 427 if (bNoSmallPictures == true) 428 { 429 return false; 430 } 431 return true; 432 } 433 434 } 435