merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / XMLSettingsImporter.java
blob9dd535c3b008ba8ac1c64d3682637b2692c2bd39
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: XMLSettingsImporter.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.beans.XPropertySet;
42 import com.sun.star.document.XImporter;
43 import com.sun.star.frame.XController;
44 import com.sun.star.frame.XModel;
45 import com.sun.star.lang.XComponent;
46 import com.sun.star.lang.XMultiServiceFactory;
47 import com.sun.star.sheet.XSpreadsheetDocument;
48 import com.sun.star.uno.UnoRuntime;
49 import com.sun.star.uno.XInterface;
51 /**
52 * Test for object which is represented by service
53 * <code>com.sun.star.comp.Calc.XMLSettingsImporter</code>. <p>
54 * Object implements the following interfaces :
55 * <ul>
56 * <li><code>com::sun::star::lang::XInitialization</code></li>
57 * <li><code>com::sun::star::document::XImporter</code></li>
58 * <li><code>com::sun::star::document::XFilter</code></li>
59 * <li><code>com::sun::star::document::ImportFilter</code></li>
60 * <li><code>com::sun::star::beans::XPropertySet</code></li>
61 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
63 * </ul>
64 * @see com.sun.star.lang.XInitialization
65 * @see com.sun.star.document.XImporter
66 * @see com.sun.star.document.XFilter
67 * @see com.sun.star.document.ImportFilter
68 * @see com.sun.star.beans.XPropertySet
69 * @see com.sun.star.xml.sax.XDocumentHandler
70 * @see ifc.lang._XInitialization
71 * @see ifc.document._XImporter
72 * @see ifc.document._XFilter
73 * @see ifc.document._XExporter
74 * @see ifc.beans._XPropertySet
75 * @see ifc.xml.sax._XDocumentHandler
77 public class XMLSettingsImporter extends TestCase {
78 static XSpreadsheetDocument xSheetDoc;
79 static XComponent comp ;
81 /**
82 * New spreadsheet document created.
84 protected void initialize( TestParameters tParam, PrintWriter log ) {
85 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
87 try {
88 log.println( "creating a Spreadsheet document" );
89 xSheetDoc = SOF.createCalcDoc( null );
90 comp = (XComponent) UnoRuntime.queryInterface
91 (XComponent.class, xSheetDoc) ;
92 } catch ( com.sun.star.uno.Exception e ) {
93 // Some exception occures.FAILED
94 e.printStackTrace( log );
95 throw new StatusException( "Couldn't create document", e );
99 /**
100 * Spreadsheet document destroyed.
102 protected void cleanup( TestParameters tParam, PrintWriter log ) {
103 log.println( " disposing document " );
104 util.DesktopTools.closeDoc(comp);
108 * Creating a Testenvironment for the interfaces to be tested.
109 * Creates an instance of the service
110 * <code>com.sun.star.comp.Calc.XMLSettingsImporter</code><p>
112 * The calc document is set as a target document for importer.
113 * Imported XML-data contains only settings tags including tag
114 * with new number of iteration steps.
115 * After import 'IterationCount' proeprty getting from
116 * target document is checked.
117 * Object relations created :
118 * <ul>
119 * <li> <code>'XDocumentHandler.XMLData'</code> for
120 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
121 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
122 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
123 * <li> <code>'TargetDocument'</code> for
124 * {@link ifc.document._XImporter} interface </li>
125 * </ul>
127 public synchronized TestEnvironment createTestEnvironment( TestParameters tParam,
128 PrintWriter log )
129 throws StatusException {
131 XInterface oObj = null;
132 Object oInt = null ;
134 // creation of testobject here
135 // first we write what we are intend to do to log file
136 log.println( "creating a test environment" );
138 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ;
139 final XPropertySet xPropSet ;
141 try {
142 oInt = xMSF.createInstance
143 ("com.sun.star.comp.Calc.XMLSettingsImporter") ;
144 XImporter imp = (XImporter) UnoRuntime.queryInterface
145 (XImporter.class, oInt) ;
146 imp.setTargetDocument(comp) ;
148 XModel xSheetModel = (XModel)
149 UnoRuntime.queryInterface(XModel.class, xSheetDoc);
150 XController xController = xSheetModel.getCurrentController();
151 xPropSet = (XPropertySet)
152 UnoRuntime.queryInterface(XPropertySet.class, xController);
153 } catch (com.sun.star.uno.Exception e) {
154 e.printStackTrace(log) ;
155 throw new StatusException("Can't create component.", e) ;
158 oObj = (XInterface) oInt ;
160 // create testobject here
161 log.println( "creating a new environment for Paragraph object" );
162 TestEnvironment tEnv = new TestEnvironment( oObj );
164 // adding relation
165 tEnv.addObjRelation("TargetDocument", comp) ;
167 // adding relation for XDocumentHandler
168 String[][] xml = new String[][] {
169 {"start", "office:document-settings",
170 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
171 "xmlns:xlink", "CDATA", "http://www.w3.org/1999/xlink",
172 "xmlns:config", "CDATA", "http://openoffice.org/2001/config"},
173 {"start", "office:settings"},
174 {"start", "config:config-item-set",
175 "config:name", "CDATA", "view-settings"},
176 {"start", "config:config-item-map-indexed",
177 "config:name", "CDATA", "Views"},
178 {"start", "config:config-item-map-entry"},
179 {"start", "config:config-item",
180 "config:name", "CDATA", "ShowGrid",
181 "config:type", "CDATA", "boolean"},
182 {"chars", "false"},
183 {"end", "config:config-item"},
184 {"start", "config:config-item",
185 "config:name", "CDATA", "ZoomType",
186 "config:type", "CDATA", "short"},
187 {"chars", "0"},
188 {"start", "config:config-item",
189 "config:name", "CDATA", "ZoomValue",
190 "config:type", "CDATA", "int"},
191 {"chars", "124"},
192 {"end", "config:config-item"},
193 {"end", "config:config-item"},
194 {"end", "config:config-item-map-entry"},
195 {"end", "config:config-item-map-indexed"},
196 {"end", "config:config-item-set"},
197 {"end", "office:settings"},
198 {"end", "office:document-settings"}} ;
200 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
202 final PrintWriter logF = log ;
204 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
205 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
206 public boolean checkImport() {
207 try {
208 Object gVal = xPropSet.getPropertyValue("ShowGrid") ;
209 logF.println("ShowGrid = " + gVal ) ;
210 return "false".equals(gVal) ;
211 } catch (com.sun.star.uno.Exception e) {
212 logF.println("Exception occured while checking filter :") ;
213 e.printStackTrace(logF) ;
214 return false ;
217 }) ;
219 return tEnv;
220 } // finish method getTestEnvironment