merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / XMLImporter.java
blobbf838cb5ca9df68e5fbf25f0c98b51d2ea0f9f60
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLImporter.java,v $
10 * $Revision: 1.8 $
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._sc;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.SOfficeFactory;
41 import com.sun.star.document.XImporter;
42 import com.sun.star.lang.XComponent;
43 import com.sun.star.lang.XMultiServiceFactory;
44 import com.sun.star.sheet.XSpreadsheetDocument;
45 import com.sun.star.sheet.XSpreadsheets;
46 import com.sun.star.uno.UnoRuntime;
47 import com.sun.star.uno.XInterface;
48 /**
49 * Test for object which is represented by service
50 * <code>com.sun.star.comp.Calc.XMLImporter</code>. <p>
51 * Object implements the following interfaces :
52 * <ul>
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 * </ul>
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 XMLImporter extends TestCase {
76 static XComponent xSheetDoc;
78 /**
79 * New spreadsheet document created.
81 protected void initialize( TestParameters tParam, PrintWriter log ) {
82 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
84 try {
85 log.println( "creating a Spreadsheet document" );
86 XSpreadsheetDocument xSpreadsheetDoc = SOF.createCalcDoc( null );
87 xSheetDoc = (XComponent) UnoRuntime.queryInterface
88 (XComponent.class, xSpreadsheetDoc);
89 } catch ( com.sun.star.uno.Exception e ) {
90 // Some exception occures.FAILED
91 e.printStackTrace( log );
92 throw new StatusException( "Couldn't create document", e );
96 /**
97 * Spreadsheet document destroyed.
99 protected void cleanup( TestParameters tParam, PrintWriter log ) {
100 log.println( " disposing document " );
101 util.DesktopTools.closeDoc(xSheetDoc);
105 * Creating a Testenvironment for the interfaces to be tested.
106 * Creates an instance of the service
107 * <code>com.sun.star.comp.Calc.XMLImporter</code><p>
109 * The calc document is set as a target document for importer.
110 * Imported tags contain new value for table name.
111 * After import table name getting from
112 * target document is checked.
113 * Object relations created :
114 * <ul>
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>
121 * </ul>
123 public synchronized TestEnvironment createTestEnvironment( TestParameters tParam,
124 PrintWriter log )
125 throws StatusException {
127 XInterface oObj = null;
128 Object oInt = null ;
129 final String impValue = "XMLImporter_test" ;
131 // creation of testobject here
132 // first we write what we are intend to do to log file
133 log.println( "creating a test environment" );
135 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ;
137 try {
138 oInt = xMSF.createInstance("com.sun.star.comp.Calc.XMLImporter") ;
139 XImporter imp = (XImporter) UnoRuntime.queryInterface
140 (XImporter.class, oInt) ;
141 imp.setTargetDocument(xSheetDoc);
142 } catch (com.sun.star.uno.Exception e) {
143 e.printStackTrace(log) ;
144 throw new StatusException("Can't create component.", e) ;
147 oObj = (XInterface) oInt ;
149 // create testobject here
150 log.println( "creating a new environment for Paragraph object" );
151 TestEnvironment tEnv = new TestEnvironment( oObj );
153 // adding relation
154 tEnv.addObjRelation("TargetDocument", xSheetDoc) ;
156 // adding relation for XDocumentHandler
157 String[][] xml = new String[][] {
158 {"start", "office:document",
159 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
160 "xmlns:text", "CDATA", "http://openoffice.org/2000/text",
161 "xmlns:table", "CDATA", "http://openoffice.org/2000/table",
162 "office:class", "CDATA", "spreadsheet"
164 {"start", "office:body"},
165 {"start", "table:table",
166 "table:name", "CDATA", impValue},
167 {"end", "table:table"},
168 {"end", "office:body"},
169 {"end", "office:document"}} ;
171 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
173 final PrintWriter fLog = log ;
174 XSpreadsheetDocument xSpreadsheetDoc = (XSpreadsheetDocument)
175 UnoRuntime.queryInterface(XSpreadsheetDocument.class, xSheetDoc);
176 final XSpreadsheets sheets = xSpreadsheetDoc.getSheets() ;
177 log.println("Sheets before importing :") ;
178 String[] names = sheets.getElementNames() ;
179 for (int i = 0; i < names.length; i++) {
180 log.println(" " + names[i]) ;
182 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
183 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
184 public boolean checkImport() {
185 fLog.println("Sheet names :") ;
186 String[] snames = sheets.getElementNames() ;
187 for (int i = 0; i < snames.length; i++) {
188 fLog.println(" " + snames[i]) ;
191 return sheets.hasByName(impValue) ;
193 }) ;
195 return tEnv;
196 } // finish method getTestEnvironment