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
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.SOfficeFactory
;
28 import com
.sun
.star
.document
.XImporter
;
29 import com
.sun
.star
.lang
.XComponent
;
30 import com
.sun
.star
.lang
.XMultiServiceFactory
;
31 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
32 import com
.sun
.star
.sheet
.XSpreadsheets
;
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.Calc.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>
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 XMLContentImporter
extends TestCase
{
63 private XSpreadsheetDocument xSheetDoc
;
64 static XComponent comp
;
67 * New spreadsheet document created.
70 protected void initialize( TestParameters tParam
, PrintWriter log
) throws Exception
{
71 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
73 log
.println( "creating a Spreadsheet document" );
74 xSheetDoc
= SOF
.createCalcDoc( null );
75 comp
= UnoRuntime
.queryInterface
76 (XComponent
.class, xSheetDoc
) ;
80 * Spreadsheet document destroyed.
83 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
84 log
.println( " disposing document " );
85 util
.DesktopTools
.closeDoc(comp
);
89 * Creating a TestEnvironment for the interfaces to be tested.
90 * Creates an instance of the service
91 * <code>com.sun.star.comp.Calc.XMLContentImporter</code><p>
93 * The calc document is set as a target document for importer.
94 * Imported XML-data contains only content tags including table
95 * with test table name.
96 * After import table name getting from
97 * target document is checked.
98 * Object relations created :
100 * <li> <code>'XDocumentHandler.XMLData'</code> for
101 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
102 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
103 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
104 * <li> <code>'TargetDocument'</code> for
105 * {@link ifc.document._XImporter} interface </li>
109 public TestEnvironment
createTestEnvironment( TestParameters tParam
,
113 XInterface oObj
= null;
116 // creation of testobject here
117 // first we write what we are intend to do to log file
118 log
.println( "creating a test environment" );
120 XMultiServiceFactory xMSF
= tParam
.getMSF() ;
122 oInt
= xMSF
.createInstance
123 ("com.sun.star.comp.Calc.XMLContentImporter") ;
124 XImporter imp
= UnoRuntime
.queryInterface
125 (XImporter
.class, oInt
) ;
126 imp
.setTargetDocument(comp
);
128 oObj
= (XInterface
) oInt
;
130 // create testobject here
131 log
.println( "creating a new environment for Paragraph object" );
132 TestEnvironment tEnv
= new TestEnvironment( oObj
);
135 tEnv
.addObjRelation("TargetDocument", comp
) ;
137 final String impValue
= "XMLContentImporter_test" ;
138 // adding relation for XDocumentHandler
139 String
[][] xml
= new String
[][] {
140 {"start", "office:document-content",
141 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
142 "xmlns:text", "CDATA", "http://openoffice.org/2000/text",
143 "xmlns:table", "CDATA", "http://openoffice.org/2000/table",
144 "office:class", "CDATA", "spreadsheet"
146 {"start", "office:body"},
147 {"start", "table:table",
148 "table:name", "CDATA", impValue
},
149 {"end", "table:table"},
150 {"end", "office:body"},
151 {"end", "office:document-content"}} ;
153 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
155 //save to log content before import
156 final PrintWriter fLog
= log
;
157 final XSpreadsheets xSheets
= xSheetDoc
.getSheets();
159 log
.println("Sheets before importing :") ;
160 String
[] names
= xSheets
.getElementNames() ;
161 for (int i
= 0; i
< names
.length
; i
++) {
162 log
.println(" " + names
[i
]) ;
165 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
166 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
167 public boolean checkImport() {
168 fLog
.println("Sheet names :") ;
169 String
[] snames
= xSheets
.getElementNames() ;
170 for (int i
= 0; i
< snames
.length
; i
++) {
171 fLog
.println(" " + snames
[i
]) ;
173 return xSheets
.hasByName(impValue
) ;
178 } // finish method getTestEnvironment