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
;
24 import lib
.TestEnvironment
;
25 import lib
.TestParameters
;
26 import util
.SOfficeFactory
;
28 import com
.sun
.star
.document
.XDocumentPropertiesSupplier
;
29 import com
.sun
.star
.document
.XDocumentProperties
;
30 import com
.sun
.star
.lang
.XMultiServiceFactory
;
31 import com
.sun
.star
.text
.XTextDocument
;
32 import com
.sun
.star
.uno
.UnoRuntime
;
33 import com
.sun
.star
.uno
.XInterface
;
36 * Test for object which is represented by service
37 * <code>com.sun.star.comp.Writer.XMLMetaImporter</code>. <p>
38 * Object implements the following interfaces :
40 * <li><code>com::sun::star::lang::XInitialization</code></li>
41 * <li><code>com::sun::star::document::XImporter</code></li>
42 * <li><code>com::sun::star::document::XFilter</code></li>
43 * <li><code>com::sun::star::document::ImportFilter</code></li>
44 * <li><code>com::sun::star::beans::XPropertySet</code></li>
45 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
48 * @see com.sun.star.lang.XInitialization
49 * @see com.sun.star.document.XImporter
50 * @see com.sun.star.document.XFilter
51 * @see com.sun.star.document.ImportFilter
52 * @see com.sun.star.beans.XPropertySet
53 * @see com.sun.star.xml.sax.XDocumentHandler
54 * @see ifc.lang._XInitialization
55 * @see ifc.document._XImporter
56 * @see ifc.document._XFilter
57 * @see ifc.document._XExporter
58 * @see ifc.beans._XPropertySet
59 * @see ifc.xml.sax._XDocumentHandler
61 public class XMLMetaImporter
extends TestCase
{
62 XTextDocument xTextDoc
;
65 * New text document created.
68 protected void initialize( TestParameters tParam
, PrintWriter log
) throws Exception
{
69 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
71 log
.println( "creating a textdocument" );
72 xTextDoc
= SOF
.createTextDoc( null );
76 * Text document destroyed.
79 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
80 log
.println( " disposing xTextDoc " );
81 util
.DesktopTools
.closeDoc(xTextDoc
);
85 * Creating a TestEnvironment for the interfaces to be tested.
86 * Creates an instance of the service
87 * <code>com.sun.star.comp.Writer.XMLMetaImporter</code><p>
89 * The text document is set as a target document for importer.
90 * Imported XML-data contains only meta tags including
91 * title tag with test name.
92 * After import title name getting from target document is checked.
93 * Object relations created :
95 * <li> <code>'XDocumentHandler.XMLData'</code> for
96 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
97 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
98 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
99 * <li> <code>'TargetDocument'</code> for
100 * {@link ifc.document._XImporter} interface </li>
104 public TestEnvironment
createTestEnvironment( TestParameters tParam
,
108 XInterface oObj
= null;
110 final String impTitle
= "XMLMetaImporter test." ;
112 // creation of testobject here
113 // first we write what we are intend to do to log file
114 log
.println( "creating a test environment" );
116 XMultiServiceFactory xMSF
= tParam
.getMSF() ;
118 oInt
= xMSF
.createInstance
119 ("com.sun.star.comp.Writer.XMLMetaImporter") ;
121 oObj
= (XInterface
) oInt
;
123 // create testobject here
124 log
.println( "creating a new environment for Paragraph object" );
125 TestEnvironment tEnv
= new TestEnvironment( oObj
);
128 tEnv
.addObjRelation("TargetDocument", xTextDoc
) ;
130 // adding relation for XDocumentHandler
131 String
[][] xml
= new String
[][] {
132 {"start", "office:document-meta" ,
133 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
134 "xmlns:dc", "CDATA", "http://purl.org/dc/elements/1.1/"},
135 {"start", "office:meta"} ,
136 {"start", "dc:title"},
139 {"end", "office:meta"},
140 {"end", "office:document-meta"}} ;
142 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
144 XDocumentPropertiesSupplier xPropSup
= UnoRuntime
.queryInterface
145 (XDocumentPropertiesSupplier
.class, xTextDoc
);
146 final XDocumentProperties xDocProps
= xPropSup
.getDocumentProperties();
147 final PrintWriter logF
= log
;
149 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
150 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
151 public boolean checkImport() {
152 String title
= xDocProps
.getTitle();
153 logF
.println("Title returned = '" + title
+ "'") ;
154 return impTitle
.equals(title
) ;
159 } // finish method getTestEnvironment