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 .
19 package mod
._xmloff
.Impress
;
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
.container
.XNameAccess
;
30 import com
.sun
.star
.lang
.XComponent
;
31 import com
.sun
.star
.lang
.XMultiServiceFactory
;
32 import com
.sun
.star
.style
.XStyleFamiliesSupplier
;
33 import com
.sun
.star
.uno
.UnoRuntime
;
34 import com
.sun
.star
.uno
.XInterface
;
37 * Test for object which is represented by service
38 * <code>com.sun.star.comp.Impress.XMLStylesImporter</code>. <p>
39 * Object implements the following interfaces :
41 * <li><code>com::sun::star::lang::XInitialization</code></li>
42 * <li><code>com::sun::star::document::XImporter</code></li>
43 * <li><code>com::sun::star::document::XFilter</code></li>
44 * <li><code>com::sun::star::document::ImportFilter</code></li>
45 * <li><code>com::sun::star::beans::XPropertySet</code></li>
46 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
49 * @see com.sun.star.lang.XInitialization
50 * @see com.sun.star.document.XImporter
51 * @see com.sun.star.document.XFilter
52 * @see com.sun.star.document.ImportFilter
53 * @see com.sun.star.beans.XPropertySet
54 * @see com.sun.star.xml.sax.XDocumentHandler
55 * @see ifc.lang._XInitialization
56 * @see ifc.document._XImporter
57 * @see ifc.document._XFilter
58 * @see ifc.document._XExporter
59 * @see ifc.beans._XPropertySet
60 * @see ifc.xml.sax._XDocumentHandler
62 public class XMLStylesImporter
extends TestCase
{
63 XComponent xImpressDoc
= null;
66 * New spreadsheet document created.
69 protected void initialize( TestParameters tParam
, PrintWriter log
) {
71 // get a soffice factory object
72 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF());
75 log
.println( "creating an impress document" );
76 xImpressDoc
= SOF
.createImpressDoc(null);
77 } catch ( Exception e
) {
78 // Some exception occurs.FAILED
79 e
.printStackTrace( log
);
80 throw new StatusException( "Couldn't create document", e
);
85 * Spreadsheet document destroyed.
88 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
89 log
.println( " disposing document " );
90 xImpressDoc
.dispose();
94 * Creating a Testenvironment for the interfaces to be tested.
95 * Creates an instance of the service
96 * <code>com.sun.star.comp.Impress.XMLStylesImporter</code><p>
98 * The Impress document is set as a target document for importer.
99 * Imported XML-data contains only style tags including tag
100 * with new style name.
101 * After import style names getting from target document is checked.
102 * Object relations created :
104 * <li> <code>'XDocumentHandler.XMLData'</code> for
105 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
106 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
107 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
108 * <li> <code>'TargetDocument'</code> for
109 * {@link ifc.document._XImporter} interface </li>
113 public synchronized TestEnvironment createTestEnvironment
114 (TestParameters tParam
, PrintWriter log
) throws StatusException
{
116 XInterface oObj
= null;
118 final String impValue
= "XMLImporter_test" ;
120 // creation of testobject here
121 // first we write what we are intend to do to log file
122 log
.println( "creating a test environment" );
124 XMultiServiceFactory xMSF
= tParam
.getMSF() ;
127 oInt
= xMSF
.createInstance
128 ("com.sun.star.comp.Impress.XMLStylesImporter") ;
130 } catch (com
.sun
.star
.uno
.Exception e
) {
131 e
.printStackTrace(log
) ;
132 throw new StatusException("Can't create component.", e
) ;
135 oObj
= (XInterface
) oInt
;
137 // create testobject here
138 log
.println( "creating a new environment for Paragraph object" );
139 TestEnvironment tEnv
= new TestEnvironment( oObj
);
142 tEnv
.addObjRelation("TargetDocument", xImpressDoc
) ;
144 String
[][] xml
= new String
[][] {
145 {"start", "office:document-styles",
146 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
147 "xmlns:style", "CDATA", "http://openoffice.org/2000/style",
148 "xmlns:fo", "CDATA", "http://www.w3.org/1999/XSL/Format",
149 "xmlns:table", "CDATA", "http://openoffice.org/2000/table"},
150 {"start", "office:styles"},
151 {"start", "style:style",
152 "style:name", "CDATA", impValue
,
153 "style:family", "CDATA", "graphics",
154 "style:parent-style-name", "CDATA", "standard"},
155 {"end", "style:style"},
156 {"end", "office:styles"},
157 {"end", "office:document-styles"}} ;
159 // adding relation for XDocumentHandler
160 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
161 XNameAccess styles
= null ;
163 XStyleFamiliesSupplier sup
= UnoRuntime
.queryInterface(XStyleFamiliesSupplier
.class,
165 XNameAccess oStyleFamilies
= sup
.getStyleFamilies();
166 Object family
= oStyleFamilies
.getByName("graphics") ;
167 styles
= UnoRuntime
.queryInterface
168 (XNameAccess
.class, family
) ;
169 log
.println("Styles before:") ;
170 String
[] names
= styles
.getElementNames() ;
171 for (int i
= 0; i
< names
.length
; i
++) {
172 log
.println(" " + names
[i
]) ;
174 } catch (com
.sun
.star
.uno
.Exception e
) {
175 e
.printStackTrace(log
) ;
177 final XNameAccess stylesF
= styles
;
178 final PrintWriter logF
= log
;
179 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
180 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
181 public boolean checkImport() {
182 logF
.println("Styles after:") ;
183 String
[] names
= stylesF
.getElementNames() ;
184 for (int i
= 0; i
< names
.length
; i
++) {
185 logF
.println(" " + names
[i
]) ;
187 return stylesF
.hasByName(impValue
) ;
192 } // end of getTestEnvironment