merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _xmloff / Draw / XMLContentExporter.java
blob0f8c43dbf74edd6dfa772b53088d950f84bd441a
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: XMLContentExporter.java,v $
10 * $Revision: 1.5 $
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.Draw;
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;
40 import util.XMLTools;
42 import com.sun.star.container.XNamed;
43 import com.sun.star.document.XExporter;
44 import com.sun.star.drawing.XDrawPage;
45 import com.sun.star.drawing.XDrawPages;
46 import com.sun.star.drawing.XDrawPagesSupplier;
47 import com.sun.star.lang.XComponent;
48 import com.sun.star.lang.XMultiServiceFactory;
49 import com.sun.star.uno.Any;
50 import com.sun.star.uno.Exception;
51 import com.sun.star.uno.Type;
52 import com.sun.star.uno.UnoRuntime;
53 import com.sun.star.uno.XInterface;
54 import com.sun.star.xml.sax.XDocumentHandler;
56 /**
57 * Test for object which is represented by service
58 * <code>com.sun.star.comp.Draw.XMLContentExporter</code>. <p>
59 * Object implements the following interfaces :
60 * <ul>
61 * <li><code>com::sun::star::lang::XInitialization</code></li>
62 * <li><code>com::sun::star::document::ExportFilter</code></li>
63 * <li><code>com::sun::star::document::XFilter</code></li>
64 * <li><code>com::sun::star::document::XExporter</code></li>
65 * <li><code>com::sun::star::beans::XPropertySet</code></li>
66 * </ul>
67 * @see com.sun.star.lang.XInitialization
68 * @see com.sun.star.document.ExportFilter
69 * @see com.sun.star.document.XFilter
70 * @see com.sun.star.document.XExporter
71 * @see com.sun.star.beans.XPropertySet
72 * @see ifc.lang._XInitialization
73 * @see ifc.document._ExportFilter
74 * @see ifc.document._XFilter
75 * @see ifc.document._XExporter
76 * @see ifc.beans._XPropertySet
78 public class XMLContentExporter extends TestCase {
79 XComponent xDrawDoc = null;
81 /**
82 * New text document created.
84 protected void initialize( TestParameters tParam, PrintWriter log ) {
85 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
87 try {
88 log.println( "creating a drawdocument" );
89 xDrawDoc = SOF.createDrawDoc(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( " disposing xDrawDoc " );
102 xDrawDoc.dispose();
106 * Creating a Testenvironment for the interfaces to be tested.
107 * Creates an instance of the service
108 * <code>com.sun.star.comp.Draw.XMLContentExporter</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 draw document is set as a source document for exporter
113 * created. Then a new page (Slide) created in this document and
114 * both two pages renamed to 'NewSlide1' and 'NewSlide2'. After this
115 * filter checks that new tags exist in the XML output.
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 protected synchronized TestEnvironment createTestEnvironment
127 (TestParameters tParam, PrintWriter log) {
129 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ;
130 XInterface oObj = null;
131 FilterChecker filter = new FilterChecker(log);
132 Any arg = new Any(new Type(XDocumentHandler.class),filter);
134 // Adding tags for checking existance of head tag and other tags
135 filter.addTag(new XMLTools.Tag("office:document-content"));
136 filter.addTag(new XMLTools.Tag("office:body"));
137 filter.addTagEnclosed(
138 new XMLTools.Tag("draw:page"),
139 new XMLTools.Tag("office:body"));
140 filter.addTag(new XMLTools.Tag("draw:page","draw:name","NewSlide1"));
141 filter.addTag(new XMLTools.Tag("draw:page","draw:name","NewSlide2"));
143 try {
144 oObj = (XInterface) xMSF.createInstanceWithArguments(
145 "com.sun.star.comp.Draw.XMLContentExporter",
146 new Object[] {arg});
147 XExporter xEx = (XExporter)
148 UnoRuntime.queryInterface(XExporter.class,oObj);
149 //xEx.setSourceDocument(xDrawDoc);
151 XDrawPagesSupplier supp = (XDrawPagesSupplier)
152 UnoRuntime.queryInterface(XDrawPagesSupplier.class, xDrawDoc);
153 XDrawPages set = supp.getDrawPages();
155 // This is an XML-export BUG (new slide named "NewSlide2"
156 // can not be exported to XML)
157 set.insertNewByIndex(1);
159 XDrawPage page1 = (XDrawPage)
160 UnoRuntime.queryInterface(XDrawPage.class, set.getByIndex(0));
161 XNamed NPage1 = (XNamed)
162 UnoRuntime.queryInterface(XNamed.class,page1);
163 NPage1.setName("NewSlide1");
164 XDrawPage page2 = (XDrawPage)
165 UnoRuntime.queryInterface(XDrawPage.class, set.getByIndex(1));
166 XNamed NPage2 = (XNamed)
167 UnoRuntime.queryInterface(XNamed.class,page2);
168 NPage2.setName("NewSlide2");
169 xEx.setSourceDocument(xDrawDoc);
170 } catch (com.sun.star.uno.Exception e) {
171 e.printStackTrace(log) ;
172 throw new StatusException("Can't create component.", e) ;
175 // create testobject here
176 log.println( "creating a new environment" );
177 TestEnvironment tEnv = new TestEnvironment( oObj );
179 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor(
180 new String[] {"FilterName"},
181 new Object[] {"sdraw: StarOffice XML (Draw)"}));
182 tEnv.addObjRelation("SourceDocument",xDrawDoc);
183 tEnv.addObjRelation("XFilter.Checker", filter);
184 return tEnv;
189 * This class checks the XML for tags and data required and returns
190 * checking result to <code>XFilter</code> interface test. All
191 * the information about errors occured in XML data is written
192 * to log specified.
193 * @see ifc.document._XFilter
195 protected class FilterChecker extends XMLTools.XMLChecker
196 implements ifc.document._XFilter.FilterChecker {
199 * Creates a class which will write information
200 * into log specified.
202 public FilterChecker(PrintWriter log) {
203 super(log,true) ;
206 * <code>_XFilter.FilterChecker</code> interface method
207 * which returns the result of XML checking.
208 * @return <code>true</code> if the XML data exported was
209 * valid (i.e. all necessary tags and character data exists),
210 * <code>false</code> if some errors occured.
212 public boolean checkFilter() {
213 return check();