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
.PropertyAttribute
;
21 import com
.sun
.star
.beans
.XPropertySet
;
22 import com
.sun
.star
.container
.XIndexAccess
;
23 import com
.sun
.star
.container
.XNameAccess
;
24 import com
.sun
.star
.container
.XNameContainer
;
25 import com
.sun
.star
.lang
.XMultiServiceFactory
;
26 import com
.sun
.star
.style
.XStyle
;
27 import com
.sun
.star
.style
.XStyleFamiliesSupplier
;
28 import com
.sun
.star
.text
.XText
;
29 import com
.sun
.star
.text
.XTextCursor
;
30 import com
.sun
.star
.text
.XTextDocument
;
31 import com
.sun
.star
.uno
.UnoRuntime
;
32 import com
.sun
.star
.uno
.XInterface
;
34 import java
.io
.PrintWriter
;
37 import lib
.StatusException
;
39 import lib
.TestEnvironment
;
40 import lib
.TestParameters
;
41 import util
.DesktopTools
;
42 import util
.SOfficeFactory
;
46 * Test for object which is represented by service
47 * <code>com.sun.star.style.ConditionalParagraphStyle</code>. <p>
48 * @see com.sun.star.style.ConditionalParagraphStyle
50 public class ConditionalParagraphStyle
extends TestCase
{
52 XTextDocument xTextDoc
;
53 SOfficeFactory SOF
= null;
56 * Creates text document.
59 protected void initialize( TestParameters tParam
, PrintWriter log
) throws Exception
{
60 SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
61 log
.println( "creating a textdocument" );
62 xTextDoc
= SOF
.createTextDoc( null );
66 * Disposes text document.
69 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
70 log
.println( " disposing xTextDoc " );
71 DesktopTools
.closeDoc(xTextDoc
);
75 * Create a new instance of the conditional
76 * paragraph style, and insert it into the document.
77 * @see com.sun.star.style.ConditionalParagraphStyle
78 * @param tParam The test parameters
79 * @param log The log writer.
82 protected TestEnvironment
createTestEnvironment(TestParameters tParam
, PrintWriter log
) throws Exception
{
83 TestEnvironment tEnv
= null;
84 XNameAccess oSFNA
= null;
86 XStyle oMyStyle
= null;
88 log
.println("creating a test environment");
90 log
.println("getting style");
91 XStyleFamiliesSupplier oSFS
= UnoRuntime
.queryInterface(XStyleFamiliesSupplier
.class,
93 XNameAccess oSF
= oSFS
.getStyleFamilies();
94 oSFNA
= UnoRuntime
.queryInterface(
95 XNameAccess
.class,oSF
.getByName("ParagraphStyles"));
96 XIndexAccess oSFIA
= UnoRuntime
.queryInterface(XIndexAccess
.class, oSFNA
);
97 oStyle
= UnoRuntime
.queryInterface(
98 XStyle
.class,oSFIA
.getByIndex(1));
100 log
.print("Creating a user-defined style... ");
101 XMultiServiceFactory oMSF
= UnoRuntime
.queryInterface(XMultiServiceFactory
.class, xTextDoc
);
102 XInterface oInt
= (XInterface
)
103 oMSF
.createInstance("com.sun.star.style.ConditionalParagraphStyle");
104 oMyStyle
= UnoRuntime
.queryInterface(XStyle
.class, oInt
);
107 if (oMyStyle
== null) {
108 log
.println("FAILED");
109 throw new StatusException(Status
.failed("Couldn't create an own style "));
115 XNameContainer oSFNC
= UnoRuntime
.queryInterface(XNameContainer
.class, oSFNA
);
117 if ( oSFNC
.hasByName("My Style") )
118 oSFNC
.removeByName("My Style");
119 oSFNC
.insertByName("My Style", oMyStyle
);
121 XText oText
= xTextDoc
.getText();
122 XTextCursor oCursor
= oText
.createTextCursor();
123 XPropertySet xProp
= UnoRuntime
.queryInterface(XPropertySet
.class, oCursor
);
124 xProp
.setPropertyValue("ParaStyleName", oMyStyle
.getName());
126 log
.println("creating a new environment for object");
127 tEnv
= new TestEnvironment(oMyStyle
);
128 tEnv
.addObjRelation("PoolStyle", oStyle
);
130 XPropertySet xStyleProp
= UnoRuntime
.queryInterface(XPropertySet
.class, oMyStyle
);
131 short exclude
= PropertyAttribute
.READONLY
;
132 String
[] skipPropertiesNamed
= { "ParaBackGraphicURL" };
134 String
[] names
= utils
.getFilteredPropertyNames(xStyleProp
, (short)0, exclude
, skipPropertiesNamed
);
136 tEnv
.addObjRelation("PropertyNames", names
);
137 tEnv
.addObjRelation("SkipProperties", skipPropertiesNamed
);