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.
57 protected void initialize( TestParameters tParam
, PrintWriter log
) {
58 SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
60 log
.println( "creating a textdocument" );
61 xTextDoc
= SOF
.createTextDoc( null );
62 } catch ( com
.sun
.star
.uno
.Exception e
) {
63 e
.printStackTrace( log
);
64 throw new StatusException( "Couldn't create document", e
);
69 * Disposes text document.
72 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
73 log
.println( " disposing xTextDoc " );
74 DesktopTools
.closeDoc(xTextDoc
);
78 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) {
79 TestEnvironment tEnv
= null;
80 XNameAccess oSFNA
= null;
82 XStyle oMyStyle
= null;
84 log
.println("creating a test environment");
87 log
.println("getting style");
88 XStyleFamiliesSupplier oSFS
= UnoRuntime
.queryInterface(XStyleFamiliesSupplier
.class,
90 XNameAccess oSF
= oSFS
.getStyleFamilies();
91 oSFNA
= UnoRuntime
.queryInterface(
92 XNameAccess
.class,oSF
.getByName("PageStyles")); // get the page style
93 XIndexAccess oSFIA
= UnoRuntime
.queryInterface(XIndexAccess
.class, oSFNA
);
94 oStyle
= UnoRuntime
.queryInterface(
95 XStyle
.class,oSFIA
.getByIndex(0));
96 log
.println("Chosen pool style: "+oStyle
.getName());
98 } catch ( com
.sun
.star
.lang
.WrappedTargetException e
) {
99 log
.println("Error: exception occurred.");
100 e
.printStackTrace(log
);
101 throw new StatusException( "Couldn't create environment ", e
);
102 } catch ( com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
103 log
.println("Error: exception occurred.");
104 e
.printStackTrace(log
);
105 throw new StatusException( "Couldn't create environment ", e
);
106 } catch ( com
.sun
.star
.container
.NoSuchElementException e
) {
107 log
.println("Error: exception occurred.");
108 e
.printStackTrace(log
);
109 throw new StatusException( "Couldn't create environment ", e
);
113 log
.print("Creating a user-defined style... ");
114 XMultiServiceFactory oMSF
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
115 XInterface oInt
= (XInterface
)
116 oMSF
.createInstance("com.sun.star.style.PageStyle");
117 oMyStyle
= UnoRuntime
.queryInterface(XStyle
.class, oInt
);
118 } catch ( com
.sun
.star
.uno
.Exception e
) {
119 log
.println("Error: exception occurred.");
120 e
.printStackTrace(log
);
121 throw new StatusException( "Couldn't create environment ", e
);
125 if (oMyStyle
== null)
126 log
.println("FAILED");
130 XNameContainer oSFNC
= UnoRuntime
.queryInterface(XNameContainer
.class, oSFNA
);
134 if ( oSFNC
.hasByName("My Style") )
135 oSFNC
.removeByName("My Style");
136 oSFNC
.insertByName("My Style", oMyStyle
);
137 } catch ( com
.sun
.star
.lang
.WrappedTargetException e
) {
138 e
.printStackTrace(log
);
139 throw new StatusException( "Couldn't create environment ", e
);
140 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
141 e
.printStackTrace(log
);
142 throw new StatusException( "Couldn't create environment ", e
);
143 } catch ( com
.sun
.star
.container
.NoSuchElementException e
) {
144 e
.printStackTrace(log
);
145 throw new StatusException( "Couldn't create environment ", e
);
146 } catch ( com
.sun
.star
.container
.ElementExistException e
) {
147 e
.printStackTrace(log
);
148 throw new StatusException( "Couldn't create environment ", e
);
151 XText oText
= xTextDoc
.getText();
152 XTextCursor oCursor
= oText
.createTextCursor();
153 XPropertySet xProp
= UnoRuntime
.queryInterface(XPropertySet
.class, oCursor
);
154 Property
[] props
= xProp
.getPropertySetInfo().getProperties();
155 for (int i
=0; i
<props
.length
; i
++)
156 System
.out
.println("# Property: " + props
[i
].Name
+ " val: " + props
[i
].Type
.toString() + " attr: " + props
[i
].Attributes
);
158 xProp
.setPropertyValue("PageDescName", oMyStyle
.getName());
159 } catch ( com
.sun
.star
.lang
.WrappedTargetException e
) {
160 e
.printStackTrace( log
);
161 throw new StatusException( "Couldn't create environment ", e
);
162 } catch ( com
.sun
.star
.lang
.IllegalArgumentException e
) {
163 e
.printStackTrace( log
);
164 throw new StatusException( "Couldn't create environment ", e
);
165 } catch ( com
.sun
.star
.beans
.PropertyVetoException e
) {
166 e
.printStackTrace( log
);
167 throw new StatusException( "Couldn't create environment ", e
);
168 } catch ( com
.sun
.star
.beans
.UnknownPropertyException e
) {
169 e
.printStackTrace( log
);
170 throw new StatusException( "Couldn't create environment ", e
);
173 // oMyStyle = oStyle;
174 log
.println("creating a new environment for object");
175 tEnv
= new TestEnvironment(oMyStyle
);
176 tEnv
.addObjRelation("PoolStyle", oStyle
);
178 tEnv
.addObjRelation("FollowStyle", "Envelope");
179 XPropertySet xStyleProp
= UnoRuntime
.queryInterface(XPropertySet
.class, oMyStyle
);
181 short exclude
= PropertyAttribute
.READONLY
;
182 String
[] names
= utils
.getFilteredPropertyNames(xStyleProp
, (short)0, exclude
);
183 tEnv
.addObjRelation("PropertyNames", names
);