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
.lang
.XMultiServiceFactory
;
30 import com
.sun
.star
.text
.XTextDocument
;
31 import com
.sun
.star
.uno
.UnoRuntime
;
32 import com
.sun
.star
.uno
.XInterface
;
35 * Test for object which is represented by service
36 * <code>com.sun.star.comp.Writer.XMLContentImporter</code>. <p>
37 * Object implements the following interfaces :
39 * <li><code>com::sun::star::lang::XInitialization</code></li>
40 * <li><code>com::sun::star::document::XImporter</code></li>
41 * <li><code>com::sun::star::document::XFilter</code></li>
42 * <li><code>com::sun::star::document::ImportFilter</code></li>
43 * <li><code>com::sun::star::beans::XPropertySet</code></li>
44 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
47 * @see com.sun.star.lang.XInitialization
48 * @see com.sun.star.document.XImporter
49 * @see com.sun.star.document.XFilter
50 * @see com.sun.star.document.ImportFilter
51 * @see com.sun.star.beans.XPropertySet
52 * @see com.sun.star.xml.sax.XDocumentHandler
53 * @see ifc.lang._XInitialization
54 * @see ifc.document._XImporter
55 * @see ifc.document._XFilter
56 * @see ifc.document._XExporter
57 * @see ifc.beans._XPropertySet
58 * @see ifc.xml.sax._XDocumentHandler
60 public class XMLContentImporter
extends TestCase
{
61 XTextDocument xTextDoc
;
64 * New text document created.
66 protected void initialize( TestParameters tParam
, PrintWriter log
) {
67 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
70 log
.println( "creating a textdocument" );
71 xTextDoc
= SOF
.createTextDoc( null );
72 } catch ( com
.sun
.star
.uno
.Exception e
) {
73 // Some exception occurs.FAILED
74 e
.printStackTrace( log
);
75 throw new StatusException( "Couldn't create document", e
);
80 * Text document destroyed.
82 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
83 log
.println( " disposing xTextDoc " );
84 util
.DesktopTools
.closeDoc(xTextDoc
);
88 * Creating a Testenvironment for the interfaces to be tested.
89 * Creates an instance of the service
90 * <code>com.sun.star.comp.Writer.XMLContentImporter</code><p>
92 * The text document is set as a target document for importer.
93 * Imported XML-data contains only content tags including test text.
94 * After import text getting from target document is checked.
95 * Object relations created :
97 * <li> <code>'XDocumentHandler.XMLData'</code> for
98 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
99 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
100 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
101 * <li> <code>'TargetDocument'</code> for
102 * {@link ifc.document._XImporter} interface </li>
105 public synchronized TestEnvironment
createTestEnvironment( TestParameters tParam
,
107 throws StatusException
{
109 XInterface oObj
= null;
111 final String impText
= "XMLContentImporter test." ;
113 // creation of testobject here
114 // first we write what we are intend to do to log file
115 log
.println( "creating a test environment" );
117 XMultiServiceFactory xMSF
= (XMultiServiceFactory
)tParam
.getMSF() ;
120 oInt
= xMSF
.createInstance
121 ("com.sun.star.comp.Writer.XMLContentImporter") ;
122 //XImporter imp = (XImporter) UnoRuntime.queryInterface
123 // (XImporter.class, oInt) ;
124 //imp.setTargetDocument(xTextDoc) ;
125 } catch (com
.sun
.star
.uno
.Exception e
) {
126 e
.printStackTrace(log
) ;
127 throw new StatusException("Can't create component.", e
) ;
130 oObj
= (XInterface
) oInt
;
132 // create testobject here
133 log
.println( "creating a new environment for Paragraph object" );
134 TestEnvironment tEnv
= new TestEnvironment( oObj
);
137 tEnv
.addObjRelation("TargetDocument", xTextDoc
) ;
139 // adding relation for XDocumentHandler
140 String
[][] xml
= new String
[][] {
141 {"start", "office:document-content",
142 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
143 "xmlns:text", "CDATA", "http://openoffice.org/2000/text"
145 {"start", "office:body"},
149 {"end", "office:body"},
150 {"end", "office:document-content"}} ;
152 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
154 final XTextDocument textDoc
= UnoRuntime
.queryInterface
155 (XTextDocument
.class, xTextDoc
) ;
156 final PrintWriter fLog
= log
;
157 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
158 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
159 public boolean checkImport() {
160 String docText
= textDoc
.getText().getString() ;
161 fLog
.println("Document text returned = '" + docText
+ "'") ;
162 return impText
.equals(docText
) ;
167 } // finish method getTestEnvironment