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.
72 protected void initialize( TestParameters tParam
, PrintWriter log
) {
73 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
76 log
.println( "creating a Spreadsheet document" );
77 xSheetDoc
= SOF
.createCalcDoc( null );
78 comp
= UnoRuntime
.queryInterface
79 (XComponent
.class, xSheetDoc
) ;
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
);
88 * Spreadsheet document destroyed.
90 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
91 log
.println( " disposing document " );
92 util
.DesktopTools
.closeDoc(comp
);
96 * Creating a Testenvironment for the interfaces to be tested.
97 * Creates an instance of the service
98 * <code>com.sun.star.comp.Calc.XMLSettingsImporter</code><p>
100 * The calc document is set as a target document for importer.
101 * Imported XML-data contains only settings tags including tag
102 * with new number of iteration steps.
103 * After import 'IterationCount' proeprty getting from
104 * target document is checked.
105 * Object relations created :
107 * <li> <code>'XDocumentHandler.XMLData'</code> for
108 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
109 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
110 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
111 * <li> <code>'TargetDocument'</code> for
112 * {@link ifc.document._XImporter} interface </li>
115 public synchronized TestEnvironment
createTestEnvironment( TestParameters tParam
,
117 throws StatusException
{
119 XInterface oObj
= null;
122 // creation of testobject here
123 // first we write what we are intend to do to log file
124 log
.println( "creating a test environment" );
126 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)tParam
.getMSF() ;
127 final XPropertySet xPropSet
;
130 oInt
= xMSF
.createInstance
131 ("com.sun.star.comp.Calc.XMLSettingsImporter") ;
132 XImporter imp
= UnoRuntime
.queryInterface
133 (XImporter
.class, oInt
) ;
134 imp
.setTargetDocument(comp
) ;
136 XModel xSheetModel
= UnoRuntime
.queryInterface(XModel
.class, xSheetDoc
);
137 XController xController
= xSheetModel
.getCurrentController();
138 xPropSet
= UnoRuntime
.queryInterface(XPropertySet
.class, xController
);
139 } catch (com
.sun
.star
.uno
.Exception e
) {
140 e
.printStackTrace(log
) ;
141 throw new StatusException("Can't create component.", e
) ;
144 oObj
= (XInterface
) oInt
;
146 // create testobject here
147 log
.println( "creating a new environment for Paragraph object" );
148 TestEnvironment tEnv
= new TestEnvironment( oObj
);
151 tEnv
.addObjRelation("TargetDocument", comp
) ;
153 // adding relation for XDocumentHandler
154 String
[][] xml
= new String
[][] {
155 {"start", "office:document-settings",
156 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
157 "xmlns:xlink", "CDATA", "http://www.w3.org/1999/xlink",
158 "xmlns:config", "CDATA", "http://openoffice.org/2001/config"},
159 {"start", "office:settings"},
160 {"start", "config:config-item-set",
161 "config:name", "CDATA", "view-settings"},
162 {"start", "config:config-item-map-indexed",
163 "config:name", "CDATA", "Views"},
164 {"start", "config:config-item-map-entry"},
165 {"start", "config:config-item",
166 "config:name", "CDATA", "ShowGrid",
167 "config:type", "CDATA", "boolean"},
169 {"end", "config:config-item"},
170 {"start", "config:config-item",
171 "config:name", "CDATA", "ZoomType",
172 "config:type", "CDATA", "short"},
174 {"start", "config:config-item",
175 "config:name", "CDATA", "ZoomValue",
176 "config:type", "CDATA", "int"},
178 {"end", "config:config-item"},
179 {"end", "config:config-item"},
180 {"end", "config:config-item-map-entry"},
181 {"end", "config:config-item-map-indexed"},
182 {"end", "config:config-item-set"},
183 {"end", "office:settings"},
184 {"end", "office:document-settings"}} ;
186 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
188 final PrintWriter logF
= log
;
190 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
191 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
192 public boolean checkImport() {
194 Object gVal
= xPropSet
.getPropertyValue("ShowGrid") ;
195 logF
.println("ShowGrid = " + gVal
) ;
196 return "false".equals(gVal
) ;
197 } catch (com
.sun
.star
.uno
.Exception e
) {
198 logF
.println("Exception occurred while checking filter :") ;
199 e
.printStackTrace(logF
) ;
206 } // finish method getTestEnvironment