1970a06e3SLiu Zhe /**************************************************************
22d72893bSLiu Zhe  *
3970a06e3SLiu Zhe  * Licensed to the Apache Software Foundation (ASF) under one
4970a06e3SLiu Zhe  * or more contributor license agreements.  See the NOTICE file
5970a06e3SLiu Zhe  * distributed with this work for additional information
6970a06e3SLiu Zhe  * regarding copyright ownership.  The ASF licenses this file
7970a06e3SLiu Zhe  * to you under the Apache License, Version 2.0 (the
8970a06e3SLiu Zhe  * "License"); you may not use this file except in compliance
9970a06e3SLiu Zhe  * with the License.  You may obtain a copy of the License at
10970a06e3SLiu Zhe  *
11970a06e3SLiu Zhe  *   http://www.apache.org/licenses/LICENSE-2.0
12970a06e3SLiu Zhe  *
13970a06e3SLiu Zhe  * Unless required by applicable law or agreed to in writing,
14970a06e3SLiu Zhe  * software distributed under the License is distributed on an
15970a06e3SLiu Zhe  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16970a06e3SLiu Zhe  * KIND, either express or implied.  See the License for the
17970a06e3SLiu Zhe  * specific language governing permissions and limitations
18970a06e3SLiu Zhe  * under the License.
19970a06e3SLiu Zhe  *
20970a06e3SLiu Zhe  *************************************************************/
212d72893bSLiu Zhe package testlib.uno;
222d72893bSLiu 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;
282d72893bSLiu Zhe import com.sun.star.container.XIndexAccess;
292d72893bSLiu Zhe import com.sun.star.drawing.XDrawPage;
302d72893bSLiu Zhe import com.sun.star.drawing.XDrawPagesSupplier;
312d72893bSLiu Zhe import com.sun.star.drawing.XShapes;
32*43a102b2SLi Feng Wang import com.sun.star.frame.XStorable;
332d72893bSLiu Zhe import com.sun.star.lang.XComponent;
342d72893bSLiu Zhe import com.sun.star.uno.UnoRuntime;
352d72893bSLiu Zhe 
362d72893bSLiu Zhe /**
372d72893bSLiu Zhe  *
382d72893bSLiu Zhe  *
392d72893bSLiu Zhe  */
40f0480a3dSLiu Zhe public class SDUtil {
412d72893bSLiu Zhe 
42*43a102b2SLi Feng Wang 	private static HashMap filterName = new HashMap();
43*43a102b2SLi Feng Wang 
443908dc91SLiu Zhe 	private SDUtil() {
453908dc91SLiu Zhe 
462d72893bSLiu Zhe 	}
472d72893bSLiu Zhe 
483908dc91SLiu Zhe 	public static Object getPageByIndex(XComponent doc, int index) throws Exception {
493908dc91SLiu Zhe 		XDrawPagesSupplier xDrawPagesSupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(XDrawPagesSupplier.class, doc);
503908dc91SLiu Zhe 		Object drawPages = xDrawPagesSupplier.getDrawPages();
513908dc91SLiu Zhe 		XIndexAccess xIndexedDrawPages = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, drawPages);
523908dc91SLiu Zhe 		return xIndexedDrawPages.getByIndex(index);
532d72893bSLiu Zhe 	}
543908dc91SLiu Zhe 
553908dc91SLiu Zhe 	public static Object getShapeOfPageByIndex(Object page, int index) throws Exception {
563908dc91SLiu Zhe 		XDrawPage xDrawPage = (XDrawPage) UnoRuntime.queryInterface(XDrawPage.class, page);
573908dc91SLiu Zhe 		XShapes m_xdrawShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xDrawPage);
583908dc91SLiu Zhe 		return m_xdrawShapes.getByIndex(index);
592d72893bSLiu Zhe 	}
60*43a102b2SLi Feng Wang 
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 	}
882d72893bSLiu Zhe 
892d72893bSLiu Zhe }
90