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
.Draw
;
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
.container
.XNamed
;
30 import com
.sun
.star
.drawing
.XDrawPages
;
31 import com
.sun
.star
.drawing
.XDrawPagesSupplier
;
32 import com
.sun
.star
.lang
.XComponent
;
33 import com
.sun
.star
.lang
.XMultiServiceFactory
;
34 import com
.sun
.star
.uno
.UnoRuntime
;
35 import com
.sun
.star
.uno
.XInterface
;
38 * Test for object which is represented by service
39 * <code>com.sun.star.comp.Draw.XMLImporter</code>. <p>
40 * Object implements the following interfaces :
42 * <li><code>com::sun::star::lang::XInitialization</code></li>
43 * <li><code>com::sun::star::document::XImporter</code></li>
44 * <li><code>com::sun::star::document::XFilter</code></li>
45 * <li><code>com::sun::star::document::ImportFilter</code></li>
46 * <li><code>com::sun::star::beans::XPropertySet</code></li>
47 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
49 * @see com.sun.star.lang.XInitialization
50 * @see com.sun.star.document.XImporter
51 * @see com.sun.star.document.XFilter
52 * @see com.sun.star.document.ImportFilter
53 * @see com.sun.star.beans.XPropertySet
54 * @see com.sun.star.xml.sax.XDocumentHandler
55 * @see ifc.lang._XInitialization
56 * @see ifc.document._XImporter
57 * @see ifc.document._XFilter
58 * @see ifc.document._XExporter
59 * @see ifc.beans._XPropertySet
60 * @see ifc.xml.sax._XDocumentHandler
62 public class XMLImporter
extends TestCase
{
63 XComponent xDrawDoc
= null;
66 * New spreadsheet document created.
69 protected void initialize( TestParameters tParam
, PrintWriter log
) {
71 // get a soffice factory object
72 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF());
75 log
.println( "creating a drawdocument" );
76 xDrawDoc
= SOF
.createDrawDoc(null);
77 } catch ( Exception e
) {
78 // Some exception occurs.FAILED
79 e
.printStackTrace( log
);
80 throw new StatusException( "Couldn't create document", e
);
85 * Spreadsheet document destroyed.
88 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
89 log
.println( " disposing document " );
94 * Creating a Testenvironment for the interfaces to be tested.
95 * Creates an instance of the service
96 * <code>com.sun.star.comp.Draw.XMLImporter</code><p>
98 * The Draw document is set as a target document for importer.
99 * Imported XML-data contains only content tags including pages
100 * named 'NewSlide1' and 'NewSlide2'.
101 * Pages getting from target document are checked after import.
102 * Object relations created :
104 * <li> <code>'XDocumentHandler.XMLData'</code> for
105 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
106 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
107 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
108 * <li> <code>'TargetDocument'</code> for
109 * {@link ifc.document._XImporter} interface </li>
113 public synchronized TestEnvironment createTestEnvironment
114 (TestParameters tParam
, PrintWriter log
) throws StatusException
{
116 XInterface oObj
= null;
119 // creation of testobject here
120 // first we write what we are intend to do to log file
121 log
.println( "creating a test environment" );
123 XMultiServiceFactory xMSF
= tParam
.getMSF() ;
126 oInt
= xMSF
.createInstance("com.sun.star.comp.Draw.XMLImporter") ;
128 } catch (com
.sun
.star
.uno
.Exception e
) {
129 e
.printStackTrace(log
) ;
130 throw new StatusException("Can't create component.", e
) ;
133 oObj
= (XInterface
) oInt
;
135 // create testobject here
136 log
.println( "creating a new environment for Paragraph object" );
137 TestEnvironment tEnv
= new TestEnvironment( oObj
);
140 tEnv
.addObjRelation("TargetDocument", xDrawDoc
) ;
142 // adding relation for XDocumentHandler
143 String
[][] xml
= new String
[][] {
144 {"start", "office:document",
145 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
146 "xmlns:draw", "CDATA", "http://openoffice.org/2000/drawing",
147 "office:class", "CDATA", "drawing"
148 ,"office:version", "CDATA", "1.0"
150 {"start", "office:body"},
151 {"start", "draw:page",
152 "draw:name", "CDATA", "NewSlide1",
153 "draw:master-page-name", "CDATA", "Default"},
154 {"end", "draw:page"},
155 {"start", "draw:page",
156 "draw:name", "CDATA", "NewSlide2",
157 "draw:master-page-name", "CDATA", "Default"},
159 {"end", "draw:page"},
160 {"end", "office:body"},
161 {"end", "office:document"}} ;
163 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
165 //save to log content before import
166 final PrintWriter fLog
= log
;
168 // Checking target document after import
169 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
170 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
171 public boolean checkImport() {
172 XDrawPagesSupplier supp
= UnoRuntime
.queryInterface
173 (XDrawPagesSupplier
.class, xDrawDoc
);
174 final XDrawPages xPages
= supp
.getDrawPages();
175 XNamed
[] pageArray
= new XNamed
[ xPages
.getCount() ];
176 for (int i
=0; i
< xPages
.getCount(); i
++) {
178 pageArray
[i
] = UnoRuntime
.queryInterface
179 (XNamed
.class, xPages
.getByIndex(i
));
180 } catch (com
.sun
.star
.uno
.Exception e
) {
181 e
.printStackTrace(fLog
) ;
182 throw new StatusException
183 ("Can't get page name by index.", e
) ;
186 fLog
.println("Slide names after import:");
187 for ( int i
= 0; i
< xPages
.getCount(); i
++ ) {
188 if ((pageArray
[i
].getName().equals("NewSlide1"))
189 || (pageArray
[i
].getName().equals("NewSlide2"))) {
190 fLog
.println(" " + pageArray
[i
].getName());
193 fLog
.println("Error: some imported values are not exist in target document!");
202 } // end of getTestEnvironment