1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLContentImporter.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod
._xmloff
.Chart
;
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
41 import com
.sun
.star
.beans
.XPropertySet
;
42 import com
.sun
.star
.chart
.XChartDocument
;
43 import com
.sun
.star
.lang
.XComponent
;
44 import com
.sun
.star
.lang
.XMultiServiceFactory
;
45 import com
.sun
.star
.uno
.UnoRuntime
;
46 import com
.sun
.star
.uno
.XInterface
;
49 * Test for object which is represented by service
50 * <code>com.sun.star.comp.Chart.XMLContentImporter</code>. <p>
51 * Object implements the following interfaces :
53 * <li><code>com::sun::star::lang::XInitialization</code></li>
54 * <li><code>com::sun::star::document::XImporter</code></li>
55 * <li><code>com::sun::star::document::XFilter</code></li>
56 * <li><code>com::sun::star::document::ImportFilter</code></li>
57 * <li><code>com::sun::star::beans::XPropertySet</code></li>
58 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
60 * @see com.sun.star.lang.XInitialization
61 * @see com.sun.star.document.XImporter
62 * @see com.sun.star.document.XFilter
63 * @see com.sun.star.document.ImportFilter
64 * @see com.sun.star.beans.XPropertySet
65 * @see com.sun.star.xml.sax.XDocumentHandler
66 * @see ifc.lang._XInitialization
67 * @see ifc.document._XImporter
68 * @see ifc.document._XFilter
69 * @see ifc.document._XExporter
70 * @see ifc.beans._XPropertySet
71 * @see ifc.xml.sax._XDocumentHandler
73 public class XMLContentImporter
extends TestCase
{
75 XChartDocument xChartDoc
= null;
78 * New chart document created.
80 protected void initialize( TestParameters tParam
, PrintWriter log
) {
81 // get a soffice factory object
82 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
85 log
.println( "creating a chartdocument" );
86 xChartDoc
= SOF
.createChartDoc(null);
87 } catch ( Exception e
) {
88 // Some exception occures.FAILED
89 e
.printStackTrace( log
);
90 throw new StatusException( "Couldn't create document", e
);
99 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
100 log
.println( " disposing document " );
105 * Creating a Testenvironment for the interfaces to be tested.
106 * Creates an instance of the service
107 * <code>com.sun.star.comp.Chart.XMLContentImporter</code><p>
109 * The chart document is set as a target document for importer.
110 * Imported XML-data contains the tag which specifies the title
112 * After import title name getting from target document is checked.
113 * Object relations created :
115 * <li> <code>'XDocumentHandler.XMLData'</code> for
116 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
117 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
118 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
119 * <li> <code>'TargetDocument'</code> for
120 * {@link ifc.document._XImporter} interface </li>
123 public synchronized TestEnvironment createTestEnvironment
124 (TestParameters tParam
, PrintWriter log
) {
126 XInterface oObj
= null;
128 final String impValue
= "XMLContentImporter_test" ;
130 // creation of testobject here
131 // first we write what we are intend to do to log file
132 log
.println( "creating a test environment" );
134 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)tParam
.getMSF() ;
136 final XPropertySet xTitleProp
;
138 oInt
= xMSF
.createInstance
139 ("com.sun.star.comp.Chart.XMLContentImporter") ;
142 Object oTitle
= xChartDoc
.getTitle() ;
143 xTitleProp
= (XPropertySet
) UnoRuntime
.queryInterface
144 (XPropertySet
.class, oTitle
) ;
145 } catch (com
.sun
.star
.uno
.Exception e
) {
146 e
.printStackTrace(log
) ;
147 throw new StatusException("Can't create component.", e
) ;
150 oObj
= (XInterface
) oInt
;
152 // create testobject here
153 log
.println( "creating a new environment for Paragraph object" );
154 TestEnvironment tEnv
= new TestEnvironment( oObj
);
157 tEnv
.addObjRelation("TargetDocument", comp
) ;
159 // adding relation for XDocumentHandler
160 String
[][] xml
= new String
[][] {
161 {"start", "office:document-content",
162 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
163 "xmlns:text", "CDATA", "http://openoffice.org/2000/text",
164 "xmlns:chart", "CDATA", "http://openoffice.org/2000/chart",
165 "xmlns:table", "CDATA", "http://openoffice.org/2000/table",
166 "xmlns:svg", "CDATA", "http://openoffice.org/2000/svg",
167 "office:class", "CDATA", "chart"
168 ,"office:version", "CDATA", "1.0"
170 {"start", "office:body"},
171 {"start", "chart:chart"},
172 {"start", "chart:title"},
176 {"end", "chart:title"},
177 {"end", "chart:chart"},
178 {"end", "office:body"},
179 {"end", "office:document-content"}} ;
181 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
183 final PrintWriter logF
= log
;
185 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
186 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
187 public boolean checkImport() {
189 String title
= (String
)
190 xTitleProp
.getPropertyValue("String") ;
191 logF
.println("Title returned = '" + title
+ "'") ;
192 return impValue
.equals(title
) ;
193 } catch (com
.sun
.star
.uno
.Exception e
) {
195 ("Exception occured while checking filter :") ;
196 e
.printStackTrace(logF
) ;
204 } // finish method getTestEnvironment