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 .
19 package mod
._xmloff
.Impress
;
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.SOfficeFactory
;
29 import com
.sun
.star
.beans
.XPropertySet
;
30 import com
.sun
.star
.frame
.XController
;
31 import com
.sun
.star
.frame
.XModel
;
32 import com
.sun
.star
.lang
.XComponent
;
33 import com
.sun
.star
.lang
.XMultiServiceFactory
;
34 import com
.sun
.star
.uno
.UnoRuntime
;
35 import com
.sun
.star
.uno
.XInterface
;
38 * Test for object which is represented by service
39 * <code>com.sun.star.comp.Impress.XMLSettingsImporter</code>. <p>
40 * Object implements the following interfaces :
42 * <li><code>com::sun::star::lang::XInitialization</code></li>
43 * <li><code>com::sun::star::document::XImporter</code></li>
44 * <li><code>com::sun::star::document::XFilter</code></li>
45 * <li><code>com::sun::star::document::ImportFilter</code></li>
46 * <li><code>com::sun::star::beans::XPropertySet</code></li>
47 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
50 * @see com.sun.star.lang.XInitialization
51 * @see com.sun.star.document.XImporter
52 * @see com.sun.star.document.XFilter
53 * @see com.sun.star.document.ImportFilter
54 * @see com.sun.star.beans.XPropertySet
55 * @see com.sun.star.xml.sax.XDocumentHandler
56 * @see ifc.lang._XInitialization
57 * @see ifc.document._XImporter
58 * @see ifc.document._XFilter
59 * @see ifc.document._XExporter
60 * @see ifc.beans._XPropertySet
61 * @see ifc.xml.sax._XDocumentHandler
63 public class XMLSettingsImporter
extends TestCase
{
64 XComponent xImpressDoc
= null;
67 * New impress document created.
70 protected void initialize( TestParameters tParam
, PrintWriter log
) {
72 // get a soffice factory object
73 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF());
76 log
.println( "creating an impress document" );
77 xImpressDoc
= SOF
.createImpressDoc(null);
78 } catch ( Exception e
) {
79 // Some exception occurs.FAILED
80 e
.printStackTrace( log
);
81 throw new StatusException( "Couldn't create document", e
);
86 * Impress document destroyed.
89 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
90 log
.println( " disposing document " );
91 xImpressDoc
.dispose();
95 * Creating a Testenvironment for the interfaces to be tested.
96 * Creates an instance of the service
97 * <code>com.sun.star.comp.Impress.XMLStylesImporter</code><p>
99 * The Impress document is set as a target document for importer.
100 * Value of a property "IsLayerMode" has imported as 'true' to a target
101 * document. After import property value getting from target document
103 * Object relations created :
105 * <li> <code>'XDocumentHandler.XMLData'</code> for
106 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
107 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
108 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
109 * <li> <code>'TargetDocument'</code> for
110 * {@link ifc.document._XImporter} interface </li>
114 public synchronized TestEnvironment createTestEnvironment
115 (TestParameters tParam
, PrintWriter log
) throws StatusException
{
117 XInterface oObj
= null;
120 // creation of testobject here
121 // first we write what we are intend to do to log file
122 log
.println( "creating a test environment" );
124 XMultiServiceFactory xMSF
= tParam
.getMSF() ;
127 oInt
= xMSF
.createInstance
128 ("com.sun.star.comp.Impress.XMLSettingsImporter") ;
130 } catch (com
.sun
.star
.uno
.Exception e
) {
131 e
.printStackTrace(log
) ;
132 throw new StatusException("Can't create component.", e
) ;
135 oObj
= (XInterface
) oInt
;
137 // create testobject here
138 log
.println( "creating a new environment for Paragraph object" );
139 TestEnvironment tEnv
= new TestEnvironment( oObj
);
142 tEnv
.addObjRelation("TargetDocument", xImpressDoc
) ;
144 // adding relation for XDocumentHandler
145 String
[][] xml
= new String
[][] {
146 {"start", "office:document-settings",
147 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
148 "xmlns:xlink", "CDATA", "http://www.w3.org/1999/xlink",
149 "xmlns:presentation", "CDATA",
150 "http://openoffice.org/2000/presentation",
151 "xmlns:config", "CDATA", "http://openoffice.org/2001/config",
152 "office:version", "CDATA", "1.0"},
153 {"start", "office:settings"},
154 {"start", "config:config-item-map-indexed", "config:name",
156 {"start", "config:config-item-map-entry"},
157 {"start","config:config-item", "config:name", "CDATA",
160 {"end", "config:config-item"},
161 {"end", "config:config-item-map-entry"},
162 {"end", "config:config-item-map-indexed"},
163 {"end", "office:settings"},
164 {"end", "office:document-settings"}} ;
166 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
168 // get property before import
169 XModel xImpressModel
= UnoRuntime
.queryInterface(XModel
.class, xImpressDoc
);
170 XController xController
= xImpressModel
.getCurrentController();
171 final XPropertySet xPropSet
= UnoRuntime
.queryInterface(XPropertySet
.class, xController
);
173 log
.println("Property \"IsLayerMode\" before import is " +
174 xPropSet
.getPropertyValue("IsLayerMode"));
175 } catch (com
.sun
.star
.uno
.Exception e
) {
176 e
.printStackTrace(log
);
177 throw new StatusException("Can't create component.", e
);
179 final PrintWriter logF
= log
;
180 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
181 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
182 public boolean checkImport() {
185 propValue
= (Boolean
) xPropSet
.getPropertyValue
187 } catch (com
.sun
.star
.uno
.Exception e
) {
188 e
.printStackTrace(logF
);
189 throw new StatusException
190 ("Can't get property value.", e
);
192 logF
.println("Property \"IsLayerMode\" after import is "
194 return propValue
.booleanValue();
199 } // end of getTestEnvironment