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.
67 protected void initialize( TestParameters tParam
, PrintWriter log
) {
68 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
71 log
.println( "creating a textdocument" );
72 xTextDoc
= SOF
.createTextDoc( null );
73 } catch ( com
.sun
.star
.uno
.Exception e
) {
74 // Some exception occurs.FAILED
75 e
.printStackTrace( log
);
76 throw new StatusException( "Couldn't create document", e
);
81 * Text document destroyed.
84 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
85 log
.println( " disposing xTextDoc " );
86 util
.DesktopTools
.closeDoc(xTextDoc
);
90 * Creating a Testenvironment for the interfaces to be tested.
91 * Creates an instance of the service
92 * <code>com.sun.star.comp.Writer.XMLContentImporter</code><p>
94 * The text document is set as a target document for importer.
95 * Imported XML-data contains only content tags including test text.
96 * After import text getting from target document is checked.
97 * Object relations created :
99 * <li> <code>'XDocumentHandler.XMLData'</code> for
100 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
101 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
102 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
103 * <li> <code>'TargetDocument'</code> for
104 * {@link ifc.document._XImporter} interface </li>
108 public synchronized TestEnvironment
createTestEnvironment( TestParameters tParam
,
110 throws StatusException
{
112 XInterface oObj
= null;
114 final String impText
= "XMLContentImporter test." ;
116 // creation of testobject here
117 // first we write what we are intend to do to log file
118 log
.println( "creating a test environment" );
120 XMultiServiceFactory xMSF
= tParam
.getMSF() ;
123 oInt
= xMSF
.createInstance
124 ("com.sun.star.comp.Writer.XMLContentImporter") ;
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