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
.XDrawPages
;
32 import com
.sun
.star
.drawing
.XDrawPagesSupplier
;
33 import com
.sun
.star
.lang
.XComponent
;
34 import com
.sun
.star
.lang
.XMultiServiceFactory
;
35 import com
.sun
.star
.uno
.Any
;
36 import com
.sun
.star
.uno
.Exception
;
37 import com
.sun
.star
.uno
.Type
;
38 import com
.sun
.star
.uno
.UnoRuntime
;
39 import com
.sun
.star
.uno
.XInterface
;
40 import com
.sun
.star
.xml
.sax
.XDocumentHandler
;
43 * Test for object which is represented by service
44 * <code>com.sun.star.comp.Impress.XMLOasisContentExporter</code>. <p>
45 * Object implements the following interfaces :
47 * <li><code>com::sun::star::lang::XInitialization</code></li>
48 * <li><code>com::sun::star::document::ExportFilter</code></li>
49 * <li><code>com::sun::star::document::XFilter</code></li>
50 * <li><code>com::sun::star::document::XExporter</code></li>
51 * <li><code>com::sun::star::beans::XPropertySet</code></li>
53 * @see com.sun.star.lang.XInitialization
54 * @see com.sun.star.document.ExportFilter
55 * @see com.sun.star.document.XFilter
56 * @see com.sun.star.document.XExporter
57 * @see com.sun.star.beans.XPropertySet
58 * @see ifc.lang._XInitialization
59 * @see ifc.document._ExportFilter
60 * @see ifc.document._XFilter
61 * @see ifc.document._XExporter
62 * @see ifc.beans._XPropertySet
64 public class XMLContentExporter
extends TestCase
{
65 XComponent xImpressDoc
= null;
68 * New text document created.
71 protected void initialize( TestParameters tParam
, PrintWriter log
) throws Exception
{
73 // get a soffice factory object
74 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF());
76 log
.println( "creating an impress document" );
77 xImpressDoc
= SOF
.createImpressDoc(null);
81 * Document disposed here.
84 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
85 log
.println( " disposing xImpressDoc " );
86 xImpressDoc
.dispose();
90 * Creating a TestEnvironment for the interfaces to be tested.
91 * Creates an instance of the service
92 * <code>com.sun.star.comp.Impress.XMLOasisContentExporter</code> with
93 * argument which is an implementation of <code>XDocumentHandler</code>
94 * and which can check if required tags and character data is
96 * The impress document is set as a source document for exporter
97 * created. The existing draw page is gotten a new name. This made
98 * for checking if this new name is successfully exported within
99 * the document content.
100 * Object relations created :
102 * <li> <code>'MediaDescriptor'</code> for
103 * {@link ifc.document._XFilter} interface </li>
104 * <li> <code>'XFilter.Checker'</code> for
105 * {@link ifc.document._XFilter} interface </li>
106 * <li> <code>'SourceDocument'</code> for
107 * {@link ifc.document._XExporter} interface </li>
111 public TestEnvironment createTestEnvironment
112 (TestParameters tParam
, PrintWriter log
) throws Exception
{
114 XMultiServiceFactory xMSF
= tParam
.getMSF() ;
115 XInterface oObj
= null;
116 final String expPageName
= "XMLContentExporter" ;
118 FilterChecker filter
= new FilterChecker(log
);
119 Any arg
= new Any(new Type(XDocumentHandler
.class),filter
);
121 oObj
= (XInterface
) xMSF
.createInstanceWithArguments(
122 "com.sun.star.comp.Impress.XMLOasisContentExporter",
124 XExporter xEx
= UnoRuntime
.queryInterface(XExporter
.class,oObj
);
125 xEx
.setSourceDocument(xImpressDoc
);
127 // assigning a draw page a new name
128 XDrawPagesSupplier xPagesSup
= UnoRuntime
.queryInterface
129 (XDrawPagesSupplier
.class, xImpressDoc
) ;
130 XDrawPages xPages
= xPagesSup
.getDrawPages() ;
131 XNamed xPageName
= UnoRuntime
.queryInterface
132 (XNamed
.class, xPages
.getByIndex(0)) ;
133 xPageName
.setName(expPageName
) ;
135 // adding tags required to be in XML data exported.
136 filter
.addTag(new XMLTools
.Tag("office:document-content")) ;
137 filter
.addTagEnclosed(new XMLTools
.Tag("office:body"),
138 new XMLTools
.Tag("office:document-content")) ;
139 filter
.addTagEnclosed(
140 new XMLTools
.Tag("draw:page", "draw:name", expPageName
),
141 new XMLTools
.Tag("office:body")) ;
143 // create testobject here
144 log
.println( "creating a new environment" );
145 TestEnvironment tEnv
= new TestEnvironment( oObj
);
147 tEnv
.addObjRelation("MediaDescriptor", XMLTools
.createMediaDescriptor(
148 new String
[] {"FilterName"},
149 new Object
[] {"simpress: StarOffice XML (Impress)"}));
150 tEnv
.addObjRelation("SourceDocument",xImpressDoc
);
151 tEnv
.addObjRelation("XFilter.Checker", filter
) ;
153 log
.println("Implementation Name: "+util
.utils
.getImplName(oObj
));
160 * This class checks the XML for tags and data required and returns
161 * checking result to <code>XFilter</code> interface test. All
162 * the information about errors occurred in XML data is written
164 * @see ifc.document._XFilter
166 private class FilterChecker
extends XMLTools
.XMLChecker
167 implements ifc
.document
._XFilter
.FilterChecker
{
170 * Creates a class which will write information
171 * into log specified.
173 private FilterChecker(PrintWriter log
) {
177 * <code>_XFilter.FilterChecker</code> interface method
178 * which returns the result of XML checking.
179 * @return <code>true</code> if the XML data exported was
180 * valid (i.e. all necessary tags and character data exists),
181 * <code>false</code> if some errors occurred.
183 public boolean checkFilter() {