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