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
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.SOfficeFactory
;
28 import com
.sun
.star
.container
.XNameAccess
;
29 import com
.sun
.star
.document
.XImporter
;
30 import com
.sun
.star
.lang
.XComponent
;
31 import com
.sun
.star
.lang
.XMultiServiceFactory
;
32 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
33 import com
.sun
.star
.style
.XStyleFamiliesSupplier
;
34 import com
.sun
.star
.uno
.UnoRuntime
;
35 import com
.sun
.star
.uno
.XInterface
;
38 * Test for object which is represented by service
39 * <code>com.sun.star.comp.Calc.XMLStylesImporter</code>. <p>
40 * Object implements the following interfaces :
42 * <li><code>com::sun::star::lang::XInitialization</code></li>
43 * <li><code>com::sun::star::document::XImporter</code></li>
44 * <li><code>com::sun::star::document::XFilter</code></li>
45 * <li><code>com::sun::star::document::ImportFilter</code></li>
46 * <li><code>com::sun::star::beans::XPropertySet</code></li>
47 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
50 * @see com.sun.star.lang.XInitialization
51 * @see com.sun.star.document.XImporter
52 * @see com.sun.star.document.XFilter
53 * @see com.sun.star.document.ImportFilter
54 * @see com.sun.star.beans.XPropertySet
55 * @see com.sun.star.xml.sax.XDocumentHandler
56 * @see ifc.lang._XInitialization
57 * @see ifc.document._XImporter
58 * @see ifc.document._XFilter
59 * @see ifc.document._XExporter
60 * @see ifc.beans._XPropertySet
61 * @see ifc.xml.sax._XDocumentHandler
63 public class XMLStylesImporter
extends TestCase
{
64 private XSpreadsheetDocument xSheetDoc
;
65 static XComponent comp
;
68 * New spreadsheet document created.
71 protected void initialize( TestParameters tParam
, PrintWriter log
) throws Exception
{
72 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
74 log
.println( "creating a Spreadsheet document" );
75 xSheetDoc
= SOF
.createCalcDoc( null );
76 comp
= UnoRuntime
.queryInterface
77 (XComponent
.class, xSheetDoc
) ;
81 * Spreadsheet document destroyed.
84 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
85 log
.println( " disposing document " );
86 util
.DesktopTools
.closeDoc(comp
);
90 * Creating a TestEnvironment for the interfaces to be tested.
91 * Creates an instance of the service
92 * <code>com.sun.star.comp.Calc.XMLStylesImporter</code><p>
94 * The calc document is set as a target document for importer.
95 * Imported XML-data contains only style tags including tag
96 * with new style name.
97 * After import style names getting from
98 * target document is checked.
99 * Object relations created :
101 * <li> <code>'XDocumentHandler.XMLData'</code> for
102 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
103 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
104 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
105 * <li> <code>'TargetDocument'</code> for
106 * {@link ifc.document._XImporter} interface </li>
110 public TestEnvironment
createTestEnvironment( TestParameters tParam
,
114 XInterface oObj
= null;
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
= tParam
.getMSF() ;
123 oInt
= xMSF
.createInstance
124 ("com.sun.star.comp.Calc.XMLStylesImporter") ;
125 XImporter imp
= UnoRuntime
.queryInterface
126 (XImporter
.class, oInt
) ;
127 imp
.setTargetDocument(comp
) ;
129 oObj
= (XInterface
) oInt
;
131 // create testobject here
132 log
.println( "creating a new environment for Paragraph object" );
133 TestEnvironment tEnv
= new TestEnvironment( oObj
);
136 tEnv
.addObjRelation("TargetDocument", comp
) ;
138 final String impStyleName
= "XMLStylesImporter" ;
140 // adding relation for XDocumentHandler
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", impStyleName
,
150 "style:family", "CDATA", "table-cell",
151 "style:parent-style-name", "CDATA", "Default"},
152 { "start", "style:properties",
153 "fo:width", "CDATA", "12cm",
154 "fo:background-color", "CDATA", "light-grey"},
155 {"end", "style:properties"},
156 {"end", "style:style"},
157 {"end", "office:styles"},
158 {"end", "office:document-styles"}} ;
160 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
162 XNameAccess styles
= null ;
164 XStyleFamiliesSupplier sup
= UnoRuntime
.queryInterface
165 (XStyleFamiliesSupplier
.class, xSheetDoc
);
166 XNameAccess oStyleFamilies
= sup
.getStyleFamilies();
167 Object family
= oStyleFamilies
.getByName("CellStyles") ;
168 styles
= UnoRuntime
.queryInterface
169 (XNameAccess
.class, family
) ;
170 log
.println("Styles before:") ;
171 String
[] names
= styles
.getElementNames() ;
172 for (int i
= 0; i
< names
.length
; i
++) {
173 log
.println(" " + names
[i
]) ;
175 } catch (com
.sun
.star
.uno
.Exception e
) {
176 e
.printStackTrace(log
) ;
178 final XNameAccess stylesF
= styles
;
179 final PrintWriter logF
= log
;
181 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
182 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
183 public boolean checkImport() {
184 logF
.println("Styles after:") ;
185 String
[] names
= stylesF
.getElementNames() ;
186 for (int i
= 0; i
< names
.length
; i
++) {
187 logF
.println(" " + names
[i
]) ;
189 return stylesF
.hasByName(impStyleName
) ;