1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwXTextField.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
41 import com
.sun
.star
.beans
.XPropertySet
;
42 import com
.sun
.star
.lang
.XMultiServiceFactory
;
43 import com
.sun
.star
.text
.XDependentTextField
;
44 import com
.sun
.star
.text
.XText
;
45 import com
.sun
.star
.text
.XTextContent
;
46 import com
.sun
.star
.text
.XTextCursor
;
47 import com
.sun
.star
.text
.XTextDocument
;
48 import com
.sun
.star
.uno
.UnoRuntime
;
49 import com
.sun
.star
.uno
.XInterface
;
54 * @see com.sun.star.lang.XComponent
55 * @see com.sun.star.text.TextContent
56 * @see com.sun.star.text.XTextContent
57 * @see com.sun.star.text.XTextField
60 public class SwXTextField
extends TestCase
{
62 XTextDocument xTextDoc
;
65 * in general this method creates a testdocument
67 * @param tParam class which contains additional test parameters
68 * @param log class to log the test state and result
75 protected void initialize( TestParameters tParam
, PrintWriter log
) {
76 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
79 log
.println( "creating a textdocument" );
80 xTextDoc
= SOF
.createTextDoc( null );
81 } catch ( com
.sun
.star
.uno
.Exception e
) {
82 // Some exception occures.FAILED
83 e
.printStackTrace( log
);
84 throw new StatusException( "Couldn't create document", e
);
89 * in general this method disposes the testenvironment and document
91 * @param tParam class which contains additional test parameters
92 * @param log class to log the test state and result
99 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
100 log
.println( " disposing xTextDoc " );
101 util
.DesktopTools
.closeDoc(xTextDoc
);
106 * creating a Testenvironment for the interfaces to be tested
108 * @param tParam class which contains additional test parameters
109 * @param log class to log the test state and result
111 * @return Status class
113 * @see TestParameters
116 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
118 XInterface oObj
= null;
120 // creation of testobject here
121 // first we write what we are intend to do to log file
122 log
.println( "creating a test environment" );
124 Object instance
= null;
126 // create testobject here
128 XMultiServiceFactory oDocMSF
= (XMultiServiceFactory
)
129 UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
131 Object FieldMaster
= oDocMSF
.createInstance
132 ( "com.sun.star.text.FieldMaster.Database" );
133 XPropertySet PFieldMaster
= (XPropertySet
) UnoRuntime
.queryInterface
134 (XPropertySet
.class,(XInterface
) FieldMaster
);
135 oObj
= (XInterface
) oDocMSF
.createInstance
136 ( "com.sun.star.text.TextField.Database" );
138 instance
= (XInterface
) oDocMSF
.createInstance
139 ( "com.sun.star.text.TextField.DateTime" );
141 XDependentTextField xTF
= (XDependentTextField
)
142 UnoRuntime
.queryInterface(XDependentTextField
.class,oObj
);
144 PFieldMaster
.setPropertyValue("DataBaseName","Address Book File");
145 PFieldMaster
.setPropertyValue("DataTableName","address");
146 PFieldMaster
.setPropertyValue("DataColumnName","FIRSTNAME");
147 XText the_Text
= xTextDoc
.getText();
148 XTextCursor the_Cursor
= the_Text
.createTextCursor();
149 XTextContent the_Field
= (XTextContent
)
150 UnoRuntime
.queryInterface(XTextContent
.class,oObj
);
152 xTF
.attachTextFieldMaster(PFieldMaster
);
153 the_Text
.insertTextContent(the_Cursor
,the_Field
,false);
155 catch (Exception ex
) {
156 log
.println("Couldn't create instance");
157 ex
.printStackTrace(log
);
160 log
.println( "creating a new environment for FieldMaster object" );
161 TestEnvironment tEnv
= new TestEnvironment( oObj
);
164 tEnv
.addObjRelation("CONTENT", (XTextContent
)
165 UnoRuntime
.queryInterface(XTextContent
.class,instance
));
166 tEnv
.addObjRelation("RANGE", xTextDoc
.getText().createTextCursor());
169 } // finish method getTestEnvironment
170 } // finish class SwXTextField