1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwXTextEmbeddedObject.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 import com
.sun
.star
.beans
.XPropertySet
;
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
41 import com
.sun
.star
.container
.XIndexAccess
;
42 import com
.sun
.star
.container
.XNameAccess
;
43 import com
.sun
.star
.lang
.XMultiServiceFactory
;
44 import com
.sun
.star
.text
.XText
;
45 import com
.sun
.star
.text
.XTextContent
;
46 import com
.sun
.star
.text
.XTextCursor
;
47 import com
.sun
.star
.text
.XTextDocument
;
48 import com
.sun
.star
.text
.XTextEmbeddedObjectsSupplier
;
49 import com
.sun
.star
.text
.XTextFrame
;
50 import com
.sun
.star
.uno
.AnyConverter
;
51 import com
.sun
.star
.uno
.Type
;
52 import com
.sun
.star
.uno
.UnoRuntime
;
53 import com
.sun
.star
.uno
.XInterface
;
54 import com
.sun
.star
.util
.XCloseable
;
60 * @see com.sun.star.container.XNamed
61 * @see com.sun.star.document.XEmbeddedObjectSupplier
62 * @see com.sun.star.lang.XComponent
63 * @see com.sun.star.text.TextEmbeddedObject
64 * @see com.sun.star.text.XTextContent
65 * @see com.sun.star.text.XTextEmbeddedObject
68 public class SwXTextEmbeddedObject
extends TestCase
{
69 XTextDocument xTextDoc
;
72 * in general this method disposes the testenvironment and document
74 * @param tParam class which contains additional test parameters
75 * @param log class to log the test state and result
82 protected void cleanup(TestParameters tParam
, PrintWriter log
) {
83 log
.println(" disposing xTextDoc ");
86 XCloseable closer
= (XCloseable
) UnoRuntime
.queryInterface(
87 XCloseable
.class, xTextDoc
);
89 } catch (com
.sun
.star
.util
.CloseVetoException e
) {
90 log
.println("couldn't close document");
91 } catch (com
.sun
.star
.lang
.DisposedException e
) {
92 log
.println("couldn't close document");
97 * creating a Testenvironment for the interfaces to be tested
99 * @param tParam class which contains additional test parameters
100 * @param log class to log the test state and result
102 * @return Status class
104 * @see TestParameters
107 protected TestEnvironment
createTestEnvironment(TestParameters tParam
,
109 XInterface oObj
= null;
111 // create testobject here
112 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
) tParam
.getMSF());
114 xTextDoc
= SOF
.createTextDoc(null);
115 } catch (com
.sun
.star
.uno
.Exception e
) {
116 e
.printStackTrace(log
);
117 throw new StatusException("Couldn't open document", e
);
120 XTextCursor xCursor
= xTextDoc
.getText().createTextCursor();
122 XMultiServiceFactory xMultiServiceFactory
= (XMultiServiceFactory
)
123 UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
124 Object o
= xMultiServiceFactory
.createInstance("com.sun.star.text.TextEmbeddedObject" );
125 XTextContent xTextContent
= (XTextContent
)UnoRuntime
.queryInterface(XTextContent
.class, o
);
126 String sChartClassID
= "12dcae26-281f-416f-a234-c3086127382e";
127 XPropertySet xPropertySet
= (XPropertySet
)
128 UnoRuntime
.queryInterface(XPropertySet
.class, xTextContent
);
129 xPropertySet
.setPropertyValue( "CLSID", sChartClassID
);
131 xTextDoc
.getText().insertTextContent( xCursor
, xTextContent
, false );
133 catch(com
.sun
.star
.uno
.Exception e
) {
134 e
.printStackTrace((java
.io
.PrintWriter
)log
);
137 XTextEmbeddedObjectsSupplier oTEOS
= (XTextEmbeddedObjectsSupplier
) UnoRuntime
.queryInterface(
138 XTextEmbeddedObjectsSupplier
.class,
141 XNameAccess oEmObj
= oTEOS
.getEmbeddedObjects();
142 XIndexAccess oEmIn
= (XIndexAccess
) UnoRuntime
.queryInterface(
143 XIndexAccess
.class, oEmObj
);
146 oObj
= (XInterface
) AnyConverter
.toObject(
147 new Type(XInterface
.class), oEmIn
.getByIndex(0));
148 } catch (com
.sun
.star
.uno
.Exception e
) {
149 e
.printStackTrace(log
);
150 throw new StatusException("Couldn't get Object", e
);
153 TestEnvironment tEnv
= new TestEnvironment(oObj
);
155 tEnv
.addObjRelation("NoAttach", "SwXTextEmbeddedObject");
157 XTextFrame aFrame
= SOF
.createTextFrame(xTextDoc
, 500, 500);
158 XText oText
= xTextDoc
.getText();
159 XTextCursor oCursor
= oText
.createTextCursor();
160 XTextContent the_content
= (XTextContent
) UnoRuntime
.queryInterface(
161 XTextContent
.class, aFrame
);
164 oText
.insertTextContent(oCursor
, the_content
, true);
165 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
166 log
.println("Couldn't insert frame " + e
.getMessage());
169 tEnv
.addObjRelation("TextFrame", aFrame
);
171 tEnv
.addObjRelation("NoSetSize", "SwXTextEmbeddedObject");
172 tEnv
.addObjRelation("NoPos", "SwXTextEmbeddedObject");
175 } // finish method getTestEnvironment
176 } // finish class SwXTextEmbeddedObject