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
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.SOfficeFactory
;
29 import com
.sun
.star
.beans
.XPropertySet
;
30 import com
.sun
.star
.document
.XExporter
;
31 import com
.sun
.star
.frame
.XController
;
32 import com
.sun
.star
.lang
.XMultiServiceFactory
;
33 import com
.sun
.star
.text
.XTextDocument
;
34 import com
.sun
.star
.uno
.Any
;
35 import com
.sun
.star
.uno
.Type
;
36 import com
.sun
.star
.uno
.UnoRuntime
;
37 import com
.sun
.star
.uno
.XInterface
;
38 import com
.sun
.star
.view
.XViewSettingsSupplier
;
39 import com
.sun
.star
.xml
.sax
.XDocumentHandler
;
42 * Test for object which is represented by service
43 * <code>com.sun.star.comp.Calc.XMLSettingsExporter</code>. <p>
44 * Object implements the following interfaces :
46 * <li><code>com::sun::star::lang::XInitialization</code></li>
47 * <li><code>com::sun::star::document::ExportFilter</code></li>
48 * <li><code>com::sun::star::document::XFilter</code></li>
49 * <li><code>com::sun::star::document::XExporter</code></li>
50 * <li><code>com::sun::star::beans::XPropertySet</code></li>
52 * @see com.sun.star.lang.XInitialization
53 * @see com.sun.star.document.ExportFilter
54 * @see com.sun.star.document.XFilter
55 * @see com.sun.star.document.XExporter
56 * @see com.sun.star.beans.XPropertySet
57 * @see ifc.lang._XInitialization
58 * @see ifc.document._ExportFilter
59 * @see ifc.document._XFilter
60 * @see ifc.document._XExporter
61 * @see ifc.beans._XPropertySet
63 public class XMLSettingsExporter
extends TestCase
{
65 XTextDocument xTextDoc
;
66 SettingsFilterChecker Filter
;
69 * New text document created.
72 protected void initialize( TestParameters tParam
, PrintWriter log
) throws Exception
{
73 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
75 log
.println( "creating a textdocument" );
76 xTextDoc
= SOF
.createTextDoc( null );
80 * Document disposed here.
83 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
84 log
.println( " disposing xTextDoc " );
85 util
.DesktopTools
.closeDoc(xTextDoc
);
89 * Creating a TestEnvironment for the interfaces to be tested.
90 * Creates an instance of the service
91 * <code>com.sun.star.comp.Calc.XMLSettingsExporter</code> with
92 * argument which is an implementation of <code>XDocumentHandler</code>
93 * and which can check if required tags and character data is
95 * The text document is set as a source document for exporter
96 * created. New document zoom is set as one of the 'View' settings. This made
97 * for checking if this setting is successfully exported within
98 * the document settings.
99 * Object relations created :
101 * <li> <code>'MediaDescriptor'</code> for
102 * {@link ifc.document._XFilter} interface </li>
103 * <li> <code>'XFilter.Checker'</code> for
104 * {@link ifc.document._XFilter} interface </li>
105 * <li> <code>'SourceDocument'</code> for
106 * {@link ifc.document._XExporter} interface </li>
110 public TestEnvironment createTestEnvironment
111 (TestParameters tParam
, PrintWriter log
) throws Exception
{
113 final short ZOOM
= 50;
115 XMultiServiceFactory xMSF
= tParam
.getMSF() ;
116 XInterface oObj
= null;
118 Filter
= new SettingsFilterChecker(log
);
119 Any arg
= new Any(new Type(XDocumentHandler
.class), Filter
);
120 oObj
= (XInterface
) xMSF
.createInstanceWithArguments(
121 "com.sun.star.comp.Writer.XMLSettingsExporter",
123 XExporter xEx
= UnoRuntime
.queryInterface
124 (XExporter
.class,oObj
);
125 xEx
.setSourceDocument(xTextDoc
);
128 XController xController
= xTextDoc
.getCurrentController();
129 XViewSettingsSupplier xViewSetSup
= UnoRuntime
.queryInterface(XViewSettingsSupplier
.class,
131 XPropertySet xPropSet
= xViewSetSup
.getViewSettings();
132 xPropSet
.setPropertyValue("ZoomValue", Short
.valueOf(ZOOM
));
134 // adding tags which must be contained in XML output
135 Filter
.addTag( new XMLTools
.Tag("office:document-settings") );
136 Filter
.addTagEnclosed(
137 new XMLTools
.Tag("office:settings"),
138 new XMLTools
.Tag("office:document-settings") );
139 Filter
.addCharactersEnclosed(
140 String
.valueOf(ZOOM
),
141 new XMLTools
.Tag("config:config-item",
142 "config:name", "ZoomFactor") );
144 // create testobject here
145 log
.println( "creating a new environment" );
146 TestEnvironment tEnv
= new TestEnvironment( oObj
);
148 tEnv
.addObjRelation("MediaDescriptor", XMLTools
.createMediaDescriptor(
149 new String
[] {"FilterName"},
150 new Object
[] {"swriter: StarOffice XML (Writer)"}));
151 tEnv
.addObjRelation("SourceDocument",xTextDoc
);
152 tEnv
.addObjRelation("XFilter.Checker", Filter
);
158 * This class checks the XML for tags and data required and returns
159 * checking result to <code>XFilter</code> interface test. All
160 * the information about errors occurred in XML data is written
162 * @see ifc.document._XFilter
164 private class SettingsFilterChecker
extends XMLTools
.XMLChecker
165 implements ifc
.document
._XFilter
.FilterChecker
{
168 * Creates a class which will write information
169 * into log specified.
171 private SettingsFilterChecker(PrintWriter log
) {
176 * <code>_XFilter.FilterChecker</code> interface method
177 * which returns the result of XML checking.
178 * @return <code>true</code> if the XML data exported was
179 * valid (i.e. all necessary tags and character data exists),
180 * <code>false</code> if some errors occurred.
182 public boolean checkFilter() {