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
.Draw
;
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
.XDrawPage
;
33 import com
.sun
.star
.drawing
.XDrawPages
;
34 import com
.sun
.star
.drawing
.XDrawPagesSupplier
;
35 import com
.sun
.star
.lang
.XComponent
;
36 import com
.sun
.star
.lang
.XMultiServiceFactory
;
37 import com
.sun
.star
.uno
.Any
;
38 import com
.sun
.star
.uno
.Exception
;
39 import com
.sun
.star
.uno
.Type
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
41 import com
.sun
.star
.uno
.XInterface
;
42 import com
.sun
.star
.xml
.sax
.XDocumentHandler
;
45 * Test for object which is represented by service
46 * <code>com.sun.star.comp.Draw.XMLExporter</code>. <p>
47 * Object implements the following interfaces :
49 * <li><code>com::sun::star::lang::XInitialization</code></li>
50 * <li><code>com::sun::star::document::ExportFilter</code></li>
51 * <li><code>com::sun::star::document::XFilter</code></li>
52 * <li><code>com::sun::star::document::XExporter</code></li>
53 * <li><code>com::sun::star::beans::XPropertySet</code></li>
55 * @see com.sun.star.lang.XInitialization
56 * @see com.sun.star.document.ExportFilter
57 * @see com.sun.star.document.XFilter
58 * @see com.sun.star.document.XExporter
59 * @see com.sun.star.beans.XPropertySet
60 * @see ifc.lang._XInitialization
61 * @see ifc.document._ExportFilter
62 * @see ifc.document._XFilter
63 * @see ifc.document._XExporter
64 * @see ifc.beans._XPropertySet
66 public class XMLExporter
extends TestCase
{
67 XComponent xDrawDoc
= null;
70 * New text document created.
73 protected void initialize( TestParameters tParam
, PrintWriter log
) {
75 // get a soffice factory object
76 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF());
79 log
.println( "creating a drawdocument" );
80 xDrawDoc
= SOF
.createDrawDoc(null);
81 } catch ( Exception e
) {
82 // Some exception occurs.FAILED
83 e
.printStackTrace( log
);
84 throw new StatusException( "Couldn't create document", e
);
89 * Document disposed here.
92 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
93 log
.println( " disposing xDrawDoc " );
98 * Creating a Testenvironment for the interfaces to be tested.
99 * Creates an instance of the service
100 * <code>com.sun.star.comp.Draw.XMLExporter</code> with
101 * argument which is an implementation of <code>XDocumentHandler</code>
102 * and which can check if required tags and character data is
104 * The draw document is set as a source document for exporter
105 * created. Then a new page (Slide) created in this document and
106 * both two pages renamed to 'NewSlide1' and 'NewSlide2'. After this
107 * filter checks that new tags exist in the XML output.
108 * Object relations created :
110 * <li> <code>'MediaDescriptor'</code> for
111 * {@link ifc.document._XFilter} interface </li>
112 * <li> <code>'XFilter.Checker'</code> for
113 * {@link ifc.document._XFilter} interface </li>
114 * <li> <code>'SourceDocument'</code> for
115 * {@link ifc.document._XExporter} interface </li>
119 protected synchronized TestEnvironment createTestEnvironment
120 (TestParameters tParam
, PrintWriter log
) {
122 XMultiServiceFactory xMSF
= tParam
.getMSF() ;
123 XInterface oObj
= null;
124 FilterChecker filter
= new FilterChecker(log
);
125 Any arg
= new Any(new Type(XDocumentHandler
.class),filter
);
127 // Adding tags for checking existence of head tag and other tags
128 filter
.addTag(new XMLTools
.Tag("office:document"));
129 filter
.addTag(new XMLTools
.Tag("office:body"));
130 filter
.addTagEnclosed(
131 new XMLTools
.Tag("draw:page"),
132 new XMLTools
.Tag("office:body"));
133 filter
.addTag(new XMLTools
.Tag("draw:page","draw:name","NewSlide1"));
134 filter
.addTag(new XMLTools
.Tag("draw:page","draw:name","NewSlide2"));
137 oObj
= (XInterface
) xMSF
.createInstanceWithArguments(
138 "com.sun.star.comp.Draw.XMLExporter", new Object
[] {arg
});
141 XDrawPagesSupplier supp
= UnoRuntime
.queryInterface(XDrawPagesSupplier
.class, xDrawDoc
);
142 XDrawPages set
= supp
.getDrawPages();
144 // This is an XML-export BUG (new slide named "NewSlide2" can not be exported to XML)
145 set
.insertNewByIndex(1);
147 XDrawPage page1
= UnoRuntime
.queryInterface(XDrawPage
.class, set
.getByIndex(0));
148 XNamed NPage1
= UnoRuntime
.queryInterface(XNamed
.class,page1
);
149 NPage1
.setName("NewSlide1");
150 XDrawPage page2
= UnoRuntime
.queryInterface(XDrawPage
.class, set
.getByIndex(1));
151 XNamed NPage2
= UnoRuntime
.queryInterface(XNamed
.class,page2
);
152 NPage2
.setName("NewSlide2");
154 XExporter xEx
= UnoRuntime
.queryInterface(XExporter
.class,oObj
);
155 xEx
.setSourceDocument(xDrawDoc
);
157 } catch (com
.sun
.star
.uno
.Exception e
) {
158 e
.printStackTrace(log
) ;
159 throw new StatusException("Can't create component.", e
) ;
162 // create testobject here
163 log
.println( "creating a new environment" );
164 TestEnvironment tEnv
= new TestEnvironment( oObj
);
166 tEnv
.addObjRelation("MediaDescriptor", XMLTools
.createMediaDescriptor(
167 new String
[] {"FilterName"},
168 new Object
[] {"sdraw: StarOffice XML (Draw)"}));
169 tEnv
.addObjRelation("SourceDocument",xDrawDoc
);
170 tEnv
.addObjRelation("XFilter.Checker", filter
);
175 * This class checks the XML for tags and data required and returns
176 * checking result to <code>XFilter</code> interface test. All
177 * the information about errors occurred in XML data is written
179 * @see ifc.document._XFilter
181 private class FilterChecker
extends XMLTools
.XMLChecker
182 implements ifc
.document
._XFilter
.FilterChecker
{
185 * Creates a class which will write information
186 * into log specified.
188 private FilterChecker(PrintWriter log
) {
192 * <code>_XFilter.FilterChecker</code> interface method
193 * which returns the result of XML checking.
194 * @return <code>true</code> if the XML data exported was
195 * valid (i.e. all necessary tags and character data exists),
196 * <code>false</code> if some errors occurred.
198 public boolean checkFilter() {