1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLSettingsImporter.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
41 import com
.sun
.star
.beans
.XPropertySet
;
42 import com
.sun
.star
.frame
.XController
;
43 import com
.sun
.star
.lang
.XMultiServiceFactory
;
44 import com
.sun
.star
.text
.XTextDocument
;
45 import com
.sun
.star
.uno
.UnoRuntime
;
46 import com
.sun
.star
.uno
.XInterface
;
47 import com
.sun
.star
.view
.XViewSettingsSupplier
;
50 * Test for object which is represented by service
51 * <code>com.sun.star.comp.Writer.XMLSettingsImporter</code>. <p>
52 * Object implements the following interfaces :
54 * <li><code>com::sun::star::lang::XInitialization</code></li>
55 * <li><code>com::sun::star::document::XImporter</code></li>
56 * <li><code>com::sun::star::document::XFilter</code></li>
57 * <li><code>com::sun::star::document::ImportFilter</code></li>
58 * <li><code>com::sun::star::beans::XPropertySet</code></li>
59 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
62 * @see com.sun.star.lang.XInitialization
63 * @see com.sun.star.document.XImporter
64 * @see com.sun.star.document.XFilter
65 * @see com.sun.star.document.ImportFilter
66 * @see com.sun.star.beans.XPropertySet
67 * @see com.sun.star.xml.sax.XDocumentHandler
68 * @see ifc.lang._XInitialization
69 * @see ifc.document._XImporter
70 * @see ifc.document._XFilter
71 * @see ifc.document._XExporter
72 * @see ifc.beans._XPropertySet
73 * @see ifc.xml.sax._XDocumentHandler
75 public class XMLSettingsImporter
extends TestCase
{
76 XTextDocument xTextDoc
;
79 * New text document created.
81 protected void initialize( TestParameters tParam
, PrintWriter log
) {
82 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
85 log
.println( "creating a textdocument" );
86 xTextDoc
= SOF
.createTextDoc( null );
87 } catch ( com
.sun
.star
.uno
.Exception e
) {
88 // Some exception occures.FAILED
89 e
.printStackTrace( log
);
90 throw new StatusException( "Couldn't create document", e
);
95 * Text document destroyed.
97 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
98 log
.println( " disposing xTextDoc " );
99 util
.DesktopTools
.closeDoc(xTextDoc
);
103 * Creating a Testenvironment for the interfaces to be tested.
104 * Creates an instance of the service
105 * <code>com.sun.star.comp.Writer.XMLSettingsImporter</code><p>
107 * The text document is set as a target document for importer.
108 * Imported XML-data contains only settings tags including
109 * title tag with test zoom factor.
110 * After import zoom factor getting from target document is checked.
111 * Object relations created :
113 * <li> <code>'XDocumentHandler.XMLData'</code> for
114 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
115 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
116 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
117 * <li> <code>'TargetDocument'</code> for
118 * {@link ifc.document._XImporter} interface </li>
121 public synchronized TestEnvironment createTestEnvironment
122 (TestParameters tParam
, PrintWriter log
) throws StatusException
{
124 XInterface oObj
= null;
126 final short impZoom
= 50 ;
128 // creation of testobject here
129 // first we write what we are intend to do to log file
130 log
.println( "creating a test environment" );
132 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)tParam
.getMSF() ;
135 oInt
= xMSF
.createInstance
136 ("com.sun.star.comp.Writer.XMLSettingsImporter") ;
138 } catch (com
.sun
.star
.uno
.Exception e
) {
139 e
.printStackTrace(log
) ;
140 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", xTextDoc
) ;
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:config", "CDATA", "http://openoffice.org/2001/config",
158 "xmlns:xlink", "CDATA", "http://www.w3.org/1999/xlink",
160 {"start", "office:settings"},
161 {"start", "config:config-item-set",
162 "config:name", "CDATA", "view-settings"
164 {"start", "config:config-item-map-indexed",
165 "config:name", "CDATA", "Views"},
166 {"start", "config:config-item-map-entry"},
167 {"start", "config:config-item",
168 "config:name", "CDATA", "ZoomFactor",
169 "config:type", "CDATA", "short"
171 {"chars", String
.valueOf(impZoom
)},
172 {"end", "config:config-item"},
173 {"start", "config:config-item",
174 "config:name", "CDATA", "ZoomType",
175 "config:type", "CDATA", "short"
178 {"end", "config:config-item"},
179 {"end", "config:config-item-map-entry"},
180 {"end", "config:config-item-map-indexed"},
181 {"end", "config:config-item-set"},
182 {"end", "office:settings"},
183 {"end", "office:document-settings"}} ;
185 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
187 final PrintWriter logF
= log
;
188 XController xController
= xTextDoc
.getCurrentController();
189 XViewSettingsSupplier xViewSetSup
= (XViewSettingsSupplier
)
190 UnoRuntime
.queryInterface(XViewSettingsSupplier
.class, xController
);
191 final XPropertySet xPropSet
= xViewSetSup
.getViewSettings();
192 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
193 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
194 public boolean checkImport() {
196 Short gValue
= (Short
)
197 xPropSet
.getPropertyValue("ZoomValue");
198 logF
.println("ZoomValue property value = " + gValue
) ;
199 return impZoom
== gValue
.shortValue() ;
200 } catch (com
.sun
.star
.uno
.Exception e
) {
201 logF
.println("Exception while checking import :") ;
202 e
.printStackTrace(logF
) ;
209 } // finish method getTestEnvironment