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
.container
.XNameAccess
;
30 import com
.sun
.star
.document
.XImporter
;
31 import com
.sun
.star
.lang
.XComponent
;
32 import com
.sun
.star
.lang
.XMultiServiceFactory
;
33 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
34 import com
.sun
.star
.style
.XStyleFamiliesSupplier
;
35 import com
.sun
.star
.uno
.UnoRuntime
;
36 import com
.sun
.star
.uno
.XInterface
;
39 * Test for object which is represented by service
40 * <code>com.sun.star.comp.Calc.XMLStylesImporter</code>. <p>
41 * Object implements the following interfaces :
43 * <li><code>com::sun::star::lang::XInitialization</code></li>
44 * <li><code>com::sun::star::document::XImporter</code></li>
45 * <li><code>com::sun::star::document::XFilter</code></li>
46 * <li><code>com::sun::star::document::ImportFilter</code></li>
47 * <li><code>com::sun::star::beans::XPropertySet</code></li>
48 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
51 * @see com.sun.star.lang.XInitialization
52 * @see com.sun.star.document.XImporter
53 * @see com.sun.star.document.XFilter
54 * @see com.sun.star.document.ImportFilter
55 * @see com.sun.star.beans.XPropertySet
56 * @see com.sun.star.xml.sax.XDocumentHandler
57 * @see ifc.lang._XInitialization
58 * @see ifc.document._XImporter
59 * @see ifc.document._XFilter
60 * @see ifc.document._XExporter
61 * @see ifc.beans._XPropertySet
62 * @see ifc.xml.sax._XDocumentHandler
64 public class XMLStylesImporter
extends TestCase
{
65 private XSpreadsheetDocument xSheetDoc
;
66 static XComponent comp
;
69 * New spreadsheet document created.
71 protected void initialize( TestParameters tParam
, PrintWriter log
) {
72 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
75 log
.println( "creating a Spreadsheet document" );
76 xSheetDoc
= SOF
.createCalcDoc( null );
77 comp
= UnoRuntime
.queryInterface
78 (XComponent
.class, xSheetDoc
) ;
79 } catch ( com
.sun
.star
.uno
.Exception e
) {
80 // Some exception occurs.FAILED
81 e
.printStackTrace( log
);
82 throw new StatusException( "Couldn't create document", e
);
87 * Spreadsheet document destroyed.
89 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
90 log
.println( " disposing document " );
91 util
.DesktopTools
.closeDoc(comp
);
95 * Creating a Testenvironment for the interfaces to be tested.
96 * Creates an instance of the service
97 * <code>com.sun.star.comp.Calc.XMLStylesImporter</code><p>
99 * The calc document is set as a target document for importer.
100 * Imported XML-data contains only style tags including tag
101 * with new style name.
102 * After import style names getting from
103 * target document is checked.
104 * Object relations created :
106 * <li> <code>'XDocumentHandler.XMLData'</code> for
107 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
108 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
109 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
110 * <li> <code>'TargetDocument'</code> for
111 * {@link ifc.document._XImporter} interface </li>
114 public synchronized TestEnvironment
createTestEnvironment( TestParameters tParam
,
116 throws StatusException
{
118 XInterface oObj
= null;
121 // creation of testobject here
122 // first we write what we are intend to do to log file
123 log
.println( "creating a test environment" );
125 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)tParam
.getMSF() ;
128 oInt
= xMSF
.createInstance
129 ("com.sun.star.comp.Calc.XMLStylesImporter") ;
130 XImporter imp
= UnoRuntime
.queryInterface
131 (XImporter
.class, oInt
) ;
132 imp
.setTargetDocument(comp
) ;
133 } catch (com
.sun
.star
.uno
.Exception e
) {
134 e
.printStackTrace(log
) ;
135 throw new StatusException("Can't create component.", e
) ;
138 oObj
= (XInterface
) oInt
;
140 // create testobject here
141 log
.println( "creating a new environment for Paragraph object" );
142 TestEnvironment tEnv
= new TestEnvironment( oObj
);
145 tEnv
.addObjRelation("TargetDocument", comp
) ;
147 final String impStyleName
= "XMLStylesImporter" ;
149 // adding relation for XDocumentHandler
150 String
[][] xml
= new String
[][] {
151 {"start", "office:document-styles",
152 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
153 "xmlns:style", "CDATA", "http://openoffice.org/2000/style",
154 "xmlns:fo", "CDATA", "http://www.w3.org/1999/XSL/Format",
155 "xmlns:table", "CDATA", "http://openoffice.org/2000/table"},
156 {"start", "office:styles"},
157 {"start", "style:style",
158 "style:name", "CDATA", impStyleName
,
159 "style:family", "CDATA", "table-cell",
160 "style:parent-style-name", "CDATA", "Default"},
161 { "start", "style:properties",
162 "fo:width", "CDATA", "12cm",
163 "fo:background-color", "CDATA", "light-grey"},
164 {"end", "style:properties"},
165 {"end", "style:style"},
166 {"end", "office:styles"},
167 {"end", "office:document-styles"}} ;
169 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
171 XNameAccess styles
= null ;
173 XStyleFamiliesSupplier sup
= UnoRuntime
.queryInterface
174 (XStyleFamiliesSupplier
.class, xSheetDoc
);
175 XNameAccess oStyleFamilies
= sup
.getStyleFamilies();
176 Object family
= oStyleFamilies
.getByName("CellStyles") ;
177 styles
= UnoRuntime
.queryInterface
178 (XNameAccess
.class, family
) ;
179 log
.println("Styles before:") ;
180 String
[] names
= styles
.getElementNames() ;
181 for (int i
= 0; i
< names
.length
; i
++) {
182 log
.println(" " + names
[i
]) ;
184 } catch (com
.sun
.star
.uno
.Exception e
) {
185 e
.printStackTrace(log
) ;
187 final XNameAccess stylesF
= styles
;
188 final PrintWriter logF
= log
;
190 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
191 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
192 public boolean checkImport() {
193 logF
.println("Styles after:") ;
194 String
[] names
= stylesF
.getElementNames() ;
195 for (int i
= 0; i
< names
.length
; i
++) {
196 logF
.println(" " + names
[i
]) ;
198 return stylesF
.hasByName(impStyleName
) ;