Author: wanglf
Date: Wed Oct 24 10:05:57 2012
New Revision: 1401603

URL: http://svn.apache.org/viewvc?rev=1401603&view=rev
Log:
#120968 - [testuno]Check graphic position and size properties
 patch by louql, reviewed by WangLiFeng

Added:
    incubator/ooo/trunk/test/testuno/data/uno/sd/
    incubator/ooo/trunk/test/testuno/data/uno/sd/36.gif   (with props)
    incubator/ooo/trunk/test/testuno/source/fvt/uno/sd/graphic/
    
incubator/ooo/trunk/test/testuno/source/fvt/uno/sd/graphic/GraphicPro_Position.java
    
incubator/ooo/trunk/test/testuno/source/fvt/uno/sd/graphic/GraphicPro_Size.java
    incubator/ooo/trunk/test/testuno/source/testlib/uno/GraphicUtil.java
Modified:
    incubator/ooo/trunk/test/testuno/source/testlib/uno/SDUtil.java

Added: incubator/ooo/trunk/test/testuno/data/uno/sd/36.gif
URL: 
http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testuno/data/uno/sd/36.gif?rev=1401603&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/ooo/trunk/test/testuno/data/uno/sd/36.gif
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: 
incubator/ooo/trunk/test/testuno/source/fvt/uno/sd/graphic/GraphicPro_Position.java
URL: 
http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testuno/source/fvt/uno/sd/graphic/GraphicPro_Position.java?rev=1401603&view=auto
==============================================================================
--- 
incubator/ooo/trunk/test/testuno/source/fvt/uno/sd/graphic/GraphicPro_Position.java
 (added)
+++ 
incubator/ooo/trunk/test/testuno/source/fvt/uno/sd/graphic/GraphicPro_Position.java
 Wed Oct 24 10:05:57 2012
@@ -0,0 +1,148 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+package fvt.uno.sd.graphic;
+import static org.junit.Assert.*;
+import static testlib.uno.GraphicUtil.getGraphicsOfPage;
+import static testlib.uno.GraphicUtil.getSizePixelOfGraphicFile;
+import static testlib.uno.GraphicUtil.insertGraphic;
+import static testlib.uno.SDUtil.saveFileAs;
+
+import java.util.Arrays;
+import java.util.Collection;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import org.openoffice.test.uno.UnoApp;
+import org.openoffice.test.common.FileUtil;
+import org.openoffice.test.common.Testspace;
+
+import testlib.uno.SDUtil;
+
+import com.sun.star.awt.Point;
+import com.sun.star.awt.Size;
+import com.sun.star.drawing.XDrawPage;
+import com.sun.star.drawing.XShape;
+import com.sun.star.lang.XComponent;
+import com.sun.star.uno.UnoRuntime;
+
+@RunWith(Parameterized.class)
+public class GraphicPro_Position {
+
+       private static final UnoApp app = new UnoApp();
+
+       private XComponent m_xSDComponent = null;
+       private XDrawPage m_xCurrentPage=null;
+       private Point m_position=null;
+       private Point m_expectedPosition=null;
+       private String m_fileType = null;
+       
+       public GraphicPro_Position(Point position, String fileType, Point 
expectedPosition){
+               m_position = position;
+               m_fileType = fileType;
+               m_expectedPosition = expectedPosition;
+       }
+       @Parameters
+    public static Collection<Object[]> data() {       
+        Point pNegative2 = new Point(-28000,-28000); //minimum
+        Point pNegative3 = new Point(-1000,-1000); 
+        Point pZero = new Point(0,0);
+        Point pPositive1 = new Point(1000,1000);
+        Point pPositive2 = new Point(34833,34833); //maximum        
+       return Arrays.asList(new Object[][]{                    
+                       {pNegative2, "odp", pNegative2},
+                       {pNegative2, "ppt", pNegative2},
+                       {pNegative3, "odp", pNegative3},
+                       {pNegative3, "ppt", pNegative3},
+                       {pZero, "odp", pZero},
+                       {pZero, "ppt", pZero},
+                       {pPositive1, "odp", pPositive1},
+                       {pPositive1, "ppt", pPositive1},
+                       {pPositive2, "odp", pPositive2},
+                       {pPositive2, "ppt", pPositive2}                 
+        });
+    }
+
+       @Before
+       public void setUpDocument() throws Exception {
+               m_xSDComponent = (XComponent) UnoRuntime.queryInterface(
+                               XComponent.class, app.newDocument("simpress")); 
        
+               Object drawPage = SDUtil.getPageByIndex(m_xSDComponent, 0);     
                
+               m_xCurrentPage = 
(XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, drawPage);               
+               String graphicURL = 
FileUtil.getUrl(Testspace.prepareData("uno/sd/36.gif"));
+               
+               Size orgSize = getSizePixelOfGraphicFile(app,graphicURL);
+           Size newSize = new Size(orgSize.Width*2645/100, 
orgSize.Height*2645/100);
+               insertGraphic(m_xSDComponent, m_xCurrentPage, graphicURL, 
newSize, new Point(5000, 5000));
+       }
+
+       @After
+       public void tearDownDocument() {
+               app.closeDocument(m_xSDComponent);
+
+       }
+
+       @BeforeClass
+       public static void setUpConnection() throws Exception {
+               app.start();
+       }
+
+       @AfterClass
+       public static void tearDownConnection() throws InterruptedException,
+                       Exception {
+               app.close();
+               //remove the temp file
+               FileUtil.deleteFile(Testspace.getPath("temp"));
+       }
+       
+       
+       private XDrawPage load(String filePath) throws Exception{
+               m_xSDComponent = (XComponent) 
UnoRuntime.queryInterface(XComponent.class, 
+                               app.loadDocument(filePath));            
+               Object drawPage = SDUtil.getPageByIndex(m_xSDComponent, 0);     
      
+               return (XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, 
drawPage);
+       }
+
+       @Test
+       public void testPosition() throws Exception {
+               String fileName = "GraphicPro_Position";                
+               String filePath = 
Testspace.getPath("temp/"+fileName+"."+m_fileType);
+               Object[] graphics = getGraphicsOfPage(m_xCurrentPage);
+               Object oGraphic = graphics[0];
+               XShape xGraphicShape = 
(XShape)UnoRuntime.queryInterface(XShape.class, oGraphic);
+               
+               xGraphicShape.setPosition(m_position);
+               
+               saveFileAs(m_xSDComponent, fileName, m_fileType);
+               app.closeDocument(m_xSDComponent);
+               
+               XDrawPage CurrentPage = load(filePath);
+               Object oGraphic2 = getGraphicsOfPage(CurrentPage)[0];
+               XShape xGraphicShape2 = 
(XShape)UnoRuntime.queryInterface(XShape.class, oGraphic2);
+               
+               assertEquals("Position X of graphic error", 
m_expectedPosition.X, xGraphicShape2.getPosition().X, 2);
+               assertEquals("Position Y of graphic error", 
m_expectedPosition.Y, xGraphicShape2.getPosition().Y, 2);
+       }
+}

