2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.io
.PrintWriter
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.SOfficeFactory
;
28 import com
.sun
.star
.beans
.XPropertySet
;
29 import com
.sun
.star
.lang
.XMultiServiceFactory
;
30 import com
.sun
.star
.text
.XDependentTextField
;
31 import com
.sun
.star
.text
.XText
;
32 import com
.sun
.star
.text
.XTextContent
;
33 import com
.sun
.star
.text
.XTextCursor
;
34 import com
.sun
.star
.text
.XTextDocument
;
35 import com
.sun
.star
.uno
.UnoRuntime
;
36 import com
.sun
.star
.uno
.XInterface
;
41 * @see com.sun.star.lang.XComponent
42 * @see com.sun.star.text.TextContent
43 * @see com.sun.star.text.XTextContent
44 * @see com.sun.star.text.XTextField
47 public class SwXTextField
extends TestCase
{
49 XTextDocument xTextDoc
;
52 * in general this method creates a testdocument
54 * @param tParam class which contains additional test parameters
55 * @param log class to log the test state and result
63 protected void initialize( TestParameters tParam
, PrintWriter log
) throws Exception
{
64 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
65 log
.println( "creating a textdocument" );
66 xTextDoc
= SOF
.createTextDoc( null );
70 * in general this method disposes the testenvironment and document
72 * @param tParam class which contains additional test parameters
73 * @param log class to log the test state and result
81 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
82 log
.println( " disposing xTextDoc " );
83 util
.DesktopTools
.closeDoc(xTextDoc
);
88 * creating a TestEnvironment for the interfaces to be tested
90 * @param tParam class which contains additional test parameters
91 * @param log class to log the test state and result
93 * @return Status class
99 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
101 XInterface oObj
= null;
103 // creation of testobject here
104 // first we write what we are intend to do to log file
105 log
.println( "creating a test environment" );
107 Object instance
= null;
109 // create testobject here
111 XMultiServiceFactory oDocMSF
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
113 Object FieldMaster
= oDocMSF
.createInstance
114 ( "com.sun.star.text.FieldMaster.Database" );
115 XPropertySet PFieldMaster
= UnoRuntime
.queryInterface
116 (XPropertySet
.class,FieldMaster
);
117 oObj
= (XInterface
) oDocMSF
.createInstance
118 ( "com.sun.star.text.TextField.Database" );
120 instance
= oDocMSF
.createInstance
121 ( "com.sun.star.text.TextField.DateTime" );
123 XDependentTextField xTF
= UnoRuntime
.queryInterface(XDependentTextField
.class,oObj
);
125 PFieldMaster
.setPropertyValue("DataBaseName","Address Book File");
126 PFieldMaster
.setPropertyValue("DataTableName","address");
127 PFieldMaster
.setPropertyValue("DataColumnName","FIRSTNAME");
128 XText the_Text
= xTextDoc
.getText();
129 XTextCursor the_Cursor
= the_Text
.createTextCursor();
130 XTextContent the_Field
= UnoRuntime
.queryInterface(XTextContent
.class,oObj
);
132 xTF
.attachTextFieldMaster(PFieldMaster
);
133 the_Text
.insertTextContent(the_Cursor
,the_Field
,false);
135 catch (Exception ex
) {
136 log
.println("Couldn't create instance");
137 ex
.printStackTrace(log
);
140 log
.println( "creating a new environment for FieldMaster object" );
141 TestEnvironment tEnv
= new TestEnvironment( oObj
);
144 tEnv
.addObjRelation("CONTENT", UnoRuntime
.queryInterface(XTextContent
.class,instance
));
145 tEnv
.addObjRelation("RANGE", xTextDoc
.getText().createTextCursor());
148 } // finish method getTestEnvironment
149 } // finish class SwXTextField