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: SwXEndnoteProperties.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 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
42 import com
.sun
.star
.beans
.XPropertySet
;
43 import com
.sun
.star
.lang
.XMultiServiceFactory
;
44 import com
.sun
.star
.text
.XEndnotesSupplier
;
45 import com
.sun
.star
.text
.XText
;
46 import com
.sun
.star
.text
.XTextContent
;
47 import com
.sun
.star
.text
.XTextCursor
;
48 import com
.sun
.star
.text
.XTextDocument
;
49 import com
.sun
.star
.uno
.UnoRuntime
;
50 import com
.sun
.star
.uno
.XInterface
;
53 * Test for object which is represented by service
54 * <code>com.sun.star.text.FootnoteSettings</code>. <p>
55 * Object implements the following interfaces :
57 * <li> <code>com::sun::star::text::FootnoteSettings</code></li>
59 * This object test <b> is NOT </b> designed to be run in several
60 * threads concurently.
61 * @see com.sun.star.text.FootnoteSettings
62 * @see ifc.text._FootnoteSettings
64 public class SwXEndnoteProperties
extends TestCase
{
65 XTextDocument xTextDoc
;
68 * Creates text document.
70 protected void initialize( TestParameters tParam
, PrintWriter log
) {
71 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
73 log
.println( "creating a textdocument" );
74 xTextDoc
= SOF
.createTextDoc( null );
75 } catch ( com
.sun
.star
.uno
.Exception e
) {
76 e
.printStackTrace( log
);
77 throw new StatusException( "Couldn't create document", e
);
82 * Disposes text document.
84 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
85 log
.println( " disposing xTextDoc " );
86 util
.DesktopTools
.closeDoc(xTextDoc
);
90 * Creating a Testenvironment for the interfaces to be tested.
91 * Creates an instance of the service
92 * <code>com.sun.star.text.Endnote</code>. Then created endnote is inserted
93 * to the text document, and finally endnote settings are gotten from text
94 * document using <code>XEndnotesSupplier</code> interface.
96 public synchronized TestEnvironment
createTestEnvironment(
97 TestParameters Param
, PrintWriter log
) throws StatusException
{
98 XEndnotesSupplier oInterface
= null;
99 XInterface oObj
= null;
102 log
.println( "Creating a test environment" );
103 XMultiServiceFactory msf
= (XMultiServiceFactory
)
104 UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
105 log
.println("creating a endnote");
107 oEndnote
= (XInterface
) UnoRuntime
.queryInterface(XInterface
.class,
108 msf
.createInstance("com.sun.star.text.Endnote"));
109 } catch (com
.sun
.star
.uno
.Exception e
) {
110 e
.printStackTrace(log
);
111 throw new StatusException("Couldn't create endnote", e
);
114 XText oText
= xTextDoc
.getText();
115 XTextCursor oCursor
= oText
.createTextCursor();
117 log
.println("inserting the footnote into text document");
118 XTextContent xTC
= (XTextContent
)
119 UnoRuntime
.queryInterface(XTextContent
.class, oEndnote
);
121 oText
.insertTextContent(oCursor
, xTC
, false);
122 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
123 e
.printStackTrace(log
);
124 throw new StatusException("Couldn't insert the endnote", e
);
127 oInterface
= (XEndnotesSupplier
)
128 UnoRuntime
.queryInterface(XEndnotesSupplier
.class, xTextDoc
);
129 oObj
= oInterface
.getEndnoteSettings();
130 dbg
.printPropertiesNames((XPropertySet
) oObj
);
132 TestEnvironment tEnv
= new TestEnvironment(oObj
);