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
._xmloff
.Impress
;
21 import java
.io
.PrintWriter
;
23 import lib
.StatusException
;
25 import lib
.TestEnvironment
;
26 import lib
.TestParameters
;
27 import util
.SOfficeFactory
;
30 import com
.sun
.star
.container
.XNamed
;
31 import com
.sun
.star
.document
.XExporter
;
32 import com
.sun
.star
.drawing
.XDrawPages
;
33 import com
.sun
.star
.drawing
.XDrawPagesSupplier
;
34 import com
.sun
.star
.lang
.XComponent
;
35 import com
.sun
.star
.lang
.XMultiServiceFactory
;
36 import com
.sun
.star
.uno
.Any
;
37 import com
.sun
.star
.uno
.Exception
;
38 import com
.sun
.star
.uno
.Type
;
39 import com
.sun
.star
.uno
.UnoRuntime
;
40 import com
.sun
.star
.uno
.XInterface
;
41 import com
.sun
.star
.xml
.sax
.XDocumentHandler
;
44 * Test for object which is represented by service
45 * <code>com.sun.star.comp.Impress.XMLContentExporter</code>. <p>
46 * Object implements the following interfaces :
48 * <li><code>com::sun::star::lang::XInitialization</code></li>
49 * <li><code>com::sun::star::document::ExportFilter</code></li>
50 * <li><code>com::sun::star::document::XFilter</code></li>
51 * <li><code>com::sun::star::document::XExporter</code></li>
52 * <li><code>com::sun::star::beans::XPropertySet</code></li>
54 * @see com.sun.star.lang.XInitialization
55 * @see com.sun.star.document.ExportFilter
56 * @see com.sun.star.document.XFilter
57 * @see com.sun.star.document.XExporter
58 * @see com.sun.star.beans.XPropertySet
59 * @see ifc.lang._XInitialization
60 * @see ifc.document._ExportFilter
61 * @see ifc.document._XFilter
62 * @see ifc.document._XExporter
63 * @see ifc.beans._XPropertySet
65 public class XMLContentExporter
extends TestCase
{
66 XComponent xImpressDoc
= null;
69 * New text document created.
72 protected void initialize( TestParameters tParam
, PrintWriter log
) {
74 // get a soffice factory object
75 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF());
78 log
.println( "creating an impress document" );
79 xImpressDoc
= SOF
.createImpressDoc(null);
80 } catch ( Exception e
) {
81 // Some exception occurs.FAILED
82 e
.printStackTrace( log
);
83 throw new StatusException( "Couldn't create document", e
);
88 * Document disposed here.
91 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
92 log
.println( " disposing xImpressDoc " );
93 xImpressDoc
.dispose();
97 * Creating a Testenvironment for the interfaces to be tested.
98 * Creates an instance of the service
99 * <code>com.sun.star.comp.Impress.XMLContentExporter</code> with
100 * argument which is an implementation of <code>XDocumentHandler</code>
101 * and which can check if required tags and character data is
103 * The impress document is set as a source document for exporter
104 * created. The existing draw page is gotten a new name. This made
105 * for checking if this new name is successfully exported within
106 * the document content.
107 * Object relations created :
109 * <li> <code>'MediaDescriptor'</code> for
110 * {@link ifc.document._XFilter} interface </li>
111 * <li> <code>'XFilter.Checker'</code> for
112 * {@link ifc.document._XFilter} interface </li>
113 * <li> <code>'SourceDocument'</code> for
114 * {@link ifc.document._XExporter} interface </li>
118 public synchronized TestEnvironment createTestEnvironment
119 (TestParameters tParam
, PrintWriter log
) throws StatusException
{
121 XMultiServiceFactory xMSF
= tParam
.getMSF() ;
122 XInterface oObj
= null;
123 final String expPageName
= "XMLContentExporter" ;
125 FilterChecker filter
= new FilterChecker(log
);
126 Any arg
= new Any(new Type(XDocumentHandler
.class),filter
);
129 oObj
= (XInterface
) xMSF
.createInstanceWithArguments(
130 "com.sun.star.comp.Impress.XMLContentExporter",
132 XExporter xEx
= UnoRuntime
.queryInterface(XExporter
.class,oObj
);
133 xEx
.setSourceDocument(xImpressDoc
);
135 // assigning a draw page a new name
136 XDrawPagesSupplier xPagesSup
= UnoRuntime
.queryInterface
137 (XDrawPagesSupplier
.class, xImpressDoc
) ;
138 XDrawPages xPages
= xPagesSup
.getDrawPages() ;
139 XNamed xPageName
= UnoRuntime
.queryInterface
140 (XNamed
.class, xPages
.getByIndex(0)) ;
141 xPageName
.setName(expPageName
) ;
142 } catch (com
.sun
.star
.uno
.Exception e
) {
143 e
.printStackTrace(log
) ;
144 throw new StatusException("Can't create component.", e
) ;
147 // adding tags required to be in XML data exported.
148 filter
.addTag(new XMLTools
.Tag("office:document-content")) ;
149 filter
.addTagEnclosed(new XMLTools
.Tag("office:body"),
150 new XMLTools
.Tag("office:document-content")) ;
151 filter
.addTagEnclosed(
152 new XMLTools
.Tag("draw:page", "draw:name", expPageName
),
153 new XMLTools
.Tag("office:body")) ;
155 // create testobject here
156 log
.println( "creating a new environment" );
157 TestEnvironment tEnv
= new TestEnvironment( oObj
);
159 tEnv
.addObjRelation("MediaDescriptor", XMLTools
.createMediaDescriptor(
160 new String
[] {"FilterName"},
161 new Object
[] {"simpress: StarOffice XML (Impress)"}));
162 tEnv
.addObjRelation("SourceDocument",xImpressDoc
);
163 tEnv
.addObjRelation("XFilter.Checker", filter
) ;
165 log
.println("Implementation Name: "+util
.utils
.getImplName(oObj
));
172 * This class checks the XML for tags and data required and returns
173 * checking result to <code>XFilter</code> interface test. All
174 * the information about errors occurred in XML data is written
176 * @see ifc.document._XFilter
178 private class FilterChecker
extends XMLTools
.XMLChecker
179 implements ifc
.document
._XFilter
.FilterChecker
{
182 * Creates a class which will write information
183 * into log specified.
185 private FilterChecker(PrintWriter log
) {
189 * <code>_XFilter.FilterChecker</code> interface method
190 * which returns the result of XML checking.
191 * @return <code>true</code> if the XML data exported was
192 * valid (i.e. all necessary tags and character data exists),
193 * <code>false</code> if some errors occurred.
195 public boolean checkFilter() {