1ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5ef39d40dSAndrew Rist * distributed with this work for additional information 6ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17ef39d40dSAndrew Rist * specific language governing permissions and limitations 18ef39d40dSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20ef39d40dSAndrew Rist *************************************************************/ 21ef39d40dSAndrew Rist 22ef39d40dSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package mod._sw; 25cdf0e10cSrcweir 26cdf0e10cSrcweir import java.io.PrintWriter; 27cdf0e10cSrcweir 28cdf0e10cSrcweir import lib.StatusException; 29cdf0e10cSrcweir import lib.TestCase; 30cdf0e10cSrcweir import lib.TestEnvironment; 31cdf0e10cSrcweir import lib.TestParameters; 32cdf0e10cSrcweir import util.SOfficeFactory; 33cdf0e10cSrcweir 34cdf0e10cSrcweir import com.sun.star.beans.XPropertySet; 35cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 36cdf0e10cSrcweir import com.sun.star.text.TextContentAnchorType; 37cdf0e10cSrcweir import com.sun.star.text.XText; 38cdf0e10cSrcweir import com.sun.star.text.XTextContent; 39cdf0e10cSrcweir import com.sun.star.text.XTextCursor; 40cdf0e10cSrcweir import com.sun.star.text.XTextDocument; 41cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 42cdf0e10cSrcweir import com.sun.star.uno.XInterface; 43cdf0e10cSrcweir 44cdf0e10cSrcweir public class SwXTextGraphicObject extends TestCase { 45cdf0e10cSrcweir 46cdf0e10cSrcweir XTextDocument xTextDoc; 47cdf0e10cSrcweir 48cdf0e10cSrcweir /** 49cdf0e10cSrcweir * in general this method creates a testdocument 50cdf0e10cSrcweir * 51cdf0e10cSrcweir * @param tParam class which contains additional test parameters 52cdf0e10cSrcweir * @param log class to log the test state and result 53cdf0e10cSrcweir * 54cdf0e10cSrcweir * 55cdf0e10cSrcweir * @see TestParameters 56cdf0e10cSrcweir * @see PrintWriter 57cdf0e10cSrcweir * 58cdf0e10cSrcweir */ initialize( TestParameters tParam, PrintWriter log )59cdf0e10cSrcweir protected void initialize( TestParameters tParam, PrintWriter log ) { 60cdf0e10cSrcweir SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 61cdf0e10cSrcweir try { 62cdf0e10cSrcweir log.println( "creating a textdoc" ); 63*170fb961SPedro Giffuni xTextDoc = SOF.createTextDoc( null ); 64cdf0e10cSrcweir } catch ( Exception e ) { 65cdf0e10cSrcweir // Some exception occures.FAILED 66cdf0e10cSrcweir e.printStackTrace( log ); 67cdf0e10cSrcweir throw new StatusException( "Couldn't create document", e ); 68cdf0e10cSrcweir } 69cdf0e10cSrcweir } 70cdf0e10cSrcweir 71cdf0e10cSrcweir /** 72cdf0e10cSrcweir * in general this method disposes the testenvironment and document 73cdf0e10cSrcweir * 74cdf0e10cSrcweir * @param tParam class which contains additional test parameters 75cdf0e10cSrcweir * @param log class to log the test state and result 76cdf0e10cSrcweir * 77cdf0e10cSrcweir * 78cdf0e10cSrcweir * @see TestParameters 79cdf0e10cSrcweir * @see PrintWriter 80cdf0e10cSrcweir * 81cdf0e10cSrcweir */ cleanup( TestParameters tParam, PrintWriter log )82cdf0e10cSrcweir protected void cleanup( TestParameters tParam, PrintWriter log ) { 83cdf0e10cSrcweir log.println( " disposing xDrawDoc " ); 84cdf0e10cSrcweir util.DesktopTools.closeDoc(xTextDoc); 85cdf0e10cSrcweir } 86cdf0e10cSrcweir 87cdf0e10cSrcweir 88cdf0e10cSrcweir /** 89cdf0e10cSrcweir * creating a Testenvironment for the interfaces to be tested 90cdf0e10cSrcweir * 91cdf0e10cSrcweir * @param tParam class which contains additional test parameters 92cdf0e10cSrcweir * @param log class to log the test state and result 93cdf0e10cSrcweir * 94cdf0e10cSrcweir * @return Status class 95cdf0e10cSrcweir * 96cdf0e10cSrcweir * @see TestParameters 97cdf0e10cSrcweir * @see PrintWriter 98cdf0e10cSrcweir */ createTestEnvironment(TestParameters tParam, PrintWriter log)99cdf0e10cSrcweir protected TestEnvironment createTestEnvironment 100cdf0e10cSrcweir (TestParameters tParam, PrintWriter log) { 101cdf0e10cSrcweir 102cdf0e10cSrcweir XInterface oObj = null; 103cdf0e10cSrcweir Object oGObject = null; 104cdf0e10cSrcweir Object xTextFrame = null; 105cdf0e10cSrcweir SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 106cdf0e10cSrcweir 107cdf0e10cSrcweir Object instance = null; 108cdf0e10cSrcweir 109cdf0e10cSrcweir try { 110cdf0e10cSrcweir oGObject = SOF.createInstance 111cdf0e10cSrcweir (xTextDoc,"com.sun.star.text.GraphicObject"); 112cdf0e10cSrcweir instance = SOF.createInstance 113cdf0e10cSrcweir (xTextDoc,"com.sun.star.text.GraphicObject"); 114cdf0e10cSrcweir xTextFrame = SOF.createTextFrame(xTextDoc, 500, 500); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir catch (Exception ex) { 117cdf0e10cSrcweir log.println("Couldn't create instance"); 118cdf0e10cSrcweir ex.printStackTrace(log); 119cdf0e10cSrcweir throw new StatusException("Couldn't create instance", ex ); 120cdf0e10cSrcweir } 121cdf0e10cSrcweir 122cdf0e10cSrcweir oObj = (XInterface) oGObject; 123cdf0e10cSrcweir 124cdf0e10cSrcweir XText the_text = xTextDoc.getText(); 125cdf0e10cSrcweir XTextCursor the_cursor = the_text.createTextCursor(); 126cdf0e10cSrcweir XTextContent the_content = (XTextContent) 127cdf0e10cSrcweir UnoRuntime.queryInterface(XTextContent.class,oObj); 128cdf0e10cSrcweir 129cdf0e10cSrcweir log.println("inserting Frame"); 130cdf0e10cSrcweir try{ 131cdf0e10cSrcweir XTextContent Framecontent = (XTextContent) UnoRuntime.queryInterface( 132cdf0e10cSrcweir XTextContent.class, xTextFrame); 133cdf0e10cSrcweir the_text.insertTextContent(the_cursor, Framecontent, true); 134cdf0e10cSrcweir } catch (Exception e) { 135cdf0e10cSrcweir System.out.println("Couldn't insert text frame"); 136cdf0e10cSrcweir e.printStackTrace(); 137cdf0e10cSrcweir throw new StatusException("Couldn't insert text frame", e ); 138cdf0e10cSrcweir } 139cdf0e10cSrcweir 140cdf0e10cSrcweir 141cdf0e10cSrcweir log.println( "inserting graphic" ); 142cdf0e10cSrcweir try { 143cdf0e10cSrcweir the_text.insertTextContent(the_cursor,the_content,true); 144cdf0e10cSrcweir } catch (Exception e) { 145cdf0e10cSrcweir System.out.println("Couldn't insert Content"); 146cdf0e10cSrcweir e.printStackTrace(); 147cdf0e10cSrcweir throw new StatusException("Couldn't insert Content", e ); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir 150cdf0e10cSrcweir log.println( "adding graphic" ); 151cdf0e10cSrcweir XPropertySet oProps = (XPropertySet) 152cdf0e10cSrcweir UnoRuntime.queryInterface(XPropertySet.class,oObj); 153cdf0e10cSrcweir try { 154cdf0e10cSrcweir String wat = util.utils.getFullTestURL("space-metal.jpg"); 155cdf0e10cSrcweir oProps.setPropertyValue("AnchorType", 156cdf0e10cSrcweir TextContentAnchorType.AT_PARAGRAPH); 157cdf0e10cSrcweir oProps.setPropertyValue("GraphicURL",wat); 158cdf0e10cSrcweir oProps.setPropertyValue("HoriOrientPosition",new Integer(5500)); 159cdf0e10cSrcweir oProps.setPropertyValue("VertOrientPosition",new Integer(4200)); 160cdf0e10cSrcweir oProps.setPropertyValue("Width",new Integer(4400)); 161cdf0e10cSrcweir oProps.setPropertyValue("Height",new Integer(4000)); 162cdf0e10cSrcweir } catch (Exception e) { 163cdf0e10cSrcweir System.out.println("Couldn't set property 'GraphicURL'"); 164cdf0e10cSrcweir e.printStackTrace(); 165cdf0e10cSrcweir throw new StatusException 166cdf0e10cSrcweir ("Couldn't set property 'GraphicURL'", e ); 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir TestEnvironment tEnv = new TestEnvironment( oObj ); 170cdf0e10cSrcweir 171cdf0e10cSrcweir log.println( "adding ObjRelation for XShape " 172cdf0e10cSrcweir +"(get/setPosition won't work there)" ); 173cdf0e10cSrcweir tEnv.addObjRelation("NoPos", "SwXTextGraphicObject"); 174cdf0e10cSrcweir tEnv.addObjRelation("NoSetSize","SwXTextGraphicObject"); 175cdf0e10cSrcweir Object ImgMap = null; 176cdf0e10cSrcweir //creating ObjectRelation for the property 177cdf0e10cSrcweir // 'ImageMap' of 'TextGraphicObject' 178cdf0e10cSrcweir try { 179cdf0e10cSrcweir XMultiServiceFactory xDocMSF = (XMultiServiceFactory) 180cdf0e10cSrcweir UnoRuntime.queryInterface 181cdf0e10cSrcweir (XMultiServiceFactory.class,xTextDoc); 182cdf0e10cSrcweir ImgMap = xDocMSF.createInstance 183cdf0e10cSrcweir ("com.sun.star.image.ImageMapRectangleObject"); 184cdf0e10cSrcweir } 185cdf0e10cSrcweir catch (Exception ex) { 186cdf0e10cSrcweir ex.printStackTrace(); 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 189cdf0e10cSrcweir tEnv.addObjRelation("IMGMAP",ImgMap); 190cdf0e10cSrcweir 191cdf0e10cSrcweir tEnv.addObjRelation("CONTENT", (XTextContent) 192cdf0e10cSrcweir UnoRuntime.queryInterface(XTextContent.class,instance)); 193cdf0e10cSrcweir tEnv.addObjRelation("RANGE", xTextDoc.getText().createTextCursor()); 194cdf0e10cSrcweir 195cdf0e10cSrcweir //object relation for text.BaseFrameProperties 196cdf0e10cSrcweir tEnv.addObjRelation("TextFrame", xTextFrame); 197cdf0e10cSrcweir 198cdf0e10cSrcweir return tEnv; 199cdf0e10cSrcweir 200cdf0e10cSrcweir } // finish method getTestEnvironment 201cdf0e10cSrcweir 202cdf0e10cSrcweir } // finish class SwXTextGraphicObject 203cdf0e10cSrcweir 204