Added: 
incubator/ooo/trunk/test/testuno/source/fvt/uno/sd/graphic/GraphicPro_Size.java
URL: 
http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testuno/source/fvt/uno/sd/graphic/GraphicPro_Size.java?rev=1401603&view=auto
==============================================================================
--- 
incubator/ooo/trunk/test/testuno/source/fvt/uno/sd/graphic/GraphicPro_Size.java 
(added)
+++ 
incubator/ooo/trunk/test/testuno/source/fvt/uno/sd/graphic/GraphicPro_Size.java 
Wed Oct 24 10:05:57 2012
@@ -0,0 +1,143 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+package fvt.uno.sd.graphic;
+import static org.junit.Assert.*;
+import static testlib.uno.GraphicUtil.getGraphicsOfPage;
+import static testlib.uno.GraphicUtil.getSizePixelOfGraphicFile;
+import static testlib.uno.GraphicUtil.insertGraphic;
+import static testlib.uno.SDUtil.saveFileAs;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import org.openoffice.test.uno.UnoApp;
+import org.openoffice.test.common.FileUtil;
+import org.openoffice.test.common.Testspace;
+
+import testlib.uno.SDUtil;
+
+import com.sun.star.awt.Point;
+import com.sun.star.awt.Size;
+import com.sun.star.drawing.XDrawPage;
+import com.sun.star.drawing.XShape;
+import com.sun.star.lang.XComponent;
+import com.sun.star.uno.UnoRuntime;
+
+@RunWith(Parameterized.class)
+public class GraphicPro_Size {
+
+       private static final UnoApp app = new UnoApp();
+
+       private XComponent m_xSDComponent = null;
+       private XDrawPage m_xCurrentPage=null;
+       private Size m_Size=null;
+       private Size m_ExpectedSize=null;
+       private String m_fileType = null;
+
+       public GraphicPro_Size(Size size, String fileType, Size expectedSize){
+               m_Size = size;
+               m_fileType = fileType;
+               m_ExpectedSize = expectedSize;
+       }
+       @Parameters
+    public static Collection<Object[]> data() {     
+        Size sMinimum = new Size(1,1); //minimum in UI
+        Size sNormal = new Size(2000,2000);
+        Size sMaximum = new Size(52448,28852); //maximum in UI
+        
+       return Arrays.asList(new Object[][]{                    
+                       {sMinimum, "odp", sMinimum},
+                       {sMinimum, "ppt", sMinimum},
+                       {sNormal, "odp", sNormal},
+                       {sNormal, "ppt", sNormal},
+                       {sMaximum, "odp", sMaximum},
+                       {sMaximum, "ppt", sMaximum}                             
        
+        });
+    }
+    
+       @Before
+       public void setUpDocument() throws Exception {
+               m_xSDComponent = (XComponent) UnoRuntime.queryInterface(
+                               XComponent.class, app.newDocument("simpress")); 
        
+               Object drawPage = SDUtil.getPageByIndex(m_xSDComponent, 0);     
                
+               m_xCurrentPage = 
(XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, drawPage);
+               
+               String graphicURL = 
FileUtil.getUrl(Testspace.prepareData("uno/sd/36.gif"));            
+               Size orgSize = getSizePixelOfGraphicFile(app,graphicURL);
+           Size newSize = new Size(orgSize.Width*2645/100, 
orgSize.Height*2645/100);
+               insertGraphic(m_xSDComponent, m_xCurrentPage, graphicURL, 
newSize, new Point(5000, 5000));
+       }
+
+       @After
+       public void tearDownDocument() {
+               app.closeDocument(m_xSDComponent);
+
+       }
+
+       @BeforeClass
+       public static void setUpConnection() throws Exception {
+               app.start();
+       }
+
+       @AfterClass
+       public static void tearDownConnection() throws InterruptedException,
+                       Exception {
+               app.close();
+               //remove the temp file
+               FileUtil.deleteFile(Testspace.getPath("temp"));
+       }
+
+       private XDrawPage load(String filePath) throws Exception{
+               m_xSDComponent = (XComponent) 
UnoRuntime.queryInterface(XComponent.class, 
+                               app.loadDocument(filePath));            
+               Object drawPage = SDUtil.getPageByIndex(m_xSDComponent, 0);     
      
+               return (XDrawPage)UnoRuntime.queryInterface(XDrawPage.class, 
drawPage);
+       }
+       
+       @Test
+       public void testGraphicSize() throws Exception{
+               String fileName = "GraphicPro_Size";            
+               String filePath = 
Testspace.getPath("temp/"+fileName+"."+m_fileType);
+               Object[] graphics = getGraphicsOfPage(m_xCurrentPage);
+               Object oGraphic = graphics[0];
+               XShape xGraphicShape = 
(XShape)UnoRuntime.queryInterface(XShape.class, oGraphic);
+               
+               xGraphicShape.setSize(m_Size);
+               
+               saveFileAs(m_xSDComponent, fileName, m_fileType);
+               app.closeDocument(m_xSDComponent);
+               
+               XDrawPage CurrentPage = load(filePath);
+               Object oGraphic2 = getGraphicsOfPage(CurrentPage)[0];
+               XShape xGraphicShape2 = 
(XShape)UnoRuntime.queryInterface(XShape.class, oGraphic2);
+               
+               assertEquals("Height of graphic error", m_ExpectedSize.Height, 
xGraphicShape2.getSize().Height, 3);
+               assertEquals("Width of graphic error", m_ExpectedSize.Width, 
xGraphicShape2.getSize().Width, 3);
+       }
+}

