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
;
29 import com
.sun
.star
.beans
.XPropertySet
;
30 import com
.sun
.star
.document
.XImporter
;
31 import com
.sun
.star
.frame
.XController
;
32 import com
.sun
.star
.frame
.XModel
;
33 import com
.sun
.star
.lang
.XComponent
;
34 import com
.sun
.star
.lang
.XMultiServiceFactory
;
35 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
36 import com
.sun
.star
.uno
.UnoRuntime
;
37 import com
.sun
.star
.uno
.XInterface
;
40 * Test for object which is represented by service
41 * <code>com.sun.star.comp.Calc.XMLSettingsImporter</code>. <p>
42 * Object implements the following interfaces :
44 * <li><code>com::sun::star::lang::XInitialization</code></li>
45 * <li><code>com::sun::star::document::XImporter</code></li>
46 * <li><code>com::sun::star::document::XFilter</code></li>
47 * <li><code>com::sun::star::document::ImportFilter</code></li>
48 * <li><code>com::sun::star::beans::XPropertySet</code></li>
49 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
52 * @see com.sun.star.lang.XInitialization
53 * @see com.sun.star.document.XImporter
54 * @see com.sun.star.document.XFilter
55 * @see com.sun.star.document.ImportFilter
56 * @see com.sun.star.beans.XPropertySet
57 * @see com.sun.star.xml.sax.XDocumentHandler
58 * @see ifc.lang._XInitialization
59 * @see ifc.document._XImporter
60 * @see ifc.document._XFilter
61 * @see ifc.document._XExporter
62 * @see ifc.beans._XPropertySet
63 * @see ifc.xml.sax._XDocumentHandler
65 public class XMLSettingsImporter
extends TestCase
{
66 private XSpreadsheetDocument xSheetDoc
;
67 static XComponent comp
;
70 * New spreadsheet document created.
73 protected void initialize( TestParameters tParam
, PrintWriter log
) {
74 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
77 log
.println( "creating a Spreadsheet document" );
78 xSheetDoc
= SOF
.createCalcDoc( null );
79 comp
= UnoRuntime
.queryInterface
80 (XComponent
.class, xSheetDoc
) ;
81 } catch ( com
.sun
.star
.uno
.Exception e
) {
82 // Some exception occurs.FAILED
83 e
.printStackTrace( log
);
84 throw new StatusException( "Couldn't create document", e
);
89 * Spreadsheet document destroyed.
92 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
93 log
.println( " disposing document " );
94 util
.DesktopTools
.closeDoc(comp
);
98 * Creating a Testenvironment for the interfaces to be tested.
99 * Creates an instance of the service
100 * <code>com.sun.star.comp.Calc.XMLSettingsImporter</code><p>
102 * The calc document is set as a target document for importer.
103 * Imported XML-data contains only settings tags including tag
104 * with new number of iteration steps.
105 * After import 'IterationCount' property getting from
106 * target document is checked.
107 * Object relations created :
109 * <li> <code>'XDocumentHandler.XMLData'</code> for
110 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
111 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
112 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
113 * <li> <code>'TargetDocument'</code> for
114 * {@link ifc.document._XImporter} interface </li>
118 public synchronized TestEnvironment
createTestEnvironment( TestParameters tParam
,
120 throws StatusException
{
122 XInterface oObj
= null;
125 // creation of testobject here
126 // first we write what we are intend to do to log file
127 log
.println( "creating a test environment" );
129 XMultiServiceFactory xMSF
= tParam
.getMSF() ;
130 final XPropertySet xPropSet
;
133 oInt
= xMSF
.createInstance
134 ("com.sun.star.comp.Calc.XMLSettingsImporter") ;
135 XImporter imp
= UnoRuntime
.queryInterface
136 (XImporter
.class, oInt
) ;
137 imp
.setTargetDocument(comp
) ;
139 XModel xSheetModel
= UnoRuntime
.queryInterface(XModel
.class, xSheetDoc
);
140 XController xController
= xSheetModel
.getCurrentController();
141 xPropSet
= UnoRuntime
.queryInterface(XPropertySet
.class, xController
);
142 } catch (com
.sun
.star
.uno
.Exception e
) {
143 e
.printStackTrace(log
) ;
144 throw new StatusException("Can't create component.", e
) ;
147 oObj
= (XInterface
) oInt
;
149 // create testobject here
150 log
.println( "creating a new environment for Paragraph object" );
151 TestEnvironment tEnv
= new TestEnvironment( oObj
);
154 tEnv
.addObjRelation("TargetDocument", comp
) ;
156 // adding relation for XDocumentHandler
157 String
[][] xml
= new String
[][] {
158 {"start", "office:document-settings",
159 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
160 "xmlns:xlink", "CDATA", "http://www.w3.org/1999/xlink",
161 "xmlns:config", "CDATA", "http://openoffice.org/2001/config"},
162 {"start", "office:settings"},
163 {"start", "config:config-item-set",
164 "config:name", "CDATA", "view-settings"},
165 {"start", "config:config-item-map-indexed",
166 "config:name", "CDATA", "Views"},
167 {"start", "config:config-item-map-entry"},
168 {"start", "config:config-item",
169 "config:name", "CDATA", "ShowGrid",
170 "config:type", "CDATA", "boolean"},
172 {"end", "config:config-item"},
173 {"start", "config:config-item",
174 "config:name", "CDATA", "ZoomType",
175 "config:type", "CDATA", "short"},
177 {"start", "config:config-item",
178 "config:name", "CDATA", "ZoomValue",
179 "config:type", "CDATA", "int"},
181 {"end", "config:config-item"},
182 {"end", "config:config-item"},
183 {"end", "config:config-item-map-entry"},
184 {"end", "config:config-item-map-indexed"},
185 {"end", "config:config-item-set"},
186 {"end", "office:settings"},
187 {"end", "office:document-settings"}} ;
189 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
191 final PrintWriter logF
= log
;
193 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
194 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
195 public boolean checkImport() {
197 Object gVal
= xPropSet
.getPropertyValue("ShowGrid") ;
198 logF
.println("ShowGrid = " + gVal
) ;
199 return "false".equals(gVal
) ;
200 } catch (com
.sun
.star
.uno
.Exception e
) {
201 logF
.println("Exception occurred while checking filter :") ;
202 e
.printStackTrace(logF
) ;
209 } // finish method getTestEnvironment