merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / XMLContentImporter.java
blobf28c1f59a54f1488cf187c43eea81844330c47c0
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: XMLContentImporter.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;
49 /**
50 * Test for object which is represented by service
51 * <code>com.sun.star.comp.Calc.XMLContentImporter</code>. <p>
52 * Object implements the following interfaces :
53 * <ul>
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 * </ul>
62 * @see com.sun.star.lang.XInitialization
63 * @see com.sun.star.document.XImporter
64 * @see com.sun.star.document.XFilter
65 * @see com.sun.star.document.ImportFilter
66 * @see com.sun.star.beans.XPropertySet
67 * @see com.sun.star.xml.sax.XDocumentHandler
68 * @see ifc.lang._XInitialization
69 * @see ifc.document._XImporter
70 * @see ifc.document._XFilter
71 * @see ifc.document._XExporter
72 * @see ifc.beans._XPropertySet
73 * @see ifc.xml.sax._XDocumentHandler
75 public class XMLContentImporter extends TestCase {
76 static XSpreadsheetDocument xSheetDoc;
77 static XComponent comp ;
79 /**
80 * New spreadsheet document created.
82 protected void initialize( TestParameters tParam, PrintWriter log ) {
83 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
85 try {
86 log.println( "creating a Spreadsheet document" );
87 xSheetDoc = SOF.createCalcDoc( null );
88 comp = (XComponent) UnoRuntime.queryInterface
89 (XComponent.class, xSheetDoc) ;
90 } catch ( com.sun.star.uno.Exception e ) {
91 // Some exception occures.FAILED
92 e.printStackTrace( log );
93 throw new StatusException( "Couldn't create document", e );
97 /**
98 * Spreadsheet document destroyed.
100 protected void cleanup( TestParameters tParam, PrintWriter log ) {
101 log.println( " disposing document " );
102 util.DesktopTools.closeDoc(comp);
106 * Creating a Testenvironment for the interfaces to be tested.
107 * Creates an instance of the service
108 * <code>com.sun.star.comp.Calc.XMLContentImporter</code><p>
110 * The calc document is set as a target document for importer.
111 * Imported XML-data contains only content tags including table
112 * with test table name.
113 * After import table name getting from
114 * target document is checked.
115 * Object relations created :
116 * <ul>
117 * <li> <code>'XDocumentHandler.XMLData'</code> for
118 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
119 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
120 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
121 * <li> <code>'TargetDocument'</code> for
122 * {@link ifc.document._XImporter} interface </li>
123 * </ul>
125 public synchronized TestEnvironment createTestEnvironment( TestParameters tParam,
126 PrintWriter log )
127 throws StatusException {
129 XInterface oObj = null;
130 Object oInt = null ;
132 // creation of testobject here
133 // first we write what we are intend to do to log file
134 log.println( "creating a test environment" );
136 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ;
138 try {
139 oInt = xMSF.createInstance
140 ("com.sun.star.comp.Calc.XMLContentImporter") ;
141 XImporter imp = (XImporter) UnoRuntime.queryInterface
142 (XImporter.class, oInt) ;
143 imp.setTargetDocument(comp);
144 } catch (com.sun.star.uno.Exception e) {
145 e.printStackTrace(log) ;
146 throw new StatusException("Can't create component.", e) ;
149 oObj = (XInterface) oInt ;
151 // create testobject here
152 log.println( "creating a new environment for Paragraph object" );
153 TestEnvironment tEnv = new TestEnvironment( oObj );
155 // adding relations
156 tEnv.addObjRelation("TargetDocument", comp) ;
158 final String impValue = "XMLContentImporter_test" ;
159 // adding relation for XDocumentHandler
160 String[][] xml = new String[][] {
161 {"start", "office:document-content",
162 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
163 "xmlns:text", "CDATA", "http://openoffice.org/2000/text",
164 "xmlns:table", "CDATA", "http://openoffice.org/2000/table",
165 "office:class", "CDATA", "spreadsheet"
167 {"start", "office:body"},
168 {"start", "table:table",
169 "table:name", "CDATA", impValue},
170 {"end", "table:table"},
171 {"end", "office:body"},
172 {"end", "office:document-content"}} ;
174 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
176 //save to log content before import
177 final PrintWriter fLog = log;
178 final XSpreadsheets xSheets = xSheetDoc.getSheets();
180 log.println("Sheets before importing :") ;
181 String[] names = xSheets.getElementNames() ;
182 for (int i = 0; i < names.length; i++) {
183 log.println(" " + names[i]) ;
186 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
187 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
188 public boolean checkImport() {
189 fLog.println("Sheet names :") ;
190 String[] snames = xSheets.getElementNames() ;
191 for (int i = 0; i < snames.length; i++) {
192 fLog.println(" " + snames[i]) ;
194 return xSheets.hasByName(impValue) ;
196 }) ;
198 return tEnv;
199 } // finish method getTestEnvironment