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