1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
|
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
package convwatch;
import com.sun.star.lang.XMultiServiceFactory;
import lib.TestParameters;
import java.io.File;
import com.sun.star.container.XNameAccess;
import com.sun.star.uno.UnoRuntime;
/**
* This class object is more a Helper or Controller.
* It stores information like:
* - How to create a document (with a OpenOffice.org method, or with MS Word, or with OpenOffice.org as pdf)
* - some more infos for OpenOffice.org method
* - a service factory pointer
* - if hidden mode should use
* - target name
*
* - printer name
*
* - how to handle .xml files, which in Microsoft could be Excel or Word documents
*
* HOWTO USE:
* For OOo,
* create an GraphicalTestArguments with a set of TestParameters
* GraphicalTestArguments a = new GraphicalTestArguments(params);
*
* If you wish to use pdf export instead of normal printer output, set also the reference type to 'pdf'
* a.setReferenceType("pdf");
*
*
* For MS Office:
* create an GraphicalTestArguments and set the reference type to 'msoffice'
* GraphicalTestArguments a = new GraphicalTestArguments(params);
* a.setReferenceType("msoffice");
*
* within windows it's better to set also a printer name so it's simply possible to use for normal work the default printer
* and for such tests with ConvWatch a extra printer.
* a.setPrinterName("CrossOffice Printer");
*
*/
public class GraphicalTestArguments
{
/**
2DO:
Possible reference types are currently
// ooo
// pdf
// msoffice
*/
private String m_sReferenceType = "OOo";
private String m_sTargetFrameName = "_blank";
private String m_sPrinterName = null;
// Hidden = true hiddes a used OpenOffice.org, all code is executed in the background
// This parameter is not used for RefType: msoffice
private boolean m_bHidden = true;
private String m_sDefaultXMLFormatApplication = null;
private boolean m_bIncludeSubdirectories;
private TestParameters m_aCurrentParams;
private int m_nMaxPages = 0; // default is 0 (print all pages)
private String m_sOnlyPage = ""; // default is "", there is no page which we want to print only.
private int m_nResolutionInDPI = 0;
private boolean m_bStoreFile = true;
private boolean m_bResuseOffice = false;
private String m_sDistinct = null;
private boolean m_bCreateDefaultReference = false;
public GraphicalTestArguments(TestParameters param)
{
m_aCurrentParams = param;
// collect interesting information from the ComplexTestCase
// REFERENCE_TYPE ----------
String sReferenceType = (String)param.get( PropertyName.DOC_COMPARATOR_REFERENCE_TYPE );
if (sReferenceType == null || sReferenceType.length() == 0)
{
}
else
{
setReferenceType(sReferenceType);
}
// PRINTER_NAME ----------
String sPrinterName = (String)param.get( PropertyName.DOC_COMPARATOR_PRINTER_NAME );
if (sPrinterName == null || sPrinterName.length() == 0)
{
}
else
{
setPrinterName(sPrinterName);
}
// DEFAULT_XML_FORMAT_APP ------
String sDefaultXMLFormatApp = (String)param.get( PropertyName.DOC_COMPARATOR_DEFAULT_XML_FORMAT_APP );
if (sDefaultXMLFormatApp == null || sDefaultXMLFormatApp.length() == 0)
{
}
else
{
setDefaultXMLFormatApp(sDefaultXMLFormatApp);
}
m_bIncludeSubdirectories = true;
String sRECURSIVE = (String)param.get( PropertyName.DOC_COMPARATOR_INCLUDE_SUBDIRS );
// TODO: I need to get the boolean value with get("name") because, if it is not given getBool() returns
// with a default of 'false' which is not very helpful if the default should be 'true'
// maybe a getBoolean("name", true) could be a better choice.
if (sRECURSIVE == null)
{
sRECURSIVE = "true";
}
if (sRECURSIVE.equalsIgnoreCase("no") ||
sRECURSIVE.equalsIgnoreCase("false"))
{
m_bIncludeSubdirectories = false;
}
m_nMaxPages = param.getInt( PropertyName.DOC_COMPARATOR_PRINT_MAX_PAGE );
m_sOnlyPage = (String)param.get(PropertyName.DOC_COMPARATOR_PRINT_ONLY_PAGE);
m_nResolutionInDPI = param.getInt( PropertyName.DOC_COMPARATOR_GFX_OUTPUT_DPI_RESOLUTION );
if (m_nResolutionInDPI == 0)
{
// 212 DPI is 1754 x 2474 pixel for DIN A4
m_nResolutionInDPI = 212;
}
String sImportFilterName = (String)param.get(PropertyName.DOC_CONVERTER_IMPORT_FILTER_NAME);
if (sImportFilterName != null && sImportFilterName.length() > 0)
{
m_sImportFilterName = sImportFilterName;
if (sImportFilterName.equalsIgnoreCase("help"))
{
showInternalFilterName(sImportFilterName, getMultiServiceFactory() );
GlobalLogWriter.get().println("Must quit.");
}
}
String sExportFilterName = (String)param.get(PropertyName.DOC_CONVERTER_EXPORT_FILTER_NAME);
if (sExportFilterName != null && sExportFilterName.length() > 0)
{
m_sExportFilterName = sExportFilterName;
if (sExportFilterName.equalsIgnoreCase("help"))
{
showInternalFilterName(sExportFilterName, getMultiServiceFactory() );
GlobalLogWriter.get().println("Must quit.");
}
}
String sOfficeProgram = (String)param.get(PropertyName.DOC_CONVERTER_OFFICE_PROGRAM);
if (sOfficeProgram != null && sOfficeProgram.length() > 0)
{
m_sOfficeProgram = sOfficeProgram;
}
String sREUSE_OFFICE = (String)param.get( PropertyName.DOC_CONVERTER_REUSE_OFFICE);
if (sREUSE_OFFICE == null)
{
sREUSE_OFFICE = "false";
}
m_bResuseOffice =
sREUSE_OFFICE.equalsIgnoreCase("yes") ||
sREUSE_OFFICE.equalsIgnoreCase("true");
String sHTMLOutputPrefix = (String)param.get( PropertyName.DOC_COMPARATOR_HTML_OUTPUT_PREFIX);
if (sHTMLOutputPrefix == null)
{
m_sHTMLOutputPrefix = "";
}
else
{
m_sHTMLOutputPrefix = sHTMLOutputPrefix;
}
String sWithBorderMove = (String)param.get( PropertyName.DOC_COMPARATOR_GFXCMP_WITH_BORDERMOVE);
if (sWithBorderMove == null)
{
sWithBorderMove = "";
// m_tWithBorderMove = TriState.UNSET;
m_tWithBorderMove = TriState.FALSE;
}
if (sWithBorderMove.equalsIgnoreCase("yes") ||
sWithBorderMove.equalsIgnoreCase("true"))
{
m_tWithBorderMove = TriState.TRUE;
}
else if (sWithBorderMove.equalsIgnoreCase("no") ||
sWithBorderMove.equalsIgnoreCase("false"))
{
m_tWithBorderMove = TriState.FALSE;
}
else
{
m_tWithBorderMove = TriState.FALSE;
// m_tWithBorderMove = TriState.UNSET;
}
String sLeaveOutNames = (String)param.get(PropertyName.DOC_COMPARATOR_LEAVE_OUT_FILES);
String sDBInfoString = (String)param.get(PropertyName.DOC_COMPARATOR_DB_INFO_STRING);
if (sDBInfoString != null)
{
m_sDBInfoString = sDBInfoString;
}
// DISTINCT ----------
String sDistinct = (String)param.get( "DISTINCT" );
if (sDistinct == null || sDistinct.length() == 0)
{
sDistinct = "";
}
else
{
m_sDistinct = sDistinct;
}
// HIDDEN
String sOfficeViewable = (String)param.get(PropertyName.OFFICE_VIEWABLE);
if (sOfficeViewable != null)
{
if (sOfficeViewable.equalsIgnoreCase("yes") ||
sOfficeViewable.equalsIgnoreCase("true"))
{
setViewable();
}
else
{
setHidden();
}
}
// CREATE_DEFAULT
String sCreateDefault = (String)param.get(PropertyName.CREATE_DEFAULT);
if (sCreateDefault != null)
{
m_bCreateDefaultReference =
sCreateDefault.equalsIgnoreCase("yes") ||
sCreateDefault.equalsIgnoreCase("true");
}
}
public boolean checkIfUsableDocumentType(String _sName)
{
// @todo
// check if the name is in the leave out list and then return 'false'
return !(_sName.toLowerCase().endsWith(".jpg") ||
_sName.toLowerCase().endsWith(".png") ||
_sName.toLowerCase().endsWith(".gif") ||
_sName.toLowerCase().endsWith(".bmp") ||
_sName.toLowerCase().endsWith(".prn") ||
_sName.toLowerCase().endsWith(".ps"));
}
private static void showInternalFilterName(String _sFilterName, XMultiServiceFactory _xMSF)
{
if (_sFilterName.length() == 0)
{
return;
}
if (_xMSF == null)
{
GlobalLogWriter.get().println("MultiServiceFactory not set.");
return;
}
Object aObj = null;
try
{
aObj = _xMSF.createInstance("com.sun.star.document.FilterFactory");
}
catch(com.sun.star.uno.Exception e)
{
GlobalLogWriter.get().println("Can't get com.sun.star.document.FilterFactory.");
return;
}
if (aObj != null)
{
XNameAccess aNameAccess = UnoRuntime.queryInterface(XNameAccess.class, aObj);
if (aNameAccess != null)
{
if (_sFilterName.equalsIgnoreCase("help"))
{
GlobalLogWriter.get().println("Show all possible ElementNames from current version." );
String[] aElementNames = aNameAccess.getElementNames();
for (int i = 0; i<aElementNames.length; i++)
{
GlobalLogWriter.get().println(aElementNames[i]);
}
}
}
}
}
// set methods
public void setReferenceType(String _sType)
{
// special casse, null is not allowed, set to default.
if (_sType == null)
{
m_sReferenceType = "OOo";
}
else
{
m_sReferenceType = _sType;
}
}
public void setTargetFrameName(String _sTargetFrameName) {m_sTargetFrameName = _sTargetFrameName;}
public void setPrinterName(String _sName) {m_sPrinterName = _sName;}
private void setHidden() { m_bHidden = true;}
private void setViewable() {m_bHidden = false;}
public void setDefaultXMLFormatApp(String _sNameOfApp) {m_sDefaultXMLFormatApplication = _sNameOfApp;}
// get methods
public XMultiServiceFactory getMultiServiceFactory()
{
XMultiServiceFactory xMSF = m_aCurrentParams.getMSF();
// check if MultiServiceFactory is given
if (getReferenceType().equalsIgnoreCase("pdf") ||
getReferenceType().equalsIgnoreCase("ooo"))
{
if (xMSF == null)
{
GlobalLogWriter.get().println("ERROR! MultiServiceFactory not given.");
}
}
return xMSF;
}
public String getReferenceType() {return m_sReferenceType;}
public String getTargetFrameName() {return m_sTargetFrameName;}
public String getPrinterName() {return m_sPrinterName;}
public boolean isHidden() {return m_bHidden;}
public String getDefaultXMLFormatApp() {return m_sDefaultXMLFormatApplication;}
/**
* @return true, if subdirectories should run through
*/
public boolean includeSubDirectories() {return m_bIncludeSubdirectories;}
/**
* @return the number of pages to be print
*/
public int getMaxPages() {return m_nMaxPages;}
/**
* @return as string, which pages should be print, e.g. '1-4;6' here, page 1 to 4 and page 6.
*/
public String getOnlyPages()
{
if (m_sOnlyPage == null)
{
return "";
}
return m_sOnlyPage;
}
/**
* @return true, if there should not print all pages at all, use getMaxPages() and or getOnlyPages() to get which pages to print
*/
public boolean printAllPages()
{
return !((getMaxPages() > 0) || (getOnlyPages().length() != 0));
}
/**
* @return integer value, which contain resolution in DPI.
*/
public int getResolutionInDPI() {return m_nResolutionInDPI;}
private static void checkIfMSWindowsConformPath(String _sPath)
{
if (_sPath != null && _sPath.length() > 1)
{
if (_sPath.charAt(1) == ':')
{
if (_sPath.charAt(2) != '\\')
{
GlobalLogWriter.get().println("This is not a Microsoft Windows conform path: '" + _sPath + "' please fix.");
System.exit(1);
}
}
}
}
/**
* @return the INPUT_PATH out of the TestParameters
*/
public String getInputPath()
{
String sInputPath;
sInputPath = (String)m_aCurrentParams.get(PropertyName.DOC_COMPARATOR_INPUT_PATH);
checkIfMSWindowsConformPath(sInputPath);
return sInputPath;
}
/**
* @return the OUTPUT_PATH out of the TestParameters
*/
public String getOutputPath()
{
String sOutputPath;
sOutputPath = (String)m_aCurrentParams.get(PropertyName.DOC_COMPARATOR_OUTPUT_PATH);
checkIfMSWindowsConformPath(sOutputPath);
return sOutputPath;
}
/**
* @return the REFERENCE_PATH out of the TestParameters
*/
public String getReferencePath()
{
String sReferencePath;
sReferencePath = (String)m_aCurrentParams.get(PropertyName.DOC_COMPARATOR_REFERENCE_PATH);
checkIfMSWindowsConformPath(sReferencePath);
return sReferencePath;
}
/**
* @return the DIFF_PATH out of the TestParameters
*/
public String getDiffPath()
{
String sDiffPath;
sDiffPath = (String)m_aCurrentParams.get(PropertyName.DOC_COMPARATOR_DIFF_PATH);
checkIfMSWindowsConformPath(sDiffPath);
return sDiffPath;
}
public boolean getOverwrite()
{
boolean bOverwrite = m_aCurrentParams.getBool( PropertyName.DOC_COMPARATOR_OVERWRITE_REFERENCE);
return bOverwrite;
}
public String getReferenceInputPath()
{
String sReferenceInputPath;
sReferenceInputPath = (String)m_aCurrentParams.get(PropertyName.DOC_COMPARATOR_REFERENCE_INPUT_PATH);
return sReferenceInputPath;
}
/**
* Helper function to get the buildid of the current used OpenOffice.org
* out of the AppExecutionCommand the build ID
*/
public String getBuildID()
{
String sAPP = (String)m_aCurrentParams.get(util.PropertyName.APP_EXECUTION_COMMAND);
// return getBuildID(sAPP);
// TODO: here we need the getBuildID(string) method
String sBuildID = convwatch.BuildID.getBuildID(sAPP);
return sBuildID;
}
public boolean shouldOfficeStart()
{
String sNoOffice = (String)m_aCurrentParams.get( "NoOffice" );
if (sNoOffice != null)
{
if (sNoOffice.toLowerCase().startsWith("t") || sNoOffice.toLowerCase().startsWith("y"))
{
return false;
}
}
return true;
}
// Handle for Reference Build ID, is set in ConvWatch.createPostscriptStartCheck()
private String m_sRefBuildID;
public void setRefBuildID(String _sRef)
{
m_sRefBuildID = _sRef;
}
public String getRefBuildID()
{
return m_sRefBuildID;
}
public void disallowStore()
{
m_bStoreFile = false;
}
public void allowStore()
{
m_bStoreFile = true;
}
public boolean isStoreAllowed()
{
return m_bStoreFile;
}
public boolean createDefaultReference()
{
return m_bCreateDefaultReference;
}
// get/set for FilterName
// get the right Filtername (internal Name) from
// http://framework.openoffice.org/files/documents/25/897/filter_description.html
private String m_sImportFilterName = "";
private String m_sExportFilterName = "";
public void setImportFilterName(String _sImportFilterName)
{
m_sImportFilterName = _sImportFilterName;
}
public String getImportFilterName()
{
return m_sImportFilterName;
}
public void setExportFilterName(String _sExportFilterName)
{
m_sExportFilterName = _sExportFilterName;
}
public String getExportFilterName()
{
return m_sExportFilterName;
}
private String m_sOfficeProgram = "";
public void setOfficeProgram(String _sName)
{
m_sOfficeProgram = _sName;
}
public String getOfficeProgram()
{
return m_sOfficeProgram;
}
public boolean restartOffice()
{
return !m_bResuseOffice;
}
private String m_sHTMLOutputPrefix = "";
public String getHTMLOutputPrefix()
{
return m_sHTMLOutputPrefix;
}
private TriState m_tWithBorderMove = TriState.UNSET;
public TriState getBorderMove()
{
return m_tWithBorderMove;
}
public void setBorderMove(TriState _tBorderMove)
{
m_tWithBorderMove = _tBorderMove;
}
private String m_sDocumentType = "";
public void setDocumentType(String _sName)
{
m_sDocumentType = _sName;
}
public String getDocumentType()
{
return m_sDocumentType;
}
/*
helper class for performance analyser features
*/
private PerformanceContainer m_aPerformanceContainer = null;
public PerformanceContainer getPerformance()
{
if (m_aPerformanceContainer == null)
{
m_aPerformanceContainer = new PerformanceContainer();
}
return m_aPerformanceContainer;
}
private String m_aInputFile;
public void setInputFile(String _sInputFile)
{
m_aInputFile = _sInputFile;
}
public String getInputFile()
{
return m_aInputFile;
}
private String m_sDBInfoString;
public String getDBInfoString()
{
if (m_sDBInfoString != null)
{
if (m_sDBInfoString.length() == 0)
{
return null;
}
}
return m_sDBInfoString;
}
public boolean cancelRequest()
{
File aCancelFile = null;
String fs;
fs = System.getProperty("file.separator");
String sTempPath = (String)m_aCurrentParams.get( PropertyName.TEMPPATH );
if (sTempPath != null)
{
String sGDC_Dir = sTempPath;
if (m_sDistinct.length() > 0)
{
sGDC_Dir = sGDC_Dir + fs + m_sDistinct;
}
String sCancelFile = sGDC_Dir + fs + "cancel_compare.txt";
aCancelFile = new File(sCancelFile);
if (aCancelFile.exists())
{
GlobalLogWriter.get().println("ATTENTION: Found file: '" + sCancelFile + "'.");
GlobalLogWriter.get().println("User has canceled the program flow.");
return true;
}
}
return false;
}
}
/*
public class MSGraphicalTestArguments extends GraphicalTestArguments
{
MSGraphicalTestArguments()
{
setReferenceType("msoffice");
}
}
public class OOoGraphicalTestArguments extends GraphicalTestArguments
{
OOoGraphicalTestArguments(XMultiServiceFactory _aFactory)
{
setMultiServiceFactory(_aFactory);
}
}
*/
|