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
.lang
.XComponent
;
30 import com
.sun
.star
.lang
.XMultiServiceFactory
;
31 import com
.sun
.star
.uno
.UnoRuntime
;
32 import com
.sun
.star
.uno
.XInterface
;
35 * Test for object which is represented by service
36 * <code>com.sun.star.comp.Math.XMLSettingsImporter</code>. <p>
37 * Object implements the following interfaces :
39 * <li><code>com::sun::star::lang::XInitialization</code></li>
40 * <li><code>com::sun::star::document::XImporter</code></li>
41 * <li><code>com::sun::star::document::XFilter</code></li>
42 * <li><code>com::sun::star::document::ImportFilter</code></li>
43 * <li><code>com::sun::star::beans::XPropertySet</code></li>
44 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
46 * @see com.sun.star.lang.XInitialization
47 * @see com.sun.star.document.XImporter
48 * @see com.sun.star.document.XFilter
49 * @see com.sun.star.document.ImportFilter
50 * @see com.sun.star.beans.XPropertySet
51 * @see com.sun.star.xml.sax.XDocumentHandler
52 * @see ifc.lang._XInitialization
53 * @see ifc.document._XImporter
54 * @see ifc.document._XFilter
55 * @see ifc.document._XExporter
56 * @see ifc.beans._XPropertySet
57 * @see ifc.xml.sax._XDocumentHandler
59 public class XMLSettingsImporter
extends TestCase
{
63 * New math document created.
66 protected void initialize( TestParameters tParam
, PrintWriter log
) throws Exception
{
68 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
69 xMathDoc
= SOF
.openDoc("smath","_blank");
76 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
77 log
.println( " disposing xMathDoc " );
82 * Creating a TestEnvironment for the interfaces to be tested.
83 * Creates an instance of the service
84 * <code>com.sun.star.comp.Math.XMLSettingsImporter</code><p>
86 * The math document is set as a target document for importer.
87 * Imported XML-data contains the tag which specifies new
88 * 'TopMargin' property value.
89 * After import 'TopMargin' property value of target document
91 * Object relations created :
93 * <li> <code>'XDocumentHandler.XMLData'</code> for
94 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
95 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
96 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
97 * <li> <code>'TargetDocument'</code> for
98 * {@link ifc.document._XImporter} interface </li>
102 public TestEnvironment createTestEnvironment
103 ( TestParameters Param
, PrintWriter log
)
106 XMultiServiceFactory xMSF
= Param
.getMSF();
107 XInterface oObj
= null;
108 final short impMargin
= 67 ;
110 oObj
= (XInterface
)xMSF
.createInstance(
111 "com.sun.star.comp.Math.XMLSettingsImporter");
113 TestEnvironment tEnv
= new TestEnvironment(oObj
);
115 tEnv
.addObjRelation("TargetDocument",xMathDoc
);
117 String
[][] xml
= new String
[][] {
118 {"start", "office:document-settings",
119 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
120 "xmlns:config", "CDATA", "http://openoffice.org/2001/config",
121 "xmlns:xlink", "CDATA", "http://www.w3.org/1999/xlink",
122 "office:version", "CDATA", "1.0"
124 {"start", "office:settings"},
125 {"start", "config:config-item-set",
126 "config:name", "CDATA", "configuration-settings"},
128 {"start", "config:config-item",
129 "config:name", "CDATA", "TopMargin",
130 "config:type", "CDATA", "short"},
131 {"chars", String
.valueOf(impMargin
)},
132 {"end", "config:config-item"},
133 {"end", "config:config-item-set"},
134 {"end", "office:settings"},
135 {"end", "office:document-settings"}} ;
137 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
139 final PrintWriter logF
= log
;
140 final XPropertySet xPS
= UnoRuntime
.queryInterface
141 (XPropertySet
.class, xMathDoc
) ;
143 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
144 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
145 public boolean checkImport() {
147 Short gMargin
= (Short
) xPS
.getPropertyValue
149 logF
.println("Margin returned: " + gMargin
);
150 return impMargin
== gMargin
.shortValue() ;
151 } catch (com
.sun
.star
.uno
.Exception e
) {
152 logF
.println("Exception occurred while checking filter :") ;
153 e
.printStackTrace(logF
) ;