merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sw / XMLStylesImporter.java
blobffd0b3a54121c89b8d3b1411310a65ccc2b8258c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLStylesImporter.java,v $
10 * $Revision: 1.7 $
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 ************************************************************************/
31 package mod._sw;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
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;
48 /**
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 :
52 * <ul>
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>
60 * </ul>
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;
77 /**
78 * New text document created.
80 protected void initialize( TestParameters tParam, PrintWriter log ) {
81 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
83 try {
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 );
93 /**
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 :
111 * <ul>
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>
118 * </ul>
120 public synchronized TestEnvironment createTestEnvironment( TestParameters tParam,
121 PrintWriter log )
122 throws StatusException {
124 XInterface oObj = null;
125 Object oInt = 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() ;
134 try {
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 );
149 // adding relation
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() {
176 try {
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) ;
183 return false ;
186 }) ;
188 return tEnv;
189 } // finish method getTestEnvironment