1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 package graphical; 23 24 import com.sun.star.lang.XMultiServiceFactory; 25 import lib.TestParameters; 26 27 /** 28 * This class object is more a Helper or Controller. 29 * It stores information like: 30 * - How to create a document (with a OpenOffice method, or with MS Word, or with OpenOffice as pdf) 31 * - some more info for OpenOffice method 32 * - a service factory pointer 33 * - if hidden mode should use 34 * - target name 35 * 36 * - printer name 37 * 38 * - how to handle .xml files, which in Microsoft could be Excel or Word documents 39 * 40 * HOWTO USE: 41 * For AOO, 42 * create an ParameterHelper with a set of TestParameters 43 * ParameterHelper a = new ParameterHelper(params); 44 * 45 * If you wish to use pdf export instead of normal printer output, set also the reference type to 'pdf' 46 * a.setReferenceType("pdf"); 47 * 48 * 49 * For MS Office: 50 * create a ParameterHelper and set the reference type to 'msoffice' 51 * ParameterHelper a = new ParameterHelper(params); 52 * a.setReferenceType("msoffice"); 53 * 54 * within windows it's better to set also a printer name so it's simply possible to use for normal work the default printer 55 * and for such tests with ConvWatch a extra printer. 56 * a.setPrinterName("CrossOffice Printer"); 57 * 58 */ 59 60 public class ParameterHelper 61 { 62 /* 63 TODO: 64 Possible reference types are currently 65 // ooo 66 // pdf 67 // msoffice 68 */ 69 private String m_sReferenceType = null; 70 71 // private String m_sTargetFrameName = "_blank"; 72 73 private String m_sPrinterName = null; 74 75 private int m_nResolutionInDPI = 180; 76 77 private boolean m_bIncludeSubdirectories; 78 79 private String m_sInputPath = null; 80 private String m_sOutputPath = null; 81 // private String m_sReferencePath = null; 82 83 private TestParameters m_aCurrentParams; 84 85 // private GlobalLogWriter m_aLog; 86 87 // CONSTRUCTOR 88 private ParameterHelper(){} 89 90 public ParameterHelper(TestParameters param) 91 { 92 m_aCurrentParams = param; 93 // m_aLog = log; 94 // interpretReferenceType(); 95 // interpretPrinterName(); 96 } 97 98 99 protected TestParameters getTestParameters() 100 { 101 return m_aCurrentParams; 102 } 103 104 /** 105 * return the input path, if given. 106 * @return 107 */ 108 public String getInputPath() 109 { 110 if (m_sInputPath == null) 111 { 112 String sInputPath = (String)getTestParameters().get( PropertyName.DOC_COMPARATOR_INPUT_PATH ); 113 if (sInputPath == null || sInputPath.length() == 0) 114 { 115 GlobalLogWriter.println("Please set input path (path to documents) " + PropertyName.DOC_COMPARATOR_INPUT_PATH + "=path."); 116 } 117 else 118 { 119 m_sInputPath = helper.StringHelper.removeQuoteIfExists(sInputPath); 120 } 121 } 122 return m_sInputPath; 123 } 124 125 public String getOutputPath() 126 { 127 if (m_sOutputPath == null) 128 { 129 String sOutputPath = (String)getTestParameters().get( PropertyName.DOC_COMPARATOR_OUTPUT_PATH ); 130 if (sOutputPath == null || sOutputPath.length() == 0) 131 { 132 GlobalLogWriter.println("Please set output path (path where to store document results) " + PropertyName.DOC_COMPARATOR_OUTPUT_PATH + "=path."); 133 } 134 else 135 { 136 m_sOutputPath = helper.StringHelper.removeQuoteIfExists(sOutputPath); 137 } 138 } 139 return m_sOutputPath; 140 } 141 142 // public String getReferencePath() 143 // { 144 // if (m_sReferencePath == null) 145 // { 146 // String sReferencePath = (String)getTestParameters().get( PropertyName.DOC_COMPARATOR_REFERENCE_PATH ); 147 // if (sReferencePath == null || sReferencePath.length() == 0) 148 // { 149 // GlobalLogWriter.println("Please set reference path (path to reference documents) " + PropertyName.DOC_COMPARATOR_REFERENCE_PATH + "=path."); 150 // } 151 // else 152 // { 153 // m_sReferencePath = sReferencePath; 154 // } 155 // } 156 // return m_sReferencePath; 157 // } 158 159 160 public boolean isIncludeSubDirectories() 161 { 162 m_bIncludeSubdirectories = true; 163 String sRECURSIVE = (String)getTestParameters().get( PropertyName.DOC_COMPARATOR_INCLUDE_SUBDIRS ); 164 // TODO: I need to get the boolean value with get("name") because, if it is not given getBool() returns 165 // with a default of 'false' which is not very helpful if the default should be 'true' 166 // maybe a getBoolean("name", true) could be a better choice. 167 if (sRECURSIVE == null) 168 { 169 sRECURSIVE = "true"; 170 } 171 if (sRECURSIVE.toLowerCase().equals("no") || 172 sRECURSIVE.toLowerCase().equals("false")) 173 { 174 m_bIncludeSubdirectories = false; 175 } 176 return m_bIncludeSubdirectories; 177 } 178 179 public String getReferenceType() 180 { 181 if (m_sReferenceType == null) 182 { 183 // REFERENCE_TYPE ---------- 184 185 String sReferenceType = (String)getTestParameters().get( PropertyName.DOC_COMPARATOR_REFERENCE_TYPE ); 186 if (sReferenceType == null || sReferenceType.length() == 0) 187 { 188 m_sReferenceType = "ps"; 189 } 190 else 191 { 192 // log.println("found REFERENCE_TYPE " + sReferenceType ); 193 m_sReferenceType = sReferenceType; 194 } 195 } 196 return m_sReferenceType; 197 } 198 199 public String getPrinterName() 200 { 201 if (m_sPrinterName == null) 202 { 203 // PRINTER_NAME ---------- 204 205 String sPrinterName = (String)getTestParameters().get( PropertyName.DOC_COMPARATOR_PRINTER_NAME ); 206 if (sPrinterName == null || sPrinterName.length() == 0) 207 { 208 m_sPrinterName = ""; 209 } 210 else 211 { 212 // log.println("found PRINTER_NAME " + sPrinterName ); 213 m_sPrinterName = sPrinterName; 214 } 215 } 216 return m_sPrinterName; 217 } 218 219 PerformanceContainer m_aPerformanceContainer = null; 220 /** 221 * helper class for performance analyzer features 222 * @return 223 */ 224 public PerformanceContainer getPerformance() 225 { 226 if (m_aPerformanceContainer == null) 227 { 228 m_aPerformanceContainer = new PerformanceContainer(); 229 } 230 return m_aPerformanceContainer; 231 } 232 233 /** 234 * Helper function to get the buildid of the current used OpenOffice 235 * out of the AppExecutionCommand the build ID 236 * @return 237 */ 238 public String getBuildID() 239 { 240 String sAPP = (String)m_aCurrentParams.get(util.PropertyName.APP_EXECUTION_COMMAND); 241 // return getBuildID(sAPP); 242 // TODO: here we need the getBuildID(string) method 243 String sBuildID = BuildID.getBuildID(sAPP); 244 return sBuildID; 245 } 246 247 /** 248 * @return integer value, which contain resolution in DPI. 249 */ 250 public int getResolutionInDPI() 251 { 252 return m_nResolutionInDPI; 253 } 254 // get methods 255 public XMultiServiceFactory getMultiServiceFactory() 256 { 257 XMultiServiceFactory xMSF = (XMultiServiceFactory)m_aCurrentParams.getMSF(); 258 259 // check if MultiServiceFactory is given 260 if (getReferenceType().toLowerCase().equals("pdf") || 261 getReferenceType().toLowerCase().equals("ps") || 262 getReferenceType().toLowerCase().equals("ooo") || 263 getReferenceType().toLowerCase().equals("o3") ) 264 { 265 if (xMSF == null) 266 { 267 GlobalLogWriter.println("ERROR! MultiServiceFactory not given."); 268 } 269 } 270 return xMSF; 271 } 272 273 // Hidden = true hides a used OpenOffice, all code is executed in the background 274 // This parameter is not used for RefType: msoffice 275 // boolean m_bHidden = true; 276 277 278 public boolean isHidden() 279 { 280 // HIDDEN 281 282 String sOfficeViewable = (String)m_aCurrentParams.get(PropertyName.OFFICE_VIEWABLE); 283 if (sOfficeViewable != null) 284 { 285 if (sOfficeViewable.toLowerCase().equals("yes") || 286 sOfficeViewable.toLowerCase().equals("true")) 287 { 288 return false; // setViewable(); 289 } 290 else 291 { 292 return true; // setHidden(); 293 } 294 } 295 return true; /* default: hidden */ 296 } 297 298 // get/set for FilterName 299 // get the right Filtername (internal Name) from 300 // http://framework.openoffice.org/files/documents/25/897/filter_description.html 301 302 String m_sImportFilterName = ""; 303 String m_sExportFilterName = ""; 304 public void setImportFilterName(String _sImportFilterName) 305 { 306 m_sImportFilterName = _sImportFilterName; 307 } 308 public String getImportFilterName() 309 { 310 return m_sImportFilterName; 311 } 312 public void setExportFilterName(String _sExportFilterName) 313 { 314 m_sExportFilterName = _sExportFilterName; 315 } 316 public String getExportFilterName() 317 { 318 return m_sExportFilterName; 319 } 320 String m_sDocumentType = ""; 321 public void setDocumentType(String _sName) 322 { 323 m_sDocumentType = _sName; 324 } 325 public String getDocumentType() 326 { 327 return m_sDocumentType; 328 } 329 330 331 // String m_sDefaultXMLFormatApplication = null; 332 // public String getDefaultXMLFormatApp() 333 // { 334 // if (m_sDefaultXMLFormatApplication == null) 335 // { 336 // // DEFAULT_XML_FORMAT_APP ------ 337 // 338 // String sDefaultXMLFormatApp = (String)m_aCurrentParams.get( PropertyName.DOC_COMPARATOR_DEFAULT_XML_FORMAT_APP ); 339 // if (sDefaultXMLFormatApp == null || sDefaultXMLFormatApp.length() == 0) 340 // { 341 // m_sDefaultXMLFormatApplication = "word"; 342 // } 343 // else 344 // { 345 // m_sDefaultXMLFormatApplication = sDefaultXMLFormatApp; 346 // } 347 // } 348 // return m_sDefaultXMLFormatApplication; 349 // } 350 351 352 // Pages ------------------------------------------------------------------- 353 354 /** 355 * @return the number of pages to be print 356 */ 357 public int getMaxPages() 358 { 359 // default is 0 (print all pages) 360 int nMaxPages = m_aCurrentParams.getInt( PropertyName.DOC_COMPARATOR_PRINT_MAX_PAGE ); 361 return nMaxPages; 362 } 363 364 /** 365 * @return as string, which pages should be print, e.g. '1-4;6' here, page 1 to 4 and page 6. 366 */ 367 public String getOnlyPages() 368 { 369 // default is null, there is no page which we want to print only. 370 String sOnlyPage = (String)m_aCurrentParams.get(PropertyName.DOC_COMPARATOR_PRINT_ONLY_PAGE); 371 if (sOnlyPage == null) 372 { 373 sOnlyPage = ""; 374 } 375 return sOnlyPage; 376 } 377 378 /** 379 * @return true, if there should not print all pages at all, use getMaxPages() and or getOnlyPages() to get which pages to print 380 */ 381 public boolean printAllPages() 382 { 383 if ( (getMaxPages() > 0) || 384 (getOnlyPages().length() != 0)) 385 { 386 return false; 387 } 388 return true; 389 } 390 391 public boolean getOverwrite() 392 { 393 boolean bOverwrite = m_aCurrentParams.getBool( PropertyName.DOC_COMPARATOR_OVERWRITE_REFERENCE); 394 return bOverwrite; 395 } 396 397 private String m_sHTMLPrefix = null; 398 public String getHTMLPrefix() 399 { 400 if (m_sHTMLPrefix == null) 401 { 402 String sPrefix = (String)getTestParameters().get( PropertyName.DOC_COMPARATOR_HTML_OUTPUT_PREFIX ); 403 if (sPrefix == null || sPrefix.length() == 0) 404 { 405 GlobalLogWriter.println("Please set HTML prefix " + PropertyName.DOC_COMPARATOR_HTML_OUTPUT_PREFIX + "=prefix."); 406 } 407 else 408 { 409 m_sHTMLPrefix = sPrefix; 410 } 411 } 412 return m_sHTMLPrefix; 413 } 414 415 public boolean createSmallPictures() 416 { 417 // boolean bCreateSmallPictures = true; 418 boolean bNoSmallPictures = m_aCurrentParams.getBool( PropertyName.NO_SMALL_PICTURES); 419 if (bNoSmallPictures == true) 420 { 421 return false; 422 } 423 return true; 424 } 425 426 } 427