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 2343a102b2SLi Feng Wang import java.util.HashMap; 2443a102b2SLi Feng Wang 2543a102b2SLi Feng Wang import org.openoffice.test.common.Testspace; 2643a102b2SLi Feng Wang 2743a102b2SLi 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; 31*28725c19SLi Feng Wang import com.sun.star.drawing.XShape; 322d72893bSLiu Zhe import com.sun.star.drawing.XShapes; 3343a102b2SLi Feng Wang import com.sun.star.frame.XStorable; 342d72893bSLiu Zhe import com.sun.star.lang.XComponent; 35*28725c19SLi Feng Wang import com.sun.star.uno.Exception; 362d72893bSLiu Zhe import com.sun.star.uno.UnoRuntime; 372d72893bSLiu Zhe 382d72893bSLiu Zhe /** 392d72893bSLiu Zhe * 402d72893bSLiu Zhe * 412d72893bSLiu Zhe */ 42f0480a3dSLiu Zhe public class SDUtil { 432d72893bSLiu Zhe 4443a102b2SLi Feng Wang private static HashMap filterName = new HashMap(); 4543a102b2SLi Feng Wang SDUtil()463908dc91SLiu Zhe private SDUtil() { 473908dc91SLiu Zhe 482d72893bSLiu Zhe } 492d72893bSLiu Zhe getPageByIndex(XComponent doc, int index)503908dc91SLiu Zhe public static Object getPageByIndex(XComponent doc, int index) throws Exception { 513908dc91SLiu Zhe XDrawPagesSupplier xDrawPagesSupplier = (XDrawPagesSupplier) UnoRuntime.queryInterface(XDrawPagesSupplier.class, doc); 523908dc91SLiu Zhe Object drawPages = xDrawPagesSupplier.getDrawPages(); 533908dc91SLiu Zhe XIndexAccess xIndexedDrawPages = (XIndexAccess) UnoRuntime.queryInterface(XIndexAccess.class, drawPages); 543908dc91SLiu Zhe return xIndexedDrawPages.getByIndex(index); 552d72893bSLiu Zhe } 563908dc91SLiu Zhe getShapeOfPageByIndex(Object page, int index)573908dc91SLiu Zhe public static Object getShapeOfPageByIndex(Object page, int index) throws Exception { 583908dc91SLiu Zhe XDrawPage xDrawPage = (XDrawPage) UnoRuntime.queryInterface(XDrawPage.class, page); 593908dc91SLiu Zhe XShapes m_xdrawShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xDrawPage); 603908dc91SLiu Zhe return m_xdrawShapes.getByIndex(index); 612d72893bSLiu Zhe } 6243a102b2SLi Feng Wang getShapesOfPageByType(XDrawPage xDrawPage, String shapeType)63*28725c19SLi Feng Wang public static Object[] getShapesOfPageByType(XDrawPage xDrawPage, String shapeType) throws Exception { 64*28725c19SLi Feng Wang XShapes m_xdrawShapes = (XShapes) UnoRuntime.queryInterface(XShapes.class, xDrawPage); 65*28725c19SLi Feng Wang int count = m_xdrawShapes.getCount(); 66*28725c19SLi Feng Wang Object[] temp = new Object[count]; 67*28725c19SLi Feng Wang int shapeNum=0; 68*28725c19SLi Feng Wang for(int i=0;i<count; i++) 69*28725c19SLi Feng Wang { 70*28725c19SLi Feng Wang Object shape = m_xdrawShapes.getByIndex(i); 71*28725c19SLi Feng Wang XShape xshape = (XShape)UnoRuntime.queryInterface(XShape.class, shape); 72*28725c19SLi Feng Wang String type = xshape.getShapeType(); 73*28725c19SLi Feng Wang if(type.equals(shapeType)) 74*28725c19SLi Feng Wang { 75*28725c19SLi Feng Wang temp[shapeNum] = shape; 76*28725c19SLi Feng Wang shapeNum++; 77*28725c19SLi Feng Wang } 78*28725c19SLi Feng Wang } 79*28725c19SLi Feng Wang 80*28725c19SLi Feng Wang Object[] shapes = new Object[shapeNum]; 81*28725c19SLi Feng Wang System.arraycopy(temp, 0, shapes, 0, shapeNum); 82*28725c19SLi Feng Wang return shapes; 83*28725c19SLi Feng Wang } 84*28725c19SLi Feng Wang saveFileAs(XComponent sdComponent, String fileName, String extName)8543a102b2SLi Feng Wang public static void saveFileAs(XComponent sdComponent, String fileName, String extName) throws Exception { 8643a102b2SLi Feng Wang 8743a102b2SLi Feng Wang initFilterName(); 8843a102b2SLi Feng Wang 8943a102b2SLi Feng Wang String storeUrl = Testspace.getUrl("temp/" + fileName + "." + extName); 9043a102b2SLi Feng Wang 9143a102b2SLi Feng Wang PropertyValue[] storeProps = new PropertyValue[2]; 9243a102b2SLi Feng Wang storeProps[0] = new PropertyValue(); 9343a102b2SLi Feng Wang storeProps[0].Name = "FilterName"; 9443a102b2SLi Feng Wang storeProps[0].Value = filterName.get(extName); 9543a102b2SLi Feng Wang storeProps[1] = new PropertyValue(); 9643a102b2SLi Feng Wang storeProps[1].Name = "Overwrite"; 9743a102b2SLi Feng Wang storeProps[1].Value = new Boolean(true); 9843a102b2SLi Feng Wang 9943a102b2SLi Feng Wang XStorable sdStorable = 10043a102b2SLi Feng Wang (XStorable) UnoRuntime.queryInterface(XStorable.class, sdComponent); 10143a102b2SLi Feng Wang sdStorable.storeAsURL(storeUrl, storeProps); 10243a102b2SLi Feng Wang } 10343a102b2SLi Feng Wang initFilterName()10443a102b2SLi Feng Wang private static void initFilterName() throws Exception { 10543a102b2SLi Feng Wang if (filterName.size() > 0) { 10643a102b2SLi Feng Wang return; 10743a102b2SLi Feng Wang } 10843a102b2SLi Feng Wang 10943a102b2SLi Feng Wang filterName.put("odp", "impress8"); 11043a102b2SLi Feng Wang filterName.put("ppt", "MS PowerPoint 97"); 11143a102b2SLi Feng Wang } 1122d72893bSLiu Zhe 1132d72893bSLiu Zhe } 114