1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLStylesImporter.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
41 import com
.sun
.star
.beans
.XPropertySet
;
42 import com
.sun
.star
.lang
.XMultiServiceFactory
;
43 import com
.sun
.star
.text
.XFootnotesSupplier
;
44 import com
.sun
.star
.text
.XTextDocument
;
45 import com
.sun
.star
.uno
.UnoRuntime
;
46 import com
.sun
.star
.uno
.XInterface
;
49 * Test for object which is represented by service
50 * <code>com.sun.star.comp.Writer.XMLStylesImporter</code>. <p>
51 * Object implements the following interfaces :
53 * <li><code>com::sun::star::lang::XInitialization</code></li>
54 * <li><code>com::sun::star::document::XImporter</code></li>
55 * <li><code>com::sun::star::document::XFilter</code></li>
56 * <li><code>com::sun::star::document::ImportFilter</code></li>
57 * <li><code>com::sun::star::beans::XPropertySet</code></li>
58 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
61 * @see com.sun.star.lang.XInitialization
62 * @see com.sun.star.document.XImporter
63 * @see com.sun.star.document.XFilter
64 * @see com.sun.star.document.ImportFilter
65 * @see com.sun.star.beans.XPropertySet
66 * @see com.sun.star.xml.sax.XDocumentHandler
67 * @see ifc.lang._XInitialization
68 * @see ifc.document._XImporter
69 * @see ifc.document._XFilter
70 * @see ifc.document._XExporter
71 * @see ifc.beans._XPropertySet
72 * @see ifc.xml.sax._XDocumentHandler
74 public class XMLStylesImporter
extends TestCase
{
75 XTextDocument xTextDoc
;
78 * New text document created.
80 protected void initialize( TestParameters tParam
, PrintWriter log
) {
81 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
84 log
.println( "creating a textdocument" );
85 xTextDoc
= SOF
.createTextDoc( null );
86 } catch ( com
.sun
.star
.uno
.Exception e
) {
87 // Some exception occures.FAILED
88 e
.printStackTrace( log
);
89 throw new StatusException( "Couldn't create document", e
);
94 * Text document destroyed.
96 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
97 log
.println( " disposing xTextDoc " );
98 util
.DesktopTools
.closeDoc(xTextDoc
);
102 * Creating a Testenvironment for the interfaces to be tested.
103 * Creates an instance of the service
104 * <code>com.sun.star.comp.Writer.XMLStylesImporter</code><p>
106 * The text document is set as a target document for importer.
107 * Imported XML-data contains only style tags including
108 * title tag with test prefix.
109 * After import prefixes getting from target document is checked.
110 * Object relations created :
112 * <li> <code>'XDocumentHandler.XMLData'</code> for
113 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
114 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
115 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
116 * <li> <code>'TargetDocument'</code> for
117 * {@link ifc.document._XImporter} interface </li>
120 public synchronized TestEnvironment
createTestEnvironment( TestParameters tParam
,
122 throws StatusException
{
124 XInterface oObj
= null;
126 final String impPrefix
= "Prefix" ;
128 // creation of testobject here
129 // first we write what we are intend to do to log file
130 log
.println( "creating a test environment" );
132 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)tParam
.getMSF() ;
135 oInt
= xMSF
.createInstance
136 ("com.sun.star.comp.Writer.XMLStylesImporter") ;
138 } catch (com
.sun
.star
.uno
.Exception e
) {
139 e
.printStackTrace(log
) ;
140 throw new StatusException("Can't create component.", e
) ;
143 oObj
= (XInterface
) oInt
;
145 // create testobject here
146 log
.println( "creating a new environment for Paragraph object" );
147 TestEnvironment tEnv
= new TestEnvironment( oObj
);
150 tEnv
.addObjRelation("TargetDocument", xTextDoc
) ;
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:text", "CDATA", "http://openoffice.org/2000/text"
159 {"start", "office:styles"},
160 {"start", "text:footnotes-configuration",
161 "style:num-prefix", "CDATA", impPrefix
},
162 {"end", "text:footnotes-configuration"},
163 {"end", "office:styles"},
164 {"end", "office:document-styles"}} ;
166 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
168 XFootnotesSupplier supp
= (XFootnotesSupplier
) UnoRuntime
.queryInterface
169 (XFootnotesSupplier
.class, xTextDoc
);
170 final XPropertySet set
= supp
.getFootnoteSettings();
171 final PrintWriter logF
= log
;
173 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
174 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
175 public boolean checkImport() {
177 String prefix
= (String
) set
.getPropertyValue("Prefix");
178 logF
.println("Prefix returned = '" + prefix
+ "'") ;
179 return impPrefix
.equals(prefix
) ;
180 } catch (com
.sun
.star
.uno
.Exception e
) {
181 logF
.println("Exception occured while checking filter :") ;
182 e
.printStackTrace(logF
) ;
189 } // finish method getTestEnvironment