1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLSettingsExporter.java,v $
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 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
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
;
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 :
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>
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
;
82 * New text document created.
84 protected void initialize( TestParameters tParam
, PrintWriter log
) {
85 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
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
);
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
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 :
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>
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
);
139 oObj
= (XInterface
) xMSF
.createInstanceWithArguments(
140 "com.sun.star.comp.Writer.XMLSettingsExporter",
142 XExporter xEx
= (XExporter
) UnoRuntime
.queryInterface
143 (XExporter
.class,oObj
);
144 xEx
.setSourceDocument(xTextDoc
);
147 XController xController
= xTextDoc
.getCurrentController();
148 XViewSettingsSupplier xViewSetSup
= (XViewSettingsSupplier
)
149 UnoRuntime
.queryInterface(XViewSettingsSupplier
.class,
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
);
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
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
) {
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() {