xref: /AOO41X/test/testuno/source/fvt/uno/ffc/FFCTest.java (revision 2b9e17ed6adfef1ffc7a02da13a1b860598c6d35)
1eba4d44aSLiu Zhe /**************************************************************
2eba4d44aSLiu Zhe  *
3eba4d44aSLiu Zhe  * Licensed to the Apache Software Foundation (ASF) under one
4eba4d44aSLiu Zhe  * or more contributor license agreements.  See the NOTICE file
5eba4d44aSLiu Zhe  * distributed with this work for additional information
6eba4d44aSLiu Zhe  * regarding copyright ownership.  The ASF licenses this file
7eba4d44aSLiu Zhe  * to you under the Apache License, Version 2.0 (the
8eba4d44aSLiu Zhe  * "License"); you may not use this file except in compliance
9eba4d44aSLiu Zhe  * with the License.  You may obtain a copy of the License at
10eba4d44aSLiu Zhe  *
11eba4d44aSLiu Zhe  *   http://www.apache.org/licenses/LICENSE-2.0
12eba4d44aSLiu Zhe  *
13eba4d44aSLiu Zhe  * Unless required by applicable law or agreed to in writing,
14eba4d44aSLiu Zhe  * software distributed under the License is distributed on an
15eba4d44aSLiu Zhe  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16eba4d44aSLiu Zhe  * KIND, either express or implied.  See the License for the
17eba4d44aSLiu Zhe  * specific language governing permissions and limitations
18eba4d44aSLiu Zhe  * under the License.
19eba4d44aSLiu Zhe  */
200afc47faSDongJun Zong package fvt.uno.ffc;
21eba4d44aSLiu Zhe 
22eba4d44aSLiu Zhe import java.io.File;
23eba4d44aSLiu Zhe import java.io.FilenameFilter;
24eba4d44aSLiu Zhe import java.util.HashMap;
25eba4d44aSLiu Zhe import java.util.List;
26eba4d44aSLiu Zhe import java.util.Map;
27eba4d44aSLiu Zhe 
28eba4d44aSLiu Zhe import junit.framework.Assert;
29eba4d44aSLiu Zhe 
30eba4d44aSLiu Zhe import org.junit.After;
31eba4d44aSLiu Zhe import org.junit.Before;
32eba4d44aSLiu Zhe import org.junit.BeforeClass;
33*2b9e17edSLi Feng Wang import org.junit.Ignore;
34eba4d44aSLiu Zhe import org.junit.Rule;
35eba4d44aSLiu Zhe import org.junit.Test;
36eba4d44aSLiu Zhe import org.junit.runner.RunWith;
37eba4d44aSLiu Zhe import org.openoffice.test.OpenOffice;
38eba4d44aSLiu Zhe import org.openoffice.test.common.FileProvider;
39eba4d44aSLiu Zhe import org.openoffice.test.common.FileProvider.FileRepos;
40eba4d44aSLiu Zhe import org.openoffice.test.common.FileUtil;
41eba4d44aSLiu Zhe import org.openoffice.test.common.Logger;
42eba4d44aSLiu Zhe import org.openoffice.test.common.SystemUtil;
43eba4d44aSLiu Zhe import org.openoffice.test.common.Testspace;
44eba4d44aSLiu Zhe import org.openoffice.test.uno.UnoApp;
45eba4d44aSLiu Zhe 
46eba4d44aSLiu Zhe import com.sun.star.beans.PropertyValue;
47eba4d44aSLiu Zhe import com.sun.star.document.MacroExecMode;
48eba4d44aSLiu Zhe import com.sun.star.frame.XComponentLoader;
49eba4d44aSLiu Zhe import com.sun.star.frame.XStorable;
50eba4d44aSLiu Zhe import com.sun.star.io.IOException;
51eba4d44aSLiu Zhe import com.sun.star.lang.IllegalArgumentException;
52eba4d44aSLiu Zhe import com.sun.star.lang.XComponent;
53eba4d44aSLiu Zhe import com.sun.star.uno.UnoRuntime;
54eba4d44aSLiu Zhe /**
55eba4d44aSLiu Zhe  * Pls place a suite file in directory "suite" which is same level with test uno. like bewlow
56eba4d44aSLiu Zhe  * -suite
57eba4d44aSLiu Zhe  * -testuno
58eba4d44aSLiu Zhe  * The suite file content is like this format
59eba4d44aSLiu Zhe  * ftp://user:password@192.168.0.1/public/sample/testsample.doc
60eba4d44aSLiu Zhe  * ..
61eba4d44aSLiu Zhe  * ..
62eba4d44aSLiu Zhe  * ftp://user:password@192.168.0.1/public/sample/testsample2.doc
63eba4d44aSLiu Zhe  *This script is used to test FFC by UNO API
64eba4d44aSLiu Zhe  *It cover below scenario:
65eba4d44aSLiu Zhe  *MS2003/2010 format->ODF format
66eba4d44aSLiu Zhe  *New Saved ODF Format file -> MS 2003 Format
67eba4d44aSLiu Zhe  *New Saved ODF Format file -> PDF
68eba4d44aSLiu Zhe  *
69eba4d44aSLiu Zhe  */
70*2b9e17edSLi Feng Wang @RunWith(FileProvider.class)
71eba4d44aSLiu Zhe public class FFCTest {
72eba4d44aSLiu Zhe 	@Rule
73eba4d44aSLiu Zhe 	public Logger log = Logger.getLogger(this, false);
74eba4d44aSLiu Zhe 
754da5b138SDongJun Zong 
764da5b138SDongJun Zong 	private static  UnoApp app = null;
77eba4d44aSLiu Zhe 	private static Map<String, String> filterMap = new HashMap<String, String>();
78eba4d44aSLiu Zhe 	@FileRepos
79*2b9e17edSLi Feng Wang 	public static String suiteDir = "../suite/";
80eba4d44aSLiu Zhe 	private String fileURL = "";
81eba4d44aSLiu Zhe 	private String operateFilePath = "";
82eba4d44aSLiu Zhe 	private static Map<String, String> formatMap = new HashMap<String, String>();
83eba4d44aSLiu Zhe 	private static File testSpaceFile = Testspace.getFile();
84eba4d44aSLiu Zhe 	private boolean isSucceed = false;
85eba4d44aSLiu Zhe 	private static String  tempFolder = testSpaceFile.getAbsolutePath() + File.separator + "temp";
86eba4d44aSLiu Zhe 
87*2b9e17edSLi Feng Wang 	private static String failedFilesDir  = "output/failedSampleFiles/";
88eba4d44aSLiu Zhe //	@Parameters
89eba4d44aSLiu Zhe //	public static Collection<String[]>  data() throws Exception{
90eba4d44aSLiu Zhe //		initMap();
91eba4d44aSLiu Zhe //		ArrayList<String[]> list = new ArrayList<String[]>();
92eba4d44aSLiu Zhe //		List<String> suitePathList = new ArrayList<String>();
93eba4d44aSLiu Zhe //		FileReader fileReader = null;
94eba4d44aSLiu Zhe //		BufferedReader reader = null;
95eba4d44aSLiu Zhe //		File suites = new File(suiteDir);
96eba4d44aSLiu Zhe //		if (suites.exists() && suites.list().length > 0) {
97eba4d44aSLiu Zhe //			isSuiteFileExist = true;
98eba4d44aSLiu Zhe //			for(File file: suites.listFiles()){
99eba4d44aSLiu Zhe //				if(FileUtil.getFileExtName(file.getName()).toLowerCase().equals("suite")){
100eba4d44aSLiu Zhe //					suitePathList.add(file.getAbsolutePath());
101eba4d44aSLiu Zhe //				}
102eba4d44aSLiu Zhe //			}
103eba4d44aSLiu Zhe //			try{
104eba4d44aSLiu Zhe //				for (String suitePath : suitePathList) {
105eba4d44aSLiu Zhe //					fileReader = new FileReader(suitePath);
106eba4d44aSLiu Zhe //					reader = new BufferedReader(fileReader);
107eba4d44aSLiu Zhe //					String line = null;
108eba4d44aSLiu Zhe //					while((line = reader.readLine()) != null){
109eba4d44aSLiu Zhe //						if (!"".equals(line)) {
110eba4d44aSLiu Zhe //							list.add(new String[]{line});
111eba4d44aSLiu Zhe //						}
112eba4d44aSLiu Zhe //					}
113eba4d44aSLiu Zhe //					if(reader != null){
114eba4d44aSLiu Zhe //						reader.close();
115eba4d44aSLiu Zhe //						reader = null;
116eba4d44aSLiu Zhe //					}
117eba4d44aSLiu Zhe //					if(fileReader != null){
118eba4d44aSLiu Zhe //						fileReader.close();
119eba4d44aSLiu Zhe //						fileReader = null;
120eba4d44aSLiu Zhe //					}
121eba4d44aSLiu Zhe //				}
122eba4d44aSLiu Zhe //
123eba4d44aSLiu Zhe //			}catch(Exception e){
124eba4d44aSLiu Zhe //				throw new Exception("throw exception when read suite file. " + e.getMessage());
125eba4d44aSLiu Zhe //			}finally{
126eba4d44aSLiu Zhe //				try{
127eba4d44aSLiu Zhe //					if(reader != null){
128eba4d44aSLiu Zhe //						reader.close();
129eba4d44aSLiu Zhe //						reader = null;
130eba4d44aSLiu Zhe //					}
131eba4d44aSLiu Zhe //					if(fileReader != null){
132eba4d44aSLiu Zhe //						fileReader.close();
133eba4d44aSLiu Zhe //						fileReader = null;
134eba4d44aSLiu Zhe //					}
135eba4d44aSLiu Zhe //				}catch(Exception io){
136eba4d44aSLiu Zhe //				}
137eba4d44aSLiu Zhe //			}
138eba4d44aSLiu Zhe //		} else {// run files from ffc data directory
139eba4d44aSLiu Zhe //			File ffcDataHome = new File("data\\ffc");
140eba4d44aSLiu Zhe //			getFileList(ffcDataHome, list);
141eba4d44aSLiu Zhe //		}
142eba4d44aSLiu Zhe //
143eba4d44aSLiu Zhe //		return list;
144eba4d44aSLiu Zhe //	}
145eba4d44aSLiu Zhe //
146eba4d44aSLiu Zhe 	public static void getFileList(File dir, List<String[]> list) {
147eba4d44aSLiu Zhe 		File[] files = dir.listFiles(new FilenameFilter() {
148eba4d44aSLiu Zhe 			@Override
149eba4d44aSLiu Zhe 			public boolean accept(File dir, String name) {
150eba4d44aSLiu Zhe 				File file =  new File(dir.getAbsolutePath() + File.separator + name);
151eba4d44aSLiu Zhe 				String filename = new File(name).getName().toLowerCase();
152eba4d44aSLiu Zhe 				boolean accept;
153eba4d44aSLiu Zhe 				if (file.isDirectory()) {
154eba4d44aSLiu Zhe 					accept = true;
155eba4d44aSLiu Zhe 				} else {
156eba4d44aSLiu Zhe 					accept =  filename.endsWith(".docx")
157eba4d44aSLiu Zhe 					|| filename.endsWith(".pptx")
158eba4d44aSLiu Zhe 					|| filename.endsWith(".xlsx")
159eba4d44aSLiu Zhe 					|| filename.endsWith(".ppt")
160eba4d44aSLiu Zhe 					|| filename.endsWith(".xls")
161eba4d44aSLiu Zhe 					|| 	filename.endsWith(".doc") ;
162eba4d44aSLiu Zhe 				}
163eba4d44aSLiu Zhe 
164eba4d44aSLiu Zhe 				return accept;
165eba4d44aSLiu Zhe 			}
166eba4d44aSLiu Zhe 
167eba4d44aSLiu Zhe 		});
168eba4d44aSLiu Zhe 		if (files == null)
169eba4d44aSLiu Zhe 			return;
170eba4d44aSLiu Zhe 
171eba4d44aSLiu Zhe 		for (File file : files) {
172eba4d44aSLiu Zhe 			if (file.isDirectory()) {
173eba4d44aSLiu Zhe 				getFileList(file, list);
174eba4d44aSLiu Zhe 			} else {
175eba4d44aSLiu Zhe 				list.add(new String[] {file.getAbsolutePath().replace(dir.getParentFile().getAbsolutePath(), "").replace("\\", "/")});
176eba4d44aSLiu Zhe 
177eba4d44aSLiu Zhe 			}
178eba4d44aSLiu Zhe 		}
179eba4d44aSLiu Zhe 	}
180eba4d44aSLiu Zhe 
181eba4d44aSLiu Zhe 	public FFCTest(String url) {
182eba4d44aSLiu Zhe 		this.fileURL = url;
183eba4d44aSLiu Zhe 	}
184eba4d44aSLiu Zhe 
185eba4d44aSLiu Zhe 	@BeforeClass
186eba4d44aSLiu Zhe 	public static void init() {
187eba4d44aSLiu Zhe 		initMap();
1884da5b138SDongJun Zong 
189eba4d44aSLiu Zhe 		//Disable automation
1904da5b138SDongJun Zong 
1914da5b138SDongJun Zong 		OpenOffice defaultOpenOffice = new OpenOffice();
1924da5b138SDongJun Zong 		defaultOpenOffice.addArgs("-nofirststartwizard", "-norestore", "-quickstart=no");
1934da5b138SDongJun Zong 		defaultOpenOffice.setUnoUrl(OpenOffice.DEFAULT_UNO_URL);
1944da5b138SDongJun Zong 		defaultOpenOffice.addArgs("-invisible", "-conversionmode", "-headless", "-hidemenu");
1954da5b138SDongJun Zong 		app = new UnoApp(defaultOpenOffice);
196eba4d44aSLiu Zhe 
197eba4d44aSLiu Zhe 		File failedDirec = Testspace.getFile(failedFilesDir);
198eba4d44aSLiu Zhe 		failedDirec.mkdirs();
199eba4d44aSLiu Zhe 	}
200eba4d44aSLiu Zhe 
201eba4d44aSLiu Zhe 	@Before
202eba4d44aSLiu Zhe 	public void setUp() throws Exception {
203eba4d44aSLiu Zhe 		operateFilePath =  Testspace.prepareData(fileURL);
204eba4d44aSLiu Zhe 
205916c15c1SDongJun Zong 
206eba4d44aSLiu Zhe 		app.start();
207eba4d44aSLiu Zhe 	}
208eba4d44aSLiu Zhe 	@After
209eba4d44aSLiu Zhe 	public void tearDown() throws Exception {
210eba4d44aSLiu Zhe 		if (!isSucceed) {
211eba4d44aSLiu Zhe 			FileUtil.copyFile(operateFilePath, Testspace.getFile(failedFilesDir).getAbsolutePath());
212eba4d44aSLiu Zhe 			FileUtil.appendStringToFile( Testspace.getFile(failedFilesDir + File.separator + "failedFiles.files").getAbsolutePath(), fileURL +"\r\n");
213eba4d44aSLiu Zhe 			app.close();
214eba4d44aSLiu Zhe 			SystemUtil.killProcess("WerFault.*");
215eba4d44aSLiu Zhe 			SystemUtil.sleep(2);
216eba4d44aSLiu Zhe 			SystemUtil.killProcess("EQNEDT32.*");
217eba4d44aSLiu Zhe 			//WerFault.exe
218eba4d44aSLiu Zhe 			//EQNEDT32.EXE
219eba4d44aSLiu Zhe 		}
220eba4d44aSLiu Zhe 	}
221eba4d44aSLiu Zhe 
222eba4d44aSLiu Zhe 
223eba4d44aSLiu Zhe 
224*2b9e17edSLi Feng Wang 	@Test(timeout=1000*60*10)
225*2b9e17edSLi Feng Wang 	@Ignore
226*2b9e17edSLi Feng Wang 	public void exportTest() throws Exception {
227*2b9e17edSLi Feng Wang 		//MS Office Format ->ODF
228*2b9e17edSLi Feng Wang 		boolean flag = false;
229*2b9e17edSLi Feng Wang 
230*2b9e17edSLi Feng Wang 		String saveAsODF = exportAsODF(operateFilePath);
231*2b9e17edSLi Feng Wang 		System.out.println("MS ->ODF finished");
232*2b9e17edSLi Feng Wang 		//ODF->MS
233*2b9e17edSLi Feng Wang 		String savedMSFilePath = exportAsODF(saveAsODF);
234*2b9e17edSLi Feng Wang 		File savedMSFile = new File(savedMSFilePath);
235*2b9e17edSLi Feng Wang 		Assert.assertTrue("FFC Test for file : "+ savedMSFilePath, savedMSFile.exists());
236*2b9e17edSLi Feng Wang 		System.out.println("ODF->MS Finished");
237*2b9e17edSLi Feng Wang 
238*2b9e17edSLi Feng Wang 
239*2b9e17edSLi Feng Wang 		//Export ODF->PDF
240*2b9e17edSLi Feng Wang 		exportAsPDF(saveAsODF);
241*2b9e17edSLi Feng Wang 		System.out.println("ODF->PDF Finished");
242*2b9e17edSLi Feng Wang 		flag = true;
243*2b9e17edSLi Feng Wang 		Assert.assertTrue("FFC Test for file : "+ operateFilePath, flag);
244*2b9e17edSLi Feng Wang 		isSucceed = true;
245*2b9e17edSLi Feng Wang 	}
246eba4d44aSLiu Zhe 	private String getSuffix(String file) {
247eba4d44aSLiu Zhe 		String lowerCaseName = file.toLowerCase();
248eba4d44aSLiu Zhe 		String suffix = lowerCaseName.substring(lowerCaseName.lastIndexOf("."));
249eba4d44aSLiu Zhe 		return suffix;
250eba4d44aSLiu Zhe 	}
251eba4d44aSLiu Zhe 	/**
252916c15c1SDongJun Zong 	 * return the Export ODF file path
253eba4d44aSLiu Zhe 	 * @throws IOException
254eba4d44aSLiu Zhe 	 * @throws IllegalArgumentException
255eba4d44aSLiu Zhe 	 */
256eba4d44aSLiu Zhe 	private String exportAsODF(String testFile) throws IOException, IllegalArgumentException {
257eba4d44aSLiu Zhe 		XComponent document = loadSampleFile(testFile);
258916c15c1SDongJun Zong 		try {
259916c15c1SDongJun Zong 			Thread.sleep(2000);
260916c15c1SDongJun Zong 		} catch (InterruptedException e) {
261916c15c1SDongJun Zong 			e.printStackTrace();
262916c15c1SDongJun Zong 		}
263eba4d44aSLiu Zhe 		String suffix = getSuffix(testFile);
264eba4d44aSLiu Zhe 		String filterName = filterMap.get(suffix);
265eba4d44aSLiu Zhe 		PropertyValue[] lProperties = null;
266eba4d44aSLiu Zhe 		lProperties = new PropertyValue[3];
267eba4d44aSLiu Zhe 		lProperties[0] = new PropertyValue();
268eba4d44aSLiu Zhe 		lProperties[0].Name = "FilterName";
269eba4d44aSLiu Zhe 		lProperties[0].Value = filterName;
270eba4d44aSLiu Zhe 		lProperties[1] = new PropertyValue();
271eba4d44aSLiu Zhe 		lProperties[1].Name = "Overwrite";
272eba4d44aSLiu Zhe 		lProperties[1].Value = Boolean.TRUE;
273eba4d44aSLiu Zhe 		lProperties[2] = new PropertyValue();
274eba4d44aSLiu Zhe 		lProperties[2].Name = "AsyncMode";
275eba4d44aSLiu Zhe 		lProperties[2].Value = new Boolean(false);
276eba4d44aSLiu Zhe 
277eba4d44aSLiu Zhe 		XStorable store = (XStorable) UnoRuntime.queryInterface(XStorable.class, document);
278eba4d44aSLiu Zhe 		File file = new File(testFile);
279eba4d44aSLiu Zhe 		String fileName = file.getName();
280eba4d44aSLiu Zhe 		String saveAsFilePath = file.getParentFile().getAbsolutePath() + File.separator + fileName + "." + formatMap.get(suffix);//TODO
281eba4d44aSLiu Zhe 		store.storeAsURL(Testspace.getUrl(saveAsFilePath), lProperties);
282916c15c1SDongJun Zong 		try {
283916c15c1SDongJun Zong 			Thread.sleep(3000);
284916c15c1SDongJun Zong 		} catch (InterruptedException e) {
285916c15c1SDongJun Zong 			e.printStackTrace();
286916c15c1SDongJun Zong 		}
287eba4d44aSLiu Zhe 		app.closeDocument(document);
288916c15c1SDongJun Zong 		try {
289916c15c1SDongJun Zong 			Thread.sleep(2000);
290916c15c1SDongJun Zong 		} catch (InterruptedException e) {
291916c15c1SDongJun Zong 			e.printStackTrace();
292916c15c1SDongJun Zong 		}
293eba4d44aSLiu Zhe 		return saveAsFilePath;
294eba4d44aSLiu Zhe 	}
295eba4d44aSLiu Zhe 
296eba4d44aSLiu Zhe 	private void exportAsPDF(String testFilePath) throws Exception {
297eba4d44aSLiu Zhe 		XComponent xComponent = loadSampleFile(testFilePath);
298eba4d44aSLiu Zhe 		XStorable xStorable = (XStorable) UnoRuntime.queryInterface(
299eba4d44aSLiu Zhe 				XStorable.class, xComponent);
300eba4d44aSLiu Zhe 
301eba4d44aSLiu Zhe 		PropertyValue[] aMediaDescriptor = new PropertyValue[1];
302eba4d44aSLiu Zhe 		aMediaDescriptor[0] = new PropertyValue();
303eba4d44aSLiu Zhe 		aMediaDescriptor[0].Name = "FilterName";
304eba4d44aSLiu Zhe 		aMediaDescriptor[0].Value = "writer_pdf_Export";
305eba4d44aSLiu Zhe 		File file = new File(testFilePath);
306eba4d44aSLiu Zhe 		String fileName = file.getName();
307eba4d44aSLiu Zhe 		String saveAsFilePath =  file.getParentFile().getAbsolutePath() + File.separator + fileName + ".pdf" ;
308eba4d44aSLiu Zhe 		// export to pdf
309eba4d44aSLiu Zhe 		xStorable.storeToURL(Testspace.getUrl(saveAsFilePath), aMediaDescriptor);
310916c15c1SDongJun Zong 		try {
311916c15c1SDongJun Zong 			Thread.sleep(5000);
312916c15c1SDongJun Zong 		} catch (InterruptedException e) {
313916c15c1SDongJun Zong 			e.printStackTrace();
314916c15c1SDongJun Zong 		}
315eba4d44aSLiu Zhe 		// close this document
316eba4d44aSLiu Zhe 		app.closeDocument(xComponent);
317eba4d44aSLiu Zhe 		File pdfFile = new File(saveAsFilePath);
318eba4d44aSLiu Zhe 		Assert.assertTrue("Verify sampe file " + testFilePath + " exprot to pdf!", pdfFile.exists());
319eba4d44aSLiu Zhe 	}
320eba4d44aSLiu Zhe 
321eba4d44aSLiu Zhe 	public static void initMap() {
322eba4d44aSLiu Zhe 		filterMap.put(".doc", "writer8");
323eba4d44aSLiu Zhe 		filterMap.put(".docx", "writer8");
324eba4d44aSLiu Zhe 		filterMap.put(".odt", "MS Word 97");
325eba4d44aSLiu Zhe 		filterMap.put(".ppt", "impress8");
326eba4d44aSLiu Zhe 		filterMap.put(".pptx", "impress8");
327eba4d44aSLiu Zhe 		filterMap.put(".odp", "MS PowerPoint 97");
328eba4d44aSLiu Zhe 		filterMap.put(".xls", "calc8");
329eba4d44aSLiu Zhe 		filterMap.put(".xlsx", "calc8");
330eba4d44aSLiu Zhe 		filterMap.put(".ods", "MS Excel 97");
331eba4d44aSLiu Zhe 
332eba4d44aSLiu Zhe 		formatMap.put(".doc", "odt");
333eba4d44aSLiu Zhe 		formatMap.put(".docx", "odt");
334eba4d44aSLiu Zhe 		formatMap.put(".odt", "doc");
335eba4d44aSLiu Zhe 
336eba4d44aSLiu Zhe 		formatMap.put(".ppt", "odp");
337eba4d44aSLiu Zhe 		formatMap.put(".pptx", "odp");
338eba4d44aSLiu Zhe 		formatMap.put(".odp", "ppt");
339eba4d44aSLiu Zhe 
340eba4d44aSLiu Zhe 		formatMap.put(".xls", "ods");
341eba4d44aSLiu Zhe 		formatMap.put(".xlsx", "ods");
342eba4d44aSLiu Zhe 		formatMap.put(".ods", "xls");
343eba4d44aSLiu Zhe 	}
344eba4d44aSLiu Zhe 	private XComponent loadSampleFile(String filePath) throws IOException, IllegalArgumentException {
345eba4d44aSLiu Zhe 		if (!"".equals(filePath)) {
346eba4d44aSLiu Zhe 			PropertyValue[] loadProps = null;
347eba4d44aSLiu Zhe 			if (filePath.endsWith("x")) {//ooxml sample file
348eba4d44aSLiu Zhe 				loadProps = new PropertyValue[4];
349eba4d44aSLiu Zhe 				loadProps[0] = new PropertyValue();
350eba4d44aSLiu Zhe 				loadProps[0].Name = "Hidden";
351eba4d44aSLiu Zhe 				loadProps[0].Value = Boolean.TRUE;
352eba4d44aSLiu Zhe 				loadProps[1] = new PropertyValue();
353eba4d44aSLiu Zhe 				loadProps[1].Name = "FilterName";
354eba4d44aSLiu Zhe 				String filePathLowCase = filePath.toLowerCase();
355eba4d44aSLiu Zhe 				if(filePathLowCase.endsWith("docx")) {
356eba4d44aSLiu Zhe 					loadProps[1].Value = "MS Word 2007 XML";
357eba4d44aSLiu Zhe 				}
358eba4d44aSLiu Zhe 				if(filePathLowCase.endsWith("pptx")){
359eba4d44aSLiu Zhe 					loadProps[1].Value = "MS PowerPoint 2007 XML";
360eba4d44aSLiu Zhe 				}
361eba4d44aSLiu Zhe 				if(filePathLowCase.endsWith("xlsx")) {
362eba4d44aSLiu Zhe 					loadProps[1].Value = "MS Excel 2007 XML";
363eba4d44aSLiu Zhe 				}
364eba4d44aSLiu Zhe 				loadProps[2] = new PropertyValue();
365eba4d44aSLiu Zhe 				loadProps[2].Name = "ReadOnly";
366eba4d44aSLiu Zhe 				loadProps[2].Value = true;
367eba4d44aSLiu Zhe 				loadProps[3] = new PropertyValue();
368eba4d44aSLiu Zhe 				loadProps[3].Name = "MacroExecutionMode";
369eba4d44aSLiu Zhe 				loadProps[3].Value = MacroExecMode.NEVER_EXECUTE;
370eba4d44aSLiu Zhe 			} else {
371eba4d44aSLiu Zhe 				loadProps = new PropertyValue[3];
372eba4d44aSLiu Zhe 				loadProps[0] = new PropertyValue();
373eba4d44aSLiu Zhe 				loadProps[0].Name = "Hidden";
374eba4d44aSLiu Zhe 				loadProps[0].Value = Boolean.TRUE;
375eba4d44aSLiu Zhe 				loadProps[1] = new PropertyValue();
376eba4d44aSLiu Zhe 				loadProps[1].Name = "ReadOnly";
377eba4d44aSLiu Zhe 				loadProps[1].Value = Boolean.TRUE;
378eba4d44aSLiu Zhe 				loadProps[2] = new PropertyValue();
379eba4d44aSLiu Zhe 				loadProps[2].Name = "AsyncMode";
380eba4d44aSLiu Zhe 				loadProps[2].Value = new Boolean(false);
381eba4d44aSLiu Zhe 			}
382eba4d44aSLiu Zhe 
383eba4d44aSLiu Zhe 			String urlPath = Testspace.getUrl(filePath);
384eba4d44aSLiu Zhe 			XComponentLoader componentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, app.getDesktop());
385eba4d44aSLiu Zhe 			return componentLoader.loadComponentFromURL(urlPath, "_blank", 0, loadProps);
386eba4d44aSLiu Zhe 		}
387eba4d44aSLiu Zhe 		return null;
388eba4d44aSLiu Zhe 	}
389eba4d44aSLiu Zhe 	/**
390eba4d44aSLiu Zhe 	 * the url is like this format:
391eba4d44aSLiu Zhe 	 * ftp://user:password@192.168.0.1/public/sample/testsample.doc
392eba4d44aSLiu Zhe 	 * @param url
393eba4d44aSLiu Zhe 	 * @return
394eba4d44aSLiu Zhe 	 */
395eba4d44aSLiu Zhe 	public String downloadFile(String url) {
396eba4d44aSLiu Zhe 		File urlFile = new File( new File(url.replaceAll("%20", " ")).getName());
397eba4d44aSLiu Zhe 
398eba4d44aSLiu Zhe 		File tempFolderFile = new File(tempFolder);
399eba4d44aSLiu Zhe 		if (!tempFolderFile.exists()) {
400eba4d44aSLiu Zhe 			tempFolderFile.mkdir();
401eba4d44aSLiu Zhe 		}
402eba4d44aSLiu Zhe 		String testFile = testSpaceFile.getAbsolutePath() + File.separator + "temp" + File.separator + urlFile.getName();
403eba4d44aSLiu Zhe 		FileUtil.download(url, new File(testFile));
404eba4d44aSLiu Zhe 		return testFile;
405eba4d44aSLiu Zhe 	}
406eba4d44aSLiu Zhe 
407eba4d44aSLiu Zhe 
408eba4d44aSLiu Zhe 
409eba4d44aSLiu Zhe }
410