Added: incubator/ooo/trunk/test/testuno/source/testlib/uno/GraphicUtil.java
URL: 
http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testuno/source/testlib/uno/GraphicUtil.java?rev=1401603&view=auto
==============================================================================
--- incubator/ooo/trunk/test/testuno/source/testlib/uno/GraphicUtil.java (added)
+++ incubator/ooo/trunk/test/testuno/source/testlib/uno/GraphicUtil.java Wed 
Oct 24 10:05:57 2012
@@ -0,0 +1,159 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+package testlib.uno;
+import static org.junit.Assert.*;
+import static testlib.uno.GraphicUtil.getSizePixelOfGraphicFile;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.openoffice.test.uno.UnoApp;
+import org.openoffice.test.common.FileUtil;
+import org.openoffice.test.common.Testspace;
+
+import com.sun.star.beans.Property;
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.beans.UnknownPropertyException;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.beans.XPropertySetInfo;
+import com.sun.star.drawing.XDrawPage;
+import com.sun.star.drawing.XShape;
+import com.sun.star.drawing.XShapes;
+import com.sun.star.graphic.XGraphic;
+import com.sun.star.graphic.XGraphicObject;
+import com.sun.star.graphic.XGraphicProvider;
+import com.sun.star.lang.WrappedTargetException;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.lang.XServiceName;
+import com.sun.star.uno.Exception;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.awt.Point;
+import com.sun.star.awt.Size;
+//import com.sun.star.uno.AnyConverter;
+
+public class GraphicUtil {
+       
+       public static String getUniqueIDbyXGraphic(UnoApp unoApp, XGraphic 
xgraphic) throws Exception{
+               Object graphicObj = 
unoApp.getServiceFactory().createInstance("com.sun.star.graphic.GraphicObject");
+               XGraphicObject xgraphicObj = 
(XGraphicObject)UnoRuntime.queryInterface(XGraphicObject.class, graphicObj);
+               xgraphicObj.setGraphic(xgraphic);
+               
+               return xgraphicObj.getUniqueID();
+       }
+       
+//     String sUrl = "file:///F:/work/36.gif";
+       public static String getUniqueIDOfGraphicFile(UnoApp unoApp, String 
sUrl) throws Exception{             
+               XGraphic xgraphic = getXGraphicOfGraphicFile(unoApp,sUrl);      
        
+               String uniqueID = getUniqueIDbyXGraphic(unoApp, xgraphic);
+               
+               return uniqueID;
+       }
+       
+       public static XGraphic getXGraphicOfGraphicFile(UnoApp unoApp, String 
sUrl) throws Exception
+       {
+               Object graphicObj = 
unoApp.getServiceFactory().createInstance("com.sun.star.graphic.GraphicProvider");
+               XGraphicProvider xgraphicProvider = 
(XGraphicProvider)UnoRuntime.queryInterface(XGraphicProvider.class, graphicObj);
+               PropertyValue[] sourceProps = new PropertyValue[1];
+               sourceProps[0]       = new PropertyValue();
+               sourceProps[0].Name  = "URL";
+               sourceProps[0].Value = sUrl;
+               return xgraphicProvider.queryGraphic(sourceProps);              
+       }
+       
+       public static Size getSize100thMMOfGraphicFile(UnoApp unoApp, String 
sUrl) throws Exception
+       {
+               Object graphicObj = 
unoApp.getServiceFactory().createInstance("com.sun.star.graphic.GraphicProvider");
+               XGraphicProvider xgraphicProvider = 
(XGraphicProvider)UnoRuntime.queryInterface(XGraphicProvider.class, graphicObj);
+               PropertyValue[] sourceProps = new PropertyValue[1];
+               sourceProps[0]       = new PropertyValue();
+               sourceProps[0].Name  = "URL";
+               sourceProps[0].Value = sUrl;
+               XPropertySet xGraphicPro = 
xgraphicProvider.queryGraphicDescriptor(sourceProps);                
+               Size size = (Size)xGraphicPro.getPropertyValue("Size100thMM");
+               return size;
+       }
+       
+       public static Size getSizePixelOfGraphicFile(UnoApp unoApp, String 
sUrl) throws Exception
+       {
+               Object graphicObj = 
unoApp.getServiceFactory().createInstance("com.sun.star.graphic.GraphicProvider");
+               XGraphicProvider xgraphicProvider = 
(XGraphicProvider)UnoRuntime.queryInterface(XGraphicProvider.class, graphicObj);
+               PropertyValue[] sourceProps = new PropertyValue[1];
+               sourceProps[0]       = new PropertyValue();
+               sourceProps[0].Name  = "URL";
+               sourceProps[0].Value = sUrl;
+               XPropertySet xGraphicPro = 
xgraphicProvider.queryGraphicDescriptor(sourceProps);
+               Size size = (Size)xGraphicPro.getPropertyValue("SizePixel");
+               return size;
+       }
+       
+       
+       //GraphicObjectShape
+       public static Object[] getGraphicsOfPage(XDrawPage xDrawPage) throws 
Exception {
+               XShapes m_xdrawShapes = (XShapes) 
UnoRuntime.queryInterface(XShapes.class, xDrawPage);
+               int count = m_xdrawShapes.getCount();
+               Object[] temp = new Object[count];
+               int graphicNum=0;
+               for(int i=0;i<count; i++)
+               {
+                       Object shape = m_xdrawShapes.getByIndex(i);
+                       XShape xshape = 
(XShape)UnoRuntime.queryInterface(XShape.class, shape);         
+                       String type = xshape.getShapeType();
+                       
if(type.equals("com.sun.star.drawing.GraphicObjectShape"))
+                       {
+                               temp[graphicNum] = shape;
+                               graphicNum++;                           
+                       }
+               }
+               
+               Object[] graphics = new Object[graphicNum];
+               System.arraycopy(temp, 0, graphics, 0, graphicNum);
+               return graphics;
+       }
+       
+       /*Insert a graphic into a Impress
+        * component: the Impress document
+        * toPage: the page that the graphic will be inserted to
+        * graphicURL: the file path of the graphic, e.g. file:///c:/test.png
+        * size: size of the graphic to be inserted
+        * position: position of the graphic to be inserted
+        * */
+       public static void insertGraphic(XComponent component, XDrawPage 
toPage, String graphicURL, Size size, Point position) throws Exception
+       {               
+               XMultiServiceFactory xDrawFactory = 
+                   (XMultiServiceFactory)UnoRuntime.queryInterface(
+                       XMultiServiceFactory.class, component);
+
+           Object oGraphic = 
xDrawFactory.createInstance("com.sun.star.drawing.GraphicObjectShape");
+           XPropertySet xGraphicPro = 
(XPropertySet)UnoRuntime.queryInterface(XPropertySet.class, oGraphic);
+           xGraphicPro.setPropertyValue("GraphicURL", graphicURL);
+           
+           XShape xDrawShape = (XShape)UnoRuntime.queryInterface(XShape.class, 
oGraphic);
+           
+           xDrawShape.setSize(size); 
+           xDrawShape.setPosition(position);
+
+           toPage.add(xDrawShape);
+       }
+       
+}

