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: SwXHeadFootText.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
.InstCreator
;
40 import util
.ParagraphDsc
;
41 import util
.SOfficeFactory
;
44 import com
.sun
.star
.beans
.XPropertySet
;
45 import com
.sun
.star
.container
.XNameAccess
;
46 import com
.sun
.star
.lang
.XMultiServiceFactory
;
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
.XTextDocument
;
51 import com
.sun
.star
.uno
.AnyConverter
;
52 import com
.sun
.star
.uno
.Type
;
53 import com
.sun
.star
.uno
.UnoRuntime
;
54 import com
.sun
.star
.uno
.XInterface
;
58 * Object implements the following interfaces :
60 * <li> <code>com::sun::star::text::XTextRangeMover</code></li>
61 * <li> <code>com::sun::star::text::XSimpleText</code></li>
62 * <li> <code>com::sun::star::text::XTextRange</code></li>
63 * <li> <code>com::sun::star::text::XRelativeTextContentInsert</code></li>
64 * <li> <code>com::sun::star::text::XTextRangeCompare</code></li>
65 * <li> <code>com::sun::star::container::XElementAccess</code></li>
66 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
67 * <li> <code>com::sun::star::text::XText</code></li>
69 * This object test <b> is NOT </b> designed to be run in several
70 * threads concurently.
71 * @see com.sun.star.text.XTextRangeMover
72 * @see com.sun.star.text.XSimpleText
73 * @see com.sun.star.text.XTextRange
74 * @see com.sun.star.text.XRelativeTextContentInsert
75 * @see com.sun.star.text.XTextRangeCompare
76 * @see com.sun.star.container.XElementAccess
77 * @see com.sun.star.container.XEnumerationAccess
78 * @see com.sun.star.text.XText
79 * @see ifc.text._XTextRangeMover
80 * @see ifc.text._XSimpleText
81 * @see ifc.text._XTextRange
82 * @see ifc.text._XRelativeTextContentInsert
83 * @see ifc.text._XTextRangeCompare
84 * @see ifc.container._XElementAccess
85 * @see ifc.container._XEnumerationAccess
86 * @see ifc.text._XText
88 public class SwXHeadFootText
extends TestCase
{
89 XTextDocument xTextDoc
;
92 * Creates text document.
94 protected void initialize( TestParameters tParam
, PrintWriter log
) {
95 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
) tParam
.getMSF() );
97 log
.println( "creating a textdocument" );
98 xTextDoc
= SOF
.createTextDoc( null );
99 } catch ( com
.sun
.star
.uno
.Exception e
) {
100 e
.printStackTrace( log
);
101 throw new StatusException( "Couldn't create document", e
);
106 * Disposes text document.
108 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
109 log
.println( " disposing xTextDoc " );
110 util
.DesktopTools
.closeDoc(xTextDoc
);
114 * Creating a Testenvironment for the interfaces to be tested. At first
115 * style families are obtained from text document, then style 'Standard' has
116 * gotten from style family 'PageStyles'. At the end, document header and
117 * footer are switched on and document text is obtained.
118 * Object relations created :
120 * <li> <code>'XTEXTINFO'</code> for
121 * {@link ifc.text._XRelativeTextContentInsert},
122 * {@link ifc.text._XText} : creates tables 6x4</li>
123 * <li> <code>'TEXTDOC'</code> for
124 * {@link ifc.text._XTextRangeCompare} : text document</li>
125 * <li> <code>'PARA'</code> for
126 * {@link ifc.text._XRelativeTextContentInsert} : paragraph creator</li>
129 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
130 XInterface oObj
= null;
131 XPropertySet PropSet
;
132 XNameAccess PageStyles
= null;
133 XStyle StdStyle
= null;
135 log
.println( "creating a test environment" );
136 XStyleFamiliesSupplier StyleFam
= (XStyleFamiliesSupplier
)
137 UnoRuntime
.queryInterface(XStyleFamiliesSupplier
.class, xTextDoc
);
138 XNameAccess StyleFamNames
= StyleFam
.getStyleFamilies();
140 // obtains style 'Standatd' from style family 'PageStyles'
142 PageStyles
= (XNameAccess
) AnyConverter
.toObject(
143 new Type(XNameAccess
.class),StyleFamNames
.getByName("PageStyles"));
144 StdStyle
= (XStyle
) AnyConverter
.toObject(
145 new Type(XStyle
.class),PageStyles
.getByName("Standard"));
146 } catch ( com
.sun
.star
.lang
.WrappedTargetException e
) {
147 e
.printStackTrace(log
);
148 throw new StatusException("Error getting style by name!", e
);
149 } catch ( com
.sun
.star
.container
.NoSuchElementException e
) {
150 e
.printStackTrace(log
);
151 throw new StatusException("Error, no such style name! ", e
);
152 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
153 e
.printStackTrace(log
);
154 throw new StatusException("Error getting style by name!", e
);
157 PropSet
= (XPropertySet
)
158 UnoRuntime
.queryInterface( XPropertySet
.class, StdStyle
);
160 // changing/getting some properties
162 log
.println( "Switching on header" );
163 PropSet
.setPropertyValue("HeaderIsOn", new Boolean(true));
164 log
.println( "Switching on footer" );
165 PropSet
.setPropertyValue("FooterIsOn", new Boolean(true));
166 log
.println( "Get header text" );
167 oObj
= (XText
) UnoRuntime
.queryInterface(
168 XText
.class, PropSet
.getPropertyValue("HeaderText"));
169 } catch ( com
.sun
.star
.lang
.WrappedTargetException e
) {
170 e
.printStackTrace(log
);
171 throw new StatusException("Couldn't set/get propertyValue...", e
);
172 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
173 e
.printStackTrace(log
);
174 throw new StatusException("Couldn't set/get propertyValue...", e
);
175 } catch ( com
.sun
.star
.beans
.PropertyVetoException e
) {
176 e
.printStackTrace(log
);
177 throw new StatusException("Couldn't set/get propertyValue...", e
);
178 } catch ( com
.sun
.star
.beans
.UnknownPropertyException e
) {
179 e
.printStackTrace(log
);
180 throw new StatusException("Couldn't set/get propertyValue...", e
);
183 log
.println( "creating a new environment for bodytext object" );
184 TestEnvironment tEnv
= new TestEnvironment( oObj
);
186 log
.println( " adding Paragraph" );
187 ParagraphDsc pDsc
= new ParagraphDsc();
188 tEnv
.addObjRelation( "PARA", new InstCreator( xTextDoc
, pDsc
) );
190 log
.println( "adding InstDescriptor object" );
191 TableDsc tDsc
= new TableDsc( 6, 4 );
193 log
.println( "adding InstCreator object" );
194 tEnv
.addObjRelation( "XTEXTINFO", new InstCreator( xTextDoc
, tDsc
) );
196 tEnv
.addObjRelation( "TEXT", oObj
);
199 } // finish method getTestEnvironment
201 } // finish class SwXHeadFootText