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 .
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
.document
.XImporter
;
30 import com
.sun
.star
.lang
.XComponent
;
31 import com
.sun
.star
.lang
.XMultiServiceFactory
;
32 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
33 import com
.sun
.star
.sheet
.XSpreadsheets
;
34 import com
.sun
.star
.uno
.UnoRuntime
;
35 import com
.sun
.star
.uno
.XInterface
;
37 * Test for object which is represented by service
38 * <code>com.sun.star.comp.Calc.XMLImporter</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>
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
{
64 static XComponent xSheetDoc
;
67 * New spreadsheet document created.
69 protected void initialize( TestParameters tParam
, PrintWriter log
) {
70 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
73 log
.println( "creating a Spreadsheet document" );
74 XSpreadsheetDocument xSpreadsheetDoc
= SOF
.createCalcDoc( null );
75 xSheetDoc
= UnoRuntime
.queryInterface
76 (XComponent
.class, xSpreadsheetDoc
);
77 } catch ( com
.sun
.star
.uno
.Exception e
) {
78 // Some exception occurs.FAILED
79 e
.printStackTrace( log
);
80 throw new StatusException( "Couldn't create document", e
);
85 * Spreadsheet document destroyed.
87 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
88 log
.println( " disposing document " );
89 util
.DesktopTools
.closeDoc(xSheetDoc
);
93 * Creating a Testenvironment for the interfaces to be tested.
94 * Creates an instance of the service
95 * <code>com.sun.star.comp.Calc.XMLImporter</code><p>
97 * The calc document is set as a target document for importer.
98 * Imported tags contain new value for table name.
99 * After import table name getting from
100 * target document is checked.
101 * Object relations created :
103 * <li> <code>'XDocumentHandler.XMLData'</code> for
104 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
105 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
106 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
107 * <li> <code>'TargetDocument'</code> for
108 * {@link ifc.document._XImporter} interface </li>
111 public synchronized TestEnvironment
createTestEnvironment( TestParameters tParam
,
113 throws StatusException
{
115 XInterface oObj
= null;
117 final String impValue
= "XMLImporter_test" ;
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
= (XMultiServiceFactory
)tParam
.getMSF() ;
126 oInt
= xMSF
.createInstance("com.sun.star.comp.Calc.XMLImporter") ;
127 XImporter imp
= UnoRuntime
.queryInterface
128 (XImporter
.class, oInt
) ;
129 imp
.setTargetDocument(xSheetDoc
);
130 } catch (com
.sun
.star
.uno
.Exception e
) {
131 e
.printStackTrace(log
) ;
132 throw new StatusException("Can't create component.", e
) ;
135 oObj
= (XInterface
) oInt
;
137 // create testobject here
138 log
.println( "creating a new environment for Paragraph object" );
139 TestEnvironment tEnv
= new TestEnvironment( oObj
);
142 tEnv
.addObjRelation("TargetDocument", xSheetDoc
) ;
144 // adding relation for XDocumentHandler
145 String
[][] xml
= new String
[][] {
146 {"start", "office:document",
147 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
148 "xmlns:text", "CDATA", "http://openoffice.org/2000/text",
149 "xmlns:table", "CDATA", "http://openoffice.org/2000/table",
150 "office:class", "CDATA", "spreadsheet"
152 {"start", "office:body"},
153 {"start", "table:table",
154 "table:name", "CDATA", impValue
},
155 {"end", "table:table"},
156 {"end", "office:body"},
157 {"end", "office:document"}} ;
159 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
161 final PrintWriter fLog
= log
;
162 XSpreadsheetDocument xSpreadsheetDoc
= UnoRuntime
.queryInterface(XSpreadsheetDocument
.class, xSheetDoc
);
163 final XSpreadsheets sheets
= xSpreadsheetDoc
.getSheets() ;
164 log
.println("Sheets before importing :") ;
165 String
[] names
= sheets
.getElementNames() ;
166 for (int i
= 0; i
< names
.length
; i
++) {
167 log
.println(" " + names
[i
]) ;
169 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
170 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
171 public boolean checkImport() {
172 fLog
.println("Sheet names :") ;
173 String
[] snames
= sheets
.getElementNames() ;
174 for (int i
= 0; i
< snames
.length
; i
++) {
175 fLog
.println(" " + snames
[i
]) ;
178 return sheets
.hasByName(impValue
) ;
183 } // finish method getTestEnvironment