xref: /AOO42X/test/testuno/source/testlib/uno/SDUtil.java (revision 43a102b2d160fdbc9485ed1f9c40936b61a06131)
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 package testlib.uno;
22 
23 import java.util.HashMap;
24 
25 import org.openoffice.test.common.Testspace;
26 
27 import com.sun.star.beans.PropertyValue;
28 import com.sun.star.container.XIndexAccess;
29 import com.sun.star.drawing.XDrawPage;
30 import com.sun.star.drawing.XDrawPagesSupplier;
31 import com.sun.star.drawing.XShapes;
32 import com.sun.star.frame.XStorable;
33 import com.sun.star.lang.XComponent;
34 import com.sun.star.uno.UnoRuntime;
35 
36 /**
37  *
38  *
39  */
40 public class SDUtil {
41 
42     private static HashMap filterName = new HashMap();
43 
44     private SDUtil() {
45 
46     }
47 
48     public static Object getPageByIndex(XComponent doc, int index) throws Exception {
49         XDrawPagesSupplier xDrawPagesSupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(XDrawPagesSupplier.class, doc);
50         Object drawPages = xDrawPagesSupplier.getDrawPages();
51         XIndexAccess xIndexedDrawPages = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, drawPages);
52         return xIndexedDrawPages.getByIndex(index);
53     }
54 
55     public static Object getShapeOfPageByIndex(Object page, int index) throws Exception {
56         XDrawPage xDrawPage = (XDrawPage) UnoRuntime.queryInterface(XDrawPage.class, page);
57         XShapes m_xdrawShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xDrawPage);
58         return m_xdrawShapes.getByIndex(index);
59     }
60 
61     public static void saveFileAs(XComponent sdComponent, String fileName, String extName) throws Exception {
62 
63         initFilterName();
64 
65         String storeUrl = Testspace.getUrl("temp/" + fileName + "." + extName);
66 
67         PropertyValue[] storeProps = new PropertyValue[2];
68         storeProps[0] = new PropertyValue();
69         storeProps[0].Name = "FilterName";
70         storeProps[0].Value = filterName.get(extName);
71         storeProps[1] = new PropertyValue();
72         storeProps[1].Name = "Overwrite";
73         storeProps[1].Value = new Boolean(true);
74 
75         XStorable sdStorable =
76                 (XStorable) UnoRuntime.queryInterface(XStorable.class, sdComponent);
77         sdStorable.storeAsURL(storeUrl, storeProps);
78     }
79 
80     private static void initFilterName() throws Exception {
81         if (filterName.size() > 0) {
82             return;
83         }
84 
85         filterName.put("odp", "impress8");
86         filterName.put("ppt", "MS PowerPoint 97");
87     }
88 
89 }
90