1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package mod._sw; 29 30 import com.sun.star.beans.XPropertySet; 31 import java.io.PrintWriter; 32 33 import lib.StatusException; 34 import lib.TestCase; 35 import lib.TestEnvironment; 36 import lib.TestParameters; 37 import util.SOfficeFactory; 38 39 import com.sun.star.lang.XMultiServiceFactory; 40 import com.sun.star.text.XTextContent; 41 import com.sun.star.text.XTextCursor; 42 import com.sun.star.text.XTextDocument; 43 import com.sun.star.text.XTextEmbeddedObjectsSupplier; 44 import com.sun.star.uno.UnoRuntime; 45 import com.sun.star.uno.XInterface; 46 47 48 public class SwXTextEmbeddedObjects extends TestCase { 49 50 XTextDocument oDoc; 51 52 /** 53 * in general this method creates a testdocument 54 * 55 * @param tParam class which contains additional test parameters 56 * @param log class to log the test state and result 57 * 58 * 59 * @see TestParameters 60 * @see PrintWriter 61 * 62 */ 63 protected void initialize( TestParameters tParam, PrintWriter log ) { 64 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 65 66 try { 67 oDoc = SOF.createTextDoc(null); 68 } catch ( com.sun.star.uno.Exception e ) { 69 // Some exception occures.FAILED 70 e.printStackTrace( log ); 71 throw new StatusException( "Couldn?t create document", e ); 72 } 73 } 74 75 /** 76 * in general this method disposes the testenvironment and document 77 * 78 * @param tParam class which contains additional test parameters 79 * @param log class to log the test state and result 80 * 81 * 82 * @see TestParameters 83 * @see PrintWriter 84 * 85 */ 86 protected void cleanup( TestParameters tParam, PrintWriter log ) { 87 log.println( " disposing xTextDoc " ); 88 util.DesktopTools.closeDoc(oDoc); 89 } 90 91 92 /** 93 * creating a Testenvironment for the interfaces to be tested 94 * 95 * @param tParam class which contains additional test parameters 96 * @param log class to log the test state and result 97 * 98 * @return Status class 99 * 100 * @see TestParameters 101 * @see PrintWriter 102 */ 103 public TestEnvironment createTestEnvironment( TestParameters tParam, 104 PrintWriter log ) throws StatusException { 105 106 XInterface oObj = null; 107 108 // create testobject here 109 XTextCursor xCursor = oDoc.getText().createTextCursor(); 110 try { 111 XMultiServiceFactory xMultiServiceFactory = (XMultiServiceFactory) 112 UnoRuntime.queryInterface(XMultiServiceFactory.class, oDoc); 113 Object o = xMultiServiceFactory.createInstance("com.sun.star.text.TextEmbeddedObject" ); 114 XTextContent xTextContent = (XTextContent)UnoRuntime.queryInterface(XTextContent.class, o); 115 String sChartClassID = "12dcae26-281f-416f-a234-c3086127382e"; 116 XPropertySet xPropertySet = (XPropertySet) 117 UnoRuntime.queryInterface(XPropertySet.class, xTextContent); 118 xPropertySet.setPropertyValue( "CLSID", sChartClassID ); 119 120 oDoc.getText().insertTextContent( xCursor, xTextContent, false ); 121 } 122 catch(com.sun.star.uno.Exception e) { 123 e.printStackTrace((java.io.PrintWriter)log); 124 } 125 126 XTextEmbeddedObjectsSupplier oTEOS = (XTextEmbeddedObjectsSupplier) 127 UnoRuntime.queryInterface(XTextEmbeddedObjectsSupplier.class, oDoc); 128 129 oObj = oTEOS.getEmbeddedObjects(); 130 131 TestEnvironment tEnv = new TestEnvironment( oObj ); 132 return tEnv; 133 134 } // finish method getTestEnvironment 135 136 } // finish class SwXTextEmbeddedObjects 137 138