merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / XMLSettingsExporter.java
blob8868f1d6cce21a40c48e4c09829d0fa286af0827
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: XMLSettingsExporter.java,v $
10 * $Revision: 1.9 $
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;
40 import util.XMLTools;
42 import com.sun.star.beans.XPropertySet;
43 import com.sun.star.document.XExporter;
44 import com.sun.star.frame.XController;
45 import com.sun.star.frame.XModel;
46 import com.sun.star.lang.XComponent;
47 import com.sun.star.lang.XMultiServiceFactory;
48 import com.sun.star.uno.Any;
49 import com.sun.star.uno.Type;
50 import com.sun.star.uno.UnoRuntime;
51 import com.sun.star.uno.XInterface;
52 import com.sun.star.xml.sax.XDocumentHandler;
54 /**
55 * Test for object which is represented by service
56 * <code>com.sun.star.comp.Calc.XMLSettingsExporter</code>. <p>
57 * Object implements the following interfaces :
58 * <ul>
59 * <li><code>com::sun::star::lang::XInitialization</code></li>
60 * <li><code>com::sun::star::document::ExportFilter</code></li>
61 * <li><code>com::sun::star::document::XFilter</code></li>
62 * <li><code>com::sun::star::document::XExporter</code></li>
63 * <li><code>com::sun::star::beans::XPropertySet</code></li>
64 * </ul>
65 * @see com.sun.star.lang.XInitialization
66 * @see com.sun.star.document.ExportFilter
67 * @see com.sun.star.document.XFilter
68 * @see com.sun.star.document.XExporter
69 * @see com.sun.star.beans.XPropertySet
70 * @see ifc.lang._XInitialization
71 * @see ifc.document._ExportFilter
72 * @see ifc.document._XFilter
73 * @see ifc.document._XExporter
74 * @see ifc.beans._XPropertySet
76 public class XMLSettingsExporter extends TestCase {
78 static XComponent xSheetDoc;
80 /**
81 * New spreadsheet document created.
83 protected void initialize( TestParameters tParam, PrintWriter log ) {
84 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
86 try {
87 log.println( "creating a calc document" );
88 xSheetDoc = SOF.openDoc("scalc","_blank");
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 disposed
99 protected void cleanup( TestParameters tParam, PrintWriter log ) {
100 log.println( " disposing xCalcDoc " );
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.XMLSettingsExporter</code> with
108 * argument which is an implementation of <code>XDocumentHandler</code>
109 * and which can check if required tags and character data is
110 * exported. <p>
111 * The calc document is set as a source document for exporter
112 * created. Sets settings' property 'ShowGrid' to 'false', then checks
113 * it in the exported xml document.<p>
114 * Object relations created :
115 * <ul>
116 * <li> <code>'MediaDescriptor'</code> for
117 * {@link ifc.document._XFilter} interface </li>
118 * <li> <code>'XFilter.Checker'</code> for
119 * {@link ifc.document._XFilter} interface </li>
120 * <li> <code>'SourceDocument'</code> for
121 * {@link ifc.document._XExporter} interface </li>
122 * </ul>
124 public synchronized TestEnvironment createTestEnvironment( TestParameters tParam,
125 PrintWriter log )
126 throws StatusException {
128 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ;
129 XInterface oObj = null;
130 SettingsFilterChecker filter = new SettingsFilterChecker(log);
131 Any arg = new Any(new Type(XDocumentHandler.class), filter);
132 try {
133 oObj = (XInterface) xMSF.createInstanceWithArguments(
134 "com.sun.star.comp.Calc.XMLSettingsExporter",
135 new Object[] {arg} );
136 XExporter xEx = (XExporter) UnoRuntime.queryInterface
137 (XExporter.class,oObj);
138 xEx.setSourceDocument(xSheetDoc);
140 //set some settings
141 XModel xSheetModel = (XModel)
142 UnoRuntime.queryInterface(XModel.class, xSheetDoc);
143 XController xController = xSheetModel.getCurrentController();
144 XPropertySet xPropSet = (XPropertySet)
145 UnoRuntime.queryInterface(XPropertySet.class, xController);
146 xPropSet.setPropertyValue("ShowGrid", "false");
148 util.CalcTools.fillCalcSheetWithContent(xSheetDoc,1, 3, 3, 50, 50);
150 } catch (com.sun.star.uno.Exception e) {
151 e.printStackTrace(log) ;
152 throw new StatusException("Can't create component.", e) ;
153 } catch (java.lang.Exception e) {
154 e.printStackTrace(log);
155 throw new StatusException("Can't create environment.", e);
158 //Create and prepare filter
159 // adding tags which must be contained in XML output
160 filter.addTag(new XMLTools.Tag("office:document-settings") );
161 filter.addTagEnclosed(
162 new XMLTools.Tag("office:settings"),
163 new XMLTools.Tag("office:document-settings") );
164 filter.addCharactersEnclosed(
165 "false",
166 new XMLTools.Tag("config:config-item", "config:name", "ShowGrid") );
168 // create testobject here
169 log.println( "creating a new environment" );
170 TestEnvironment tEnv = new TestEnvironment( oObj );
172 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
173 new String[] {"FilterName"},
174 new Object[] {"scalc: StarOffice XML (Calc)"}));
175 tEnv.addObjRelation("SourceDocument",xSheetDoc);
176 tEnv.addObjRelation("XFilter.Checker", filter) ;
177 return tEnv;
181 * This class checks the XML for tags and data required and returns
182 * checking result to <code>XFilter</code> interface test. All
183 * the information about errors occured in XML data is written
184 * to log specified.
185 * @see ifc.document._XFilter
187 protected class SettingsFilterChecker extends XMLTools.XMLChecker
188 implements ifc.document._XFilter.FilterChecker {
191 * Creates a class which will write information
192 * into log specified.
194 public SettingsFilterChecker(PrintWriter log) {
195 super(log, false) ;
198 * <code>_XFilter.FilterChecker</code> interface method
199 * which returns the result of XML checking.
200 * @return <code>true</code> if the XML data exported was
201 * valid (i.e. all necessary tags and character data exists),
202 * <code>false</code> if some errors occured.
204 public boolean checkFilter() {
205 return check();