Modified: incubator/ooo/trunk/test/testuno/source/testlib/uno/SDUtil.java
URL: 
http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testuno/source/testlib/uno/SDUtil.java?rev=1401603&r1=1401602&r2=1401603&view=diff
==============================================================================
--- incubator/ooo/trunk/test/testuno/source/testlib/uno/SDUtil.java (original)
+++ incubator/ooo/trunk/test/testuno/source/testlib/uno/SDUtil.java Wed Oct 24 
10:05:57 2012
@@ -20,10 +20,16 @@
  *************************************************************/
 package testlib.uno;
 
+import java.util.HashMap;
+
+import org.openoffice.test.common.Testspace;
+
+import com.sun.star.beans.PropertyValue;
 import com.sun.star.container.XIndexAccess;
 import com.sun.star.drawing.XDrawPage;
 import com.sun.star.drawing.XDrawPagesSupplier;
 import com.sun.star.drawing.XShapes;
+import com.sun.star.frame.XStorable;
 import com.sun.star.lang.XComponent;
 import com.sun.star.uno.UnoRuntime;
 
@@ -33,6 +39,8 @@ import com.sun.star.uno.UnoRuntime;
  */
 public class SDUtil {
 
+       private static HashMap filterName = new HashMap(); 
+       
        private SDUtil() {
 
        }
@@ -49,5 +57,33 @@ public class SDUtil {
                XShapes m_xdrawShapes = (XShapes) 
UnoRuntime.queryInterface(XShapes.class, xDrawPage);
                return m_xdrawShapes.getByIndex(index);
        }
+       
+       public static void saveFileAs(XComponent sdComponent, String fileName, 
String extName) throws Exception {
+               
+               initFilterName();
+
+               String storeUrl = Testspace.getUrl("temp/" + fileName + "." + 
extName);
+               
+               PropertyValue[] storeProps = new PropertyValue[2];
+               storeProps[0] = new PropertyValue();
+               storeProps[0].Name = "FilterName";
+               storeProps[0].Value = filterName.get(extName);
+               storeProps[1] = new PropertyValue();
+               storeProps[1].Name = "Overwrite";
+               storeProps[1].Value = new Boolean(true);
+               
+               XStorable sdStorable = 
+                               (XStorable) 
UnoRuntime.queryInterface(XStorable.class, sdComponent);
+               sdStorable.storeAsURL(storeUrl, storeProps);
+       }
+       
+       private static void initFilterName() throws Exception {
+               if (filterName.size() > 0) {
+                       return;
+               }
+               
+               filterName.put("odp", "impress8");
+               filterName.put("ppt", "MS PowerPoint 97");
+       }
 
 }


Reply via email to