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 convwatch; 25 26 // imports 27 import java.io.File; 28 import java.io.FileFilter; 29 import java.util.ArrayList; 30 31 import com.sun.star.lang.XMultiServiceFactory; 32 33 import convwatch.DirectoryHelper; 34 import convwatch.OfficePrint; 35 import convwatch.ConvWatchException; 36 import convwatch.EnhancedComplexTestCase; 37 import convwatch.PropertyName; 38 import helper.OfficeProvider; 39 40 /** 41 * The following Complex Test will test 42 * an already created document and it's postscript output (by an older office version) 43 * with a new office version. 44 * This test use Ghostscript for the jpeg export and graphically compare tools from ImageMagick. 45 * Read the manual for more information. 46 * 47 * this is only the starter program 48 * more is found in qadevOOo/runner/convwatch/* 49 */ 50 51 public class DocumentConverter extends EnhancedComplexTestCase 52 { 53 // The first of the mandatory functions: 54 /** 55 * Return the name of the test. 56 * In this case it is the actual name of the service. 57 * @return The tested service. 58 */ getTestObjectName()59 public String getTestObjectName() { 60 return "DocumentConverter runner"; 61 } 62 63 // The second of the mandatory functions: return all test methods as an 64 // array. There is only one test function in this example. 65 /** 66 * Return all test methods. 67 * @return The test methods. 68 */ getTestMethodNames()69 public String[] getTestMethodNames() { 70 return new String[]{"convert"}; 71 } 72 73 // This test is fairly simple, so there is no need for before() or after() 74 // methods. 75 before()76 public void before() 77 { 78 // System.out.println("before()"); 79 } 80 after()81 public void after() 82 { 83 // System.out.println("after()"); 84 } 85 86 // The test method itself. 87 private String m_sInputPath = ""; 88 private String m_sReferencePath = ""; 89 private boolean m_bIncludeSubdirectories = true; 90 initMember()91 void initMember() 92 { 93 // MUST PARAMETER 94 // INPUT_PATH ---------- 95 String sINPATH = (String)param.get( PropertyName.DOC_COMPARATOR_INPUT_PATH ); 96 boolean bQuit = false; 97 String sError = ""; 98 if (sINPATH == null || sINPATH.length() == 0) 99 { 100 log.println("Please set input path (path to documents) " + PropertyName.DOC_COMPARATOR_INPUT_PATH + "=path."); 101 bQuit = true; 102 } 103 else 104 { 105 log.println("found " + PropertyName.DOC_COMPARATOR_INPUT_PATH + " " + sINPATH); 106 m_sInputPath = sINPATH; 107 } 108 109 // REFERENCE_PATH ---------- 110 String sREF = (String)param.get( PropertyName.DOC_COMPARATOR_REFERENCE_PATH ); 111 if (sREF == null || sREF.length() == 0) 112 { 113 log.println("Please set output path (path to a directory, where the references should stay) " + PropertyName.DOC_COMPARATOR_REFERENCE_PATH + "=path."); 114 bQuit = true; 115 } 116 else 117 { 118 log.println("found " + PropertyName.DOC_COMPARATOR_REFERENCE_PATH + " " + sREF); 119 m_sReferencePath = sREF; 120 } 121 122 if (bQuit == true) 123 { 124 // log.println("must quit."); 125 assure("Must quit, Parameter problems.", false); 126 } 127 128 if (m_sInputPath.startsWith("file:") || 129 m_sReferencePath.startsWith("file:")) 130 { 131 assure("We can't handle file: URL right, use system path instead.", false); 132 } 133 134 } 135 136 /** 137 * Function returns a List of software which must accessable as an external executable 138 */ mustInstalledSoftware()139 protected Object[] mustInstalledSoftware() 140 { 141 ArrayList aList = new ArrayList(); 142 // aList.add("perl -version"); 143 return aList.toArray(); 144 } 145 146 // the test ====================================================================== convert()147 public void convert() 148 { 149 GlobalLogWriter.set(log); 150 // check if all need software is installed and accessable 151 checkEnvironment(mustInstalledSoftware()); 152 153 // test_removeFirstDirectorysAndBasenameFrom(); 154 // Get the MultiServiceFactory. 155 // XMultiServiceFactory xMSF = (XMultiServiceFactory)param.getMSF(); 156 GraphicalTestArguments aGTA = getGraphicalTestArguments(); 157 if (aGTA == null) 158 { 159 assure("Must quit", false); 160 } 161 162 initMember(); 163 164 File aInputPath = new File(m_sInputPath); 165 if (aInputPath.isDirectory()) 166 { 167 String fs = System.getProperty("file.separator"); 168 169 String sRemovePath = aInputPath.getAbsolutePath(); 170 // a whole directory 171 FileFilter aFileFilter = FileHelper.getFileFilter(); 172 173 Object[] aList = DirectoryHelper.traverse(m_sInputPath, aFileFilter, aGTA.includeSubDirectories()); 174 for (int i=0;i<aList.length;i++) 175 { 176 String sEntry = (String)aList[i]; 177 178 String sNewReferencePath = m_sReferencePath + fs + FileHelper.removeFirstDirectorysAndBasenameFrom(sEntry, m_sInputPath); 179 log.println("- next file is: ------------------------------"); 180 log.println(sEntry); 181 182 if (aGTA.checkIfUsableDocumentType(sEntry)) 183 { 184 runGDC(sEntry, sNewReferencePath); 185 } 186 if (aGTA.cancelRequest()) 187 { 188 break; 189 } 190 } 191 } 192 else 193 { 194 if (aGTA.checkIfUsableDocumentType(m_sInputPath)) 195 { 196 runGDC(m_sInputPath, m_sReferencePath); 197 } 198 } 199 } 200 runGDC(String _sInputFile, String _sReferencePath)201 void runGDC(String _sInputFile, String _sReferencePath) 202 { 203 // first do a check if the reference not already exist, this is a big speedup, due to the fact, 204 // we don't need to start a new office. 205 GraphicalTestArguments aGTA_local = getGraphicalTestArguments(); 206 // if (GraphicalDifferenceCheck.isReferenceExists(_sInputFile, _sReferencePath, aGTA_local) == false) 207 // { 208 // start a fresh Office 209 OfficeProvider aProvider = null; 210 if (aGTA_local.restartOffice()) 211 { 212 aProvider = new OfficeProvider(); 213 XMultiServiceFactory xMSF = (XMultiServiceFactory) aProvider.getManager(param); 214 param.put("ServiceFactory", xMSF); 215 } 216 GraphicalTestArguments aGTA = getGraphicalTestArguments(); 217 218 if (aGTA.getOfficeProgram().toLowerCase().equals("msoffice")) 219 { 220 // ReferenceType is MSOffice 221 GlobalLogWriter.get().println("USE MSOFFICE AS EXPORT FORMAT."); 222 MSOfficePrint a = new MSOfficePrint(); 223 try 224 { 225 String sInputFileBasename = FileHelper.getBasename(_sInputFile); 226 String fs = System.getProperty("file.separator"); 227 FileHelper.makeDirectories("", _sReferencePath); 228 String sOutputFile = _sReferencePath; 229 if (sOutputFile.endsWith(fs)) 230 { 231 sOutputFile += sInputFileBasename; 232 } 233 else 234 { 235 sOutputFile += fs + sInputFileBasename; 236 } 237 238 a.storeToFileWithMSOffice(aGTA, _sInputFile, sOutputFile); 239 } 240 catch(ConvWatchCancelException e) 241 { 242 GlobalLogWriter.get().println(e.getMessage()); 243 } 244 catch(java.io.IOException e) 245 { 246 GlobalLogWriter.get().println(e.getMessage()); 247 } 248 } 249 else 250 { 251 try 252 { 253 OfficePrint.convertDocument(_sInputFile, _sReferencePath, aGTA); 254 } 255 catch(ConvWatchCancelException e) 256 { 257 assure(e.getMessage(), false); 258 } 259 catch(ConvWatchException e) 260 { 261 assure(e.getMessage(), false); 262 } 263 } 264 265 if (aGTA.restartOffice()) 266 { 267 // Office shutdown 268 aProvider.closeExistingOffice(param, true); 269 } 270 // } 271 } 272 } 273 274