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.lang.XMultiServiceFactory; 36 import com.sun.star.text.XDependentTextField; 37 import com.sun.star.text.XText; 38 import com.sun.star.text.XTextContent; 39 import com.sun.star.text.XTextCursor; 40 import com.sun.star.text.XTextDocument; 41 import com.sun.star.uno.UnoRuntime; 42 import com.sun.star.uno.XInterface; 43 44 /** 45 * 46 * initial description 47 * @see com.sun.star.lang.XComponent 48 * @see com.sun.star.text.TextContent 49 * @see com.sun.star.text.XTextContent 50 * @see com.sun.star.text.XTextField 51 * 52 */ 53 public class SwXTextField extends TestCase { 54 55 XTextDocument xTextDoc; 56 57 /** 58 * in general this method creates a testdocument 59 * 60 * @param tParam class which contains additional test parameters 61 * @param log class to log the test state and result 62 * 63 * 64 * @see TestParameters 65 * @see PrintWriter 66 * 67 */ initialize( TestParameters tParam, PrintWriter log )68 protected void initialize( TestParameters tParam, PrintWriter log ) { 69 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 70 71 try { 72 log.println( "creating a textdocument" ); 73 xTextDoc = SOF.createTextDoc( null ); 74 } catch ( com.sun.star.uno.Exception e ) { 75 // Some exception occured.FAILED 76 e.printStackTrace( log ); 77 throw new StatusException( "Couldn't create document", e ); 78 } 79 } 80 81 /** 82 * in general this method disposes the testenvironment and document 83 * 84 * @param tParam class which contains additional test parameters 85 * @param log class to log the test state and result 86 * 87 * 88 * @see TestParameters 89 * @see PrintWriter 90 * 91 */ cleanup( TestParameters tParam, PrintWriter log )92 protected void cleanup( TestParameters tParam, PrintWriter log ) { 93 log.println( " disposing xTextDoc " ); 94 util.DesktopTools.closeDoc(xTextDoc); 95 } 96 97 98 /** 99 * creating a Testenvironment for the interfaces to be tested 100 * 101 * @param tParam class which contains additional test parameters 102 * @param log class to log the test state and result 103 * 104 * @return Status class 105 * 106 * @see TestParameters 107 * @see PrintWriter 108 */ createTestEnvironment(TestParameters tParam, PrintWriter log)109 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) { 110 111 XInterface oObj = null; 112 113 // creation of testobject here 114 // first we write what we are intend to do to log file 115 log.println( "creating a test environment" ); 116 117 Object instance = null; 118 119 // create testobject here 120 try { 121 XMultiServiceFactory oDocMSF = (XMultiServiceFactory) 122 UnoRuntime.queryInterface(XMultiServiceFactory.class, xTextDoc); 123 124 Object FieldMaster = oDocMSF.createInstance 125 ( "com.sun.star.text.FieldMaster.Database" ); 126 XPropertySet PFieldMaster = (XPropertySet) UnoRuntime.queryInterface 127 (XPropertySet.class,(XInterface) FieldMaster); 128 oObj = (XInterface) oDocMSF.createInstance 129 ( "com.sun.star.text.TextField.Database" ); 130 131 instance = (XInterface) oDocMSF.createInstance 132 ( "com.sun.star.text.TextField.DateTime" ); 133 134 XDependentTextField xTF = (XDependentTextField) 135 UnoRuntime.queryInterface(XDependentTextField.class,oObj); 136 137 PFieldMaster.setPropertyValue("DataBaseName","Address Book File"); 138 PFieldMaster.setPropertyValue("DataTableName","address"); 139 PFieldMaster.setPropertyValue("DataColumnName","FIRSTNAME"); 140 XText the_Text = xTextDoc.getText(); 141 XTextCursor the_Cursor = the_Text.createTextCursor(); 142 XTextContent the_Field = (XTextContent) 143 UnoRuntime.queryInterface(XTextContent.class,oObj); 144 145 xTF.attachTextFieldMaster(PFieldMaster); 146 the_Text.insertTextContent(the_Cursor,the_Field,false); 147 } 148 catch (Exception ex) { 149 log.println("Couldn't create instance"); 150 ex.printStackTrace(log); 151 } 152 153 log.println( "creating a new environment for FieldMaster object" ); 154 TestEnvironment tEnv = new TestEnvironment( oObj ); 155 156 157 tEnv.addObjRelation("CONTENT", (XTextContent) 158 UnoRuntime.queryInterface(XTextContent.class,instance)); 159 tEnv.addObjRelation("RANGE", xTextDoc.getText().createTextCursor()); 160 161 return tEnv; 162 } // finish method getTestEnvironment 163 } // finish class SwXTextField 164 165