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.
68 protected void initialize( TestParameters tParam
, PrintWriter log
) {
70 // get a soffice factory object
71 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF());
74 log
.println( "creating an impress document" );
75 xImpressDoc
= SOF
.createImpressDoc(null);
76 } catch ( Exception e
) {
77 // Some exception occurs.FAILED
78 e
.printStackTrace( log
);
79 throw new StatusException( "Couldn't create document", e
);
84 * Spreadsheet document destroyed.
86 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
87 log
.println( " disposing document " );
88 xImpressDoc
.dispose();
92 * Creating a Testenvironment for the interfaces to be tested.
93 * Creates an instance of the service
94 * <code>com.sun.star.comp.Impress.XMLStylesImporter</code><p>
96 * The Impress document is set as a target document for importer.
97 * Imported XML-data contains only style tags including tag
98 * with new style name.
99 * After import style names getting from target document is checked.
100 * Object relations created :
102 * <li> <code>'XDocumentHandler.XMLData'</code> for
103 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
104 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
105 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
106 * <li> <code>'TargetDocument'</code> for
107 * {@link ifc.document._XImporter} interface </li>
110 public synchronized TestEnvironment createTestEnvironment
111 (TestParameters tParam
, PrintWriter log
) throws StatusException
{
113 XInterface oObj
= null;
115 final String impValue
= "XMLImporter_test" ;
117 // creation of testobject here
118 // first we write what we are intend to do to log file
119 log
.println( "creating a test environment" );
121 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)tParam
.getMSF() ;
124 oInt
= xMSF
.createInstance
125 ("com.sun.star.comp.Impress.XMLStylesImporter") ;
127 } catch (com
.sun
.star
.uno
.Exception e
) {
128 e
.printStackTrace(log
) ;
129 throw new StatusException("Can't create component.", e
) ;
132 oObj
= (XInterface
) oInt
;
134 // create testobject here
135 log
.println( "creating a new environment for Paragraph object" );
136 TestEnvironment tEnv
= new TestEnvironment( oObj
);
139 tEnv
.addObjRelation("TargetDocument", xImpressDoc
) ;
141 String
[][] xml
= new String
[][] {
142 {"start", "office:document-styles",
143 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
144 "xmlns:style", "CDATA", "http://openoffice.org/2000/style",
145 "xmlns:fo", "CDATA", "http://www.w3.org/1999/XSL/Format",
146 "xmlns:table", "CDATA", "http://openoffice.org/2000/table"},
147 {"start", "office:styles"},
148 {"start", "style:style",
149 "style:name", "CDATA", impValue
,
150 "style:family", "CDATA", "graphics",
151 "style:parent-style-name", "CDATA", "standard"},
152 {"end", "style:style"},
153 {"end", "office:styles"},
154 {"end", "office:document-styles"}} ;
156 // adding relation for XDocumentHandler
157 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
158 XNameAccess styles
= null ;
160 XStyleFamiliesSupplier sup
= UnoRuntime
.queryInterface(XStyleFamiliesSupplier
.class,
162 XNameAccess oStyleFamilies
= sup
.getStyleFamilies();
163 Object family
= oStyleFamilies
.getByName("graphics") ;
164 styles
= UnoRuntime
.queryInterface
165 (XNameAccess
.class, family
) ;
166 log
.println("Styles before:") ;
167 String
[] names
= styles
.getElementNames() ;
168 for (int i
= 0; i
< names
.length
; i
++) {
169 log
.println(" " + names
[i
]) ;
171 } catch (com
.sun
.star
.uno
.Exception e
) {
172 e
.printStackTrace(log
) ;
174 final XNameAccess stylesF
= styles
;
175 final PrintWriter logF
= log
;
176 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
177 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
178 public boolean checkImport() {
179 logF
.println("Styles after:") ;
180 String
[] names
= stylesF
.getElementNames() ;
181 for (int i
= 0; i
< names
.length
; i
++) {
182 logF
.println(" " + names
[i
]) ;
184 return stylesF
.hasByName(impValue
) ;
189 } // end of getTestEnvironment