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
;
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
.Type
;
37 import com
.sun
.star
.uno
.UnoRuntime
;
38 import com
.sun
.star
.uno
.XInterface
;
39 import com
.sun
.star
.xml
.sax
.XDocumentHandler
;
43 * Test for object which is represented by service
44 * <code>com.sun.star.comp.Calc.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
{
66 static XComponent xSheetDoc
;
69 * New spreadsheet document created.
71 protected void initialize( TestParameters tParam
, PrintWriter log
) {
72 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
75 log
.println( "creating a calc document" );
76 xSheetDoc
= SOF
.openDoc("scalc","_blank");
77 } catch ( com
.sun
.star
.uno
.Exception e
) {
78 // Some exception occurs.FAILED
79 e
.printStackTrace( log
);
80 throw new StatusException( "Couldn't create document", e
);
85 * Spreadsheet document disposed
87 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
88 log
.println( " disposing xCalcDoc " );
89 util
.DesktopTools
.closeDoc(xSheetDoc
);
93 * Creating a Testenvironment for the interfaces to be tested.
94 * Creates an instance of the service
95 * <code>com.sun.star.comp.Calc.XMLMetaExporter</code> with
96 * argument which is an implementation of <code>XDocumentHandler</code>
97 * and which can check if required tags and character data is
99 * The calc document is set as a source document for exporter
100 * created. A meta property 'Title' is set to some value. This made
101 * for checking if this value is successfully exported within
102 * the document meta information.
103 * Object relations created :
105 * <li> <code>'MediaDescriptor'</code> for
106 * {@link ifc.document._XFilter} interface </li>
107 * <li> <code>'XFilter.Checker'</code> for
108 * {@link ifc.document._XFilter} interface </li>
109 * <li> <code>'SourceDocument'</code> for
110 * {@link ifc.document._XExporter} interface </li>
113 public synchronized TestEnvironment
createTestEnvironment( TestParameters tParam
,
115 throws StatusException
{
117 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)tParam
.getMSF() ;
118 XInterface oObj
= null;
119 FilterChecker filter
= new FilterChecker(log
);
120 Any arg
= new Any(new Type(XDocumentHandler
.class),filter
);
122 // Checking tags existance and changed property value
123 filter
.addTag(new XMLTools
.Tag ("office:document-meta"));
124 filter
.addTag(new XMLTools
.Tag ("office:meta"));
125 filter
.addCharactersEnclosed("TestDocument",
126 new XMLTools
.Tag ("dc:title"));
129 oObj
= (XInterface
) xMSF
.createInstanceWithArguments(
130 "com.sun.star.comp.Calc.XMLMetaExporter", new Object
[] {arg
});
131 XExporter xEx
= UnoRuntime
.queryInterface
132 (XExporter
.class,oObj
);
133 xEx
.setSourceDocument(xSheetDoc
);
135 // Obtaining and changing property values
136 XDocumentPropertiesSupplier xPropSup
= UnoRuntime
.queryInterface
137 (XDocumentPropertiesSupplier
.class, xSheetDoc
);
138 final XDocumentProperties xDocProps
= xPropSup
.getDocumentProperties();
139 xDocProps
.setTitle("TestDocument");
141 log
.println("fill sheet 1 with contnet...");
142 util
.CalcTools
.fillCalcSheetWithContent(xSheetDoc
,1, 3, 3, 50, 50);
144 } catch (com
.sun
.star
.uno
.Exception e
) {
145 e
.printStackTrace(log
) ;
146 throw new StatusException("Can't create environment.", e
) ;
147 } catch (java
.lang
.Exception e
) {
148 e
.printStackTrace(log
);
149 throw new StatusException("Can't create environment.", e
);
152 // create testobject here
153 log
.println( "creating a new environment" );
154 TestEnvironment tEnv
= new TestEnvironment( oObj
);
156 tEnv
.addObjRelation("MediaDescriptor", XMLTools
.createMediaDescriptor(
157 new String
[] {"FilterName"},
158 new Object
[] {"scalc: StarOffice XML (Calc)"}));
159 tEnv
.addObjRelation("SourceDocument",xSheetDoc
);
160 tEnv
.addObjRelation("XFilter.Checker", filter
) ;
166 * This class checks the XML for tags and data required and returns
167 * checking result to <code>XFilter</code> interface test. All
168 * the information about errors occurred in XML data is written
170 * @see ifc.document._XFilter
172 protected class FilterChecker
extends XMLTools
.XMLChecker
173 implements ifc
.document
._XFilter
.FilterChecker
{
176 * Creates a class which will write information
177 * into log specified.
179 public FilterChecker(PrintWriter log
) {
183 * <code>_XFilter.FilterChecker</code> interface method
184 * which returns the result of XML checking.
185 * @return <code>true</code> if the XML data exported was
186 * valid (i.e. all necessary tags and character data exists),
187 * <code>false</code> if some errors occurred.
189 public boolean checkFilter() {