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.
72 protected void initialize( TestParameters tParam
, PrintWriter log
) {
73 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
76 log
.println( "creating a Spreadsheet document" );
77 xSheetDoc
= SOF
.createCalcDoc( null );
78 comp
= UnoRuntime
.queryInterface
79 (XComponent
.class, xSheetDoc
) ;
80 } catch ( com
.sun
.star
.uno
.Exception e
) {
81 // Some exception occurs.FAILED
82 e
.printStackTrace( log
);
83 throw new StatusException( "Couldn't create document", e
);
88 * Spreadsheet document destroyed.
91 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
92 log
.println( " disposing document " );
93 util
.DesktopTools
.closeDoc(comp
);
97 * Creating a Testenvironment for the interfaces to be tested.
98 * Creates an instance of the service
99 * <code>com.sun.star.comp.Calc.XMLMetaImporter</code><p>
101 * The calc document is set as a target document for importer.
102 * Imported XML-data contains only meta tags including title tag
103 * with test title name.
104 * After import title name getting from
105 * target document is checked.
106 * Object relations created :
108 * <li> <code>'XDocumentHandler.XMLData'</code> for
109 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
110 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
111 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
112 * <li> <code>'TargetDocument'</code> for
113 * {@link ifc.document._XImporter} interface </li>
117 public synchronized TestEnvironment
createTestEnvironment( TestParameters tParam
,
119 throws StatusException
{
121 XInterface oObj
= null;
123 final String impTitle
= "XMLMetaImporter" ;
125 // creation of testobject here
126 // first we write what we are intend to do to log file
127 log
.println( "creating a test environment" );
129 XMultiServiceFactory xMSF
= tParam
.getMSF() ;
132 oInt
= xMSF
.createInstance
133 ("com.sun.star.comp.Calc.XMLMetaImporter") ;
134 XImporter imp
= UnoRuntime
.queryInterface
135 (XImporter
.class, oInt
) ;
136 imp
.setTargetDocument(comp
) ;
137 } catch (com
.sun
.star
.uno
.Exception e
) {
138 e
.printStackTrace(log
) ;
139 throw new StatusException("Can't create component.", e
) ;
142 oObj
= (XInterface
) oInt
;
144 // create testobject here
145 log
.println( "creating a new environment for Paragraph object" );
146 TestEnvironment tEnv
= new TestEnvironment( oObj
);
149 tEnv
.addObjRelation("TargetDocument", comp
) ;
151 // adding relation for XDocumentHandler
152 String
[][] xml
= new String
[][] {
153 {"start", "office:document-meta" ,
154 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
155 "xmlns:meta", "CDATA", "http://openoffice.org/2000/meta",
156 "xmlns:dc", "CDATA", "http://purl.org/dc/elements/1.1/"},
157 {"start", "office:meta"} ,
158 {"start", "dc:title"},
161 {"end", "office:meta"},
162 {"end", "office:document-meta"}} ;
164 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
166 XDocumentPropertiesSupplier xPropSup
= UnoRuntime
.queryInterface
167 (XDocumentPropertiesSupplier
.class, xSheetDoc
);
168 final XDocumentProperties xDocProps
= xPropSup
.getDocumentProperties();
169 final PrintWriter logF
= log
;
171 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
172 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
173 public boolean checkImport() {
174 String title
= xDocProps
.getTitle();
175 logF
.println("Title returned = '" + title
+ "'") ;
176 return impTitle
.equals(title
) ;
181 } // finish method getTestEnvironment