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
.XComponent
;
33 import com
.sun
.star
.lang
.XMultiServiceFactory
;
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
;
42 * Test for object which is represented by service
43 * <code>com.sun.star.comp.Calc.XMLMetaExporter</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
{
65 static XComponent xSheetDoc
;
68 * New spreadsheet document created.
71 protected void initialize( TestParameters tParam
, PrintWriter log
) throws Exception
{
72 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
74 log
.println( "creating a calc document" );
75 xSheetDoc
= SOF
.openDoc("scalc","_blank");
79 * Spreadsheet document disposed
82 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
83 log
.println( " disposing xCalcDoc " );
84 util
.DesktopTools
.closeDoc(xSheetDoc
);
88 * Creating a TestEnvironment for the interfaces to be tested.
89 * Creates an instance of the service
90 * <code>com.sun.star.comp.Calc.XMLMetaExporter</code> with
91 * argument which is an implementation of <code>XDocumentHandler</code>
92 * and which can check if required tags and character data is
94 * The calc document is set as a source document for exporter
95 * created. A meta property 'Title' is set to some value. This made
96 * for checking if this value is successfully exported within
97 * the document meta information.
98 * Object relations created :
100 * <li> <code>'MediaDescriptor'</code> for
101 * {@link ifc.document._XFilter} interface </li>
102 * <li> <code>'XFilter.Checker'</code> for
103 * {@link ifc.document._XFilter} interface </li>
104 * <li> <code>'SourceDocument'</code> for
105 * {@link ifc.document._XExporter} interface </li>
109 public TestEnvironment
createTestEnvironment( TestParameters tParam
,
113 XMultiServiceFactory xMSF
= tParam
.getMSF() ;
114 XInterface oObj
= null;
115 FilterChecker filter
= new FilterChecker(log
);
116 Any arg
= new Any(new Type(XDocumentHandler
.class),filter
);
118 // Checking tags existence and changed property value
119 filter
.addTag(new XMLTools
.Tag ("office:document-meta"));
120 filter
.addTag(new XMLTools
.Tag ("office:meta"));
121 filter
.addCharactersEnclosed("TestDocument",
122 new XMLTools
.Tag ("dc:title"));
124 oObj
= (XInterface
) xMSF
.createInstanceWithArguments(
125 "com.sun.star.comp.Calc.XMLMetaExporter", new Object
[] {arg
});
126 XExporter xEx
= UnoRuntime
.queryInterface
127 (XExporter
.class,oObj
);
128 xEx
.setSourceDocument(xSheetDoc
);
130 // Obtaining and changing property values
131 XDocumentPropertiesSupplier xPropSup
= UnoRuntime
.queryInterface
132 (XDocumentPropertiesSupplier
.class, xSheetDoc
);
133 final XDocumentProperties xDocProps
= xPropSup
.getDocumentProperties();
134 xDocProps
.setTitle("TestDocument");
136 log
.println("fill sheet 1 with content...");
137 util
.CalcTools
.fillCalcSheetWithContent(xSheetDoc
,1, 3, 3, 50, 50);
139 // create testobject here
140 log
.println( "creating a new environment" );
141 TestEnvironment tEnv
= new TestEnvironment( oObj
);
143 tEnv
.addObjRelation("MediaDescriptor", XMLTools
.createMediaDescriptor(
144 new String
[] {"FilterName"},
145 new Object
[] {"scalc: StarOffice XML (Calc)"}));
146 tEnv
.addObjRelation("SourceDocument",xSheetDoc
);
147 tEnv
.addObjRelation("XFilter.Checker", filter
) ;
153 * This class checks the XML for tags and data required and returns
154 * checking result to <code>XFilter</code> interface test. All
155 * the information about errors occurred in XML data is written
157 * @see ifc.document._XFilter
159 private class FilterChecker
extends XMLTools
.XMLChecker
160 implements ifc
.document
._XFilter
.FilterChecker
{
163 * Creates a class which will write information
164 * into log specified.
166 private FilterChecker(PrintWriter log
) {
170 * <code>_XFilter.FilterChecker</code> interface method
171 * which returns the result of XML checking.
172 * @return <code>true</code> if the XML data exported was
173 * valid (i.e. all necessary tags and character data exists),
174 * <code>false</code> if some errors occurred.
176 public boolean checkFilter() {