bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / XMLStylesExporter.java
blob7fb992152743aaf1725fbcfb8305546fec4a8514
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;
28 import util.XMLTools;
30 import com.sun.star.beans.XPropertySet;
31 import com.sun.star.document.XExporter;
32 import com.sun.star.lang.XMultiServiceFactory;
33 import com.sun.star.text.XFootnotesSupplier;
34 import com.sun.star.text.XTextDocument;
35 import com.sun.star.uno.Any;
36 import com.sun.star.uno.Type;
37 import com.sun.star.uno.UnoRuntime;
38 import com.sun.star.uno.XInterface;
39 import com.sun.star.xml.sax.XDocumentHandler;
41 /**
42 * Test for object which is represented by service
43 * <code>com.sun.star.comp.Calc.XMLStylesExporter</code>. <p>
44 * Object implements the following interfaces :
45 * <ul>
46 * <li><code>com::sun::star::lang::XInitialization</code></li>
47 * <li><code>com::sun::star::document::ExportFilter</code></li>
48 * <li><code>com::sun::star::document::XFilter</code></li>
49 * <li><code>com::sun::star::document::XExporter</code></li>
50 * <li><code>com::sun::star::beans::XPropertySet</code></li>
51 * </ul>
52 * @see com.sun.star.lang.XInitialization
53 * @see com.sun.star.document.ExportFilter
54 * @see com.sun.star.document.XFilter
55 * @see com.sun.star.document.XExporter
56 * @see com.sun.star.beans.XPropertySet
57 * @see ifc.lang._XInitialization
58 * @see ifc.document._ExportFilter
59 * @see ifc.document._XFilter
60 * @see ifc.document._XExporter
61 * @see ifc.beans._XPropertySet
63 public class XMLStylesExporter extends TestCase {
65 XTextDocument xTextDoc;
67 /**
68 * New text document created.
70 @Override
71 protected void initialize( TestParameters tParam, PrintWriter log ) {
72 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
74 try {
75 log.println( "creating a textdocument" );
76 xTextDoc = SOF.createTextDoc( null );
77 } catch ( com.sun.star.uno.Exception e ) {
78 // Some exception occurs.FAILED
79 e.printStackTrace( log );
80 throw new StatusException( "Couldn't create document", e );
84 /**
85 * Document disposed here.
87 @Override
88 protected void cleanup( TestParameters tParam, PrintWriter log ) {
89 log.println( " disposing xTextDoc " );
90 util.DesktopTools.closeDoc(xTextDoc);
93 /**
94 * Creating a Testenvironment for the interfaces to be tested.
95 * Creates an instance of the service
96 * <code>com.sun.star.comp.Calc.XMLStylesExporter</code> with
97 * argument which is an implementation of <code>XDocumentHandler</code>
98 * and which can check if required tags and character data is
99 * exported. <p>
100 * The text document is set as a source document for exporter
101 * created. Footnote property 'Prefix' is set to a new value. This made
102 * for checking if this property value is successfully exported within
103 * the document styles.
104 * Object relations created :
105 * <ul>
106 * <li> <code>'MediaDescriptor'</code> for
107 * {@link ifc.document._XFilter} interface </li>
108 * <li> <code>'XFilter.Checker'</code> for
109 * {@link ifc.document._XFilter} interface </li>
110 * <li> <code>'SourceDocument'</code> for
111 * {@link ifc.document._XExporter} interface </li>
112 * </ul>
114 @Override
115 public synchronized TestEnvironment createTestEnvironment
116 ( TestParameters tParam, PrintWriter log ) {
118 XMultiServiceFactory xMSF = tParam.getMSF() ;
119 XInterface oObj = null;
120 FilterChecker filter = new FilterChecker(log) ;
121 Any arg = new Any(new Type(XDocumentHandler.class),filter);
123 try {
124 oObj = (XInterface) xMSF.createInstanceWithArguments(
125 "com.sun.star.comp.Writer.XMLStylesExporter",
126 new Object[] {arg});
127 XExporter xEx = UnoRuntime.queryInterface
128 (XExporter.class,oObj);
129 xEx.setSourceDocument(xTextDoc);
130 } catch (com.sun.star.uno.Exception e) {
131 e.printStackTrace(log) ;
132 throw new StatusException("Can't create component.", e) ;
135 // Cheching Head Tag existence and that property has changed
136 filter.addTag(new XMLTools.Tag ("office:document-styles"));
137 filter.addTag(new XMLTools.Tag ("text:footnotes-configuration",
138 "style:num-prefix","New Property")) ;
140 // create testobject here
141 log.println( "creating a new environment" );
142 TestEnvironment tEnv = new TestEnvironment( oObj );
144 // Obtain Footnotes properties
145 XFootnotesSupplier supp = UnoRuntime.queryInterface
146 (XFootnotesSupplier.class, xTextDoc);
147 XPropertySet set = supp.getFootnoteSettings();
149 // Change property "Prefix"
150 try {
151 set.setPropertyValue("Prefix","New Property");
152 } catch (com.sun.star.uno.Exception e) {
153 e.printStackTrace( log );
154 throw new StatusException( "Couldn't change property value", e );
157 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
158 new String[] {"FilterName"},
159 new Object[] {"swriter: StarOffice XML (Writer)"}));
160 tEnv.addObjRelation("SourceDocument",xTextDoc);
161 tEnv.addObjRelation("XFilter.Checker", filter) ;
162 return tEnv;
167 * This class checks the XML for tags and data required and returns
168 * checking result to <code>XFilter</code> interface test. All
169 * the information about errors occurred in XML data is written
170 * to log specified.
171 * @see ifc.document._XFilter
173 private class FilterChecker extends XMLTools.XMLChecker
174 implements ifc.document._XFilter.FilterChecker {
177 * Creates a class which will write information
178 * into log specified.
180 private FilterChecker(PrintWriter log) {
181 super(log,false) ;
185 * <code>_XFilter.FilterChecker</code> interface method
186 * which returns the result of XML checking.
187 * @return <code>true</code> if the XML data exported was
188 * valid (i.e. all necessary tags and character data exists),
189 * <code>false</code> if some errors occurred.
191 public boolean checkFilter() {
192 return check();