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
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.SOfficeFactory
;
28 import com
.sun
.star
.beans
.XPropertySet
;
29 import com
.sun
.star
.chart
.XChartDocument
;
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.Chart.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
{
62 XChartDocument xChartDoc
= null;
65 * New chart document created.
68 protected void initialize( TestParameters tParam
, PrintWriter log
) throws Exception
{
69 // get a soffice factory object
70 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF());
72 log
.println( "creating a chartdocument" );
73 xChartDoc
= SOF
.createChartDoc();
82 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
83 if( xChartDoc
!=null ) {
84 log
.println( " closing xChartDoc" );
85 util
.DesktopTools
.closeDoc(xChartDoc
);
92 * Creating a TestEnvironment for the interfaces to be tested.
93 * Creates an instance of the service
94 * <code>com.sun.star.comp.Chart.XMLImporter</code><p>
96 * The chart document is set as a target document for importer.
97 * Imported XML-data contains the tag which specifies the title
99 * After import title name getting from target document is checked.
100 * Object relations created :
102 * <li> <code>'XDocumentHandler.XMLData'</code> for
103 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
104 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
105 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
106 * <li> <code>'TargetDocument'</code> for
107 * {@link ifc.document._XImporter} interface </li>
111 public TestEnvironment createTestEnvironment
112 (TestParameters tParam
, PrintWriter log
) throws Exception
{
114 XInterface oObj
= null;
116 final String impValue
= "XMLImporter_test" ;
118 // creation of testobject here
119 // first we write what we are intend to do to log file
120 log
.println( "creating a test environment" );
122 XMultiServiceFactory xMSF
= tParam
.getMSF() ;
124 final XPropertySet xTitleProp
;
125 oInt
= xMSF
.createInstance("com.sun.star.comp.Chart.XMLImporter") ;
127 Object oTitle
= xChartDoc
.getTitle() ;
128 xTitleProp
= UnoRuntime
.queryInterface
129 (XPropertySet
.class, oTitle
) ;
131 oObj
= (XInterface
) oInt
;
133 // create testobject here
134 log
.println( "creating a new environment for Paragraph object" );
135 TestEnvironment tEnv
= new TestEnvironment( oObj
);
138 tEnv
.addObjRelation("TargetDocument", comp
) ;
140 // adding relation for XDocumentHandler
141 String
[][] xml
= new String
[][] {
142 {"start", "office:document",
143 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
144 "xmlns:text", "CDATA", "http://openoffice.org/2000/text",
145 "xmlns:chart", "CDATA", "http://openoffice.org/2000/chart",
146 "xmlns:table", "CDATA", "http://openoffice.org/2000/table",
147 "xmlns:svg", "CDATA", "http://openoffice.org/2000/svg",
148 "office:class", "CDATA", "chart"
149 ,"office:version", "CDATA", "1.0"
151 {"start", "office:body"},
152 {"start", "chart:chart"},
153 {"start", "chart:title"},
157 {"end", "chart:title"},
158 {"end", "chart:chart"},
159 {"end", "office:body"},
160 {"end", "office:document-content"}} ;
162 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
164 final PrintWriter logF
= log
;
166 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
167 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
168 public boolean checkImport() {
170 String title
= (String
)
171 xTitleProp
.getPropertyValue("String") ;
172 logF
.println("Title returned = '" + title
+ "'") ;
173 return impValue
.equals(title
) ;
174 } catch (com
.sun
.star
.uno
.Exception e
) {
176 ("Exception occurred while checking filter :") ;
177 e
.printStackTrace(logF
) ;
185 } // finish method getTestEnvironment