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 38 import com.sun.star.lang.XMultiServiceFactory; 39 import com.sun.star.text.XFootnote; 40 import com.sun.star.text.XFootnotesSupplier; 41 import com.sun.star.text.XText; 42 import com.sun.star.text.XTextCursor; 43 import com.sun.star.text.XTextDocument; 44 import com.sun.star.uno.UnoRuntime; 45 import com.sun.star.uno.XInterface; 46 47 48 /** 49 * Test for object which is represented by service 50 * <code>com.sun.star.text.Footnotes</code>.<p> 51 * Object implements the following interfaces : 52 * <ul> 53 * <li> <code>com::sun::star::container::XIndexAccess</code></li> 54 * <li> <code>com::sun::star::container::XElementAccess</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.container.XIndexAccess 59 * @see com.sun.star.container.XElementAccess 60 * @see ifc.container._XIndexAccess 61 * @see ifc.container._XElementAccess 62 */ 63 public class SwXFootnotes extends TestCase { 64 XTextDocument xTextDoc; 65 66 /** 67 * Creates text document. 68 */ 69 protected void initialize( TestParameters tParam, PrintWriter log ) { 70 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 71 try { 72 log.println( "creating a textdocument" ); 73 xTextDoc = SOF.createTextDoc( null ); 74 } catch ( com.sun.star.uno.Exception e ) { 75 e.printStackTrace( log ); 76 throw new StatusException( "Couldn't create document", e ); 77 } 78 } 79 80 /** 81 * Disposes text document. 82 */ 83 protected void cleanup( TestParameters tParam, PrintWriter log ) { 84 log.println( " disposing xTextDoc " ); 85 util.DesktopTools.closeDoc(xTextDoc); 86 } 87 88 /** 89 * Creating a Testenvironment for the interfaces to be tested. 90 * Creates an instance of the service 91 * <code>com.sun.star.text.Footnote</code>. Then inserts created Footnote 92 * to the text, and finally gets all footnotes of text document 93 * through <code>XFootnotesSupplier</code> interface. 94 */ 95 public synchronized TestEnvironment createTestEnvironment( 96 TestParameters Param, PrintWriter log ) throws StatusException { 97 XFootnotesSupplier oInterface = null; 98 XInterface oObj = null; 99 100 log.println( "Creating a test environment" ); 101 XMultiServiceFactory msf = (XMultiServiceFactory) 102 UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc); 103 log.println("creating a footnote"); 104 XFootnote oFootnote; 105 106 try { 107 oFootnote = (XFootnote) UnoRuntime.queryInterface(XFootnote.class, 108 msf.createInstance("com.sun.star.text.Footnote")); 109 } catch (com.sun.star.uno.Exception e) { 110 e.printStackTrace(log); 111 throw new StatusException("Couldn't create footnote", e); 112 } 113 114 XText oText = xTextDoc.getText(); 115 XTextCursor oCursor = oText.createTextCursor(); 116 117 log.println("inserting the footnote into text document"); 118 try { 119 oText.insertTextContent(oCursor, oFootnote, false); 120 } catch (com.sun.star.lang.IllegalArgumentException e) { 121 e.printStackTrace(log); 122 throw new StatusException("Couldn't insert the footnote", e); 123 } 124 oInterface = (XFootnotesSupplier) 125 UnoRuntime.queryInterface(XFootnotesSupplier.class, xTextDoc); 126 oObj = oInterface.getFootnotes(); 127 128 log.println( "creating a new environment for Foontnotes object" ); 129 TestEnvironment tEnv = new TestEnvironment(oObj); 130 return tEnv; 131 } 132 133 } // finish class SwXFootnote 134 135