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