xref: /AOO41X/test/testuno/source/testlib/uno/SDUtil.java (revision 43a102b2d160fdbc9485ed1f9c40936b61a06131)
1e6e6073dSLiu Zhe /**************************************************************
2e6e6073dSLiu Zhe  *
3e6e6073dSLiu Zhe  * Licensed to the Apache Software Foundation (ASF) under one
4e6e6073dSLiu Zhe  * or more contributor license agreements.  See the NOTICE file
5e6e6073dSLiu Zhe  * distributed with this work for additional information
6e6e6073dSLiu Zhe  * regarding copyright ownership.  The ASF licenses this file
7e6e6073dSLiu Zhe  * to you under the Apache License, Version 2.0 (the
8e6e6073dSLiu Zhe  * "License"); you may not use this file except in compliance
9e6e6073dSLiu Zhe  * with the License.  You may obtain a copy of the License at
10e6e6073dSLiu Zhe  *
11e6e6073dSLiu Zhe  *   http://www.apache.org/licenses/LICENSE-2.0
12e6e6073dSLiu Zhe  *
13e6e6073dSLiu Zhe  * Unless required by applicable law or agreed to in writing,
14e6e6073dSLiu Zhe  * software distributed under the License is distributed on an
15e6e6073dSLiu Zhe  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16e6e6073dSLiu Zhe  * KIND, either express or implied.  See the License for the
17e6e6073dSLiu Zhe  * specific language governing permissions and limitations
18e6e6073dSLiu Zhe  * under the License.
19e6e6073dSLiu Zhe  *
20e6e6073dSLiu Zhe  *************************************************************/
21e6e6073dSLiu Zhe package testlib.uno;
22e6e6073dSLiu Zhe 
23*43a102b2SLi Feng Wang import java.util.HashMap;
24*43a102b2SLi Feng Wang 
25*43a102b2SLi Feng Wang import org.openoffice.test.common.Testspace;
26*43a102b2SLi Feng Wang 
27*43a102b2SLi Feng Wang import com.sun.star.beans.PropertyValue;
28e6e6073dSLiu Zhe import com.sun.star.container.XIndexAccess;
29e6e6073dSLiu Zhe import com.sun.star.drawing.XDrawPage;
30e6e6073dSLiu Zhe import com.sun.star.drawing.XDrawPagesSupplier;
31e6e6073dSLiu Zhe import com.sun.star.drawing.XShapes;
32*43a102b2SLi Feng Wang import com.sun.star.frame.XStorable;
33e6e6073dSLiu Zhe import com.sun.star.lang.XComponent;
34e6e6073dSLiu Zhe import com.sun.star.uno.UnoRuntime;
35e6e6073dSLiu Zhe 
36e6e6073dSLiu Zhe /**
37e6e6073dSLiu Zhe  *
38e6e6073dSLiu Zhe  *
39e6e6073dSLiu Zhe  */
40e6e6073dSLiu Zhe public class SDUtil {
41e6e6073dSLiu Zhe 
42*43a102b2SLi Feng Wang 	private static HashMap filterName = new HashMap();
43*43a102b2SLi Feng Wang 
44e6e6073dSLiu Zhe 	private SDUtil() {
45e6e6073dSLiu Zhe 
46e6e6073dSLiu Zhe 	}
47e6e6073dSLiu Zhe 
48e6e6073dSLiu Zhe 	public static Object getPageByIndex(XComponent doc, int index) throws Exception {
49e6e6073dSLiu Zhe 		XDrawPagesSupplier xDrawPagesSupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(XDrawPagesSupplier.class, doc);
50e6e6073dSLiu Zhe 		Object drawPages = xDrawPagesSupplier.getDrawPages();
51e6e6073dSLiu Zhe 		XIndexAccess xIndexedDrawPages = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, drawPages);
52e6e6073dSLiu Zhe 		return xIndexedDrawPages.getByIndex(index);
53e6e6073dSLiu Zhe 	}
54e6e6073dSLiu Zhe 
55e6e6073dSLiu Zhe 	public static Object getShapeOfPageByIndex(Object page, int index) throws Exception {
56e6e6073dSLiu Zhe 		XDrawPage xDrawPage = (XDrawPage) UnoRuntime.queryInterface(XDrawPage.class, page);
57e6e6073dSLiu Zhe 		XShapes m_xdrawShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xDrawPage);
58e6e6073dSLiu Zhe 		return m_xdrawShapes.getByIndex(index);
59e6e6073dSLiu Zhe 	}
60e6e6073dSLiu Zhe 
61*43a102b2SLi Feng Wang 	public static void saveFileAs(XComponent sdComponent, String fileName, String extName) throws Exception {
62*43a102b2SLi Feng Wang 
63*43a102b2SLi Feng Wang 		initFilterName();
64*43a102b2SLi Feng Wang 
65*43a102b2SLi Feng Wang 		String storeUrl = Testspace.getUrl("temp/" + fileName + "." + extName);
66*43a102b2SLi Feng Wang 
67*43a102b2SLi Feng Wang 		PropertyValue[] storeProps = new PropertyValue[2];
68*43a102b2SLi Feng Wang 		storeProps[0] = new PropertyValue();
69*43a102b2SLi Feng Wang 		storeProps[0].Name = "FilterName";
70*43a102b2SLi Feng Wang 		storeProps[0].Value = filterName.get(extName);
71*43a102b2SLi Feng Wang 		storeProps[1] = new PropertyValue();
72*43a102b2SLi Feng Wang 		storeProps[1].Name = "Overwrite";
73*43a102b2SLi Feng Wang 		storeProps[1].Value = new Boolean(true);
74*43a102b2SLi Feng Wang 
75*43a102b2SLi Feng Wang 		XStorable sdStorable =
76*43a102b2SLi Feng Wang 				(XStorable) UnoRuntime.queryInterface(XStorable.class, sdComponent);
77*43a102b2SLi Feng Wang 		sdStorable.storeAsURL(storeUrl, storeProps);
78*43a102b2SLi Feng Wang 	}
79*43a102b2SLi Feng Wang 
80*43a102b2SLi Feng Wang 	private static void initFilterName() throws Exception {
81*43a102b2SLi Feng Wang 		if (filterName.size() > 0) {
82*43a102b2SLi Feng Wang 			return;
83*43a102b2SLi Feng Wang 		}
84*43a102b2SLi Feng Wang 
85*43a102b2SLi Feng Wang 		filterName.put("odp", "impress8");
86*43a102b2SLi Feng Wang 		filterName.put("ppt", "MS PowerPoint 97");
87*43a102b2SLi Feng Wang 	}
88*43a102b2SLi Feng Wang 
89e6e6073dSLiu Zhe }
90