merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / runner / convwatch / DocumentConverter.java
blob4deef41d78ca66e5852456ca55a19c2ce8c60710
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DocumentConverter.java,v $
10 * $Revision: 1.8.8.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package convwatch;
33 // imports
34 import java.io.File;
35 import java.io.FileFilter;
36 import java.util.ArrayList;
38 import com.sun.star.lang.XMultiServiceFactory;
40 import convwatch.DirectoryHelper;
41 import convwatch.OfficePrint;
42 import convwatch.ConvWatchException;
43 import convwatch.EnhancedComplexTestCase;
44 import convwatch.PropertyName;
45 import helper.OfficeProvider;
47 /**
48 * The following Complex Test will test
49 * an already created document and it's postscript output (by an older office version)
50 * with a new office version.
51 * This test use Ghostscript for the jpeg export and graphically compare tools from ImageMagick.
52 * Read the manual for more information.
54 * this is only the starter program
55 * more is found in qadevOOo/runner/convwatch/*
58 public class DocumentConverter extends EnhancedComplexTestCase
60 // The first of the mandatory functions:
61 /**
62 * Return the name of the test.
63 * In this case it is the actual name of the service.
64 * @return The tested service.
66 public String getTestObjectName() {
67 return "DocumentConverter runner";
70 // The second of the mandatory functions: return all test methods as an
71 // array. There is only one test function in this example.
72 /**
73 * Return all test methods.
74 * @return The test methods.
76 public String[] getTestMethodNames() {
77 return new String[]{"convert"};
80 // This test is fairly simple, so there is no need for before() or after()
81 // methods.
83 public void before()
85 // System.out.println("before()");
88 public void after()
90 // System.out.println("after()");
93 // The test method itself.
94 private String m_sInputPath = "";
95 private String m_sReferencePath = "";
96 private boolean m_bIncludeSubdirectories = true;
98 void initMember()
100 // MUST PARAMETER
101 // INPUT_PATH ----------
102 String sINPATH = (String)param.get( PropertyName.DOC_COMPARATOR_INPUT_PATH );
103 boolean bQuit = false;
104 String sError = "";
105 if (sINPATH == null || sINPATH.length() == 0)
107 log.println("Please set input path (path to documents) " + PropertyName.DOC_COMPARATOR_INPUT_PATH + "=path.");
108 bQuit = true;
110 else
112 log.println("found " + PropertyName.DOC_COMPARATOR_INPUT_PATH + " " + sINPATH);
113 m_sInputPath = sINPATH;
116 // REFERENCE_PATH ----------
117 String sREF = (String)param.get( PropertyName.DOC_COMPARATOR_REFERENCE_PATH );
118 if (sREF == null || sREF.length() == 0)
120 log.println("Please set output path (path to a directory, where the references should stay) " + PropertyName.DOC_COMPARATOR_REFERENCE_PATH + "=path.");
121 bQuit = true;
123 else
125 log.println("found " + PropertyName.DOC_COMPARATOR_REFERENCE_PATH + " " + sREF);
126 m_sReferencePath = sREF;
129 if (bQuit == true)
131 // log.println("must quit.");
132 assure("Must quit, Parameter problems.", false);
135 if (m_sInputPath.startsWith("file:") ||
136 m_sReferencePath.startsWith("file:"))
138 assure("We can't handle file: URL right, use system path instead.", false);
144 * Function returns a List of software which must accessable as an external executable
146 protected Object[] mustInstalledSoftware()
148 ArrayList aList = new ArrayList();
149 // aList.add("perl -version");
150 return aList.toArray();
153 // the test ======================================================================
154 public void convert()
156 GlobalLogWriter.set(log);
157 // check if all need software is installed and accessable
158 checkEnvironment(mustInstalledSoftware());
160 // test_removeFirstDirectorysAndBasenameFrom();
161 // Get the MultiServiceFactory.
162 // XMultiServiceFactory xMSF = (XMultiServiceFactory)param.getMSF();
163 GraphicalTestArguments aGTA = getGraphicalTestArguments();
164 if (aGTA == null)
166 assure("Must quit", false);
169 initMember();
171 File aInputPath = new File(m_sInputPath);
172 if (aInputPath.isDirectory())
174 String fs = System.getProperty("file.separator");
176 String sRemovePath = aInputPath.getAbsolutePath();
177 // a whole directory
178 FileFilter aFileFilter = FileHelper.getFileFilter();
180 Object[] aList = DirectoryHelper.traverse(m_sInputPath, aFileFilter, aGTA.includeSubDirectories());
181 for (int i=0;i<aList.length;i++)
183 String sEntry = (String)aList[i];
185 String sNewReferencePath = m_sReferencePath + fs + FileHelper.removeFirstDirectorysAndBasenameFrom(sEntry, m_sInputPath);
186 log.println("- next file is: ------------------------------");
187 log.println(sEntry);
189 if (aGTA.checkIfUsableDocumentType(sEntry))
191 runGDC(sEntry, sNewReferencePath);
193 if (aGTA.cancelRequest())
195 break;
199 else
201 if (aGTA.checkIfUsableDocumentType(m_sInputPath))
203 runGDC(m_sInputPath, m_sReferencePath);
208 void runGDC(String _sInputFile, String _sReferencePath)
210 // first do a check if the reference not already exist, this is a big speedup, due to the fact,
211 // we don't need to start a new office.
212 GraphicalTestArguments aGTA_local = getGraphicalTestArguments();
213 // if (GraphicalDifferenceCheck.isReferenceExists(_sInputFile, _sReferencePath, aGTA_local) == false)
214 // {
215 // start a fresh Office
216 OfficeProvider aProvider = null;
217 if (aGTA_local.restartOffice())
219 aProvider = new OfficeProvider();
220 XMultiServiceFactory xMSF = (XMultiServiceFactory) aProvider.getManager(param);
221 param.put("ServiceFactory", xMSF);
223 GraphicalTestArguments aGTA = getGraphicalTestArguments();
225 if (aGTA.getOfficeProgram().toLowerCase().equals("msoffice"))
227 // ReferenceType is MSOffice
228 GlobalLogWriter.get().println("USE MSOFFICE AS EXPORT FORMAT.");
229 MSOfficePrint a = new MSOfficePrint();
232 String sInputFileBasename = FileHelper.getBasename(_sInputFile);
233 String fs = System.getProperty("file.separator");
234 FileHelper.makeDirectories("", _sReferencePath);
235 String sOutputFile = _sReferencePath;
236 if (sOutputFile.endsWith(fs))
238 sOutputFile += sInputFileBasename;
240 else
242 sOutputFile += fs + sInputFileBasename;
245 a.storeToFileWithMSOffice(aGTA, _sInputFile, sOutputFile);
247 catch(ConvWatchCancelException e)
249 GlobalLogWriter.get().println(e.getMessage());
251 catch(java.io.IOException e)
253 GlobalLogWriter.get().println(e.getMessage());
256 else
260 OfficePrint.convertDocument(_sInputFile, _sReferencePath, aGTA);
262 catch(ConvWatchCancelException e)
264 assure(e.getMessage(), false);
266 catch(ConvWatchException e)
268 assure(e.getMessage(), false);
272 if (aGTA.restartOffice())
274 // Office shutdown
275 aProvider.closeExistingOffice(param, true);
277 // }