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: ScHeaderFooterTextCursor.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
.uno
.AnyConverter
;
51 import com
.sun
.star
.uno
.Type
;
52 import com
.sun
.star
.uno
.UnoRuntime
;
53 import com
.sun
.star
.uno
.XInterface
;
56 * Test for object which is represented by service
57 * <code>com.sun.star.text.TextCursor</code>. <p>
58 * Object implements the following interfaces :
60 * <li> <code>com::sun::star::text::XTextCursor</code></li>
61 * <li> <code>com::sun::star::text::XWordCursor</code></li>
62 * <li> <code>com::sun::star::style::CharacterPropertiesComplex</code></li>
63 * <li> <code>com::sun::star::text::XTextRange</code></li>
64 * <li> <code>com::sun::star::beans::XPropertySet</code></li>
65 * <li> <code>com::sun::star::container::XContentEnumerationAccess</code></li>
66 * <li> <code>com::sun::star::beans::XPropertyState</code></li>
67 * <li> <code>com::sun::star::style::CharacterProperties</code></li>
68 * <li> <code>com::sun::star::text::XSentenceCursor</code></li>
69 * <li> <code>com::sun::star::style::ParagraphProperties</code></li>
70 * <li> <code>com::sun::star::text::XParagraphCursor</code></li>
71 * <li> <code>com::sun::star::document::XDocumentInsertable</code></li>
72 * <li> <code>com::sun::star::util::XSortable</code></li>
73 * <li> <code>com::sun::star::style::CharacterPropertiesAsian</code></li>
75 * @see com.sun.star.text.TextCursor
76 * @see com.sun.star.text.XTextCursor
77 * @see com.sun.star.text.XWordCursor
78 * @see com.sun.star.style.CharacterPropertiesComplex
79 * @see com.sun.star.text.XTextRange
80 * @see com.sun.star.beans.XPropertySet
81 * @see com.sun.star.container.XContentEnumerationAccess
82 * @see com.sun.star.beans.XPropertyState
83 * @see com.sun.star.style.CharacterProperties
84 * @see com.sun.star.text.XSentenceCursor
85 * @see com.sun.star.style.ParagraphProperties
86 * @see com.sun.star.text.XParagraphCursor
87 * @see com.sun.star.document.XDocumentInsertable
88 * @see com.sun.star.util.XSortable
89 * @see com.sun.star.style.CharacterPropertiesAsian
90 * @see ifc.text._XTextCursor
91 * @see ifc.text._XWordCursor
92 * @see ifc.style._CharacterPropertiesComplex
93 * @see ifc.text._XTextRange
94 * @see ifc.beans._XPropertySet
95 * @see ifc.container._XContentEnumerationAccess
96 * @see ifc.beans._XPropertyState
97 * @see ifc.style._CharacterProperties
98 * @see ifc.text._XSentenceCursor
99 * @see ifc.style._ParagraphProperties
100 * @see ifc.text._XParagraphCursor
101 * @see ifc.document._XDocumentInsertable
102 * @see ifc.util._XSortable
103 * @see ifc.style._CharacterPropertiesAsian
105 public class ScHeaderFooterTextCursor
extends TestCase
{
106 static XSpreadsheetDocument xSpreadsheetDoc
;
109 * Creates Spreadsheet document.
111 protected void initialize( TestParameters tParam
, PrintWriter log
) {
112 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
115 log
.println( "creating a Spreadsheet document" );
116 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
117 } catch ( com
.sun
.star
.uno
.Exception e
) {
118 // Some exception occures.FAILED
119 e
.printStackTrace( log
);
120 throw new StatusException( "Couldn't create document", e
);
125 * Disposes Spreadsheet document.
127 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
128 log
.println( " disposing xSheetDoc " );
129 XComponent oComp
= (XComponent
)
130 UnoRuntime
.queryInterface (XComponent
.class, xSpreadsheetDoc
) ;
131 util
.DesktopTools
.closeDoc(oComp
);
135 * Creating a Testenvironment for the interfaces to be tested.
136 * Retrieves the collection of style families available in the document
137 * using the interface <code>XStyleFamiliesSupplier</code>.
138 * Obtains default style from the style family <code>'PageStyles'</code>.
139 * Retrieves value of the property <code>'RightPageHeaderContent'</code>.
140 * Sets some string for the text which is printed in the center part of the
141 * header or footer using the interface <code>XHeaderFooterContent</code>
142 * and sets new value of the property <code>'RightPageHeaderContent'</code>.
143 * Creates text cursor for the text which is printed in the center part of
144 * the header or footer. This text cursor is the instance of the service
145 * <code>com.sun.star.text.TextCursor</code>.
148 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
150 XInterface oObj
= null;
151 XPropertySet PropSet
;
152 XNameAccess PageStyles
= null;
153 XStyle StdStyle
= null;
155 XStyleFamiliesSupplier StyleFam
= (XStyleFamiliesSupplier
)
156 UnoRuntime
.queryInterface(
157 XStyleFamiliesSupplier
.class,
160 XNameAccess StyleFamNames
= StyleFam
.getStyleFamilies();
162 PageStyles
= (XNameAccess
) AnyConverter
.toObject(
163 new Type(XNameAccess
.class),StyleFamNames
.getByName("PageStyles"));
164 StdStyle
= (XStyle
) AnyConverter
.toObject(
165 new Type(XStyle
.class),PageStyles
.getByName("Default"));
166 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
167 e
.printStackTrace(log
);
168 throw new StatusException("Couldn't get by name", e
);
169 } catch(com
.sun
.star
.container
.NoSuchElementException e
){
170 e
.printStackTrace(log
);
171 throw new StatusException("Couldn't get by name", e
);
172 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
){
173 e
.printStackTrace(log
);
174 throw new StatusException("Couldn't get by name", e
);
177 //get the property-set
178 PropSet
= (XPropertySet
)
179 UnoRuntime
.queryInterface(XPropertySet
.class, StdStyle
);
181 XHeaderFooterContent RPHC
= null;
182 // creation of testobject here
183 // first we write what we are intend to do to log file
184 log
.println( "creating a test environment" );
186 RPHC
= (XHeaderFooterContent
) AnyConverter
.toObject(
187 new Type(XHeaderFooterContent
.class),
188 PropSet
.getPropertyValue("RightPageHeaderContent"));
189 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
190 e
.printStackTrace(log
);
191 throw new StatusException("Couldn't get HeaderContent", e
);
192 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
){
193 e
.printStackTrace(log
);
194 throw new StatusException("Couldn't get HeaderContent", e
);
195 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
){
196 e
.printStackTrace(log
);
197 throw new StatusException("Couldn't get HeaderContent", e
);
200 XText center
= RPHC
.getCenterText();
201 center
.setString("CENTER");
204 PropSet
.setPropertyValue("RightPageHeaderContent",RPHC
);
205 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
206 e
.printStackTrace(log
);
207 throw new StatusException("Couldn't set HeaderContent", e
);
208 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
209 e
.printStackTrace(log
);
210 throw new StatusException("Couldn't set HeaderContent", e
);
211 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
212 e
.printStackTrace(log
);
213 throw new StatusException("Couldn't set HeaderContent", e
);
214 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
215 e
.printStackTrace(log
);
216 throw new StatusException("Couldn't set HeaderContent", e
);
219 // create testobject here
220 oObj
= center
.createTextCursor();
221 TestEnvironment tEnv
= new TestEnvironment(oObj
);
223 // add relation for XTextRange
224 tEnv
.addObjRelation("XTEXT",
225 UnoRuntime
.queryInterface(XText
.class,center
));
229 } // finish method getTestEnvironment
231 } // finish class ScHeaderFooterTextCursor