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
.Draw
;
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
.container
.XNamed
;
42 import com
.sun
.star
.drawing
.XDrawPages
;
43 import com
.sun
.star
.drawing
.XDrawPagesSupplier
;
44 import com
.sun
.star
.lang
.XComponent
;
45 import com
.sun
.star
.lang
.XMultiServiceFactory
;
46 import com
.sun
.star
.uno
.UnoRuntime
;
47 import com
.sun
.star
.uno
.XInterface
;
50 * Test for object which is represented by service
51 * <code>com.sun.star.comp.Draw.XMLContentImporter</code>. <p>
52 * Object implements the following interfaces :
54 * <li><code>com::sun::star::lang::XInitialization</code></li>
55 * <li><code>com::sun::star::document::XImporter</code></li>
56 * <li><code>com::sun::star::document::XFilter</code></li>
57 * <li><code>com::sun::star::document::ImportFilter</code></li>
58 * <li><code>com::sun::star::beans::XPropertySet</code></li>
59 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
61 * @see com.sun.star.lang.XInitialization
62 * @see com.sun.star.document.XImporter
63 * @see com.sun.star.document.XFilter
64 * @see com.sun.star.document.ImportFilter
65 * @see com.sun.star.beans.XPropertySet
66 * @see com.sun.star.xml.sax.XDocumentHandler
67 * @see ifc.lang._XInitialization
68 * @see ifc.document._XImporter
69 * @see ifc.document._XFilter
70 * @see ifc.document._XExporter
71 * @see ifc.beans._XPropertySet
72 * @see ifc.xml.sax._XDocumentHandler
74 public class XMLContentImporter
extends TestCase
{
75 XComponent xDrawDoc
= null;
78 * New spreadsheet document created.
80 protected void initialize( TestParameters tParam
, PrintWriter log
) {
82 // get a soffice factory object
83 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
86 log
.println( "creating a drawdocument" );
87 xDrawDoc
= SOF
.createDrawDoc(null);
88 } catch ( Exception e
) {
89 // Some exception occures.FAILED
90 e
.printStackTrace( log
);
91 throw new StatusException( "Couldn't create document", e
);
96 * Spreadsheet document destroyed.
98 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
99 log
.println( " disposing document " );
104 * Creating a Testenvironment for the interfaces to be tested.
105 * Creates an instance of the service
106 * <code>com.sun.star.comp.Draw.XMLContentImporter</code><p>
108 * The Draw document is set as a target document for importer.
109 * Imported XML-data contains only content tags including pages
110 * named 'NewSlide1' and 'NewSlide2'.
111 * Pages getting from target document is checked after import
112 * Object relations created :
114 * <li> <code>'XDocumentHandler.XMLData'</code> for
115 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
116 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
117 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
118 * <li> <code>'TargetDocument'</code> for
119 * {@link ifc.document._XImporter} interface </li>
122 public synchronized TestEnvironment createTestEnvironment
123 (TestParameters tParam
, PrintWriter log
) throws StatusException
{
125 XInterface oObj
= null;
128 // creation of testobject here
129 // first we write what we are intend to do to log file
130 log
.println( "creating a test environment" );
132 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)tParam
.getMSF() ;
135 oInt
= xMSF
.createInstance
136 ("com.sun.star.comp.Draw.XMLContentImporter") ;
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", xDrawDoc
) ;
152 // New XML document generated to be imported to Draw document
153 String
[][] xml
= new String
[][] {
154 {"start", "office:document",
155 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
156 "xmlns:draw", "CDATA", "http://openoffice.org/2000/drawing",
157 "office:class", "CDATA", "drawing"
158 ,"office:version", "CDATA", "1.0"
160 {"start", "office:body"},
161 {"start", "draw:page",
162 "draw:name", "CDATA", "NewSlide1",
163 "draw:master-page-name", "CDATA", "Default"},
164 {"end", "draw:page"},
165 {"start", "draw:page", "draw:name", "CDATA", "NewSlide2",
166 "draw:master-page-name", "CDATA", "Default"},
168 {"end", "draw:page"},
169 {"end", "office:body"},
170 {"end", "office:document"}};
172 // adding relation for XDocumentHandler
173 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
);
175 //save to log content before import
176 final PrintWriter fLog
= log
;
178 // Checking target document after import
179 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
180 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
181 public boolean checkImport() {
182 XDrawPagesSupplier supp
= (XDrawPagesSupplier
)
183 UnoRuntime
.queryInterface
184 (XDrawPagesSupplier
.class, xDrawDoc
);
185 final XDrawPages xPages
= supp
.getDrawPages();
186 XNamed
[] pageArray
= new XNamed
[ xPages
.getCount() ];
187 for (int i
=0; i
< xPages
.getCount(); i
++) {
189 pageArray
[i
] = (XNamed
) UnoRuntime
.queryInterface
190 (XNamed
.class, xPages
.getByIndex(i
));
191 } catch (com
.sun
.star
.uno
.Exception e
) {
192 e
.printStackTrace(fLog
) ;
193 throw new StatusException
194 ("Can't get page name by index.", e
) ;
197 fLog
.println("Slide names after import:");
198 for ( int i
= 0; i
< xPages
.getCount(); i
++ ) {
199 if ((pageArray
[i
].getName().equals("NewSlide1"))
200 || (pageArray
[i
].getName().equals("NewSlide2"))) {
201 fLog
.println(" " + pageArray
[i
].getName());
204 fLog
.println("Error: some imported values are not exist in target document!");