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
.beans
.XPropertySet
;
29 import com
.sun
.star
.lang
.XMultiServiceFactory
;
30 import com
.sun
.star
.text
.XFootnotesSupplier
;
31 import com
.sun
.star
.text
.XTextDocument
;
32 import com
.sun
.star
.uno
.UnoRuntime
;
33 import com
.sun
.star
.uno
.XInterface
;
36 * Test for object which is represented by service
37 * <code>com.sun.star.comp.Writer.XMLStylesImporter</code>. <p>
38 * Object implements the following interfaces :
40 * <li><code>com::sun::star::lang::XInitialization</code></li>
41 * <li><code>com::sun::star::document::XImporter</code></li>
42 * <li><code>com::sun::star::document::XFilter</code></li>
43 * <li><code>com::sun::star::document::ImportFilter</code></li>
44 * <li><code>com::sun::star::beans::XPropertySet</code></li>
45 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
48 * @see com.sun.star.lang.XInitialization
49 * @see com.sun.star.document.XImporter
50 * @see com.sun.star.document.XFilter
51 * @see com.sun.star.document.ImportFilter
52 * @see com.sun.star.beans.XPropertySet
53 * @see com.sun.star.xml.sax.XDocumentHandler
54 * @see ifc.lang._XInitialization
55 * @see ifc.document._XImporter
56 * @see ifc.document._XFilter
57 * @see ifc.document._XExporter
58 * @see ifc.beans._XPropertySet
59 * @see ifc.xml.sax._XDocumentHandler
61 public class XMLStylesImporter
extends TestCase
{
62 XTextDocument xTextDoc
;
65 * New text document created.
68 protected void initialize( TestParameters tParam
, PrintWriter log
) throws Exception
{
69 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
71 log
.println( "creating a textdocument" );
72 xTextDoc
= SOF
.createTextDoc( null );
76 * Text document destroyed.
79 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
80 log
.println( " disposing xTextDoc " );
81 util
.DesktopTools
.closeDoc(xTextDoc
);
85 * Creating a TestEnvironment for the interfaces to be tested.
86 * Creates an instance of the service
87 * <code>com.sun.star.comp.Writer.XMLStylesImporter</code><p>
89 * The text document is set as a target document for importer.
90 * Imported XML-data contains only style tags including
91 * title tag with test prefix.
92 * After import prefixes getting from target document is checked.
93 * Object relations created :
95 * <li> <code>'XDocumentHandler.XMLData'</code> for
96 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
97 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
98 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
99 * <li> <code>'TargetDocument'</code> for
100 * {@link ifc.document._XImporter} interface </li>
104 public TestEnvironment
createTestEnvironment( TestParameters tParam
,
108 XInterface oObj
= null;
110 final String impPrefix
= "Prefix" ;
112 // creation of testobject here
113 // first we write what we are intend to do to log file
114 log
.println( "creating a test environment" );
116 XMultiServiceFactory xMSF
= tParam
.getMSF() ;
118 oInt
= xMSF
.createInstance
119 ("com.sun.star.comp.Writer.XMLStylesImporter") ;
121 oObj
= (XInterface
) oInt
;
123 // create testobject here
124 log
.println( "creating a new environment for Paragraph object" );
125 TestEnvironment tEnv
= new TestEnvironment( oObj
);
128 tEnv
.addObjRelation("TargetDocument", xTextDoc
) ;
130 // adding relation for XDocumentHandler
131 String
[][] xml
= new String
[][] {
132 {"start", "office:document-styles",
133 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
134 "xmlns:style", "CDATA", "http://openoffice.org/2000/style",
135 "xmlns:text", "CDATA", "http://openoffice.org/2000/text"
137 {"start", "office:styles"},
138 {"start", "text:footnotes-configuration",
139 "style:num-prefix", "CDATA", impPrefix
},
140 {"end", "text:footnotes-configuration"},
141 {"end", "office:styles"},
142 {"end", "office:document-styles"}} ;
144 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
146 XFootnotesSupplier supp
= UnoRuntime
.queryInterface
147 (XFootnotesSupplier
.class, xTextDoc
);
148 final XPropertySet set
= supp
.getFootnoteSettings();
149 final PrintWriter logF
= log
;
151 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
152 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
153 public boolean checkImport() {
155 String prefix
= (String
) set
.getPropertyValue("Prefix");
156 logF
.println("Prefix returned = '" + prefix
+ "'") ;
157 return impPrefix
.equals(prefix
) ;
158 } catch (com
.sun
.star
.uno
.Exception e
) {
159 logF
.println("Exception occurred while checking filter :") ;
160 e
.printStackTrace(logF
) ;
167 } // finish method getTestEnvironment