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.
72 protected void initialize( TestParameters tParam
, PrintWriter log
) {
73 SOfficeFactory SOF
= SOfficeFactory
.getFactory( 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.
91 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
92 log
.println( " disposing document " );
93 util
.DesktopTools
.closeDoc(comp
);
97 * Creating a Testenvironment for the interfaces to be tested.
98 * Creates an instance of the service
99 * <code>com.sun.star.comp.Calc.XMLStylesImporter</code><p>
101 * The calc document is set as a target document for importer.
102 * Imported XML-data contains only style tags including tag
103 * with new style name.
104 * After import style names getting from
105 * target document is checked.
106 * Object relations created :
108 * <li> <code>'XDocumentHandler.XMLData'</code> for
109 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
110 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
111 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
112 * <li> <code>'TargetDocument'</code> for
113 * {@link ifc.document._XImporter} interface </li>
117 public synchronized TestEnvironment
createTestEnvironment( TestParameters tParam
,
119 throws StatusException
{
121 XInterface oObj
= null;
124 // creation of testobject here
125 // first we write what we are intend to do to log file
126 log
.println( "creating a test environment" );
128 XMultiServiceFactory xMSF
= tParam
.getMSF() ;
131 oInt
= xMSF
.createInstance
132 ("com.sun.star.comp.Calc.XMLStylesImporter") ;
133 XImporter imp
= UnoRuntime
.queryInterface
134 (XImporter
.class, oInt
) ;
135 imp
.setTargetDocument(comp
) ;
136 } catch (com
.sun
.star
.uno
.Exception e
) {
137 e
.printStackTrace(log
) ;
138 throw new StatusException("Can't create component.", e
) ;
141 oObj
= (XInterface
) oInt
;
143 // create testobject here
144 log
.println( "creating a new environment for Paragraph object" );
145 TestEnvironment tEnv
= new TestEnvironment( oObj
);
148 tEnv
.addObjRelation("TargetDocument", comp
) ;
150 final String impStyleName
= "XMLStylesImporter" ;
152 // adding relation for XDocumentHandler
153 String
[][] xml
= new String
[][] {
154 {"start", "office:document-styles",
155 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
156 "xmlns:style", "CDATA", "http://openoffice.org/2000/style",
157 "xmlns:fo", "CDATA", "http://www.w3.org/1999/XSL/Format",
158 "xmlns:table", "CDATA", "http://openoffice.org/2000/table"},
159 {"start", "office:styles"},
160 {"start", "style:style",
161 "style:name", "CDATA", impStyleName
,
162 "style:family", "CDATA", "table-cell",
163 "style:parent-style-name", "CDATA", "Default"},
164 { "start", "style:properties",
165 "fo:width", "CDATA", "12cm",
166 "fo:background-color", "CDATA", "light-grey"},
167 {"end", "style:properties"},
168 {"end", "style:style"},
169 {"end", "office:styles"},
170 {"end", "office:document-styles"}} ;
172 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
174 XNameAccess styles
= null ;
176 XStyleFamiliesSupplier sup
= UnoRuntime
.queryInterface
177 (XStyleFamiliesSupplier
.class, xSheetDoc
);
178 XNameAccess oStyleFamilies
= sup
.getStyleFamilies();
179 Object family
= oStyleFamilies
.getByName("CellStyles") ;
180 styles
= UnoRuntime
.queryInterface
181 (XNameAccess
.class, family
) ;
182 log
.println("Styles before:") ;
183 String
[] names
= styles
.getElementNames() ;
184 for (int i
= 0; i
< names
.length
; i
++) {
185 log
.println(" " + names
[i
]) ;
187 } catch (com
.sun
.star
.uno
.Exception e
) {
188 e
.printStackTrace(log
) ;
190 final XNameAccess stylesF
= styles
;
191 final PrintWriter logF
= log
;
193 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
194 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
195 public boolean checkImport() {
196 logF
.println("Styles after:") ;
197 String
[] names
= stylesF
.getElementNames() ;
198 for (int i
= 0; i
< names
.length
; i
++) {
199 logF
.println(" " + names
[i
]) ;
201 return stylesF
.hasByName(impStyleName
) ;