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