bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sc / XMLContentImporter.java
blob6d8cbecf5eec6baf823b85ca0856ff3c8e84815b
1 /*
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 .
19 package mod._sc;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
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 /**
38 * Test for object which is represented by service
39 * <code>com.sun.star.comp.Calc.XMLContentImporter</code>. <p>
40 * Object implements the following interfaces :
41 * <ul>
42 * <li><code>com::sun::star::lang::XInitialization</code></li>
43 * <li><code>com::sun::star::document::XImporter</code></li>
44 * <li><code>com::sun::star::document::XFilter</code></li>
45 * <li><code>com::sun::star::document::ImportFilter</code></li>
46 * <li><code>com::sun::star::beans::XPropertySet</code></li>
47 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
49 * </ul>
50 * @see com.sun.star.lang.XInitialization
51 * @see com.sun.star.document.XImporter
52 * @see com.sun.star.document.XFilter
53 * @see com.sun.star.document.ImportFilter
54 * @see com.sun.star.beans.XPropertySet
55 * @see com.sun.star.xml.sax.XDocumentHandler
56 * @see ifc.lang._XInitialization
57 * @see ifc.document._XImporter
58 * @see ifc.document._XFilter
59 * @see ifc.document._XExporter
60 * @see ifc.beans._XPropertySet
61 * @see ifc.xml.sax._XDocumentHandler
63 public class XMLContentImporter extends TestCase {
64 private XSpreadsheetDocument xSheetDoc;
65 static XComponent comp ;
67 /**
68 * New spreadsheet document created.
70 @Override
71 protected void initialize( TestParameters tParam, PrintWriter log ) {
72 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
74 try {
75 log.println( "creating a Spreadsheet document" );
76 xSheetDoc = SOF.createCalcDoc( null );
77 comp = UnoRuntime.queryInterface
78 (XComponent.class, xSheetDoc) ;
79 } catch ( com.sun.star.uno.Exception e ) {
80 // Some exception occurs.FAILED
81 e.printStackTrace( log );
82 throw new StatusException( "Couldn't create document", e );
86 /**
87 * Spreadsheet document destroyed.
89 @Override
90 protected void cleanup( TestParameters tParam, PrintWriter log ) {
91 log.println( " disposing document " );
92 util.DesktopTools.closeDoc(comp);
95 /**
96 * Creating a Testenvironment for the interfaces to be tested.
97 * Creates an instance of the service
98 * <code>com.sun.star.comp.Calc.XMLContentImporter</code><p>
100 * The calc document is set as a target document for importer.
101 * Imported XML-data contains only content tags including table
102 * with test table name.
103 * After import table name getting from
104 * target document is checked.
105 * Object relations created :
106 * <ul>
107 * <li> <code>'XDocumentHandler.XMLData'</code> for
108 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
109 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
110 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
111 * <li> <code>'TargetDocument'</code> for
112 * {@link ifc.document._XImporter} interface </li>
113 * </ul>
115 @Override
116 public synchronized TestEnvironment createTestEnvironment( TestParameters tParam,
117 PrintWriter log )
118 throws StatusException {
120 XInterface oObj = null;
121 Object oInt = null ;
123 // creation of testobject here
124 // first we write what we are intend to do to log file
125 log.println( "creating a test environment" );
127 XMultiServiceFactory xMSF = tParam.getMSF() ;
129 try {
130 oInt = xMSF.createInstance
131 ("com.sun.star.comp.Calc.XMLContentImporter") ;
132 XImporter imp = UnoRuntime.queryInterface
133 (XImporter.class, oInt) ;
134 imp.setTargetDocument(comp);
135 } catch (com.sun.star.uno.Exception e) {
136 e.printStackTrace(log) ;
137 throw new StatusException("Can't create component.", e) ;
140 oObj = (XInterface) oInt ;
142 // create testobject here
143 log.println( "creating a new environment for Paragraph object" );
144 TestEnvironment tEnv = new TestEnvironment( oObj );
146 // adding relations
147 tEnv.addObjRelation("TargetDocument", comp) ;
149 final String impValue = "XMLContentImporter_test" ;
150 // adding relation for XDocumentHandler
151 String[][] xml = new String[][] {
152 {"start", "office:document-content",
153 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
154 "xmlns:text", "CDATA", "http://openoffice.org/2000/text",
155 "xmlns:table", "CDATA", "http://openoffice.org/2000/table",
156 "office:class", "CDATA", "spreadsheet"
158 {"start", "office:body"},
159 {"start", "table:table",
160 "table:name", "CDATA", impValue},
161 {"end", "table:table"},
162 {"end", "office:body"},
163 {"end", "office:document-content"}} ;
165 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
167 //save to log content before import
168 final PrintWriter fLog = log;
169 final XSpreadsheets xSheets = xSheetDoc.getSheets();
171 log.println("Sheets before importing :") ;
172 String[] names = xSheets.getElementNames() ;
173 for (int i = 0; i < names.length; i++) {
174 log.println(" " + names[i]) ;
177 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
178 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
179 public boolean checkImport() {
180 fLog.println("Sheet names :") ;
181 String[] snames = xSheets.getElementNames() ;
182 for (int i = 0; i < snames.length; i++) {
183 fLog.println(" " + snames[i]) ;
185 return xSheets.hasByName(impValue) ;
187 }) ;
189 return tEnv;
190 } // finish method getTestEnvironment