merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _xmloff / Chart / XMLExporter.java
blobc439355e2152863d7e408d7746070c3f987c48e8
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: XMLExporter.java,v $
10 * $Revision: 1.6 $
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._xmloff.Chart;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.DesktopTools;
40 import util.SOfficeFactory;
41 import util.XMLTools;
43 import com.sun.star.beans.XPropertySet;
44 import com.sun.star.chart.XChartDocument;
45 import com.sun.star.document.XExporter;
46 import com.sun.star.lang.XMultiServiceFactory;
47 import com.sun.star.uno.Any;
48 import com.sun.star.uno.Exception;
49 import com.sun.star.uno.Type;
50 import com.sun.star.uno.UnoRuntime;
51 import com.sun.star.uno.XInterface;
52 import com.sun.star.xml.sax.XDocumentHandler;
54 /**
55 * Test for object which is represented by service
56 * <code>com.sun.star.comp.Chart.XMLExporter</code>. <p>
57 * Object implements the following interfaces :
58 * <ul>
59 * <li><code>com::sun::star::lang::XInitialization</code></li>
60 * <li><code>com::sun::star::document::ExportFilter</code></li>
61 * <li><code>com::sun::star::document::XFilter</code></li>
62 * <li><code>com::sun::star::document::XExporter</code></li>
63 * <li><code>com::sun::star::beans::XPropertySet</code></li>
64 * </ul>
65 * @see com.sun.star.lang.XInitialization
66 * @see com.sun.star.document.ExportFilter
67 * @see com.sun.star.document.XFilter
68 * @see com.sun.star.document.XExporter
69 * @see com.sun.star.beans.XPropertySet
70 * @see ifc.lang._XInitialization
71 * @see ifc.document._ExportFilter
72 * @see ifc.document._XFilter
73 * @see ifc.document._XExporter
74 * @see ifc.beans._XPropertySet
76 public class XMLExporter extends TestCase {
77 XChartDocument xChartDoc = null;
79 /**
80 * New text document created.
82 protected void initialize( TestParameters tParam, PrintWriter log ) {
84 // get a soffice factory object
85 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
87 try {
88 log.println( "creating a chartdocument" );
89 xChartDoc = SOF.createChartDoc(null);;
90 } catch ( Exception e ) {
91 // Some exception occures.FAILED
92 e.printStackTrace( log );
93 throw new StatusException( "Couldn't create document", e );
97 /**
98 * Document disposed here.
100 protected void cleanup( TestParameters tParam, PrintWriter log ) {
101 log.println( " close xChartDoc " );
102 DesktopTools.closeDoc(xChartDoc);
106 * Creating a Testenvironment for the interfaces to be tested.
107 * Creates an instance of the service
108 * <code>com.sun.star.comp.Chart.XMLExporter</code> with
109 * argument which is an implementation of <code>XDocumentHandler</code>
110 * and which can check if required tags and character data is
111 * exported. <p>
112 * The chart document is set as a source document for exporter
113 * created. A new 'main title' is set for chart. This made
114 * for checking if this title is successfully exported within
115 * the document content.
116 * Object relations created :
117 * <ul>
118 * <li> <code>'MediaDescriptor'</code> for
119 * {@link ifc.document._XFilter} interface </li>
120 * <li> <code>'XFilter.Checker'</code> for
121 * {@link ifc.document._XFilter} interface </li>
122 * <li> <code>'SourceDocument'</code> for
123 * {@link ifc.document._XExporter} interface </li>
124 * </ul>
126 public synchronized TestEnvironment createTestEnvironment
127 (TestParameters tParam, PrintWriter log ) {
129 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ;
130 XInterface oObj = null;
131 final String exportStr = "XMLExporter test." ;
133 FilterChecker filter = new FilterChecker(log);
134 Any arg = new Any(new Type(XDocumentHandler.class),filter);
136 try {
137 oObj = (XInterface) xMSF.createInstanceWithArguments(
138 "com.sun.star.comp.Chart.XMLExporter", new Object[] {arg});
139 XExporter xEx = (XExporter)
140 UnoRuntime.queryInterface(XExporter.class,oObj);
141 xEx.setSourceDocument(xChartDoc);
143 Object oTitle = xChartDoc.getTitle() ;
144 XPropertySet xTitleProp = (XPropertySet) UnoRuntime.queryInterface
145 (XPropertySet.class, oTitle) ;
146 xTitleProp.setPropertyValue("String", exportStr) ;
147 } catch (com.sun.star.uno.Exception e) {
148 e.printStackTrace(log) ;
149 throw new StatusException("Can't create component.", e) ;
152 filter.addTag(new XMLTools.Tag("office:document")) ;
153 filter.addTagEnclosed(new XMLTools.Tag("office:meta"),
154 new XMLTools.Tag("office:document"));
155 filter.addTagEnclosed(new XMLTools.Tag("office:body"),
156 new XMLTools.Tag("office:document"));
157 filter.addCharactersEnclosed(exportStr,
158 new XMLTools.Tag("chart:title")) ;
161 // create testobject here
162 log.println( "creating a new environment" );
163 TestEnvironment tEnv = new TestEnvironment( oObj );
165 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
166 new String[] {"FilterName"},
167 new Object[] {"schart: StarOffice XML (Chart)"}));
168 tEnv.addObjRelation("SourceDocument",xChartDoc);
169 tEnv.addObjRelation("XFilter.Checker", filter) ;
170 log.println("Implementation Name: "+util.utils.getImplName(oObj));
172 return tEnv;
177 * This class checks the XML for tags and data required and returns
178 * checking result to <code>XFilter</code> interface test. All
179 * the information about errors occured in XML data is written
180 * to log specified.
181 * @see ifc.document._XFilter
183 protected class FilterChecker extends XMLTools.XMLChecker
184 implements ifc.document._XFilter.FilterChecker {
187 * Creates a class which will write information
188 * into log specified.
190 public FilterChecker(PrintWriter log) {
191 super(log, true) ;
194 * <code>_XFilter.FilterChecker</code> interface method
195 * which returns the result of XML checking.
196 * @return <code>true</code> if the XML data exported was
197 * valid (i.e. all necessary tags and character data exists),
198 * <code>false</code> if some errors occured.
200 public boolean checkFilter() {
201 return check() ;