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 .
19 package mod
._xmloff
.Chart
;
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
.chart
.XChartDocument
;
31 import com
.sun
.star
.lang
.XComponent
;
32 import com
.sun
.star
.lang
.XMultiServiceFactory
;
33 import com
.sun
.star
.uno
.UnoRuntime
;
34 import com
.sun
.star
.uno
.XInterface
;
37 * Test for object which is represented by service
38 * <code>com.sun.star.comp.Chart.XMLImporter</code>. <p>
39 * Object implements the following interfaces :
41 * <li><code>com::sun::star::lang::XInitialization</code></li>
42 * <li><code>com::sun::star::document::XImporter</code></li>
43 * <li><code>com::sun::star::document::XFilter</code></li>
44 * <li><code>com::sun::star::document::ImportFilter</code></li>
45 * <li><code>com::sun::star::beans::XPropertySet</code></li>
46 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
48 * @see com.sun.star.lang.XInitialization
49 * @see com.sun.star.document.XImporter
50 * @see com.sun.star.document.XFilter
51 * @see com.sun.star.document.ImportFilter
52 * @see com.sun.star.beans.XPropertySet
53 * @see com.sun.star.xml.sax.XDocumentHandler
54 * @see ifc.lang._XInitialization
55 * @see ifc.document._XImporter
56 * @see ifc.document._XFilter
57 * @see ifc.document._XExporter
58 * @see ifc.beans._XPropertySet
59 * @see ifc.xml.sax._XDocumentHandler
61 public class XMLImporter
extends TestCase
{
63 XChartDocument xChartDoc
= null;
66 * New chart document created.
69 protected void initialize( TestParameters tParam
, PrintWriter log
) {
70 // get a soffice factory object
71 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF());
74 log
.println( "creating a chartdocument" );
75 xChartDoc
= SOF
.createChartDoc();
76 } catch ( Exception e
) {
77 // Some exception occurs.FAILED
78 e
.printStackTrace( log
);
79 throw new StatusException( "Couldn't create document", e
);
89 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
90 if( xChartDoc
!=null ) {
91 log
.println( " closing xChartDoc" );
92 util
.DesktopTools
.closeDoc(xChartDoc
);
99 * Creating a Testenvironment for the interfaces to be tested.
100 * Creates an instance of the service
101 * <code>com.sun.star.comp.Chart.XMLImporter</code><p>
103 * The chart document is set as a target document for importer.
104 * Imported XML-data contains the tag which specifies the title
106 * After import title name getting from target document is checked.
107 * Object relations created :
109 * <li> <code>'XDocumentHandler.XMLData'</code> for
110 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
111 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
112 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
113 * <li> <code>'TargetDocument'</code> for
114 * {@link ifc.document._XImporter} interface </li>
118 public synchronized TestEnvironment createTestEnvironment
119 (TestParameters tParam
, PrintWriter log
) {
121 XInterface oObj
= null;
123 final String impValue
= "XMLImporter_test" ;
125 // creation of testobject here
126 // first we write what we are intend to do to log file
127 log
.println( "creating a test environment" );
129 XMultiServiceFactory xMSF
= tParam
.getMSF() ;
131 final XPropertySet xTitleProp
;
133 oInt
= xMSF
.createInstance("com.sun.star.comp.Chart.XMLImporter") ;
135 Object oTitle
= xChartDoc
.getTitle() ;
136 xTitleProp
= UnoRuntime
.queryInterface
137 (XPropertySet
.class, oTitle
) ;
138 } catch (com
.sun
.star
.uno
.Exception e
) {
139 e
.printStackTrace(log
) ;
140 throw new StatusException("Can't create component.", e
) ;
143 oObj
= (XInterface
) oInt
;
145 // create testobject here
146 log
.println( "creating a new environment for Paragraph object" );
147 TestEnvironment tEnv
= new TestEnvironment( oObj
);
150 tEnv
.addObjRelation("TargetDocument", comp
) ;
152 // adding relation for XDocumentHandler
153 String
[][] xml
= new String
[][] {
154 {"start", "office:document",
155 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
156 "xmlns:text", "CDATA", "http://openoffice.org/2000/text",
157 "xmlns:chart", "CDATA", "http://openoffice.org/2000/chart",
158 "xmlns:table", "CDATA", "http://openoffice.org/2000/table",
159 "xmlns:svg", "CDATA", "http://openoffice.org/2000/svg",
160 "office:class", "CDATA", "chart"
161 ,"office:version", "CDATA", "1.0"
163 {"start", "office:body"},
164 {"start", "chart:chart"},
165 {"start", "chart:title"},
169 {"end", "chart:title"},
170 {"end", "chart:chart"},
171 {"end", "office:body"},
172 {"end", "office:document-content"}} ;
174 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
176 final PrintWriter logF
= log
;
178 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
179 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
180 public boolean checkImport() {
182 String title
= (String
)
183 xTitleProp
.getPropertyValue("String") ;
184 logF
.println("Title returned = '" + title
+ "'") ;
185 return impValue
.equals(title
) ;
186 } catch (com
.sun
.star
.uno
.Exception e
) {
188 ("Exception occurred while checking filter :") ;
189 e
.printStackTrace(logF
) ;
197 } // finish method getTestEnvironment