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.XMLImporter</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 XMLImporter
extends TestCase
{
64 * New math document created.
67 protected void initialize( TestParameters tParam
, PrintWriter log
) throws Exception
{
69 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
70 xMathDoc
= SOF
.openDoc("smath","_blank");
77 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
78 log
.println( " disposing xMathDoc " );
83 * Creating a TestEnvironment for the interfaces to be tested.
84 * Creates an instance of the service
85 * <code>com.sun.star.comp.Math.XMLImporter</code><p>
87 * The chart document is set as a target document for importer.
88 * Imported XML-data contains the tag which specifies a formula
90 * After import the formula getting from target document is checked.
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 String impFormula
= "a - b" ;
110 oObj
= (XInterface
)xMSF
.createInstance(
111 "com.sun.star.comp.Math.XMLImporter");
113 TestEnvironment tEnv
= new TestEnvironment(oObj
);
115 tEnv
.addObjRelation("TargetDocument",xMathDoc
);
117 String
[][] xml
= new String
[][] {
118 {"start", "math:math",
119 "xmlns:math", "CDATA", "http://www.w3.org/1998/Math/MathML"},
120 {"start", "math:semantics"},
121 {"start", "math:annotation",
122 "math:encoding", "CDATA", "StarMath 5.0"},
123 {"chars", impFormula
},
124 {"end", "math:annotation"},
125 {"end", "math:semantics"},
126 {"end", "math:math"}} ;
128 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
130 final PrintWriter logF
= log
;
131 final XPropertySet xPS
= UnoRuntime
.queryInterface
132 (XPropertySet
.class, xMathDoc
) ;
134 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
135 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
136 public boolean checkImport() {
138 String gFormula
= (String
) xPS
.getPropertyValue
140 logF
.println("Formula returned = '" + gFormula
+ "'") ;
141 return impFormula
.equals(gFormula
) ;
142 } catch (com
.sun
.star
.uno
.Exception e
) {
143 logF
.println("Exception occurred while checking filter :") ;
144 e
.printStackTrace(logF
) ;