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
;
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
.lang
.XMultiServiceFactory
;
32 import com
.sun
.star
.text
.XTextDocument
;
33 import com
.sun
.star
.uno
.UnoRuntime
;
34 import com
.sun
.star
.uno
.XInterface
;
35 import com
.sun
.star
.view
.XViewSettingsSupplier
;
38 * Test for object which is represented by service
39 * <code>com.sun.star.comp.Writer.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 XTextDocument xTextDoc
;
67 * New text document created.
69 protected void initialize( TestParameters tParam
, PrintWriter log
) {
70 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
73 log
.println( "creating a textdocument" );
74 xTextDoc
= SOF
.createTextDoc( null );
75 } catch ( com
.sun
.star
.uno
.Exception e
) {
76 // Some exception occurs.FAILED
77 e
.printStackTrace( log
);
78 throw new StatusException( "Couldn't create document", e
);
83 * Text document destroyed.
85 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
86 log
.println( " disposing xTextDoc " );
87 util
.DesktopTools
.closeDoc(xTextDoc
);
91 * Creating a Testenvironment for the interfaces to be tested.
92 * Creates an instance of the service
93 * <code>com.sun.star.comp.Writer.XMLSettingsImporter</code><p>
95 * The text document is set as a target document for importer.
96 * Imported XML-data contains only settings tags including
97 * title tag with test zoom factor.
98 * After import zoom factor getting from target document is checked.
99 * Object relations created :
101 * <li> <code>'XDocumentHandler.XMLData'</code> for
102 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
103 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
104 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
105 * <li> <code>'TargetDocument'</code> for
106 * {@link ifc.document._XImporter} interface </li>
109 public synchronized TestEnvironment createTestEnvironment
110 (TestParameters tParam
, PrintWriter log
) throws StatusException
{
112 XInterface oObj
= null;
114 final short impZoom
= 50 ;
116 // creation of testobject here
117 // first we write what we are intend to do to log file
118 log
.println( "creating a test environment" );
120 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)tParam
.getMSF() ;
123 oInt
= xMSF
.createInstance
124 ("com.sun.star.comp.Writer.XMLSettingsImporter") ;
126 } catch (com
.sun
.star
.uno
.Exception e
) {
127 e
.printStackTrace(log
) ;
128 throw new StatusException("Can't create component.", e
) ;
132 oObj
= (XInterface
) oInt
;
134 // create testobject here
135 log
.println( "creating a new environment for Paragraph object" );
136 TestEnvironment tEnv
= new TestEnvironment( oObj
);
139 tEnv
.addObjRelation("TargetDocument", xTextDoc
) ;
141 // adding relation for XDocumentHandler
142 String
[][] xml
= new String
[][] {
143 {"start", "office:document-settings",
144 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
145 "xmlns:config", "CDATA", "http://openoffice.org/2001/config",
146 "xmlns:xlink", "CDATA", "http://www.w3.org/1999/xlink",
148 {"start", "office:settings"},
149 {"start", "config:config-item-set",
150 "config:name", "CDATA", "view-settings"
152 {"start", "config:config-item-map-indexed",
153 "config:name", "CDATA", "Views"},
154 {"start", "config:config-item-map-entry"},
155 {"start", "config:config-item",
156 "config:name", "CDATA", "ZoomFactor",
157 "config:type", "CDATA", "short"
159 {"chars", String
.valueOf(impZoom
)},
160 {"end", "config:config-item"},
161 {"start", "config:config-item",
162 "config:name", "CDATA", "ZoomType",
163 "config:type", "CDATA", "short"
166 {"end", "config:config-item"},
167 {"end", "config:config-item-map-entry"},
168 {"end", "config:config-item-map-indexed"},
169 {"end", "config:config-item-set"},
170 {"end", "office:settings"},
171 {"end", "office:document-settings"}} ;
173 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
175 final PrintWriter logF
= log
;
176 XController xController
= xTextDoc
.getCurrentController();
177 XViewSettingsSupplier xViewSetSup
= UnoRuntime
.queryInterface(XViewSettingsSupplier
.class, xController
);
178 final XPropertySet xPropSet
= xViewSetSup
.getViewSettings();
179 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
180 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
181 public boolean checkImport() {
183 Short gValue
= (Short
)
184 xPropSet
.getPropertyValue("ZoomValue");
185 logF
.println("ZoomValue property value = " + gValue
) ;
186 return impZoom
== gValue
.shortValue() ;
187 } catch (com
.sun
.star
.uno
.Exception e
) {
188 logF
.println("Exception while checking import :") ;
189 e
.printStackTrace(logF
) ;
196 } // finish method getTestEnvironment