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
.container
.XNameAccess
;
31 import com
.sun
.star
.container
.XNameContainer
;
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
.style
.XStyle
;
36 import com
.sun
.star
.style
.XStyleFamiliesSupplier
;
37 import com
.sun
.star
.uno
.Any
;
38 import com
.sun
.star
.uno
.Exception
;
39 import com
.sun
.star
.uno
.Type
;
40 import com
.sun
.star
.uno
.UnoRuntime
;
41 import com
.sun
.star
.uno
.XInterface
;
42 import com
.sun
.star
.xml
.sax
.XDocumentHandler
;
45 * Test for object which is represented by service
46 * <code>com.sun.star.comp.Draw.XMLStylesExporter</code>. <p>
47 * Object implements the following interfaces :
49 * <li><code>com::sun::star::lang::XInitialization</code></li>
50 * <li><code>com::sun::star::document::ExportFilter</code></li>
51 * <li><code>com::sun::star::document::XFilter</code></li>
52 * <li><code>com::sun::star::document::XExporter</code></li>
53 * <li><code>com::sun::star::beans::XPropertySet</code></li>
55 * @see com.sun.star.lang.XInitialization
56 * @see com.sun.star.document.ExportFilter
57 * @see com.sun.star.document.XFilter
58 * @see com.sun.star.document.XExporter
59 * @see com.sun.star.beans.XPropertySet
60 * @see ifc.lang._XInitialization
61 * @see ifc.document._ExportFilter
62 * @see ifc.document._XFilter
63 * @see ifc.document._XExporter
64 * @see ifc.beans._XPropertySet
66 public class XMLStylesExporter
extends TestCase
{
67 XComponent xDrawDoc
= null;
68 protected static int counter
= 0;
71 * New draw document created.
74 protected void initialize( TestParameters tParam
, PrintWriter log
) {
76 // get a soffice factory object
77 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF());
80 log
.println( "creating a drawdocument" );
81 xDrawDoc
= SOF
.createDrawDoc(null);
82 } catch ( Exception e
) {
83 // Some exception occurs.FAILED
84 e
.printStackTrace( log
);
85 throw new StatusException( "Couldn't create document", e
);
90 * Document disposed here.
93 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
94 log
.println( " disposing xDrawDoc " );
99 * Creating a Testenvironment for the interfaces to be tested.
100 * Creates an instance of the service
101 * <code>com.sun.star.comp.Draw.XMLStylesExporter</code> with
102 * argument which is an implementation of <code>XDocumentHandler</code>
103 * and which can check if required tags and character data is
105 * The draw document is set as a source document for exporter
106 * created. New style is added to the style family 'graphics' with unique name
107 * every time. This made for checking if this style is successfully exported
108 * within the document styles information.
109 * Object relations created :
111 * <li> <code>'MediaDescriptor'</code> for
112 * {@link ifc.document._XFilter} interface </li>
113 * <li> <code>'XFilter.Checker'</code> for
114 * {@link ifc.document._XFilter} interface </li>
115 * <li> <code>'SourceDocument'</code> for
116 * {@link ifc.document._XExporter} interface </li>
120 public synchronized TestEnvironment
createTestEnvironment(
121 TestParameters tParam
, PrintWriter log
) throws StatusException
{
123 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
124 XMultiServiceFactory xMSF
= tParam
.getMSF() ;
125 XInterface oObj
= null;
126 FilterChecker filter
= new FilterChecker(log
) ;
127 Any arg
= new Any(new Type(XDocumentHandler
.class),filter
);
128 final String STYLE_NAME
= "New style" + counter
++ ;
131 oObj
= (XInterface
) xMSF
.createInstanceWithArguments(
132 "com.sun.star.comp.Draw.XMLStylesExporter", new Object
[] {arg
});
133 XExporter xEx
= UnoRuntime
.queryInterface(XExporter
.class,oObj
);
134 xEx
.setSourceDocument(xDrawDoc
);
136 //obtain style families
137 XStyleFamiliesSupplier styleSup
= UnoRuntime
.queryInterface(XStyleFamiliesSupplier
.class, xDrawDoc
);
138 XNameAccess StyleFamilies
= styleSup
.getStyleFamilies();
139 //obtain all style family names
140 String
[] styleFamiliesNames
= StyleFamilies
.getElementNames();
141 String styleFamilyName
= styleFamiliesNames
[0];
142 //obtain style family with name[0]
143 Object objectStyle
= StyleFamilies
.getByName(styleFamilyName
);
144 XNameContainer xStyleFamilyName
= UnoRuntime
.queryInterface(XNameContainer
.class, objectStyle
);
146 Object SC
= SOF
.createInstance(xDrawDoc
, "com.sun.star.style.Style");
147 XStyle Style
= UnoRuntime
.queryInterface(XStyle
.class,SC
);
148 //add new style to style familiy with name[0]
149 xStyleFamilyName
.insertByName(STYLE_NAME
,Style
);
150 } catch (com
.sun
.star
.uno
.Exception e
) {
151 e
.printStackTrace(log
) ;
152 throw new StatusException("Can't create component.", e
) ;
155 // Checking Head Tag existence and that property has changed
156 filter
.addTag(new XMLTools
.Tag ("office:document-styles"));
157 filter
.addTag(new XMLTools
.Tag ("office:styles"));
158 filter
.addTagEnclosed(
159 new XMLTools
.Tag("style:style"),
160 new XMLTools
.Tag("office:styles") );
161 filter
.addTag(new XMLTools
.Tag("style:style", "style:name", STYLE_NAME
));
163 // create testobject here
164 log
.println( "creating a new environment" );
165 TestEnvironment tEnv
= new TestEnvironment( oObj
);
167 tEnv
.addObjRelation("MediaDescriptor", XMLTools
.createMediaDescriptor(
168 new String
[] {"FilterName"},
169 new Object
[] {"sdraw: StarOffice XML (Draw)"}));
170 tEnv
.addObjRelation("SourceDocument",xDrawDoc
);
171 tEnv
.addObjRelation("XFilter.Checker", filter
);
176 * This class checks the XML for tags and data required and returns
177 * checking result to <code>XFilter</code> interface test. All
178 * the information about errors occurred in XML data is written
180 * @see ifc.document._XFilter
182 private class FilterChecker
extends XMLTools
.XMLChecker
183 implements ifc
.document
._XFilter
.FilterChecker
{
186 * Creates a class which will write information
187 * into log specified.
189 private FilterChecker(PrintWriter log
) {
194 * <code>_XFilter.FilterChecker</code> interface method
195 * which returns the result of XML checking.
196 * @return <code>true</code> if the XML data exported was
197 * valid (i.e. all necessary tags and character data exists),
198 * <code>false</code> if some errors occurred.
200 public boolean checkFilter() {