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 .
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.SOfficeFactory
;
30 import com
.sun
.star
.beans
.XPropertySet
;
31 import com
.sun
.star
.document
.XExporter
;
32 import com
.sun
.star
.frame
.XController
;
33 import com
.sun
.star
.lang
.XMultiServiceFactory
;
34 import com
.sun
.star
.text
.XTextDocument
;
35 import com
.sun
.star
.uno
.Any
;
36 import com
.sun
.star
.uno
.Type
;
37 import com
.sun
.star
.uno
.UnoRuntime
;
38 import com
.sun
.star
.uno
.XInterface
;
39 import com
.sun
.star
.view
.XViewSettingsSupplier
;
40 import com
.sun
.star
.xml
.sax
.XDocumentHandler
;
43 * Test for object which is represented by service
44 * <code>com.sun.star.comp.Calc.XMLSettingsExporter</code>. <p>
45 * Object implements the following interfaces :
47 * <li><code>com::sun::star::lang::XInitialization</code></li>
48 * <li><code>com::sun::star::document::ExportFilter</code></li>
49 * <li><code>com::sun::star::document::XFilter</code></li>
50 * <li><code>com::sun::star::document::XExporter</code></li>
51 * <li><code>com::sun::star::beans::XPropertySet</code></li>
53 * @see com.sun.star.lang.XInitialization
54 * @see com.sun.star.document.ExportFilter
55 * @see com.sun.star.document.XFilter
56 * @see com.sun.star.document.XExporter
57 * @see com.sun.star.beans.XPropertySet
58 * @see ifc.lang._XInitialization
59 * @see ifc.document._ExportFilter
60 * @see ifc.document._XFilter
61 * @see ifc.document._XExporter
62 * @see ifc.beans._XPropertySet
64 public class XMLSettingsExporter
extends TestCase
{
66 XTextDocument xTextDoc
;
67 SettingsFilterChecker Filter
;
70 * New text document created.
73 protected void initialize( TestParameters tParam
, PrintWriter log
) {
74 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
77 log
.println( "creating a textdocument" );
78 xTextDoc
= SOF
.createTextDoc( null );
80 } catch ( com
.sun
.star
.uno
.Exception e
) {
81 // Some exception occurs.FAILED
82 e
.printStackTrace( log
);
83 throw new StatusException( "Couldn't create document", e
);
89 * Document disposed here.
92 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
93 log
.println( " disposing xTextDoc " );
94 util
.DesktopTools
.closeDoc(xTextDoc
);
98 * Creating a Testenvironment for the interfaces to be tested.
99 * Creates an instance of the service
100 * <code>com.sun.star.comp.Calc.XMLSettingsExporter</code> with
101 * argument which is an implementation of <code>XDocumentHandler</code>
102 * and which can check if required tags and character data is
104 * The text document is set as a source document for exporter
105 * created. New document zoom is set as one of the 'View' settings. This made
106 * for checking if this setting is successfully exported within
107 * the document settings.
108 * Object relations created :
110 * <li> <code>'MediaDescriptor'</code> for
111 * {@link ifc.document._XFilter} interface </li>
112 * <li> <code>'XFilter.Checker'</code> for
113 * {@link ifc.document._XFilter} interface </li>
114 * <li> <code>'SourceDocument'</code> for
115 * {@link ifc.document._XExporter} interface </li>
119 public synchronized TestEnvironment createTestEnvironment
120 (TestParameters tParam
, PrintWriter log
) {
122 final short ZOOM
= 50;
124 XMultiServiceFactory xMSF
= tParam
.getMSF() ;
125 XInterface oObj
= null;
127 Filter
= new SettingsFilterChecker(log
);
128 Any arg
= new Any(new Type(XDocumentHandler
.class), Filter
);
130 oObj
= (XInterface
) xMSF
.createInstanceWithArguments(
131 "com.sun.star.comp.Writer.XMLSettingsExporter",
133 XExporter xEx
= UnoRuntime
.queryInterface
134 (XExporter
.class,oObj
);
135 xEx
.setSourceDocument(xTextDoc
);
138 XController xController
= xTextDoc
.getCurrentController();
139 XViewSettingsSupplier xViewSetSup
= UnoRuntime
.queryInterface(XViewSettingsSupplier
.class,
141 XPropertySet xPropSet
= xViewSetSup
.getViewSettings();
142 xPropSet
.setPropertyValue("ZoomValue", Short
.valueOf(ZOOM
));
144 } catch (com
.sun
.star
.uno
.Exception e
) {
145 e
.printStackTrace(log
) ;
146 throw new StatusException("Can't create component.", e
) ;
149 // adding tags which must be contained in XML output
150 Filter
.addTag( new XMLTools
.Tag("office:document-settings") );
151 Filter
.addTagEnclosed(
152 new XMLTools
.Tag("office:settings"),
153 new XMLTools
.Tag("office:document-settings") );
154 Filter
.addCharactersEnclosed(
155 String
.valueOf(ZOOM
),
156 new XMLTools
.Tag("config:config-item",
157 "config:name", "ZoomFactor") );
159 // create testobject here
160 log
.println( "creating a new environment" );
161 TestEnvironment tEnv
= new TestEnvironment( oObj
);
163 tEnv
.addObjRelation("MediaDescriptor", XMLTools
.createMediaDescriptor(
164 new String
[] {"FilterName"},
165 new Object
[] {"swriter: StarOffice XML (Writer)"}));
166 tEnv
.addObjRelation("SourceDocument",xTextDoc
);
167 tEnv
.addObjRelation("XFilter.Checker", Filter
);
173 * This class checks the XML for tags and data required and returns
174 * checking result to <code>XFilter</code> interface test. All
175 * the information about errors occurred in XML data is written
177 * @see ifc.document._XFilter
179 private class SettingsFilterChecker
extends XMLTools
.XMLChecker
180 implements ifc
.document
._XFilter
.FilterChecker
{
183 * Creates a class which will write information
184 * into log specified.
186 private SettingsFilterChecker(PrintWriter log
) {
191 * <code>_XFilter.FilterChecker</code> interface method
192 * which returns the result of XML checking.
193 * @return <code>true</code> if the XML data exported was
194 * valid (i.e. all necessary tags and character data exists),
195 * <code>false</code> if some errors occurred.
197 public boolean checkFilter() {