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
;
29 import com
.sun
.star
.document
.XDocumentPropertiesSupplier
;
30 import com
.sun
.star
.document
.XDocumentProperties
;
31 import com
.sun
.star
.document
.XImporter
;
32 import com
.sun
.star
.lang
.XComponent
;
33 import com
.sun
.star
.lang
.XMultiServiceFactory
;
34 import com
.sun
.star
.sheet
.XSpreadsheetDocument
;
35 import com
.sun
.star
.uno
.UnoRuntime
;
36 import com
.sun
.star
.uno
.XInterface
;
39 * Test for object which is represented by service
40 * <code>com.sun.star.comp.Calc.XMLMetaImporter</code>. <p>
41 * Object implements the following interfaces :
43 * <li><code>com::sun::star::lang::XInitialization</code></li>
44 * <li><code>com::sun::star::document::XImporter</code></li>
45 * <li><code>com::sun::star::document::XFilter</code></li>
46 * <li><code>com::sun::star::document::ImportFilter</code></li>
47 * <li><code>com::sun::star::beans::XPropertySet</code></li>
48 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
51 * @see com.sun.star.lang.XInitialization
52 * @see com.sun.star.document.XImporter
53 * @see com.sun.star.document.XFilter
54 * @see com.sun.star.document.ImportFilter
55 * @see com.sun.star.beans.XPropertySet
56 * @see com.sun.star.xml.sax.XDocumentHandler
57 * @see ifc.lang._XInitialization
58 * @see ifc.document._XImporter
59 * @see ifc.document._XFilter
60 * @see ifc.document._XExporter
61 * @see ifc.beans._XPropertySet
62 * @see ifc.xml.sax._XDocumentHandler
64 public class XMLMetaImporter
extends TestCase
{
65 private XSpreadsheetDocument xSheetDoc
;
66 static XComponent comp
;
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 Spreadsheet document" );
76 xSheetDoc
= SOF
.createCalcDoc( null );
77 comp
= UnoRuntime
.queryInterface
78 (XComponent
.class, xSheetDoc
) ;
79 } catch ( com
.sun
.star
.uno
.Exception e
) {
80 // Some exception occurs.FAILED
81 e
.printStackTrace( log
);
82 throw new StatusException( "Couldn't create document", e
);
87 * Spreadsheet document destroyed.
89 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
90 log
.println( " disposing document " );
91 util
.DesktopTools
.closeDoc(comp
);
95 * Creating a Testenvironment for the interfaces to be tested.
96 * Creates an instance of the service
97 * <code>com.sun.star.comp.Calc.XMLMetaImporter</code><p>
99 * The calc document is set as a target document for importer.
100 * Imported XML-data contains only meta tags including title tag
101 * with test title name.
102 * After import title name getting from
103 * target document is checked.
104 * Object relations created :
106 * <li> <code>'XDocumentHandler.XMLData'</code> for
107 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
108 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
109 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
110 * <li> <code>'TargetDocument'</code> for
111 * {@link ifc.document._XImporter} interface </li>
114 public synchronized TestEnvironment
createTestEnvironment( TestParameters tParam
,
116 throws StatusException
{
118 XInterface oObj
= null;
120 final String impTitle
= "XMLMetaImporter" ;
122 // creation of testobject here
123 // first we write what we are intend to do to log file
124 log
.println( "creating a test environment" );
126 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)tParam
.getMSF() ;
129 oInt
= xMSF
.createInstance
130 ("com.sun.star.comp.Calc.XMLMetaImporter") ;
131 XImporter imp
= UnoRuntime
.queryInterface
132 (XImporter
.class, oInt
) ;
133 imp
.setTargetDocument(comp
) ;
134 } catch (com
.sun
.star
.uno
.Exception e
) {
135 e
.printStackTrace(log
) ;
136 throw new StatusException("Can't create component.", e
) ;
139 oObj
= (XInterface
) oInt
;
141 // create testobject here
142 log
.println( "creating a new environment for Paragraph object" );
143 TestEnvironment tEnv
= new TestEnvironment( oObj
);
146 tEnv
.addObjRelation("TargetDocument", comp
) ;
148 // adding relation for XDocumentHandler
149 String
[][] xml
= new String
[][] {
150 {"start", "office:document-meta" ,
151 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
152 "xmlns:meta", "CDATA", "http://openoffice.org/2000/meta",
153 "xmlns:dc", "CDATA", "http://purl.org/dc/elements/1.1/"},
154 {"start", "office:meta"} ,
155 {"start", "dc:title"},
158 {"end", "office:meta"},
159 {"end", "office:document-meta"}} ;
161 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
163 XDocumentPropertiesSupplier xPropSup
= UnoRuntime
.queryInterface
164 (XDocumentPropertiesSupplier
.class, xSheetDoc
);
165 final XDocumentProperties xDocProps
= xPropSup
.getDocumentProperties();
166 final PrintWriter logF
= log
;
168 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
169 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
170 public boolean checkImport() {
171 String title
= xDocProps
.getTitle();
172 logF
.println("Title returned = '" + title
+ "'") ;
173 return impTitle
.equals(title
) ;
178 } // finish method getTestEnvironment