1*cdf0e10cSrcweir /*
2*cdf0e10cSrcweir  * ************************************************************************
3*cdf0e10cSrcweir  *
4*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5*cdf0e10cSrcweir  *
6*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
7*cdf0e10cSrcweir  *
8*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
9*cdf0e10cSrcweir  *
10*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
11*cdf0e10cSrcweir  *
12*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
13*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
14*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
15*cdf0e10cSrcweir  *
16*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
17*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
20*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
21*cdf0e10cSrcweir  *
22*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
23*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
24*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
25*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
26*cdf0e10cSrcweir  *
27*cdf0e10cSrcweir  * ***********************************************************************
28*cdf0e10cSrcweir  */
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir package graphical;
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir import complexlib.ComplexTestCase;
33*cdf0e10cSrcweir import java.io.File;
34*cdf0e10cSrcweir import java.io.FileFilter;
35*cdf0e10cSrcweir import java.util.ArrayList;
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir /**
38*cdf0e10cSrcweir  *
39*cdf0e10cSrcweir  * @author ll93751
40*cdf0e10cSrcweir  */
41*cdf0e10cSrcweir abstract public class EnhancedComplexTestCase extends ComplexTestCase implements IDocument
42*cdf0e10cSrcweir {
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir private void callEntry(String _sEntry, ParameterHelper _aParam)
46*cdf0e10cSrcweir {
47*cdf0e10cSrcweir     // log.println("- next file is: ------------------------------");
48*cdf0e10cSrcweir     log.println("      File: " + _sEntry);
49*cdf0e10cSrcweir     // TODO: check if 'sEntry' is a guilty document.
50*cdf0e10cSrcweir     File aFile = new File(_aParam.getInputPath());
51*cdf0e10cSrcweir     String sPath = _aParam.getInputPath();
52*cdf0e10cSrcweir     // problem here, isFile() checks also if the file exists, but a not existing file is not really a directory
53*cdf0e10cSrcweir     // therefore we check if the given file a path (isDirectory()) if not it must be a file
54*cdf0e10cSrcweir     if (aFile.isDirectory())
55*cdf0e10cSrcweir     {
56*cdf0e10cSrcweir     }
57*cdf0e10cSrcweir     else
58*cdf0e10cSrcweir     {
59*cdf0e10cSrcweir         // special case, if a file is given in inputpath
60*cdf0e10cSrcweir         sPath = FileHelper.getPath(_aParam.getInputPath());
61*cdf0e10cSrcweir     }
62*cdf0e10cSrcweir     String sNewSubDir = FileHelper.removeFirstDirectorysAndBasenameFrom(_sEntry, sPath);
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir //    String sNewReferencePath = _aParam.getReferencePath();
65*cdf0e10cSrcweir     String sNewOutputPath = _aParam.getOutputPath();
66*cdf0e10cSrcweir     // String sNewDiffPath = m_sDiffPath;
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir     // if there exist a subdirectory, add it to all result path
69*cdf0e10cSrcweir     if (sNewSubDir.length() > 0)
70*cdf0e10cSrcweir     {
71*cdf0e10cSrcweir //        if (sNewReferencePath != null)
72*cdf0e10cSrcweir //        {
73*cdf0e10cSrcweir //            sNewReferencePath = FileHelper.appendPath(sNewReferencePath, sNewSubDir);
74*cdf0e10cSrcweir //        }
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir         sNewOutputPath = FileHelper.appendPath(sNewOutputPath, sNewSubDir);
77*cdf0e10cSrcweir     //                        if (sNewDiffPath != null)
78*cdf0e10cSrcweir     //                        {
79*cdf0e10cSrcweir     //                            sNewDiffPath = FileHelper.appendPath(sNewDiffPath, sNewSubDir);
80*cdf0e10cSrcweir     //                        }
81*cdf0e10cSrcweir     }
82*cdf0e10cSrcweir     // log.println("sEntry: " + _sEntry + " " /* + sNewReferencePath + " " */ + sNewOutputPath);
83*cdf0e10cSrcweir     log.println("Outputpath: " + sNewOutputPath);
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir     // call interface with parameters
87*cdf0e10cSrcweir     try
88*cdf0e10cSrcweir     {
89*cdf0e10cSrcweir         checkOneFile(_sEntry, sNewOutputPath, _aParam);
90*cdf0e10cSrcweir     }
91*cdf0e10cSrcweir     catch (OfficeException e)
92*cdf0e10cSrcweir     {
93*cdf0e10cSrcweir         // TODO: unhandled yet.
94*cdf0e10cSrcweir         GlobalLogWriter.println("Warning: caught OfficeException " + e.getMessage());
95*cdf0e10cSrcweir         assure("Exception caught: " + e.getMessage(), false);
96*cdf0e10cSrcweir     }
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir }
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir /**
101*cdf0e10cSrcweir  * Run through all documents found in Inputpath.
102*cdf0e10cSrcweir  * Call the IDocument interface function call(...);
103*cdf0e10cSrcweir  * @param _aParam
104*cdf0e10cSrcweir  */
105*cdf0e10cSrcweir     public void foreachDocumentinInputPath(ParameterHelper _aParam)
106*cdf0e10cSrcweir     {
107*cdf0e10cSrcweir                 // TODO: auslagern in eine function, die ein Interface annimmt.
108*cdf0e10cSrcweir         File aInputPath = new File(_aParam.getInputPath());
109*cdf0e10cSrcweir         if (aInputPath.isDirectory())
110*cdf0e10cSrcweir         {
111*cdf0e10cSrcweir             // check a whole directory
112*cdf0e10cSrcweir             // a whole directory
113*cdf0e10cSrcweir             FileFilter aFileFilter = FileHelper.getFileFilter();
114*cdf0e10cSrcweir             traverseDirectory(aFileFilter, _aParam);
115*cdf0e10cSrcweir         }
116*cdf0e10cSrcweir         else
117*cdf0e10cSrcweir         {
118*cdf0e10cSrcweir             callEntry(_aParam.getInputPath(), _aParam);
119*cdf0e10cSrcweir         }
120*cdf0e10cSrcweir     }
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir     private void traverseDirectory(FileFilter _aFileFilter, ParameterHelper _aParam)
123*cdf0e10cSrcweir     {
124*cdf0e10cSrcweir         Object[] aList = DirectoryHelper.traverse(_aParam.getInputPath(), _aFileFilter, _aParam.isIncludeSubDirectories());
125*cdf0e10cSrcweir         if (aList.length == 0)
126*cdf0e10cSrcweir         {
127*cdf0e10cSrcweir             log.println("Nothing to do, there are no document files found.");
128*cdf0e10cSrcweir         }
129*cdf0e10cSrcweir         else
130*cdf0e10cSrcweir         {
131*cdf0e10cSrcweir             for (int i=0;i<aList.length;i++)
132*cdf0e10cSrcweir             {
133*cdf0e10cSrcweir                 String sEntry = (String)aList[i];
134*cdf0e10cSrcweir                 callEntry(sEntry, _aParam);
135*cdf0e10cSrcweir             }
136*cdf0e10cSrcweir         }
137*cdf0e10cSrcweir     }
138*cdf0e10cSrcweir /**
139*cdf0e10cSrcweir  * Run through a given index.ini or run through a given directory,
140*cdf0e10cSrcweir  * find all postscript or pdf files.
141*cdf0e10cSrcweir  * Call the IDocument interface function call(...);
142*cdf0e10cSrcweir  * @param _aParam
143*cdf0e10cSrcweir  */
144*cdf0e10cSrcweir     public void foreachPSorPDFinInputPath(ParameterHelper _aParam)
145*cdf0e10cSrcweir     {
146*cdf0e10cSrcweir         // TODO: auslagern in eine function, die ein Interface annimmt.
147*cdf0e10cSrcweir         String sInputPath = _aParam.getInputPath();
148*cdf0e10cSrcweir         File aInputPath = new File(sInputPath);
149*cdf0e10cSrcweir //        if (!aInputPath.exists())
150*cdf0e10cSrcweir //        {
151*cdf0e10cSrcweir //            GlobalLogWriter.println("Error, InputPath or File in InputPath doesn't exists. Please check: '" + sInputPath + "'");
152*cdf0e10cSrcweir //            assure("Error, InputPath or File in InputPath doesn't exists. Please check: '" + sInputPath + "'", false);
153*cdf0e10cSrcweir //        }
154*cdf0e10cSrcweir         if (aInputPath.isDirectory())
155*cdf0e10cSrcweir         {
156*cdf0e10cSrcweir             // check a whole directory
157*cdf0e10cSrcweir             // a whole directory
158*cdf0e10cSrcweir             FileFilter aFileFilter = FileHelper.getFileFilterPSorPDF();
159*cdf0e10cSrcweir             traverseDirectory(aFileFilter, _aParam);
160*cdf0e10cSrcweir         }
161*cdf0e10cSrcweir         else
162*cdf0e10cSrcweir         {
163*cdf0e10cSrcweir             // the inputpath contains a file
164*cdf0e10cSrcweir             if (sInputPath.toLowerCase().endsWith(".ini"))
165*cdf0e10cSrcweir             {
166*cdf0e10cSrcweir                 IniFile aIniFile = new IniFile(_aParam.getInputPath());
167*cdf0e10cSrcweir                 while (aIniFile.hasMoreElements())
168*cdf0e10cSrcweir                 {
169*cdf0e10cSrcweir                     String sKey = (String)aIniFile.nextElement();
170*cdf0e10cSrcweir                     String sPath = FileHelper.getPath(_aParam.getInputPath());
171*cdf0e10cSrcweir                     String sEntry = FileHelper.appendPath(sPath, sKey);
172*cdf0e10cSrcweir                     File aFile = new File(sEntry);
173*cdf0e10cSrcweir                     assure("File '" + sEntry + "' doesn't exists.", aFile.exists(), true);
174*cdf0e10cSrcweir                     if (aFile.exists())
175*cdf0e10cSrcweir                     {
176*cdf0e10cSrcweir                         callEntry(sEntry, _aParam);
177*cdf0e10cSrcweir                     }
178*cdf0e10cSrcweir                 }
179*cdf0e10cSrcweir             }
180*cdf0e10cSrcweir             else
181*cdf0e10cSrcweir             {
182*cdf0e10cSrcweir                 // call for a single pdf/ps file
183*cdf0e10cSrcweir                 if (sInputPath.toLowerCase().endsWith(".ps") ||
184*cdf0e10cSrcweir                     sInputPath.toLowerCase().endsWith(".pdf") ||
185*cdf0e10cSrcweir                     sInputPath.toLowerCase().endsWith(".prn"))
186*cdf0e10cSrcweir                 {
187*cdf0e10cSrcweir                     callEntry(sInputPath, _aParam);
188*cdf0e10cSrcweir                 }
189*cdf0e10cSrcweir                 else
190*cdf0e10cSrcweir                 {
191*cdf0e10cSrcweir                     String sInputPathWithPDF = sInputPath + ".pdf";
192*cdf0e10cSrcweir                     File aInputPathWithPDF = new File(sInputPathWithPDF);
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir                     if (aInputPathWithPDF.exists() &&
195*cdf0e10cSrcweir                         _aParam.getReferenceType().toLowerCase().equals("pdf"))
196*cdf0e10cSrcweir                     {
197*cdf0e10cSrcweir                         // create PDF only if a pdf file exists and creatortype is set to PDF
198*cdf0e10cSrcweir                         callEntry(sInputPathWithPDF, _aParam);
199*cdf0e10cSrcweir                     }
200*cdf0e10cSrcweir                     else
201*cdf0e10cSrcweir                     {
202*cdf0e10cSrcweir                         String sInputPathWithPS = sInputPath + ".ps";
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir                         File aInputPathWithPS = new File(sInputPathWithPS);
205*cdf0e10cSrcweir                         if (aInputPathWithPS.exists())
206*cdf0e10cSrcweir                         {
207*cdf0e10cSrcweir                             callEntry(sInputPathWithPS, _aParam);
208*cdf0e10cSrcweir                         }
209*cdf0e10cSrcweir                         else
210*cdf0e10cSrcweir                         {
211*cdf0e10cSrcweir                             String sPath = FileHelper.getPath(sInputPath);
212*cdf0e10cSrcweir                             String sBasename = FileHelper.getBasename(sInputPath);
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir                             // there exist an index file, therefore we assume the given
215*cdf0e10cSrcweir                             // file is already converted to postscript or pdf
216*cdf0e10cSrcweir                             runThroughEveryReportInIndex(sPath, sBasename, _aParam);
217*cdf0e10cSrcweir                         }
218*cdf0e10cSrcweir                     }
219*cdf0e10cSrcweir                 }
220*cdf0e10cSrcweir             }
221*cdf0e10cSrcweir         }
222*cdf0e10cSrcweir     }
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir     private void runThroughEveryReportInIndex(String _sPath, String _sBasename, ParameterHelper _aParam)
225*cdf0e10cSrcweir     {
226*cdf0e10cSrcweir         String sIndexFile = FileHelper.appendPath(_sPath, "index.ini");
227*cdf0e10cSrcweir         File aIndexFile = new File(sIndexFile);
228*cdf0e10cSrcweir         if (aIndexFile.exists())
229*cdf0e10cSrcweir         {
230*cdf0e10cSrcweir             IniFile aIniFile = new IniFile(sIndexFile);
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir             if (aIniFile.hasSection(_sBasename))
233*cdf0e10cSrcweir             {
234*cdf0e10cSrcweir                 // special case for odb files
235*cdf0e10cSrcweir                 int nFileCount = aIniFile.getIntValue(_sBasename, "reportcount", 0);
236*cdf0e10cSrcweir                 ArrayList<String> aList = new ArrayList<String>();
237*cdf0e10cSrcweir                 for (int i=0;i<nFileCount;i++)
238*cdf0e10cSrcweir                 {
239*cdf0e10cSrcweir                     String sValue = aIniFile.getValue(_sBasename, "report" + i);
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir                     String sPSorPDFName = getPSorPDFNameFromIniFile(aIniFile, sValue);
242*cdf0e10cSrcweir                     if (sPSorPDFName.length() > 0)
243*cdf0e10cSrcweir                     {
244*cdf0e10cSrcweir                         String sEntry = FileHelper.appendPath(_sPath, sPSorPDFName);
245*cdf0e10cSrcweir                         aList.add(sEntry);
246*cdf0e10cSrcweir                     }
247*cdf0e10cSrcweir                 }
248*cdf0e10cSrcweir                 aIniFile.close();
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir                 int nOkStatus = 0;
251*cdf0e10cSrcweir                 String sStatusRunThrough = "";
252*cdf0e10cSrcweir                 String sStatusInfo = "";
253*cdf0e10cSrcweir                 // get the bad status and store it into the
254*cdf0e10cSrcweir                 for (int i=0;i<aList.size();i++)
255*cdf0e10cSrcweir                 {
256*cdf0e10cSrcweir                     String sEntry = aList.get(i);
257*cdf0e10cSrcweir                     try
258*cdf0e10cSrcweir                     {
259*cdf0e10cSrcweir                         callEntry(sEntry, _aParam);
260*cdf0e10cSrcweir                     }
261*cdf0e10cSrcweir                     catch (AssureException e)
262*cdf0e10cSrcweir                     {
263*cdf0e10cSrcweir                         // we only need to catch the assure()
264*cdf0e10cSrcweir                         // nOkStatus += 2;
265*cdf0e10cSrcweir                     }
266*cdf0e10cSrcweir                     // we want to know the current status of the run through
267*cdf0e10cSrcweir                     // if the status is greater (more bad) then the current,
268*cdf0e10cSrcweir                     // we will remember this. Only the very bad status will
269*cdf0e10cSrcweir                     // seen.
270*cdf0e10cSrcweir                     int nCurrentOkStatus = _aParam.getTestParameters().getInt("current_ok_status");
271*cdf0e10cSrcweir                     if (nCurrentOkStatus > nOkStatus)
272*cdf0e10cSrcweir                     {
273*cdf0e10cSrcweir                         sStatusRunThrough = (String)_aParam.getTestParameters().get("current_state");
274*cdf0e10cSrcweir                         sStatusInfo = (String)_aParam.getTestParameters().get("current_info");
275*cdf0e10cSrcweir                         nOkStatus = nCurrentOkStatus;
276*cdf0e10cSrcweir                     }
277*cdf0e10cSrcweir                 }
278*cdf0e10cSrcweir                 if (nOkStatus > 0)
279*cdf0e10cSrcweir                 {
280*cdf0e10cSrcweir                     _aParam.getTestParameters().put("last_state", sStatusRunThrough);
281*cdf0e10cSrcweir                     _aParam.getTestParameters().put("last_info", sStatusInfo);
282*cdf0e10cSrcweir                 }
283*cdf0e10cSrcweir             }
284*cdf0e10cSrcweir             else
285*cdf0e10cSrcweir             {
286*cdf0e10cSrcweir                 // runThroughOneFileInIndex();
287*cdf0e10cSrcweir                 String sPSorPDFName = getPSorPDFNameFromIniFile(aIniFile, _sBasename);
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir                 aIniFile.close();
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir                 if (sPSorPDFName.length() > 0)
292*cdf0e10cSrcweir                 {
293*cdf0e10cSrcweir                     String sEntry = FileHelper.appendPath(_sPath, sPSorPDFName);
294*cdf0e10cSrcweir                     callEntry(sEntry, _aParam);
295*cdf0e10cSrcweir                 }
296*cdf0e10cSrcweir             }
297*cdf0e10cSrcweir         }
298*cdf0e10cSrcweir         else
299*cdf0e10cSrcweir         {
300*cdf0e10cSrcweir              assure("File '" + sIndexFile + "' doesn't exists.", aIndexFile.exists(), true);
301*cdf0e10cSrcweir         }
302*cdf0e10cSrcweir     }
303*cdf0e10cSrcweir 
304*cdf0e10cSrcweir     private String getPSorPDFNameFromIniFile(IniFile _aIniFile, String _sName)
305*cdf0e10cSrcweir     {
306*cdf0e10cSrcweir         boolean bHasPostscriptOrPDF = false;
307*cdf0e10cSrcweir         String sPSBasename = _sName + ".ps";
308*cdf0e10cSrcweir         if (_aIniFile.hasSection(sPSBasename))       // checks for Postscript
309*cdf0e10cSrcweir         {
310*cdf0e10cSrcweir             bHasPostscriptOrPDF = true;
311*cdf0e10cSrcweir         }
312*cdf0e10cSrcweir         else
313*cdf0e10cSrcweir         {
314*cdf0e10cSrcweir             sPSBasename = _sName + ".pdf";       // checks for PDF
315*cdf0e10cSrcweir             if (_aIniFile.hasSection(sPSBasename))
316*cdf0e10cSrcweir             {
317*cdf0e10cSrcweir                 bHasPostscriptOrPDF = true;
318*cdf0e10cSrcweir             }
319*cdf0e10cSrcweir         }
320*cdf0e10cSrcweir         if (bHasPostscriptOrPDF)
321*cdf0e10cSrcweir         {
322*cdf0e10cSrcweir             return sPSBasename;
323*cdf0e10cSrcweir         }
324*cdf0e10cSrcweir         return "";
325*cdf0e10cSrcweir     }
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir     public void runThroughOneFileInIndex(String _sPath, String _sBasename, ParameterHelper _aParam)
328*cdf0e10cSrcweir     {
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir     }
331*cdf0e10cSrcweir /**
332*cdf0e10cSrcweir  * Run through a given index.ini or run through a given directory,
333*cdf0e10cSrcweir  * find all postscript or pdf files.
334*cdf0e10cSrcweir  * Call the IDocument interface function call(...);
335*cdf0e10cSrcweir  * @param _aParam
336*cdf0e10cSrcweir  */
337*cdf0e10cSrcweir     public void foreachJPEGcompareWithJPEG(ParameterHelper _aParam)
338*cdf0e10cSrcweir     {
339*cdf0e10cSrcweir         // TODO: auslagern in eine function, die ein Interface annimmt.
340*cdf0e10cSrcweir         String sInputPath = _aParam.getInputPath();
341*cdf0e10cSrcweir         File aInputPath = new File(sInputPath);
342*cdf0e10cSrcweir //        if (!aInputPath.exists())
343*cdf0e10cSrcweir //        {
344*cdf0e10cSrcweir //            GlobalLogWriter.println("Error, InputPath or File in InputPath doesn't exists. Please check: '" + sInputPath + "'");
345*cdf0e10cSrcweir //            assure("Error, InputPath or File in InputPath doesn't exists. Please check: '" + sInputPath + "'", false);
346*cdf0e10cSrcweir //        }
347*cdf0e10cSrcweir         if (aInputPath.isDirectory())
348*cdf0e10cSrcweir         {
349*cdf0e10cSrcweir             // check a whole directory
350*cdf0e10cSrcweir             // a whole directory
351*cdf0e10cSrcweir             FileFilter aFileFilter = FileHelper.getFileFilterJPEG();
352*cdf0e10cSrcweir             traverseDirectory(aFileFilter, _aParam);
353*cdf0e10cSrcweir         }
354*cdf0e10cSrcweir         else
355*cdf0e10cSrcweir         {
356*cdf0e10cSrcweir             // the inputpath contains a file
357*cdf0e10cSrcweir             if (sInputPath.toLowerCase().endsWith(".ini"))
358*cdf0e10cSrcweir             {
359*cdf0e10cSrcweir                 IniFile aIniFile = new IniFile(_aParam.getInputPath());
360*cdf0e10cSrcweir                 while (aIniFile.hasMoreElements())
361*cdf0e10cSrcweir                 {
362*cdf0e10cSrcweir                     String sSection = (String)aIniFile.nextElement();
363*cdf0e10cSrcweir // TODO: not supported yet.
364*cdf0e10cSrcweir                     // callEveryPictureInIniFile(aIniFile, sSection, _aParam);
365*cdf0e10cSrcweir                 }
366*cdf0e10cSrcweir             }
367*cdf0e10cSrcweir             else
368*cdf0e10cSrcweir             {
369*cdf0e10cSrcweir                 // call for a single jpeg file
370*cdf0e10cSrcweir                 try
371*cdf0e10cSrcweir                 {
372*cdf0e10cSrcweir                     String sOutputFilename = _aParam.getOutputPath();
373*cdf0e10cSrcweir                     if (sInputPath.toLowerCase().endsWith(".jpg") ||
374*cdf0e10cSrcweir                         sInputPath.toLowerCase().endsWith(".jpeg")    )
375*cdf0e10cSrcweir                     {
376*cdf0e10cSrcweir                         checkOneFile(sInputPath, sOutputFilename, _aParam);
377*cdf0e10cSrcweir                     }
378*cdf0e10cSrcweir                     else
379*cdf0e10cSrcweir                     {
380*cdf0e10cSrcweir                         // check if there exists a ini file
381*cdf0e10cSrcweir                         String sPath = FileHelper.getPath(sInputPath);
382*cdf0e10cSrcweir                         String sBasename = FileHelper.getBasename(sInputPath);
383*cdf0e10cSrcweir 
384*cdf0e10cSrcweir                         runThroughEveryReportInIndex(sPath, sBasename, _aParam);
385*cdf0e10cSrcweir 
386*cdf0e10cSrcweir                         String sStatusRunThrough = (String)_aParam.getTestParameters().get("last_state");
387*cdf0e10cSrcweir                         String sStatusInfo = (String)_aParam.getTestParameters().get("last_info");
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir                         if (sStatusRunThrough != null &&
390*cdf0e10cSrcweir                             sStatusInfo != null )
391*cdf0e10cSrcweir                         {
392*cdf0e10cSrcweir                             // store the bad status in the <Name>.odb.ps.ini file
393*cdf0e10cSrcweir                             String sOutputPath = _aParam.getOutputPath();
394*cdf0e10cSrcweir                             String sBasenameIni = FileHelper.appendPath(sOutputPath, sBasename + ".ps.ini");
395*cdf0e10cSrcweir                             IniFile aBasenameIni = new IniFile(sBasenameIni);
396*cdf0e10cSrcweir                             aBasenameIni.insertValue("global", "state", sStatusRunThrough);
397*cdf0e10cSrcweir                             aBasenameIni.insertValue("global", "info", sStatusInfo);
398*cdf0e10cSrcweir                             aBasenameIni.close();
399*cdf0e10cSrcweir                         }
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir                     }
402*cdf0e10cSrcweir                 }
403*cdf0e10cSrcweir                 catch (OfficeException e)
404*cdf0e10cSrcweir                 {
405*cdf0e10cSrcweir                     // TODO: unhandled yet.
406*cdf0e10cSrcweir                     GlobalLogWriter.println("Warning: caught OfficeException " + e.getMessage());
407*cdf0e10cSrcweir                 }
408*cdf0e10cSrcweir             // callEntry(sInputPath, _aParam);
409*cdf0e10cSrcweir             }
410*cdf0e10cSrcweir         }
411*cdf0e10cSrcweir     }
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir 
414*cdf0e10cSrcweir /**
415*cdf0e10cSrcweir  * Run through a given index.ini or run through a given directory,
416*cdf0e10cSrcweir  * find all ini files.
417*cdf0e10cSrcweir  * Call the IDocument interface function call(...);
418*cdf0e10cSrcweir  * @param _aParam
419*cdf0e10cSrcweir  */
420*cdf0e10cSrcweir     public void foreachResultCreateHTML(ParameterHelper _aParam)
421*cdf0e10cSrcweir     {
422*cdf0e10cSrcweir         // TODO: auslagern in eine function, die ein Interface annimmt.
423*cdf0e10cSrcweir         String sInputPath = _aParam.getInputPath();
424*cdf0e10cSrcweir         File aInputPath = new File(sInputPath);
425*cdf0e10cSrcweir //        if (!aInputPath.exists())
426*cdf0e10cSrcweir //        {
427*cdf0e10cSrcweir //            GlobalLogWriter.println("Error, InputPath or File in InputPath doesn't exists. Please check: '" + sInputPath + "'");
428*cdf0e10cSrcweir //            assure("Error, InputPath or File in InputPath doesn't exists. Please check: '" + sInputPath + "'", false);
429*cdf0e10cSrcweir //        }
430*cdf0e10cSrcweir 
431*cdf0e10cSrcweir         // call for a single ini file
432*cdf0e10cSrcweir         if (sInputPath.toLowerCase().endsWith(".ini") )
433*cdf0e10cSrcweir         {
434*cdf0e10cSrcweir             callEntry(sInputPath, _aParam);
435*cdf0e10cSrcweir         }
436*cdf0e10cSrcweir         else
437*cdf0e10cSrcweir         {
438*cdf0e10cSrcweir             // check if there exists an ini file
439*cdf0e10cSrcweir             String sPath = FileHelper.getPath(sInputPath);
440*cdf0e10cSrcweir             String sBasename = FileHelper.getBasename(sInputPath);
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir             runThroughEveryReportInIndex(sPath, sBasename, _aParam);
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir             // Create a HTML page which shows locally to all files in .odb
445*cdf0e10cSrcweir             if (sInputPath.toLowerCase().endsWith(".odb"))
446*cdf0e10cSrcweir             {
447*cdf0e10cSrcweir                 String sIndexFile = FileHelper.appendPath(sPath, "index.ini");
448*cdf0e10cSrcweir                 File aIndexFile = new File(sIndexFile);
449*cdf0e10cSrcweir                 if (aIndexFile.exists())
450*cdf0e10cSrcweir                 {
451*cdf0e10cSrcweir                     IniFile aIniFile = new IniFile(sIndexFile);
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir                     if (aIniFile.hasSection(sBasename))
454*cdf0e10cSrcweir                     {
455*cdf0e10cSrcweir                         // special case for odb files
456*cdf0e10cSrcweir                         int nFileCount = aIniFile.getIntValue(sBasename, "reportcount", 0);
457*cdf0e10cSrcweir                         ArrayList<String> aList = new ArrayList<String>();
458*cdf0e10cSrcweir                         for (int i=0;i<nFileCount;i++)
459*cdf0e10cSrcweir                         {
460*cdf0e10cSrcweir                             String sValue = aIniFile.getValue(sBasename, "report" + i);
461*cdf0e10cSrcweir 
462*cdf0e10cSrcweir                             String sPSorPDFName = getPSorPDFNameFromIniFile(aIniFile, sValue);
463*cdf0e10cSrcweir                             if (sPSorPDFName.length() > 0)
464*cdf0e10cSrcweir                             {
465*cdf0e10cSrcweir                                 aList.add(sPSorPDFName);
466*cdf0e10cSrcweir                             }
467*cdf0e10cSrcweir                         }
468*cdf0e10cSrcweir                         if (aList.size() > 0)
469*cdf0e10cSrcweir                         {
470*cdf0e10cSrcweir                             // HTML output for the odb file, shows only all other documents.
471*cdf0e10cSrcweir                             HTMLResult aOutputter = new HTMLResult(sPath, sBasename + ".ps.html" );
472*cdf0e10cSrcweir                             aOutputter.header("content of DB file: " + sBasename);
473*cdf0e10cSrcweir                             aOutputter.indexSection(sBasename);
474*cdf0e10cSrcweir 
475*cdf0e10cSrcweir                             for (int i=0;i<aList.size();i++)
476*cdf0e10cSrcweir                             {
477*cdf0e10cSrcweir                                 String sPSFile = aList.get(i);
478*cdf0e10cSrcweir 
479*cdf0e10cSrcweir                                 // Read information out of the ini files
480*cdf0e10cSrcweir                                 String sIndexFile2 = FileHelper.appendPath(sPath, sPSFile + ".ini");
481*cdf0e10cSrcweir                                 IniFile aIniFile2 = new IniFile(sIndexFile2);
482*cdf0e10cSrcweir                                 String sStatusRunThrough = aIniFile2.getValue("global", "state");
483*cdf0e10cSrcweir                                 String sStatusMessage = ""; // aIniFile2.getValue("global", "info");
484*cdf0e10cSrcweir                                 aIniFile2.close();
485*cdf0e10cSrcweir 
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir                                 String sHTMLFile = sPSFile + ".html";
488*cdf0e10cSrcweir                                 aOutputter.indexLine(sHTMLFile, sPSFile, sStatusRunThrough, sStatusMessage);
489*cdf0e10cSrcweir                             }
490*cdf0e10cSrcweir                             aOutputter.close();
491*cdf0e10cSrcweir 
492*cdf0e10cSrcweir //                            String sHTMLFile = FileHelper.appendPath(sPath, sBasename + ".ps.html");
493*cdf0e10cSrcweir //                            try
494*cdf0e10cSrcweir //                            {
495*cdf0e10cSrcweir //
496*cdf0e10cSrcweir //                                FileOutputStream out2 = new FileOutputStream(sHTMLFile);
497*cdf0e10cSrcweir //                                PrintStream out = new PrintStream(out2);
498*cdf0e10cSrcweir //
499*cdf0e10cSrcweir //                                out.println("<HTML>");
500*cdf0e10cSrcweir //                                out.println("<BODY>");
501*cdf0e10cSrcweir //                                for (int i=0;i<aList.size();i++)
502*cdf0e10cSrcweir //                                {
503*cdf0e10cSrcweir //                                    // <A href="link">blah</A>
504*cdf0e10cSrcweir //                                    String sPSFile = (String)aList.get(i);
505*cdf0e10cSrcweir //                                    out.print("<A href=\"");
506*cdf0e10cSrcweir //                                    out.print(sPSFile + ".html");
507*cdf0e10cSrcweir //                                    out.print("\">");
508*cdf0e10cSrcweir //                                    out.print(sPSFile);
509*cdf0e10cSrcweir //                                    out.println("</A>");
510*cdf0e10cSrcweir //                                    out.println("<BR>");
511*cdf0e10cSrcweir //                                }
512*cdf0e10cSrcweir //                                out.println("</BODY></HTML>");
513*cdf0e10cSrcweir //                                out.close();
514*cdf0e10cSrcweir //                                out2.close();
515*cdf0e10cSrcweir //                            }
516*cdf0e10cSrcweir //                            catch (java.io.IOException e)
517*cdf0e10cSrcweir //                            {
518*cdf0e10cSrcweir //
519*cdf0e10cSrcweir //                            }
520*cdf0e10cSrcweir                         }
521*cdf0e10cSrcweir                     }
522*cdf0e10cSrcweir                     aIniFile.close();
523*cdf0e10cSrcweir                 }
524*cdf0e10cSrcweir 
525*cdf0e10cSrcweir             }
526*cdf0e10cSrcweir         }
527*cdf0e10cSrcweir     }
528*cdf0e10cSrcweir 
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir }
531