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.XMLImporter</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 XMLImporter
extends TestCase
{
65 * New math document created.
68 protected void initialize( TestParameters tParam
, PrintWriter log
) {
70 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
72 xMathDoc
= SOF
.openDoc("smath","_blank");
73 } catch (com
.sun
.star
.uno
.Exception ex
) {
74 ex
.printStackTrace( log
);
75 throw new StatusException( "Couldn't create document", ex
);
83 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
84 log
.println( " disposing xMathDoc " );
89 * Creating a Testenvironment for the interfaces to be tested.
90 * Creates an instance of the service
91 * <code>com.sun.star.comp.Math.XMLImporter</code><p>
93 * The chart document is set as a target document for importer.
94 * Imported XML-data contains the tag which specifies a formula
96 * After import the formula getting from target document is checked.
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 String impFormula
= "a - b" ;
117 oObj
= (XInterface
)xMSF
.createInstance(
118 "com.sun.star.comp.Math.XMLImporter");
119 } catch (com
.sun
.star
.uno
.Exception e
) {
120 e
.printStackTrace(log
);
121 throw new StatusException("Unexpected exception", e
);
124 TestEnvironment tEnv
= new TestEnvironment(oObj
);
126 tEnv
.addObjRelation("TargetDocument",xMathDoc
);
128 String
[][] xml
= new String
[][] {
129 {"start", "math:math",
130 "xmlns:math", "CDATA", "http://www.w3.org/1998/Math/MathML"},
131 {"start", "math:semantics"},
132 {"start", "math:annotation",
133 "math:encoding", "CDATA", "StarMath 5.0"},
134 {"chars", impFormula
},
135 {"end", "math:annotation"},
136 {"end", "math:semantics"},
137 {"end", "math:math"}} ;
139 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
141 final PrintWriter logF
= log
;
142 final XPropertySet xPS
= UnoRuntime
.queryInterface
143 (XPropertySet
.class, xMathDoc
) ;
145 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
146 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
147 public boolean checkImport() {
149 String gFormula
= (String
) xPS
.getPropertyValue
151 logF
.println("Formula returned = '" + gFormula
+ "'") ;
152 return impFormula
.equals(gFormula
) ;
153 } catch (com
.sun
.star
.uno
.Exception e
) {
154 logF
.println("Exception occurred while checking filter :") ;
155 e
.printStackTrace(logF
) ;