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: SwXFieldEnumeration.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
.container
.XEnumerationAccess
;
43 import com
.sun
.star
.lang
.XMultiServiceFactory
;
44 import com
.sun
.star
.text
.XDependentTextField
;
45 import com
.sun
.star
.text
.XText
;
46 import com
.sun
.star
.text
.XTextContent
;
47 import com
.sun
.star
.text
.XTextCursor
;
48 import com
.sun
.star
.text
.XTextDocument
;
49 import com
.sun
.star
.text
.XTextFieldsSupplier
;
50 import com
.sun
.star
.uno
.UnoRuntime
;
51 import com
.sun
.star
.uno
.XInterface
;
55 * Object implements the following interfaces :
57 * <li> <code>com::sun::star::container::XEnumeration</code></li>
59 * This object test <b> is NOT </b> designed to be run in several
60 * threads concurently.
61 * @see com.sun.star.container.XEnumeration
62 * @see ifc.container._XEnumeration
64 public class SwXFieldEnumeration
extends TestCase
{
65 XTextDocument xTextDoc
;
68 * Creates text document.
70 protected void initialize( TestParameters tParam
, PrintWriter log
) {
71 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
73 log
.println( "creating a textdocument" );
74 xTextDoc
= SOF
.createTextDoc( null );
75 } catch ( com
.sun
.star
.uno
.Exception e
) {
76 e
.printStackTrace( log
);
77 throw new StatusException( "Couldn't create document", e
);
82 * Disposes text document.
84 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
85 log
.println( " disposing xTextDoc " );
86 util
.DesktopTools
.closeDoc(xTextDoc
);
90 * Creating a Testenvironment for the interfaces to be tested. FieldMaster
91 * object is created and attached to Bibliography database. After setting
92 * properties of created FieldMaster object, it is attached to the TextField
93 * object. Then TextField is inserted as TextContent to the text document.
94 * At the end, TextFields of text document are obtained and
95 * enumeration of these fields is created.<br>
96 * Creates instances of the services:
97 * <code>com.sun.star.text.FieldMaster.Database</code>,
98 * <code>com.sun.star.text.TextField.Database</code>.<br>
99 * Object relations created :
101 * <li> <code>'ENUM'</code> for
102 * {@link ifc.container._XEnumeration} : text fields</li>
105 public TestEnvironment
createTestEnvironment(
106 TestParameters tParam
, PrintWriter log
) throws StatusException
{
107 XInterface oObj
= null;
108 Object FieldMaster
= null;
109 XPropertySet PFieldMaster
= null;
110 XDependentTextField xTF
= null;
111 XEnumerationAccess xFEA
= null;
113 XTextCursor the_Cursor
;
114 XTextContent the_Field
;
116 log
.println( "creating a test environment" );
117 XMultiServiceFactory oDocMSF
= (XMultiServiceFactory
)
118 UnoRuntime
.queryInterface( XMultiServiceFactory
.class, xTextDoc
);
121 FieldMaster
= oDocMSF
.createInstance
122 ( "com.sun.star.text.FieldMaster.Database" );
123 PFieldMaster
= (XPropertySet
) UnoRuntime
.queryInterface
124 (XPropertySet
.class,(XInterface
) FieldMaster
);
126 oDocMSF
.createInstance("com.sun.star.text.TextField.Database");
127 xTF
= (XDependentTextField
)
128 UnoRuntime
.queryInterface(XDependentTextField
.class,oObj
);
129 } catch ( com
.sun
.star
.uno
.Exception e
) {
130 e
.printStackTrace(log
);
134 PFieldMaster
.setPropertyValue("DataBaseName","Bibliography");
135 PFieldMaster
.setPropertyValue("DataTableName","biblio");
136 PFieldMaster
.setPropertyValue("DataColumnName","Address");
137 } catch ( com
.sun
.star
.lang
.WrappedTargetException e
) {
138 log
.println("Error: can't set PropertyValue to a FieldMaster");
139 e
.printStackTrace(log
);
140 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
141 log
.println("Error: can't set PropertyValue to a FieldMaster");
142 e
.printStackTrace(log
);
143 } catch ( com
.sun
.star
.beans
.UnknownPropertyException e
) {
144 log
.println("Error: can't set PropertyValue to a FieldMaster");
145 e
.printStackTrace(log
);
146 } catch ( com
.sun
.star
.beans
.PropertyVetoException e
) {
147 log
.println("Error: can't set PropertyValue to a FieldMaster");
148 e
.printStackTrace(log
);
151 the_Text
= xTextDoc
.getText();
152 the_Cursor
= the_Text
.createTextCursor();
153 the_Field
= (XTextContent
)
154 UnoRuntime
.queryInterface(XTextContent
.class, oObj
);
157 xTF
.attachTextFieldMaster(PFieldMaster
);
158 the_Text
.insertTextContent(the_Cursor
,the_Field
,false);
159 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
160 e
.printStackTrace(log
);
161 throw new StatusException( "Couldn't create TextField", e
);
164 // create testobject here
165 XTextFieldsSupplier oTFS
= (XTextFieldsSupplier
)
166 UnoRuntime
.queryInterface( XTextFieldsSupplier
.class, xTextDoc
);
167 xFEA
= oTFS
.getTextFields();
168 oObj
= oTFS
.getTextFields().createEnumeration();
170 log
.println( "creating a new environment for FieldEnumeration object" );
171 TestEnvironment tEnv
= new TestEnvironment( oObj
);
173 tEnv
.addObjRelation("ENUM", xFEA
);
176 } // finish method getTestEnvironment
178 } // finish class SwXFieldEnumeration