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.beans.XPropertySet; 39 import com.sun.star.container.XIndexAccess; 40 import com.sun.star.lang.XMultiServiceFactory; 41 import com.sun.star.table.XTableRows; 42 import com.sun.star.text.XText; 43 import com.sun.star.text.XTextCursor; 44 import com.sun.star.text.XTextDocument; 45 import com.sun.star.text.XTextTable; 46 import com.sun.star.uno.AnyConverter; 47 import com.sun.star.uno.Type; 48 import com.sun.star.uno.UnoRuntime; 49 import com.sun.star.uno.XInterface; 50 51 52 public class SwXTextTableRow extends TestCase { 53 XTextDocument xTextDoc; 54 55 protected void initialize( TestParameters tParam, PrintWriter log ) { 56 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 57 58 try { 59 log.println( "creating a textdocument" ); 60 xTextDoc = SOF.createTextDoc( null ); 61 } catch ( com.sun.star.uno.Exception e ) { 62 // Some exception occures.FAILED 63 e.printStackTrace( log ); 64 throw new StatusException( "Couldn't create document", e ); 65 } 66 } 67 68 protected void cleanup( TestParameters tParam, PrintWriter log ) { 69 log.println( " disposing xTextDoc " ); 70 util.DesktopTools.closeDoc(xTextDoc); 71 } 72 73 protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) { 74 75 XInterface oObj = null; 76 XTextTable oTable = null; 77 78 79 80 // creation of testobject here 81 // first we write what we are intend to do to log file 82 log.println( "Creating a test environment" ); 83 84 // get a soffice factory object 85 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF() ); 86 87 try { 88 log.println("creating a texttable"); 89 oTable = (XTextTable) SOF.createTextTable(xTextDoc,5,5); 90 } catch( Exception e ) { 91 e.printStackTrace(log); 92 } 93 94 XText oText = xTextDoc.getText(); 95 96 XTextCursor oCursor = oText.createTextCursor(); 97 98 try { 99 log.println("inserting texttable"); 100 oText.insertTextContent(oCursor, oTable, false); 101 } catch (Exception e) { 102 log.println("Exception!"); 103 } 104 105 try { 106 log.println("getting table row"); 107 XTableRows oTRn = oTable.getRows(); 108 XIndexAccess oIA = (XIndexAccess) UnoRuntime.queryInterface 109 (XIndexAccess.class,oTRn); 110 oObj = (XPropertySet) AnyConverter.toObject( 111 new Type(XPropertySet.class),oIA.getByIndex(1)); 112 } catch( Exception e ) { 113 e.printStackTrace(log); 114 } 115 116 log.println( "creating a new environment for TextTableRow object" ); 117 TestEnvironment tEnv = new TestEnvironment( oObj ); 118 119 log.println( "adding TextDocument as mod relation to environment" ); 120 tEnv.addObjRelation("TEXTDOC", xTextDoc); 121 122 123 return tEnv; 124 } // finish method getTestEnvironment 125 126 } // finish class SwXTextTableRow 127 128