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.
72 protected void initialize( TestParameters tParam
, PrintWriter log
) {
73 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
76 log
.println( "creating a textdocument" );
77 xTextDoc
= SOF
.createTextDoc( null );
79 } catch ( com
.sun
.star
.uno
.Exception e
) {
80 // Some exception occurs.FAILED
81 e
.printStackTrace( log
);
82 throw new StatusException( "Couldn't create document", e
);
88 * Document disposed here.
90 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
91 log
.println( " disposing xTextDoc " );
92 util
.DesktopTools
.closeDoc(xTextDoc
);
96 * Creating a Testenvironment for the interfaces to be tested.
97 * Creates an instance of the service
98 * <code>com.sun.star.comp.Calc.XMLSettingsExporter</code> with
99 * argument which is an implementation of <code>XDocumentHandler</code>
100 * and which can check if required tags and character data is
102 * The text document is set as a source document for exporter
103 * created. New document zoom is set as one of the 'View' settings. This made
104 * for checking if this setting is successfully exported within
105 * the document settings.
106 * Object relations created :
108 * <li> <code>'MediaDescriptor'</code> for
109 * {@link ifc.document._XFilter} interface </li>
110 * <li> <code>'XFilter.Checker'</code> for
111 * {@link ifc.document._XFilter} interface </li>
112 * <li> <code>'SourceDocument'</code> for
113 * {@link ifc.document._XExporter} interface </li>
116 public synchronized TestEnvironment createTestEnvironment
117 (TestParameters tParam
, PrintWriter log
) {
119 final short ZOOM
= 50;
121 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)tParam
.getMSF() ;
122 XInterface oObj
= null;
124 Filter
= new SettingsFilterChecker(log
);
125 Any arg
= new Any(new Type(XDocumentHandler
.class), Filter
);
127 oObj
= (XInterface
) xMSF
.createInstanceWithArguments(
128 "com.sun.star.comp.Writer.XMLSettingsExporter",
130 XExporter xEx
= UnoRuntime
.queryInterface
131 (XExporter
.class,oObj
);
132 xEx
.setSourceDocument(xTextDoc
);
135 XController xController
= xTextDoc
.getCurrentController();
136 XViewSettingsSupplier xViewSetSup
= UnoRuntime
.queryInterface(XViewSettingsSupplier
.class,
138 XPropertySet xPropSet
= xViewSetSup
.getViewSettings();
139 xPropSet
.setPropertyValue("ZoomValue", new Short(ZOOM
));
141 } catch (com
.sun
.star
.uno
.Exception e
) {
142 e
.printStackTrace(log
) ;
143 throw new StatusException("Can't create component.", e
) ;
146 // adding tags which must be contained in XML output
147 Filter
.addTag( new XMLTools
.Tag("office:document-settings") );
148 Filter
.addTagEnclosed(
149 new XMLTools
.Tag("office:settings"),
150 new XMLTools
.Tag("office:document-settings") );
151 Filter
.addCharactersEnclosed(
152 String
.valueOf(ZOOM
),
153 new XMLTools
.Tag("config:config-item",
154 "config:name", "ZoomFactor") );
156 // create testobject here
157 log
.println( "creating a new environment" );
158 TestEnvironment tEnv
= new TestEnvironment( oObj
);
160 tEnv
.addObjRelation("MediaDescriptor", XMLTools
.createMediaDescriptor(
161 new String
[] {"FilterName"},
162 new Object
[] {"swriter: StarOffice XML (Writer)"}));
163 tEnv
.addObjRelation("SourceDocument",xTextDoc
);
164 tEnv
.addObjRelation("XFilter.Checker", Filter
);
170 * This class checks the XML for tags and data required and returns
171 * checking result to <code>XFilter</code> interface test. All
172 * the information about errors occurred in XML data is written
174 * @see ifc.document._XFilter
176 protected class SettingsFilterChecker
extends XMLTools
.XMLChecker
177 implements ifc
.document
._XFilter
.FilterChecker
{
180 * Creates a class which will write information
181 * into log specified.
183 public SettingsFilterChecker(PrintWriter log
) {
188 * <code>_XFilter.FilterChecker</code> interface method
189 * which returns the result of XML checking.
190 * @return <code>true</code> if the XML data exported was
191 * valid (i.e. all necessary tags and character data exists),
192 * <code>false</code> if some errors occurred.
194 public boolean checkFilter() {