bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / XMLStylesImporter.java
blobbf3daa24f6048a1d56960b561ae8c5f6e0dc0f39
1 /*
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 .
19 package mod._sw;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.SOfficeFactory;
29 import com.sun.star.beans.XPropertySet;
30 import com.sun.star.lang.XMultiServiceFactory;
31 import com.sun.star.text.XFootnotesSupplier;
32 import com.sun.star.text.XTextDocument;
33 import com.sun.star.uno.UnoRuntime;
34 import com.sun.star.uno.XInterface;
36 /**
37 * Test for object which is represented by service
38 * <code>com.sun.star.comp.Writer.XMLStylesImporter</code>. <p>
39 * Object implements the following interfaces :
40 * <ul>
41 * <li><code>com::sun::star::lang::XInitialization</code></li>
42 * <li><code>com::sun::star::document::XImporter</code></li>
43 * <li><code>com::sun::star::document::XFilter</code></li>
44 * <li><code>com::sun::star::document::ImportFilter</code></li>
45 * <li><code>com::sun::star::beans::XPropertySet</code></li>
46 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
48 * </ul>
49 * @see com.sun.star.lang.XInitialization
50 * @see com.sun.star.document.XImporter
51 * @see com.sun.star.document.XFilter
52 * @see com.sun.star.document.ImportFilter
53 * @see com.sun.star.beans.XPropertySet
54 * @see com.sun.star.xml.sax.XDocumentHandler
55 * @see ifc.lang._XInitialization
56 * @see ifc.document._XImporter
57 * @see ifc.document._XFilter
58 * @see ifc.document._XExporter
59 * @see ifc.beans._XPropertySet
60 * @see ifc.xml.sax._XDocumentHandler
62 public class XMLStylesImporter extends TestCase {
63 XTextDocument xTextDoc;
65 /**
66 * New text document created.
68 protected void initialize( TestParameters tParam, PrintWriter log ) {
69 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
71 try {
72 log.println( "creating a textdocument" );
73 xTextDoc = SOF.createTextDoc( null );
74 } catch ( com.sun.star.uno.Exception e ) {
75 // Some exception occurs.FAILED
76 e.printStackTrace( log );
77 throw new StatusException( "Couldn't create document", e );
81 /**
82 * Text document destroyed.
84 protected void cleanup( TestParameters tParam, PrintWriter log ) {
85 log.println( " disposing xTextDoc " );
86 util.DesktopTools.closeDoc(xTextDoc);
89 /**
90 * Creating a Testenvironment for the interfaces to be tested.
91 * Creates an instance of the service
92 * <code>com.sun.star.comp.Writer.XMLStylesImporter</code><p>
94 * The text document is set as a target document for importer.
95 * Imported XML-data contains only style tags including
96 * title tag with test prefix.
97 * After import prefixes getting from target document is checked.
98 * Object relations created :
99 * <ul>
100 * <li> <code>'XDocumentHandler.XMLData'</code> for
101 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
102 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
103 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
104 * <li> <code>'TargetDocument'</code> for
105 * {@link ifc.document._XImporter} interface </li>
106 * </ul>
108 public synchronized TestEnvironment createTestEnvironment( TestParameters tParam,
109 PrintWriter log )
110 throws StatusException {
112 XInterface oObj = null;
113 Object oInt = null ;
114 final String impPrefix = "Prefix" ;
116 // creation of testobject here
117 // first we write what we are intend to do to log file
118 log.println( "creating a test environment" );
120 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ;
122 try {
123 oInt = xMSF.createInstance
124 ("com.sun.star.comp.Writer.XMLStylesImporter") ;
126 } catch (com.sun.star.uno.Exception e) {
127 e.printStackTrace(log) ;
128 throw new StatusException("Can't create component.", e) ;
131 oObj = (XInterface) oInt ;
133 // create testobject here
134 log.println( "creating a new environment for Paragraph object" );
135 TestEnvironment tEnv = new TestEnvironment( oObj );
137 // adding relation
138 tEnv.addObjRelation("TargetDocument", xTextDoc) ;
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:text", "CDATA", "http://openoffice.org/2000/text"
147 {"start", "office:styles"},
148 {"start", "text:footnotes-configuration",
149 "style:num-prefix", "CDATA", impPrefix},
150 {"end", "text:footnotes-configuration"},
151 {"end", "office:styles"},
152 {"end", "office:document-styles"}} ;
154 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
156 XFootnotesSupplier supp = UnoRuntime.queryInterface
157 (XFootnotesSupplier.class, xTextDoc);
158 final XPropertySet set = supp.getFootnoteSettings();
159 final PrintWriter logF = log ;
161 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
162 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
163 public boolean checkImport() {
164 try {
165 String prefix = (String) set.getPropertyValue("Prefix");
166 logF.println("Prefix returned = '" + prefix + "'") ;
167 return impPrefix.equals(prefix) ;
168 } catch (com.sun.star.uno.Exception e) {
169 logF.println("Exception occurred while checking filter :") ;
170 e.printStackTrace(logF) ;
171 return false ;
174 }) ;
176 return tEnv;
177 } // finish method getTestEnvironment