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
.lang
.XComponent
;
31 import com
.sun
.star
.lang
.XMultiServiceFactory
;
32 import com
.sun
.star
.uno
.UnoRuntime
;
33 import com
.sun
.star
.uno
.XInterface
;
36 * Test for object which is represented by service
37 * <code>com.sun.star.comp.Math.XMLSettingsImporter</code>. <p>
38 * Object implements the following interfaces :
40 * <li><code>com::sun::star::lang::XInitialization</code></li>
41 * <li><code>com::sun::star::document::XImporter</code></li>
42 * <li><code>com::sun::star::document::XFilter</code></li>
43 * <li><code>com::sun::star::document::ImportFilter</code></li>
44 * <li><code>com::sun::star::beans::XPropertySet</code></li>
45 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
47 * @see com.sun.star.lang.XInitialization
48 * @see com.sun.star.document.XImporter
49 * @see com.sun.star.document.XFilter
50 * @see com.sun.star.document.ImportFilter
51 * @see com.sun.star.beans.XPropertySet
52 * @see com.sun.star.xml.sax.XDocumentHandler
53 * @see ifc.lang._XInitialization
54 * @see ifc.document._XImporter
55 * @see ifc.document._XFilter
56 * @see ifc.document._XExporter
57 * @see ifc.beans._XPropertySet
58 * @see ifc.xml.sax._XDocumentHandler
60 public class XMLSettingsImporter
extends TestCase
{
64 * New math document created.
67 protected void initialize( TestParameters tParam
, PrintWriter log
) {
69 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
71 xMathDoc
= SOF
.openDoc("smath","_blank");
72 } catch (com
.sun
.star
.uno
.Exception ex
) {
73 ex
.printStackTrace( log
);
74 throw new StatusException( "Couldn't create document", ex
);
82 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
83 log
.println( " disposing xMathDoc " );
88 * Creating a Testenvironment for the interfaces to be tested.
89 * Creates an instance of the service
90 * <code>com.sun.star.comp.Math.XMLSettingsImporter</code><p>
92 * The math document is set as a target document for importer.
93 * Imported XML-data contains the tag which specifies new
94 * 'TopMargin' property value.
95 * After import 'TopMargin' property value of target document
97 * Object relations created :
99 * <li> <code>'XDocumentHandler.XMLData'</code> for
100 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
101 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
102 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
103 * <li> <code>'TargetDocument'</code> for
104 * {@link ifc.document._XImporter} interface </li>
108 public synchronized TestEnvironment createTestEnvironment
109 ( TestParameters Param
, PrintWriter log
)
110 throws StatusException
{
112 XMultiServiceFactory xMSF
= Param
.getMSF();
113 XInterface oObj
= null;
114 final short impMargin
= 67 ;
117 oObj
= (XInterface
)xMSF
.createInstance(
118 "com.sun.star.comp.Math.XMLSettingsImporter");
120 } catch (com
.sun
.star
.uno
.Exception e
) {
121 e
.printStackTrace(log
);
122 throw new StatusException("Unexpected exception", e
);
125 TestEnvironment tEnv
= new TestEnvironment(oObj
);
127 tEnv
.addObjRelation("TargetDocument",xMathDoc
);
129 String
[][] xml
= new String
[][] {
130 {"start", "office:document-settings",
131 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
132 "xmlns:config", "CDATA", "http://openoffice.org/2001/config",
133 "xmlns:xlink", "CDATA", "http://www.w3.org/1999/xlink",
134 "office:version", "CDATA", "1.0"
136 {"start", "office:settings"},
137 {"start", "config:config-item-set",
138 "config:name", "CDATA", "configuration-settings"},
140 {"start", "config:config-item",
141 "config:name", "CDATA", "TopMargin",
142 "config:type", "CDATA", "short"},
143 {"chars", String
.valueOf(impMargin
)},
144 {"end", "config:config-item"},
145 {"end", "config:config-item-set"},
146 {"end", "office:settings"},
147 {"end", "office:document-settings"}} ;
149 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
151 final PrintWriter logF
= log
;
152 final XPropertySet xPS
= UnoRuntime
.queryInterface
153 (XPropertySet
.class, xMathDoc
) ;
155 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
156 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
157 public boolean checkImport() {
159 Short gMargin
= (Short
) xPS
.getPropertyValue
161 logF
.println("Margin returned: " + gMargin
);
162 return impMargin
== gMargin
.shortValue() ;
163 } catch (com
.sun
.star
.uno
.Exception e
) {
164 logF
.println("Exception occurred while checking filter :") ;
165 e
.printStackTrace(logF
) ;