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
.document
.XDocumentPropertiesSupplier
;
30 import com
.sun
.star
.document
.XDocumentProperties
;
31 import com
.sun
.star
.document
.XExporter
;
32 import com
.sun
.star
.lang
.XComponent
;
33 import com
.sun
.star
.lang
.XMultiServiceFactory
;
34 import com
.sun
.star
.uno
.Any
;
35 import com
.sun
.star
.uno
.Exception
;
36 import com
.sun
.star
.uno
.Type
;
37 import com
.sun
.star
.uno
.UnoRuntime
;
38 import com
.sun
.star
.uno
.XInterface
;
39 import com
.sun
.star
.xml
.sax
.XDocumentHandler
;
42 * Test for object which is represented by service
43 * <code>com.sun.star.comp.Impress.XMLOasisMetaExporter</code>. <p>
44 * Object implements the following interfaces :
46 * <li><code>com::sun::star::lang::XInitialization</code></li>
47 * <li><code>com::sun::star::document::ExportFilter</code></li>
48 * <li><code>com::sun::star::document::XFilter</code></li>
49 * <li><code>com::sun::star::document::XExporter</code></li>
50 * <li><code>com::sun::star::beans::XPropertySet</code></li>
52 * @see com.sun.star.lang.XInitialization
53 * @see com.sun.star.document.ExportFilter
54 * @see com.sun.star.document.XFilter
55 * @see com.sun.star.document.XExporter
56 * @see com.sun.star.beans.XPropertySet
57 * @see ifc.lang._XInitialization
58 * @see ifc.document._ExportFilter
59 * @see ifc.document._XFilter
60 * @see ifc.document._XExporter
61 * @see ifc.beans._XPropertySet
63 public class XMLMetaExporter
extends TestCase
{
64 XComponent xImpressDoc
= null;
67 * New impress document created.
70 protected void initialize( TestParameters tParam
, PrintWriter log
) throws Exception
{
72 // get a soffice factory object
73 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF());
75 log
.println( "creating an impress document" );
76 xImpressDoc
= SOF
.createImpressDoc(null);
80 * Impress document disposed
83 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
84 log
.println( "disposing xImpressDoc " );
85 xImpressDoc
.dispose();
89 * Creating a TestEnvironment for the interfaces to be tested.
90 * Creates an instance of the service
91 * <code>com.sun.star.comp.Impress.XMLOasisMetaExporter</code> with
92 * argument which is an implementation of <code>XDocumentHandler</code>
93 * and which can check if required tags and character data is
95 * The impress document is set as a source document for exporter
96 * created. A meta property 'Title' is set to specific value. This made
97 * for checking if this value is successfully exported within
98 * the document meta information.
99 * Object relations created :
101 * <li> <code>'MediaDescriptor'</code> for
102 * {@link ifc.document._XFilter} interface </li>
103 * <li> <code>'XFilter.Checker'</code> for
104 * {@link ifc.document._XFilter} interface </li>
105 * <li> <code>'SourceDocument'</code> for
106 * {@link ifc.document._XExporter} interface </li>
110 public TestEnvironment createTestEnvironment
111 (TestParameters tParam
, PrintWriter log
) throws Exception
{
113 XMultiServiceFactory xMSF
= tParam
.getMSF() ;
114 XInterface oObj
= null;
116 FilterChecker filter
= new FilterChecker(log
);
117 Any arg
= new Any(new Type(XDocumentHandler
.class), filter
);
118 final String NAME
= "XMLMetaExporter";
120 oObj
= (XInterface
) xMSF
.createInstanceWithArguments(
121 "com.sun.star.comp.Impress.XMLOasisMetaExporter",
123 XExporter xEx
= UnoRuntime
.queryInterface(XExporter
.class,oObj
);
124 xEx
.setSourceDocument(xImpressDoc
);
127 XDocumentPropertiesSupplier xPropSup
= UnoRuntime
.queryInterface
128 (XDocumentPropertiesSupplier
.class, xImpressDoc
);
129 final XDocumentProperties xDocProps
= xPropSup
.getDocumentProperties();
130 xDocProps
.setTitle(NAME
);
132 // Checking tags existence and changed property value
133 filter
.addTag(new XMLTools
.Tag ("office:document-meta"));
134 filter
.addTagEnclosed(
135 new XMLTools
.Tag("office:meta"),
136 new XMLTools
.Tag("office:document-meta") );
137 filter
.addTagEnclosed(
138 new XMLTools
.Tag("dc:title"),
139 new XMLTools
.Tag("office:meta") );
140 filter
.addCharactersEnclosed(
142 new XMLTools
.Tag ("dc:title") );
144 // create testobject here
145 log
.println( "creating a new environment" );
146 TestEnvironment tEnv
= new TestEnvironment( oObj
);
148 tEnv
.addObjRelation("MediaDescriptor", XMLTools
.createMediaDescriptor(
149 new String
[] {"FilterName"},
150 new Object
[] {"simpress: StarOffice XML (Impress)"}));
151 tEnv
.addObjRelation("SourceDocument", xImpressDoc
);
152 tEnv
.addObjRelation("XFilter.Checker", filter
) ;
157 * This class checks the XML for tags and data required and returns
158 * checking result to <code>XFilter</code> interface test. All
159 * the information about errors occurred in XML data is written
161 * @see ifc.document._XFilter
163 private class FilterChecker
extends XMLTools
.XMLChecker
164 implements ifc
.document
._XFilter
.FilterChecker
{
167 * Creates a class which will write information
168 * into log specified.
170 private FilterChecker(PrintWriter log
) {
174 * <code>_XFilter.FilterChecker</code> interface method
175 * which returns the result of XML checking.
176 * @return <code>true</code> if the XML data exported was
177 * valid (i.e. all necessary tags and character data exists),
178 * <code>false</code> if some errors occurred.
180 public boolean checkFilter() {