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.XText; 40 import com.sun.star.text.XTextCursor; 41 import com.sun.star.text.XTextDocument; 42 import com.sun.star.text.XTextFrame; 43 import com.sun.star.text.XTextFramesSupplier; 44 import com.sun.star.uno.UnoRuntime; 45 import com.sun.star.uno.XInterface; 46 47 /** 48 * Object implements the following interfaces : 49 * <ul> 50 * <li> <code>com::sun::star::container::XContainer</code></li> 51 * <li> <code>com::sun::star::container::XNameAccess</code></li> 52 * <li> <code>com::sun::star::container::XIndexAccess</code></li> 53 * <li> <code>com::sun::star::container::XElementAccess</code></li> 54 * </ul> <p> 55 * This object test <b> is NOT </b> designed to be run in several 56 * threads concurently. 57 * @see com.sun.star.container.XContainer 58 * @see com.sun.star.container.XNameAccess 59 * @see com.sun.star.container.XIndexAccess 60 * @see com.sun.star.container.XElementAccess 61 * @see ifc.container._XContainer 62 * @see ifc.container._XNameAccess 63 * @see ifc.container._XIndexAccess 64 * @see ifc.container._XElementAccess 65 */ 66 public class SwXFrames extends TestCase { 67 XTextDocument xTextDoc; 68 69 /** 70 * Creates text document. 71 */ 72 protected void initialize( TestParameters tParam, PrintWriter log ) { 73 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 74 try { 75 log.println( "creating a textdocument" ); 76 xTextDoc = SOF.createTextDoc( null ); 77 } catch ( com.sun.star.uno.Exception e ) { 78 e.printStackTrace( log ); 79 throw new StatusException( "Couldn't create document", e ); 80 } 81 } 82 83 /** 84 * Disposes text document. 85 */ 86 protected void cleanup( TestParameters tParam, PrintWriter log ) { 87 log.println( " disposing xTextDoc " ); 88 util.DesktopTools.closeDoc(xTextDoc); 89 } 90 91 /** 92 * Creating a Testenvironment for the interfaces to be tested. 93 * Creates an instance of the service 94 * <code>com.sun.star.text.TextFrame</code>. Then inserts created text frame 95 * to the text, and finally gets all frames of text document using 96 * <code>XTextFramesSupplier</code> interface.<br> 97 */ 98 public synchronized TestEnvironment createTestEnvironment( 99 TestParameters Param, PrintWriter log ) throws StatusException { 100 XInterface oObj = null; 101 XTextFrame oFrame1 = null; 102 XText oText = null; 103 XTextCursor oCursor = null; 104 XMultiServiceFactory oDocMSF = null; 105 XTextFramesSupplier oInterface = null; 106 107 log.println( "creating a test environment" ); 108 try { 109 oDocMSF = (XMultiServiceFactory) 110 UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc); 111 Object oInt = oDocMSF.createInstance("com.sun.star.text.TextFrame"); 112 oFrame1 = (XTextFrame) 113 UnoRuntime.queryInterface( XTextFrame.class, oInt ); 114 } catch ( com.sun.star.uno.Exception e ) { 115 e.printStackTrace(log); 116 throw new StatusException 117 ("Couldn't create instance of TextFrame", e); 118 } 119 120 oText = xTextDoc.getText(); 121 oCursor = oText.createTextCursor(); 122 123 try { 124 oText.insertTextContent(oCursor, oFrame1, false); 125 } catch ( com.sun.star.lang.IllegalArgumentException e ) { 126 e.printStackTrace(log); 127 throw new StatusException 128 ("Error: can't insert text content to text document", e); 129 } 130 131 oInterface = (XTextFramesSupplier) 132 UnoRuntime.queryInterface( XTextFramesSupplier.class, xTextDoc ); 133 134 oObj = oInterface.getTextFrames(); 135 136 log.println( "creating a new environment for Frame object" ); 137 TestEnvironment tEnv = new TestEnvironment( oObj ); 138 139 return tEnv; 140 } // finish method getTestEnvironment 141 142 } // finish class SwXFrames 143 144