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
.Chart
;
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
.chart
.XChartDocument
;
31 import com
.sun
.star
.document
.XExporter
;
32 import com
.sun
.star
.lang
.XMultiServiceFactory
;
33 import com
.sun
.star
.uno
.Any
;
34 import com
.sun
.star
.uno
.Exception
;
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.Chart.XMLStylesExporter</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 XMLStylesExporter
extends TestCase
{
63 XChartDocument xChartDoc
= null;
66 * New text document created.
69 protected void initialize( TestParameters tParam
, PrintWriter log
) {
71 // get a soffice factory object
72 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF());
75 log
.println( "creating a chartdocument" );
76 xChartDoc
= SOF
.createChartDoc();
77 } catch ( Exception e
) {
78 // Some exception occurs.FAILED
79 e
.printStackTrace( log
);
80 throw new StatusException( "Couldn't create document", e
);
88 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
89 if( xChartDoc
!=null ) {
90 log
.println( " closing xChartDoc" );
91 util
.DesktopTools
.closeDoc(xChartDoc
);
97 * Creating a Testenvironment for the interfaces to be tested.
98 * Creates an instance of the service
99 * <code>com.sun.star.comp.Chart.XMLStylesExporter</code> with
100 * argument which is an implementation of <code>XDocumentHandler</code>
101 * and which can check if required tags and character data is
103 * Existing of some tags checked in XML data exported.
104 * Object relations created :
106 * <li> <code>'MediaDescriptor'</code> for
107 * {@link ifc.document._XFilter} interface </li>
108 * <li> <code>'XFilter.Checker'</code> for
109 * {@link ifc.document._XFilter} interface </li>
110 * <li> <code>'SourceDocument'</code> for
111 * {@link ifc.document._XExporter} interface </li>
115 public synchronized TestEnvironment createTestEnvironment
116 (TestParameters tParam
, PrintWriter log
) {
118 XMultiServiceFactory xMSF
= tParam
.getMSF() ;
119 XInterface oObj
= null;
121 FilterChecker filter
= new FilterChecker(log
);
122 Any arg
= new Any(new Type(XDocumentHandler
.class),filter
);
125 oObj
= (XInterface
) xMSF
.createInstanceWithArguments(
126 "com.sun.star.comp.Chart.XMLStylesExporter",
128 XExporter xEx
= UnoRuntime
.queryInterface(XExporter
.class,oObj
);
129 xEx
.setSourceDocument(xChartDoc
);
131 } catch (com
.sun
.star
.uno
.Exception e
) {
132 e
.printStackTrace(log
) ;
133 throw new StatusException("Can't create component.", e
) ;
137 filter
.addTag(new XMLTools
.Tag("office:document-styles")) ;
138 filter
.addTagEnclosed(new XMLTools
.Tag("office:styles"),
139 new XMLTools
.Tag("office:document-styles"));
141 // create testobject here
142 log
.println( "creating a new environment" );
143 TestEnvironment tEnv
= new TestEnvironment( oObj
);
145 tEnv
.addObjRelation("MediaDescriptor", XMLTools
.createMediaDescriptor(
146 new String
[] {"FilterName"},
147 new Object
[] {"schart: StarOffice XML (Chart)"}));
148 tEnv
.addObjRelation("SourceDocument",xChartDoc
);
149 tEnv
.addObjRelation("XFilter.Checker", filter
) ;
150 log
.println("Implementation Name: "+util
.utils
.getImplName(oObj
));
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() {