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
.document
.XDocumentPropertiesSupplier
;
31 import com
.sun
.star
.document
.XDocumentProperties
;
32 import com
.sun
.star
.document
.XExporter
;
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.Draw.XMLMetaExporter</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 XMLMetaExporter
extends TestCase
{
65 XComponent xDrawDoc
= null;
68 * New draw document created.
71 protected void initialize( TestParameters tParam
, PrintWriter log
) {
73 // get a soffice factory object
74 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF());
77 log
.println( "creating a drawdocument" );
78 xDrawDoc
= SOF
.createDrawDoc(null);
79 } catch ( Exception e
) {
80 // Some exception occurs.FAILED
81 e
.printStackTrace( log
);
82 throw new StatusException( "Couldn't create document", e
);
87 * Document disposed here.
90 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
91 log
.println( " disposing xDrawDoc " );
96 * Creating a Testenvironment for the interfaces to be tested.
97 * Creates an instance of the service
98 * <code>com.sun.star.comp.Draw.XMLMetaExporter</code> with
99 * argument which is an implementation of <code>XDocumentHandler</code>
100 * and which can check if required tags and character data is
102 * The draw document is set as a source document for exporter
103 * created. Set title of document to 'XMLMetaExporter'.
104 * This made for checking if this title is successfully exported within
105 * the document meta information.
106 * Object relations created :
108 * <li> <code>'MediaDescriptor'</code> for
109 * {@link ifc.document._XFilter} interface </li>
110 * <li> <code>'XFilter.Checker'</code> for
111 * {@link ifc.document._XFilter} interface </li>
112 * <li> <code>'SourceDocument'</code> for
113 * {@link ifc.document._XExporter} interface </li>
117 public synchronized TestEnvironment createTestEnvironment
118 (TestParameters tParam
, PrintWriter log
) throws StatusException
{
120 XMultiServiceFactory xMSF
= tParam
.getMSF() ;
121 XInterface oObj
= null;
122 final String TITLE
= "XMLMetaExporter";
124 FilterChecker filter
= new FilterChecker(log
) ;
125 Any arg
= new Any(new Type(XDocumentHandler
.class),filter
);
128 oObj
= (XInterface
) xMSF
.createInstanceWithArguments(
129 "com.sun.star.comp.Draw.XMLMetaExporter", new Object
[] {arg
});
130 XExporter xEx
= UnoRuntime
.queryInterface(XExporter
.class, oObj
);
131 xEx
.setSourceDocument(xDrawDoc
);
134 XDocumentPropertiesSupplier xPropSup
= UnoRuntime
.queryInterface
135 (XDocumentPropertiesSupplier
.class, xDrawDoc
);
136 final XDocumentProperties xDocProps
= xPropSup
.getDocumentProperties();
137 xDocProps
.setTitle(TITLE
);
139 } catch (com
.sun
.star
.uno
.Exception e
) {
140 e
.printStackTrace(log
) ;
141 throw new StatusException("Can't create component.", e
) ;
144 // Checking Head Tag existence and that property has changed
145 filter
.addTag(new XMLTools
.Tag ("office:document-meta"));
146 filter
.addTagEnclosed(
147 new XMLTools
.Tag("office:meta"),
148 new XMLTools
.Tag("office:document-meta") );
149 filter
.addTagEnclosed(
150 new XMLTools
.Tag("dc:title"),
151 new XMLTools
.Tag("office:meta") );
152 filter
.addCharactersEnclosed( TITLE
,
153 new XMLTools
.Tag("dc:title") );
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
[] {"sdraw: StarOffice XML (Draw)"}));
162 tEnv
.addObjRelation("SourceDocument", xDrawDoc
);
163 tEnv
.addObjRelation("XFilter.Checker", filter
);
168 * This class checks the XML for tags and data required and returns
169 * checking result to <code>XFilter</code> interface test. All
170 * the information about errors occurred in XML data is written
172 * @see ifc.document._XFilter
174 private class FilterChecker
extends XMLTools
.XMLChecker
175 implements ifc
.document
._XFilter
.FilterChecker
{
178 * Creates a class which will write information
179 * into log specified.
181 private FilterChecker(PrintWriter log
) {
186 * <code>_XFilter.FilterChecker</code> interface method
187 * which returns the result of XML checking.
188 * @return <code>true</code> if the XML data exported was
189 * valid (i.e. all necessary tags and character data exists),
190 * <code>false</code> if some errors occurred.
192 public boolean checkFilter() {