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: ScHeaderFooterContentObj.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.sheet.HeaderFooterContent</code>. <p>
58 * Object implements the following interfaces :
60 * <li> <code>com::sun::star::sheet::XHeaderFooterContent</code></li>
62 * @see com.sun.star.sheet.HeaderFooterContent
63 * @see com.sun.star.sheet.XHeaderFooterContent
64 * @see ifc.sheet._XHeaderFooterContent
66 public class ScHeaderFooterContentObj
extends TestCase
{
67 static XSpreadsheetDocument xSpreadsheetDoc
;
70 * Creates Spreadsheet document.
72 protected void initialize( TestParameters tParam
, PrintWriter log
) {
73 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
76 log
.println( "creating a Spreadsheet document" );
77 xSpreadsheetDoc
= SOF
.createCalcDoc(null);
78 } catch ( com
.sun
.star
.uno
.Exception e
) {
79 // Some exception occures.FAILED
80 e
.printStackTrace( log
);
81 throw new StatusException( "Couldn't create document", e
);
87 * Disposes Spreadsheet document.
89 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
90 log
.println( " disposing xSheetDoc " );
91 XComponent oComp
= (XComponent
)
92 UnoRuntime
.queryInterface (XComponent
.class, xSpreadsheetDoc
);
93 util
.DesktopTools
.closeDoc(oComp
);
97 * Creating a Testenvironment for the interfaces to be tested.
98 * Retrieves the collection of style families available in the document
99 * using the interface <code>XStyleFamiliesSupplier</code>.
100 * Obtains default style from the style family <code>'PageStyles'</code>.
101 * Retrieves value of the property <code>'RightPageHeaderContent'</code>.
102 * Sets some text for every part of header or footer using the interface
103 * <code>XHeaderFooterContent</code> and sets new value of the property
104 * <code>'RightPageHeaderContent'</code>. The value of this property is the
105 * instance of the service <code>com.sun.star.sheet.HeaderFooterContent</code>.
106 * @see com.sun.star.style.XStyleFamiliesSupplier
107 * @see com.sun.star.sheet.XHeaderFooterContent
108 * @see com.sun.star.sheet.HeaderFooterContent
110 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
112 XInterface oObj
= null;
113 XPropertySet PropSet
;
114 XNameAccess PageStyles
= null;
115 XStyle StdStyle
= null;
117 XStyleFamiliesSupplier StyleFam
= (XStyleFamiliesSupplier
)
118 UnoRuntime
.queryInterface(
119 XStyleFamiliesSupplier
.class,
121 XNameAccess StyleFamNames
= StyleFam
.getStyleFamilies();
123 PageStyles
= (XNameAccess
) AnyConverter
.toObject(
124 new Type(XNameAccess
.class),StyleFamNames
.getByName("PageStyles"));
125 StdStyle
= (XStyle
) AnyConverter
.toObject(
126 new Type(XStyle
.class),PageStyles
.getByName("Default"));
127 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
128 e
.printStackTrace(log
);
129 throw new StatusException("Couldn't get by name", e
);
130 } catch(com
.sun
.star
.container
.NoSuchElementException e
){
131 e
.printStackTrace(log
);
132 throw new StatusException("Couldn't get by name", e
);
133 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
){
134 e
.printStackTrace(log
);
135 throw new StatusException("Couldn't get by name", e
);
138 //get the property-set
139 PropSet
= (XPropertySet
)
140 UnoRuntime
.queryInterface(XPropertySet
.class, StdStyle
);
142 XHeaderFooterContent RPHC
= null;
143 // creation of testobject here
144 // first we write what we are intend to do to log file
145 log
.println( "creating a test environment" );
147 RPHC
= (XHeaderFooterContent
) AnyConverter
.toObject(
148 new Type(XHeaderFooterContent
.class),
149 PropSet
.getPropertyValue("RightPageHeaderContent"));
150 } catch(com
.sun
.star
.lang
.WrappedTargetException e
){
151 e
.printStackTrace(log
);
152 throw new StatusException("Couldn't get HeaderContent", e
);
153 } catch(com
.sun
.star
.beans
.UnknownPropertyException e
){
154 e
.printStackTrace(log
);
155 throw new StatusException("Couldn't get HeaderContent", e
);
156 } catch(com
.sun
.star
.lang
.IllegalArgumentException e
){
157 e
.printStackTrace(log
);
158 throw new StatusException("Couldn't get HeaderContent", e
);
161 XText center
= RPHC
.getCenterText();
162 XText left
= RPHC
.getLeftText();
163 XText right
= RPHC
.getRightText();
165 center
.setString("CENTER");
166 left
.setString("LEFT");
167 right
.setString("RIGHT");
170 PropSet
.setPropertyValue("RightPageHeaderContent", RPHC
);
171 } catch (com
.sun
.star
.lang
.WrappedTargetException e
) {
172 e
.printStackTrace(log
);
173 throw new StatusException("Couldn't set HeaderContent", e
);
174 } catch (com
.sun
.star
.lang
.IllegalArgumentException e
) {
175 e
.printStackTrace(log
);
176 throw new StatusException("Couldn't set HeaderContent", e
);
177 } catch (com
.sun
.star
.beans
.PropertyVetoException e
) {
178 e
.printStackTrace(log
);
179 throw new StatusException("Couldn't set HeaderContent", e
);
180 } catch (com
.sun
.star
.beans
.UnknownPropertyException e
) {
181 e
.printStackTrace(log
);
182 throw new StatusException("Couldn't set HeaderContent", e
);
185 // create testobject here
187 TestEnvironment tEnv
= new TestEnvironment(oObj
);
191 } // finish method getTestEnvironment
193 } // finish class ScHeaderFooterContentObj