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 .
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
.XMultiServiceFactory
;
33 import com
.sun
.star
.text
.XTextDocument
;
34 import com
.sun
.star
.uno
.Any
;
35 import com
.sun
.star
.uno
.Type
;
36 import com
.sun
.star
.uno
.UnoRuntime
;
37 import com
.sun
.star
.uno
.XInterface
;
38 import com
.sun
.star
.xml
.sax
.XDocumentHandler
;
41 * Test for object which is represented by service
42 * <code>com.sun.star.comp.Calc.XMLMetaExporter</code>. <p>
43 * Object implements the following interfaces :
45 * <li><code>com::sun::star::lang::XInitialization</code></li>
46 * <li><code>com::sun::star::document::ExportFilter</code></li>
47 * <li><code>com::sun::star::document::XFilter</code></li>
48 * <li><code>com::sun::star::document::XExporter</code></li>
49 * <li><code>com::sun::star::beans::XPropertySet</code></li>
51 * @see com.sun.star.lang.XInitialization
52 * @see com.sun.star.document.ExportFilter
53 * @see com.sun.star.document.XFilter
54 * @see com.sun.star.document.XExporter
55 * @see com.sun.star.beans.XPropertySet
56 * @see ifc.lang._XInitialization
57 * @see ifc.document._ExportFilter
58 * @see ifc.document._XFilter
59 * @see ifc.document._XExporter
60 * @see ifc.beans._XPropertySet
62 public class XMLMetaExporter
extends TestCase
{
64 XTextDocument xTextDoc
;
65 MetaFilterChecker Filter
;
68 * New text document created.
71 protected void initialize( TestParameters tParam
, PrintWriter log
) throws Exception
{
72 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
73 log
.println( "creating a textdocument" );
74 xTextDoc
= SOF
.createTextDoc( null );
78 * Document disposed here.
81 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
82 log
.println( " disposing xTextDoc " );
83 util
.DesktopTools
.closeDoc(xTextDoc
);
87 * Creating a TestEnvironment for the interfaces to be tested.
88 * Creates an instance of the service
89 * <code>com.sun.star.comp.Calc.XMLMetaExporter</code> with
90 * argument which is an implementation of <code>XDocumentHandler</code>
91 * and which can check if required tags and character data is
93 * The text document is set as a source document for exporter
94 * created. The 'Title' metadata property is set to a value. This made
95 * for checking if this property is successfully exported within
96 * the document metadata.
97 * Object relations created :
99 * <li> <code>'MediaDescriptor'</code> for
100 * {@link ifc.document._XFilter} interface </li>
101 * <li> <code>'XFilter.Checker'</code> for
102 * {@link ifc.document._XFilter} interface </li>
103 * <li> <code>'SourceDocument'</code> for
104 * {@link ifc.document._XExporter} interface </li>
108 public TestEnvironment createTestEnvironment
109 ( TestParameters tParam
, PrintWriter log
) throws Exception
{
110 final String TITLE
= "Title for testing of XMLMetaExporter";
112 XMultiServiceFactory xMSF
= tParam
.getMSF() ;
113 XInterface oObj
= null;
115 Filter
= new MetaFilterChecker(log
);
116 Any arg
= new Any(new Type(XDocumentHandler
.class), Filter
);
118 oObj
= (XInterface
) xMSF
.createInstanceWithArguments(
119 "com.sun.star.comp.Writer.XMLMetaExporter",
121 XExporter xEx
= UnoRuntime
.queryInterface
122 (XExporter
.class,oObj
);
123 xEx
.setSourceDocument(xTextDoc
);
126 XDocumentPropertiesSupplier xPropSup
= UnoRuntime
.queryInterface
127 (XDocumentPropertiesSupplier
.class, xTextDoc
);
128 final XDocumentProperties xDocProps
= xPropSup
.getDocumentProperties();
129 xDocProps
.setTitle(TITLE
);
131 // adding tags which must be contained in XML output
132 Filter
.addTag("office:document-meta");
133 Filter
.addTagEnclosed("office:meta", "office:document-meta");
134 Filter
.addCharactersEnclosed(TITLE
, "dc:title");
136 // create testobject here
137 log
.println( "creating a new environment" );
138 TestEnvironment tEnv
= new TestEnvironment( oObj
);
140 tEnv
.addObjRelation("MediaDescriptor", XMLTools
.createMediaDescriptor(
141 new String
[] {"FilterName"},
142 new Object
[] {"swriter: StarOffice XML (Writer)"}));
143 tEnv
.addObjRelation("SourceDocument", xTextDoc
);
144 tEnv
.addObjRelation("XFilter.Checker", Filter
);
149 * This class checks the XML for tags and data required and returns
150 * checking result to <code>XFilter</code> interface test. All
151 * the information about errors occurred in XML data is written
153 * @see ifc.document._XFilter
155 private class MetaFilterChecker
extends XMLTools
.XMLTagsChecker
156 implements ifc
.document
._XFilter
.FilterChecker
{
159 * Creates a class which will write information
160 * into log specified.
162 private MetaFilterChecker(PrintWriter log
) {
167 * <code>_XFilter.FilterChecker</code> interface method
168 * which returns the result of XML checking.
169 * @return <code>true</code> if the XML data exported was
170 * valid (i.e. all necessary tags and character data exists),
171 * <code>false</code> if some errors occurred.
173 public boolean checkFilter() {