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: ScHeaderFieldObj.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
.XNameAccess
;
43 import com
.sun
.star
.lang
.XComponent
;
44 import com
.sun
.star
.lang
.XMultiServiceFactory
;
45 import com
.sun
.star
.sheet
.XHeaderFooterContent
;
46 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
47 import com
.sun
.star
.style
.XStyle
;
48 import com
.sun
.star
.style
.XStyleFamiliesSupplier
;
49 import com
.sun
.star
.text
.XText
;
50 import com
.sun
.star
.text
.XTextContent
;
51 import com
.sun
.star
.text
.XTextCursor
;
52 import com
.sun
.star
.uno
.AnyConverter
;
53 import com
.sun
.star
.uno
.Type
;
54 import com
.sun
.star
.uno
.UnoRuntime
;
55 import com
.sun
.star
.uno
.XInterface
;
58 * Test for object which is represented by service
59 * <code>com.sun.star.text.TextField</code>. <p>
60 * Object implements the following interfaces :
62 * <li> <code>com::sun::star::lang::XComponent</code></li>
63 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
64 * <li> <code>com::sun::star::text::XTextField</code></li>
65 * <li> <code>com::sun::star::text::XTextContent</code></li>
66 * <li> <code>com::sun::star::text::TextContent</code></li>
68 * @see com.sun.star.text.TextField
69 * @see com.sun.star.lang.XComponent
70 * @see com.sun.star.beans.XPropertySet
71 * @see com.sun.star.text.XTextField
72 * @see com.sun.star.text.XTextContent
73 * @see com.sun.star.text.TextContent
74 * @see ifc.lang._XComponent
75 * @see ifc.beans._XPropertySet
76 * @see ifc.text._XTextField
77 * @see ifc.text._XTextContent
78 * @see ifc.text._TextContent
80 public class ScHeaderFieldObj
extends TestCase
{
81 static XSpreadsheetDocument xSpreadsheetDoc
;
84 * Creates Spreadsheet document.
86 protected void initialize( TestParameters tParam
, PrintWriter log
) {
87 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
90 log
.println( "creating a Spreadsheet document" );
91 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
92 } catch ( com
.sun
.star
.uno
.Exception e
) {
93 // Some exception occures.FAILED
94 e
.printStackTrace( log
);
95 throw new StatusException( "Couldn't create document", e
);
101 * Disposes Spreadsheet document.
103 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
104 log
.println( " disposing xSheetDoc " );
105 XComponent oComp
= (XComponent
)
106 UnoRuntime
.queryInterface (XComponent
.class, xSpreadsheetDoc
);
107 util
.DesktopTools
.closeDoc(oComp
);
111 * Creating a Testenvironment for the interfaces to be tested.
112 * Retrieves the collection of style families available in the document
113 * using the interface <code>XStyleFamiliesSupplier</code>.
114 * Obtains default style from the style family <code>'PageStyles'</code>.
115 * Retrieves the interface <code>XHeaderFooterContent</code> from the style
116 * using the property <code>'RightPageHeaderContent'</code>. Creates the
117 * instance of the service <code>com.sun.star.text.TextField.Time</code> and
118 * the instance of the service <code>com.sun.star.text.TextField.Date</code>
119 * Obtains the text (the interface <code>XText</code>) which is printed in
120 * the left part of the header or footer and inserts in it's content
121 * the second created instance.
122 * Object relations created :
124 * <li> <code>'CONTENT'</code> for
125 * {@link ifc.text._XTextContent}(the interface <code>XTextContent</code>
126 * that was queried from the second created instance) </li>
127 * <li> <code>'TEXT'</code> for
128 * {@link ifc.text._XTextContent}(the the text which is printed in the
129 * right part of the header or footer) </li>
131 * @see com.sun.star.style.XStyleFamiliesSupplier
132 * @see com.sun.star.sheet.XHeaderFooterContent
133 * @see com.sun.star.text.XText
134 * @see com.sun.star.text.XTextContent
136 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
138 XInterface oObj
= null;
139 XPropertySet PropSet
;
140 XNameAccess PageStyles
= null;
141 XStyle StdStyle
= null;
142 XTextContent oContent
= null;
143 XInterface aField
= null;
145 XStyleFamiliesSupplier StyleFam
= (XStyleFamiliesSupplier
)
146 UnoRuntime
.queryInterface(
147 XStyleFamiliesSupplier
.class,
150 XNameAccess StyleFamNames
= StyleFam
.getStyleFamilies();
152 PageStyles
= (XNameAccess
) AnyConverter
.toObject(
153 new Type(XNameAccess
.class),StyleFamNames
.getByName("PageStyles"));
154 StdStyle
= (XStyle
) AnyConverter
.toObject(
155 new Type(XStyle
.class),PageStyles
.getByName("Default"));
156 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
157 e
.printStackTrace(log
);
158 throw new StatusException("Couldn't get by name", e
);
159 } catch(com
.sun
.star
.container
.NoSuchElementException e
){
160 e
.printStackTrace(log
);
161 throw new StatusException("Couldn't get by name", e
);
162 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
){
163 e
.printStackTrace(log
);
164 throw new StatusException("Couldn't get by name", e
);
167 //get the property-set
168 PropSet
= (XPropertySet
)
169 UnoRuntime
.queryInterface(XPropertySet
.class, StdStyle
);
171 XHeaderFooterContent RPHC
= null;
172 // creation of testobject here
173 // first we write what we are intend to do to log file
174 log
.println( "creating a test environment" );
176 RPHC
= (XHeaderFooterContent
) AnyConverter
.toObject(
177 new Type(XHeaderFooterContent
.class),
178 PropSet
.getPropertyValue("RightPageHeaderContent"));
179 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
180 e
.printStackTrace(log
);
181 throw new StatusException("Couldn't get HeaderContent", e
);
182 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
183 e
.printStackTrace(log
);
184 throw new StatusException("Couldn't get HeaderContent", e
);
185 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
186 e
.printStackTrace(log
);
187 throw new StatusException("Couldn't get HeaderContent", e
);
190 XText left
= RPHC
.getLeftText();
192 XMultiServiceFactory oDocMSF
= (XMultiServiceFactory
)
193 UnoRuntime
.queryInterface(
194 XMultiServiceFactory
.class,
197 XTextContent the_Field
= null;
200 oDocMSF
.createInstance( "com.sun.star.text.TextField.Time" );
202 the_Field
= (XTextContent
)
203 UnoRuntime
.queryInterface(XTextContent
.class,oObj
);
205 aField
= (XInterface
)
206 oDocMSF
.createInstance("com.sun.star.text.TextField.Date");
207 } catch(com
.sun
.star
.uno
.Exception e
) {
208 e
.printStackTrace(log
);
209 throw new StatusException("Couldn't create instance", e
);
212 oContent
= (XTextContent
)
213 UnoRuntime
.queryInterface(XTextContent
.class, aField
);
215 XTextCursor the_Cursor
= left
.createTextCursor();
218 left
.insertTextContent(the_Cursor
,the_Field
, false);
219 PropSet
.setPropertyValue("RightPageHeaderContent", RPHC
);
220 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
) {
221 e
.printStackTrace(log
);
222 throw new StatusException("Couldn't create a test environment", e
);
223 } catch(com
.sun
.star
.lang
.WrappedTargetException e
) {
224 e
.printStackTrace(log
);
225 throw new StatusException("Couldn't create a test environment", e
);
226 } catch(com
.sun
.star
.beans
.PropertyVetoException e
) {
227 e
.printStackTrace(log
);
228 throw new StatusException("Couldn't create a test environment", e
);
229 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
) {
230 e
.printStackTrace(log
);
231 throw new StatusException("Couldn't create a test environment", e
);
234 TestEnvironment tEnv
= new TestEnvironment(oObj
);
236 tEnv
.addObjRelation("CONTENT",oContent
);
237 tEnv
.addObjRelation("TEXT", RPHC
.getRightText());
241 } // finish method getTestEnvironment
243 } // finish class ScHeaderFieldObj