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.XMLContentImporter</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 XMLContentImporter
extends TestCase
{
63 XChartDocument xChartDoc
= null;
66 * New chart document created.
68 protected void initialize( TestParameters tParam
, PrintWriter log
) {
69 // get a soffice factory object
70 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
73 log
.println( "creating a chartdocument" );
74 xChartDoc
= SOF
.createChartDoc(null);
75 } catch ( Exception e
) {
76 // Some exception occurs.FAILED
77 e
.printStackTrace( log
);
78 throw new StatusException( "Couldn't create document", e
);
87 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
88 if( xChartDoc
!=null ) {
89 log
.println( " closing xChartDoc" );
90 util
.DesktopTools
.closeDoc(xChartDoc
);
97 * Creating a Testenvironment for the interfaces to be tested.
98 * Creates an instance of the service
99 * <code>com.sun.star.comp.Chart.XMLContentImporter</code><p>
101 * The chart document is set as a target document for importer.
102 * Imported XML-data contains the tag which specifies the title
104 * After import title name getting from target document is checked.
105 * Object relations created :
107 * <li> <code>'XDocumentHandler.XMLData'</code> for
108 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
109 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
110 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
111 * <li> <code>'TargetDocument'</code> for
112 * {@link ifc.document._XImporter} interface </li>
115 public synchronized TestEnvironment createTestEnvironment
116 (TestParameters tParam
, PrintWriter log
) {
118 XInterface oObj
= null;
120 final String impValue
= "XMLContentImporter_test" ;
122 // creation of testobject here
123 // first we write what we are intend to do to log file
124 log
.println( "creating a test environment" );
126 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)tParam
.getMSF() ;
128 final XPropertySet xTitleProp
;
130 oInt
= xMSF
.createInstance
131 ("com.sun.star.comp.Chart.XMLContentImporter") ;
134 Object oTitle
= xChartDoc
.getTitle() ;
135 xTitleProp
= UnoRuntime
.queryInterface
136 (XPropertySet
.class, oTitle
) ;
137 } catch (com
.sun
.star
.uno
.Exception e
) {
138 e
.printStackTrace(log
) ;
139 throw new StatusException("Can't create component.", e
) ;
142 oObj
= (XInterface
) oInt
;
144 // create testobject here
145 log
.println( "creating a new environment for Paragraph object" );
146 TestEnvironment tEnv
= new TestEnvironment( oObj
);
149 tEnv
.addObjRelation("TargetDocument", comp
) ;
151 // adding relation for XDocumentHandler
152 String
[][] xml
= new String
[][] {
153 {"start", "office:document-content",
154 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
155 "xmlns:text", "CDATA", "http://openoffice.org/2000/text",
156 "xmlns:chart", "CDATA", "http://openoffice.org/2000/chart",
157 "xmlns:table", "CDATA", "http://openoffice.org/2000/table",
158 "xmlns:svg", "CDATA", "http://openoffice.org/2000/svg",
159 "office:class", "CDATA", "chart"
160 ,"office:version", "CDATA", "1.0"
162 {"start", "office:body"},
163 {"start", "chart:chart"},
164 {"start", "chart:title"},
168 {"end", "chart:title"},
169 {"end", "chart:chart"},
170 {"end", "office:body"},
171 {"end", "office:document-content"}} ;
173 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
175 final PrintWriter logF
= log
;
177 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
178 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
179 public boolean checkImport() {
181 String title
= (String
)
182 xTitleProp
.getPropertyValue("String") ;
183 logF
.println("Title returned = '" + title
+ "'") ;
184 return impValue
.equals(title
) ;
185 } catch (com
.sun
.star
.uno
.Exception e
) {
187 ("Exception occurred while checking filter :") ;
188 e
.printStackTrace(logF
) ;
196 } // finish method getTestEnvironment