1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package mod._sw;
25 
26 import java.io.PrintWriter;
27 
28 import lib.StatusException;
29 import lib.TestCase;
30 import lib.TestEnvironment;
31 import lib.TestParameters;
32 import util.SOfficeFactory;
33 
34 import com.sun.star.beans.XPropertySet;
35 import com.sun.star.container.XIndexAccess;
36 import com.sun.star.lang.XMultiServiceFactory;
37 import com.sun.star.table.XTableRows;
38 import com.sun.star.text.XText;
39 import com.sun.star.text.XTextCursor;
40 import com.sun.star.text.XTextDocument;
41 import com.sun.star.text.XTextTable;
42 import com.sun.star.uno.AnyConverter;
43 import com.sun.star.uno.Type;
44 import com.sun.star.uno.UnoRuntime;
45 import com.sun.star.uno.XInterface;
46 
47 
48 public class SwXTextTableRow extends TestCase {
49     XTextDocument xTextDoc;
50 
initialize( TestParameters tParam, PrintWriter log )51     protected void initialize( TestParameters tParam, PrintWriter log ) {
52         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
53 
54         try {
55             log.println( "creating a textdocument" );
56             xTextDoc = SOF.createTextDoc( null );
57         } catch ( com.sun.star.uno.Exception e ) {
58             // Some exception occures.FAILED
59             e.printStackTrace( log );
60             throw new StatusException( "Couldn't create document", e );
61         }
62     }
63 
cleanup( TestParameters tParam, PrintWriter log )64     protected void cleanup( TestParameters tParam, PrintWriter log ) {
65         log.println( "    disposing xTextDoc " );
66         util.DesktopTools.closeDoc(xTextDoc);
67     }
68 
createTestEnvironment(TestParameters Param, PrintWriter log)69     protected synchronized TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log) {
70 
71         XInterface oObj = null;
72         XTextTable oTable = null;
73 
74 
75 
76         // creation of testobject here
77         // first we write what we are intend to do to log file
78         log.println( "Creating a test environment" );
79 
80         // get a soffice factory object
81         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)Param.getMSF() );
82 
83         try {
84          log.println("creating a texttable");
85             oTable = (XTextTable) SOF.createTextTable(xTextDoc,5,5);
86         } catch( Exception e ) {
87             e.printStackTrace(log);
88         }
89 
90         XText oText = xTextDoc.getText();
91 
92         XTextCursor oCursor = oText.createTextCursor();
93 
94         try {
95             log.println("inserting texttable");
96             oText.insertTextContent(oCursor, oTable, false);
97         } catch (Exception e) {
98             log.println("Exception!");
99         }
100 
101         try {
102          log.println("getting table row");
103             XTableRows oTRn = oTable.getRows();
104             XIndexAccess oIA = (XIndexAccess) UnoRuntime.queryInterface
105                 (XIndexAccess.class,oTRn);
106             oObj = (XPropertySet) AnyConverter.toObject(
107                     new Type(XPropertySet.class),oIA.getByIndex(1));
108         } catch( Exception e ) {
109             e.printStackTrace(log);
110         }
111 
112         log.println( "creating a new environment for TextTableRow object" );
113         TestEnvironment tEnv = new TestEnvironment( oObj );
114 
115         log.println( "adding TextDocument as mod relation to environment" );
116         tEnv.addObjRelation("TEXTDOC", xTextDoc);
117 
118 
119         return tEnv;
120     } // finish method getTestEnvironment
121 
122 }    // finish class SwXTextTableRow
123 
124