2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.InstCreator
;
28 import util
.ParagraphDsc
;
29 import util
.SOfficeFactory
;
32 import com
.sun
.star
.beans
.XPropertySet
;
33 import com
.sun
.star
.container
.XNameAccess
;
34 import com
.sun
.star
.lang
.XMultiServiceFactory
;
35 import com
.sun
.star
.style
.XStyle
;
36 import com
.sun
.star
.style
.XStyleFamiliesSupplier
;
37 import com
.sun
.star
.text
.XText
;
38 import com
.sun
.star
.text
.XTextDocument
;
39 import com
.sun
.star
.uno
.AnyConverter
;
40 import com
.sun
.star
.uno
.Type
;
41 import com
.sun
.star
.uno
.UnoRuntime
;
42 import com
.sun
.star
.uno
.XInterface
;
46 * Object implements the following interfaces :
48 * <li> <code>com::sun::star::text::XTextRangeMover</code></li>
49 * <li> <code>com::sun::star::text::XSimpleText</code></li>
50 * <li> <code>com::sun::star::text::XTextRange</code></li>
51 * <li> <code>com::sun::star::text::XRelativeTextContentInsert</code></li>
52 * <li> <code>com::sun::star::text::XTextRangeCompare</code></li>
53 * <li> <code>com::sun::star::container::XElementAccess</code></li>
54 * <li> <code>com::sun::star::container::XEnumerationAccess</code></li>
55 * <li> <code>com::sun::star::text::XText</code></li>
57 * This object test <b> is NOT </b> designed to be run in several
58 * threads concurently.
59 * @see com.sun.star.text.XTextRangeMover
60 * @see com.sun.star.text.XSimpleText
61 * @see com.sun.star.text.XTextRange
62 * @see com.sun.star.text.XRelativeTextContentInsert
63 * @see com.sun.star.text.XTextRangeCompare
64 * @see com.sun.star.container.XElementAccess
65 * @see com.sun.star.container.XEnumerationAccess
66 * @see com.sun.star.text.XText
67 * @see ifc.text._XTextRangeMover
68 * @see ifc.text._XSimpleText
69 * @see ifc.text._XTextRange
70 * @see ifc.text._XRelativeTextContentInsert
71 * @see ifc.text._XTextRangeCompare
72 * @see ifc.container._XElementAccess
73 * @see ifc.container._XEnumerationAccess
74 * @see ifc.text._XText
76 public class SwXHeadFootText
extends TestCase
{
77 XTextDocument xTextDoc
;
80 * Creates text document.
82 protected void initialize( TestParameters tParam
, PrintWriter log
) {
83 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
) tParam
.getMSF() );
85 log
.println( "creating a textdocument" );
86 xTextDoc
= SOF
.createTextDoc( null );
87 } catch ( com
.sun
.star
.uno
.Exception e
) {
88 e
.printStackTrace( log
);
89 throw new StatusException( "Couldn't create document", e
);
94 * Disposes text document.
96 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
97 log
.println( " disposing xTextDoc " );
98 util
.DesktopTools
.closeDoc(xTextDoc
);
102 * Creating a Testenvironment for the interfaces to be tested. At first
103 * style families are obtained from text document, then style 'Standard' has
104 * gotten from style family 'PageStyles'. At the end, document header and
105 * footer are switched on and document text is obtained.
106 * Object relations created :
108 * <li> <code>'XTEXTINFO'</code> for
109 * {@link ifc.text._XRelativeTextContentInsert},
110 * {@link ifc.text._XText} : creates tables 6x4</li>
111 * <li> <code>'TEXTDOC'</code> for
112 * {@link ifc.text._XTextRangeCompare} : text document</li>
113 * <li> <code>'PARA'</code> for
114 * {@link ifc.text._XRelativeTextContentInsert} : paragraph creator</li>
117 protected synchronized TestEnvironment
createTestEnvironment(TestParameters Param
, PrintWriter log
) {
118 XInterface oObj
= null;
119 XPropertySet PropSet
;
120 XNameAccess PageStyles
= null;
121 XStyle StdStyle
= null;
123 log
.println( "creating a test environment" );
124 XStyleFamiliesSupplier StyleFam
= UnoRuntime
.queryInterface(XStyleFamiliesSupplier
.class, xTextDoc
);
125 XNameAccess StyleFamNames
= StyleFam
.getStyleFamilies();
127 // obtains style 'Standatd' from style family 'PageStyles'
129 PageStyles
= (XNameAccess
) AnyConverter
.toObject(
130 new Type(XNameAccess
.class),StyleFamNames
.getByName("PageStyles"));
131 StdStyle
= (XStyle
) AnyConverter
.toObject(
132 new Type(XStyle
.class),PageStyles
.getByName("Standard"));
133 } catch ( com
.sun
.star
.lang
.WrappedTargetException e
) {
134 e
.printStackTrace(log
);
135 throw new StatusException("Error getting style by name!", e
);
136 } catch ( com
.sun
.star
.container
.NoSuchElementException e
) {
137 e
.printStackTrace(log
);
138 throw new StatusException("Error, no such style name! ", e
);
139 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
140 e
.printStackTrace(log
);
141 throw new StatusException("Error getting style by name!", e
);
144 PropSet
= UnoRuntime
.queryInterface( XPropertySet
.class, StdStyle
);
146 // changing/getting some properties
148 log
.println( "Switching on header" );
149 PropSet
.setPropertyValue("HeaderIsOn", new Boolean(true));
150 log
.println( "Switching on footer" );
151 PropSet
.setPropertyValue("FooterIsOn", new Boolean(true));
152 log
.println( "Get header text" );
153 oObj
= UnoRuntime
.queryInterface(
154 XText
.class, PropSet
.getPropertyValue("HeaderText"));
155 } catch ( com
.sun
.star
.lang
.WrappedTargetException e
) {
156 e
.printStackTrace(log
);
157 throw new StatusException("Couldn't set/get propertyValue...", e
);
158 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
159 e
.printStackTrace(log
);
160 throw new StatusException("Couldn't set/get propertyValue...", e
);
161 } catch ( com
.sun
.star
.beans
.PropertyVetoException e
) {
162 e
.printStackTrace(log
);
163 throw new StatusException("Couldn't set/get propertyValue...", e
);
164 } catch ( com
.sun
.star
.beans
.UnknownPropertyException e
) {
165 e
.printStackTrace(log
);
166 throw new StatusException("Couldn't set/get propertyValue...", e
);
169 log
.println( "creating a new environment for bodytext object" );
170 TestEnvironment tEnv
= new TestEnvironment( oObj
);
172 log
.println( " adding Paragraph" );
173 ParagraphDsc pDsc
= new ParagraphDsc();
174 tEnv
.addObjRelation( "PARA", new InstCreator( xTextDoc
, pDsc
) );
176 log
.println( "adding InstDescriptor object" );
177 TableDsc tDsc
= new TableDsc( 6, 4 );
179 log
.println( "adding InstCreator object" );
180 tEnv
.addObjRelation( "XTEXTINFO", new InstCreator( xTextDoc
, tDsc
) );
182 tEnv
.addObjRelation( "TEXT", oObj
);
185 } // finish method getTestEnvironment
187 } // finish class SwXHeadFootText