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
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.SOfficeFactory
;
28 import com
.sun
.star
.beans
.XPropertySet
;
29 import com
.sun
.star
.frame
.XController
;
30 import com
.sun
.star
.lang
.XMultiServiceFactory
;
31 import com
.sun
.star
.text
.XTextDocument
;
32 import com
.sun
.star
.uno
.UnoRuntime
;
33 import com
.sun
.star
.uno
.XInterface
;
34 import com
.sun
.star
.view
.XViewSettingsSupplier
;
37 * Test for object which is represented by service
38 * <code>com.sun.star.comp.Writer.XMLSettingsImporter</code>. <p>
39 * Object implements the following interfaces :
41 * <li><code>com::sun::star::lang::XInitialization</code></li>
42 * <li><code>com::sun::star::document::XImporter</code></li>
43 * <li><code>com::sun::star::document::XFilter</code></li>
44 * <li><code>com::sun::star::document::ImportFilter</code></li>
45 * <li><code>com::sun::star::beans::XPropertySet</code></li>
46 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
49 * @see com.sun.star.lang.XInitialization
50 * @see com.sun.star.document.XImporter
51 * @see com.sun.star.document.XFilter
52 * @see com.sun.star.document.ImportFilter
53 * @see com.sun.star.beans.XPropertySet
54 * @see com.sun.star.xml.sax.XDocumentHandler
55 * @see ifc.lang._XInitialization
56 * @see ifc.document._XImporter
57 * @see ifc.document._XFilter
58 * @see ifc.document._XExporter
59 * @see ifc.beans._XPropertySet
60 * @see ifc.xml.sax._XDocumentHandler
62 public class XMLSettingsImporter
extends TestCase
{
63 XTextDocument xTextDoc
;
66 * New text document created.
69 protected void initialize( TestParameters tParam
, PrintWriter log
) throws Exception
{
70 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
72 log
.println( "creating a textdocument" );
73 xTextDoc
= SOF
.createTextDoc( null );
77 * Text document destroyed.
80 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
81 log
.println( " disposing xTextDoc " );
82 util
.DesktopTools
.closeDoc(xTextDoc
);
86 * Creating a TestEnvironment for the interfaces to be tested.
87 * Creates an instance of the service
88 * <code>com.sun.star.comp.Writer.XMLSettingsImporter</code><p>
90 * The text document is set as a target document for importer.
91 * Imported XML-data contains only settings tags including
92 * title tag with test zoom factor.
93 * After import zoom factor getting from target document is checked.
94 * Object relations created :
96 * <li> <code>'XDocumentHandler.XMLData'</code> for
97 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
98 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
99 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
100 * <li> <code>'TargetDocument'</code> for
101 * {@link ifc.document._XImporter} interface </li>
105 public TestEnvironment createTestEnvironment
106 (TestParameters tParam
, PrintWriter log
) throws Exception
{
108 XInterface oObj
= null;
110 final short impZoom
= 50 ;
112 // creation of testobject here
113 // first we write what we are intend to do to log file
114 log
.println( "creating a test environment" );
116 XMultiServiceFactory xMSF
= tParam
.getMSF() ;
118 oInt
= xMSF
.createInstance
119 ("com.sun.star.comp.Writer.XMLSettingsImporter") ;
121 oObj
= (XInterface
) oInt
;
123 // create testobject here
124 log
.println( "creating a new environment for Paragraph object" );
125 TestEnvironment tEnv
= new TestEnvironment( oObj
);
128 tEnv
.addObjRelation("TargetDocument", xTextDoc
) ;
130 // adding relation for XDocumentHandler
131 String
[][] xml
= new String
[][] {
132 {"start", "office:document-settings",
133 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
134 "xmlns:config", "CDATA", "http://openoffice.org/2001/config",
135 "xmlns:xlink", "CDATA", "http://www.w3.org/1999/xlink",
137 {"start", "office:settings"},
138 {"start", "config:config-item-set",
139 "config:name", "CDATA", "view-settings"
141 {"start", "config:config-item-map-indexed",
142 "config:name", "CDATA", "Views"},
143 {"start", "config:config-item-map-entry"},
144 {"start", "config:config-item",
145 "config:name", "CDATA", "ZoomFactor",
146 "config:type", "CDATA", "short"
148 {"chars", String
.valueOf(impZoom
)},
149 {"end", "config:config-item"},
150 {"start", "config:config-item",
151 "config:name", "CDATA", "ZoomType",
152 "config:type", "CDATA", "short"
155 {"end", "config:config-item"},
156 {"end", "config:config-item-map-entry"},
157 {"end", "config:config-item-map-indexed"},
158 {"end", "config:config-item-set"},
159 {"end", "office:settings"},
160 {"end", "office:document-settings"}} ;
162 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
164 final PrintWriter logF
= log
;
165 XController xController
= xTextDoc
.getCurrentController();
166 XViewSettingsSupplier xViewSetSup
= UnoRuntime
.queryInterface(XViewSettingsSupplier
.class, xController
);
167 final XPropertySet xPropSet
= xViewSetSup
.getViewSettings();
168 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
169 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
170 public boolean checkImport() {
172 Short gValue
= (Short
)
173 xPropSet
.getPropertyValue("ZoomValue");
174 logF
.println("ZoomValue property value = " + gValue
) ;
175 return impZoom
== gValue
.shortValue() ;
176 } catch (com
.sun
.star
.uno
.Exception e
) {
177 logF
.println("Exception while checking import :") ;
178 e
.printStackTrace(logF
) ;
185 } // finish method getTestEnvironment