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 .
20 import com
.sun
.star
.beans
.Property
;
21 import com
.sun
.star
.beans
.PropertyAttribute
;
22 import com
.sun
.star
.beans
.XPropertySet
;
23 import com
.sun
.star
.container
.XIndexAccess
;
24 import com
.sun
.star
.container
.XNameAccess
;
25 import com
.sun
.star
.container
.XNameContainer
;
26 import com
.sun
.star
.lang
.XMultiServiceFactory
;
27 import com
.sun
.star
.style
.XStyle
;
28 import com
.sun
.star
.style
.XStyleFamiliesSupplier
;
29 import com
.sun
.star
.text
.XText
;
30 import com
.sun
.star
.text
.XTextCursor
;
31 import com
.sun
.star
.text
.XTextDocument
;
32 import com
.sun
.star
.uno
.UnoRuntime
;
33 import com
.sun
.star
.uno
.XInterface
;
34 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.DesktopTools
;
40 import util
.SOfficeFactory
;
44 * Test for object which is represented by service
45 * <code>com.sun.star.style.PageStyle</code>. <p>
46 * @see com.sun.star.style.PageStyle
48 public class PageStyle
extends TestCase
{
50 XTextDocument xTextDoc
;
51 SOfficeFactory SOF
= null;
54 * Creates text document.
56 protected void initialize( TestParameters tParam
, PrintWriter log
) {
57 SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
59 log
.println( "creating a textdocument" );
60 xTextDoc
= SOF
.createTextDoc( null );
61 } catch ( com
.sun
.star
.uno
.Exception e
) {
62 e
.printStackTrace( log
);
63 throw new StatusException( "Couldn't create document", e
);
68 * Disposes text document.
70 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
71 log
.println( " disposing xTextDoc " );
72 DesktopTools
.closeDoc(xTextDoc
);
75 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
76 TestEnvironment tEnv
= null;
77 XNameAccess oSFNA
= null;
79 XStyle oMyStyle
= null;
81 log
.println("creating a test environment");
84 log
.println("getting style");
85 XStyleFamiliesSupplier oSFS
= UnoRuntime
.queryInterface(XStyleFamiliesSupplier
.class,
87 XNameAccess oSF
= oSFS
.getStyleFamilies();
88 oSFNA
= UnoRuntime
.queryInterface(
89 XNameAccess
.class,oSF
.getByName("PageStyles")); // get the page style
90 XIndexAccess oSFIA
= UnoRuntime
.queryInterface(XIndexAccess
.class, oSFNA
);
91 oStyle
= UnoRuntime
.queryInterface(
92 XStyle
.class,oSFIA
.getByIndex(0));
93 log
.println("Chosen pool style: "+oStyle
.getName());
95 } catch ( com
.sun
.star
.lang
.WrappedTargetException e
) {
96 log
.println("Error: exception occurred.");
97 e
.printStackTrace(log
);
98 throw new StatusException( "Couldn't create environment ", e
);
99 } catch ( com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
100 log
.println("Error: exception occurred.");
101 e
.printStackTrace(log
);
102 throw new StatusException( "Couldn't create environment ", e
);
103 } catch ( com
.sun
.star
.container
.NoSuchElementException e
) {
104 log
.println("Error: exception occurred.");
105 e
.printStackTrace(log
);
106 throw new StatusException( "Couldn't create environment ", e
);
110 log
.print("Creating a user-defined style... ");
111 XMultiServiceFactory oMSF
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
112 XInterface oInt
= (XInterface
)
113 oMSF
.createInstance("com.sun.star.style.PageStyle");
114 // oMSF.createInstanceWithArguments("com.sun.star.style.PageStyle",new Object[]{oStyle});
115 oMyStyle
= UnoRuntime
.queryInterface(XStyle
.class, oInt
);
116 } catch ( com
.sun
.star
.uno
.Exception e
) {
117 log
.println("Error: exception occurred.");
118 e
.printStackTrace(log
);
119 throw new StatusException( "Couldn't create environment ", e
);
123 if (oMyStyle
== null)
124 log
.println("FAILED");
128 XNameContainer oSFNC
= UnoRuntime
.queryInterface(XNameContainer
.class, oSFNA
);
132 if ( oSFNC
.hasByName("My Style") )
133 oSFNC
.removeByName("My Style");
134 oSFNC
.insertByName("My Style", oMyStyle
);
135 } catch ( com
.sun
.star
.lang
.WrappedTargetException e
) {
136 e
.printStackTrace(log
);
137 throw new StatusException( "Couldn't create environment ", e
);
138 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
139 e
.printStackTrace(log
);
140 throw new StatusException( "Couldn't create environment ", e
);
141 } catch ( com
.sun
.star
.container
.NoSuchElementException e
) {
142 e
.printStackTrace(log
);
143 throw new StatusException( "Couldn't create environment ", e
);
144 } catch ( com
.sun
.star
.container
.ElementExistException e
) {
145 e
.printStackTrace(log
);
146 throw new StatusException( "Couldn't create environment ", e
);
149 XText oText
= xTextDoc
.getText();
150 XTextCursor oCursor
= oText
.createTextCursor();
151 XPropertySet xProp
= UnoRuntime
.queryInterface(XPropertySet
.class, oCursor
);
152 Property
[] props
= xProp
.getPropertySetInfo().getProperties();
153 for (int i
=0; i
<props
.length
; i
++)
154 System
.out
.println("# Property: " + props
[i
].Name
+ " val: " + props
[i
].Type
.toString() + " attr: " + props
[i
].Attributes
);
156 xProp
.setPropertyValue("PageDescName", oMyStyle
.getName());
157 } catch ( com
.sun
.star
.lang
.WrappedTargetException e
) {
158 e
.printStackTrace( log
);
159 throw new StatusException( "Couldn't create environment ", e
);
160 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
161 e
.printStackTrace( log
);
162 throw new StatusException( "Couldn't create environment ", e
);
163 } catch ( com
.sun
.star
.beans
.PropertyVetoException e
) {
164 e
.printStackTrace( log
);
165 throw new StatusException( "Couldn't create environment ", e
);
166 } catch ( com
.sun
.star
.beans
.UnknownPropertyException e
) {
167 e
.printStackTrace( log
);
168 throw new StatusException( "Couldn't create environment ", e
);
171 // oMyStyle = oStyle;
172 log
.println("creating a new environment for object");
173 tEnv
= new TestEnvironment(oMyStyle
);
174 tEnv
.addObjRelation("PoolStyle", oStyle
);
176 tEnv
.addObjRelation("FollowStyle", "Envelope");
177 XPropertySet xStyleProp
= UnoRuntime
.queryInterface(XPropertySet
.class, oMyStyle
);
179 short exclude
= PropertyAttribute
.READONLY
;
180 String
[] names
= utils
.getFilteredPropertyNames(xStyleProp
, (short)0, exclude
);
181 tEnv
.addObjRelation("PropertyNames", names
);