merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sw / XMLSettingsExporter.java
blob6ea24e76d67c4483024308b7bf2515d0f9c33ff6
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.7 $
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._sw;
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.lang.XMultiServiceFactory;
46 import com.sun.star.text.XTextDocument;
47 import com.sun.star.uno.Any;
48 import com.sun.star.uno.Type;
49 import com.sun.star.uno.UnoRuntime;
50 import com.sun.star.uno.XInterface;
51 import com.sun.star.view.XViewSettingsSupplier;
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 XTextDocument xTextDoc;
79 SettingsFilterChecker Filter;
81 /**
82 * New text 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 textdocument" );
89 xTextDoc = SOF.createTextDoc( null );
91 } catch ( com.sun.star.uno.Exception e ) {
92 // Some exception occures.FAILED
93 e.printStackTrace( log );
94 throw new StatusException( "Couldn't create document", e );
99 /**
100 * Document disposed here.
102 protected void cleanup( TestParameters tParam, PrintWriter log ) {
103 log.println( " disposing xTextDoc " );
104 util.DesktopTools.closeDoc(xTextDoc);
108 * Creating a Testenvironment for the interfaces to be tested.
109 * Creates an instance of the service
110 * <code>com.sun.star.comp.Calc.XMLSettingsExporter</code> with
111 * argument which is an implementation of <code>XDocumentHandler</code>
112 * and which can check if required tags and character data is
113 * exported. <p>
114 * The text document is set as a source document for exporter
115 * created. New document zoom is set as one of the 'View' settings. This made
116 * for checking if this setting is successfully exported within
117 * the document settings.
118 * Object relations created :
119 * <ul>
120 * <li> <code>'MediaDescriptor'</code> for
121 * {@link ifc.document._XFilter} interface </li>
122 * <li> <code>'XFilter.Checker'</code> for
123 * {@link ifc.document._XFilter} interface </li>
124 * <li> <code>'SourceDocument'</code> for
125 * {@link ifc.document._XExporter} interface </li>
126 * </ul>
128 public synchronized TestEnvironment createTestEnvironment
129 (TestParameters tParam, PrintWriter log) {
131 final short ZOOM = 50;
133 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ;
134 XInterface oObj = null;
136 Filter = new SettingsFilterChecker(log);
137 Any arg = new Any(new Type(XDocumentHandler.class), Filter);
138 try {
139 oObj = (XInterface) xMSF.createInstanceWithArguments(
140 "com.sun.star.comp.Writer.XMLSettingsExporter",
141 new Object[] {arg});
142 XExporter xEx = (XExporter) UnoRuntime.queryInterface
143 (XExporter.class,oObj);
144 xEx.setSourceDocument(xTextDoc);
146 //set some settings
147 XController xController = xTextDoc.getCurrentController();
148 XViewSettingsSupplier xViewSetSup = (XViewSettingsSupplier)
149 UnoRuntime.queryInterface(XViewSettingsSupplier.class,
150 xController);
151 XPropertySet xPropSet = xViewSetSup.getViewSettings();
152 xPropSet.setPropertyValue("ZoomValue", new Short(ZOOM));
154 } catch (com.sun.star.uno.Exception e) {
155 e.printStackTrace(log) ;
156 throw new StatusException("Can't create component.", e) ;
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 String.valueOf(ZOOM),
166 new XMLTools.Tag("config:config-item",
167 "config:name", "ZoomFactor") );
169 // create testobject here
170 log.println( "creating a new environment" );
171 TestEnvironment tEnv = new TestEnvironment( oObj );
173 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
174 new String[] {"FilterName"},
175 new Object[] {"swriter: StarOffice XML (Writer)"}));
176 tEnv.addObjRelation("SourceDocument",xTextDoc);
177 tEnv.addObjRelation("XFilter.Checker", Filter);
178 return tEnv;
183 * This class checks the XML for tags and data required and returns
184 * checking result to <code>XFilter</code> interface test. All
185 * the information about errors occured in XML data is written
186 * to log specified.
187 * @see ifc.document._XFilter
189 protected class SettingsFilterChecker extends XMLTools.XMLChecker
190 implements ifc.document._XFilter.FilterChecker {
193 * Creates a class which will write information
194 * into log specified.
196 public SettingsFilterChecker(PrintWriter log) {
197 super(log, false) ;
201 * <code>_XFilter.FilterChecker</code> interface method
202 * which returns the result of XML checking.
203 * @return <code>true</code> if the XML data exported was
204 * valid (i.e. all necessary tags and character data exists),
205 * <code>false</code> if some errors occured.
207 public boolean checkFilter() {
208 return check();