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
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.SOfficeFactory
;
29 import com
.sun
.star
.container
.XNamed
;
30 import com
.sun
.star
.document
.XExporter
;
31 import com
.sun
.star
.drawing
.XDrawPage
;
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.XMLExporter</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 XMLExporter
extends TestCase
{
66 XComponent xImpressDoc
= null;
69 * New impress document created.
72 protected void initialize( TestParameters tParam
, PrintWriter log
) throws Exception
{
74 // get a soffice factory object
75 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF());
77 log
.println( "creating an impress document" );
78 xImpressDoc
= SOF
.createImpressDoc(null);
82 * Document disposed here.
85 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
86 log
.println( " disposing xImpressDoc " );
87 xImpressDoc
.dispose();
91 * Creating a TestEnvironment for the interfaces to be tested.
92 * Creates an instance of the service
93 * <code>com.sun.star.comp.Impress.XMLExporter</code> with
94 * argument which is an implementation of <code>XDocumentHandler</code>
95 * and which can check if required tags and character data is
97 * The impress document is set as a source document for exporter
98 * created. A new draw page with specific name created. This made
99 * for checking if this draw page is successfully exported within
101 * Object relations created :
103 * <li> <code>'MediaDescriptor'</code> for
104 * {@link ifc.document._XFilter} interface </li>
105 * <li> <code>'XFilter.Checker'</code> for
106 * {@link ifc.document._XFilter} interface </li>
107 * <li> <code>'SourceDocument'</code> for
108 * {@link ifc.document._XExporter} interface </li>
112 protected TestEnvironment createTestEnvironment
113 (TestParameters tParam
, PrintWriter log
) throws Exception
{
115 XMultiServiceFactory xMSF
= tParam
.getMSF() ;
116 XInterface oObj
= null;
118 FilterChecker Filter
= new FilterChecker(log
);
119 Any arg
= new Any(new Type(XDocumentHandler
.class), Filter
);
121 final String NAME
= "XMLExporter";
123 oObj
= (XInterface
) xMSF
.createInstanceWithArguments(
124 "com.sun.star.comp.Impress.XMLExporter", new Object
[] {arg
});
127 XDrawPagesSupplier drawPagesSupplier
= UnoRuntime
.queryInterface(XDrawPagesSupplier
.class, xImpressDoc
);
128 XDrawPages drawPages
= drawPagesSupplier
.getDrawPages();
129 //insert new draw page
130 XDrawPage newDrawPage
= drawPages
.insertNewByIndex(0);
131 //set specific test name
132 XNamed newPageNamed
= UnoRuntime
.queryInterface(XNamed
.class, newDrawPage
);
133 newPageNamed
.setName(NAME
);
134 XExporter xEx
= UnoRuntime
.queryInterface(XExporter
.class,oObj
);
135 xEx
.setSourceDocument(xImpressDoc
);
137 // adding tags which must be contained in XML output
138 Filter
.addTag( new XMLTools
.Tag("office:document") );
139 Filter
.addTagEnclosed(
140 new XMLTools
.Tag("office:body"),
141 new XMLTools
.Tag("office:document") );
142 Filter
.addTagEnclosed(
143 new XMLTools
.Tag("draw:page", "draw:name", NAME
),
144 new XMLTools
.Tag("office:body") );
147 // create testobject here
148 log
.println( "creating a new environment" );
149 TestEnvironment tEnv
= new TestEnvironment( oObj
);
151 tEnv
.addObjRelation("MediaDescriptor", XMLTools
.createMediaDescriptor(
152 new String
[] {"FilterName"},
153 new Object
[] {"simpress: StarOffice XML (Impress)"}));
154 tEnv
.addObjRelation("SourceDocument",xImpressDoc
);
155 tEnv
.addObjRelation("XFilter.Checker", Filter
) ;
161 * This class checks the XML for tags and data required and returns
162 * checking result to <code>XFilter</code> interface test. All
163 * the information about errors occurred in XML data is written
165 * @see ifc.document._XFilter
167 private class FilterChecker
extends XMLTools
.XMLChecker
168 implements ifc
.document
._XFilter
.FilterChecker
{
171 * Creates a class which will write information
172 * into log specified.
174 private FilterChecker(PrintWriter log
) {
178 * <code>_XFilter.FilterChecker</code> interface method
179 * which returns the result of XML checking.
180 * @return <code>true</code> if the XML data exported was
181 * valid (i.e. all necessary tags and character data exists),
182 * <code>false</code> if some errors occurred.
184 public boolean checkFilter() {