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
.lang
.XMultiServiceFactory
;
29 import com
.sun
.star
.text
.XTextDocument
;
30 import com
.sun
.star
.uno
.UnoRuntime
;
31 import com
.sun
.star
.uno
.XInterface
;
34 * Test for object which is represented by service
35 * <code>com.sun.star.comp.Writer.XMLContentImporter</code>. <p>
36 * Object implements the following interfaces :
38 * <li><code>com::sun::star::lang::XInitialization</code></li>
39 * <li><code>com::sun::star::document::XImporter</code></li>
40 * <li><code>com::sun::star::document::XFilter</code></li>
41 * <li><code>com::sun::star::document::ImportFilter</code></li>
42 * <li><code>com::sun::star::beans::XPropertySet</code></li>
43 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
46 * @see com.sun.star.lang.XInitialization
47 * @see com.sun.star.document.XImporter
48 * @see com.sun.star.document.XFilter
49 * @see com.sun.star.document.ImportFilter
50 * @see com.sun.star.beans.XPropertySet
51 * @see com.sun.star.xml.sax.XDocumentHandler
52 * @see ifc.lang._XInitialization
53 * @see ifc.document._XImporter
54 * @see ifc.document._XFilter
55 * @see ifc.document._XExporter
56 * @see ifc.beans._XPropertySet
57 * @see ifc.xml.sax._XDocumentHandler
59 public class XMLContentImporter
extends TestCase
{
60 XTextDocument xTextDoc
;
63 * New text document created.
66 protected void initialize( TestParameters tParam
, PrintWriter log
) throws Exception
{
67 SOfficeFactory SOF
= SOfficeFactory
.getFactory( tParam
.getMSF() );
69 log
.println( "creating a textdocument" );
70 xTextDoc
= SOF
.createTextDoc( null );
74 * Text document destroyed.
77 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
78 log
.println( " disposing xTextDoc " );
79 util
.DesktopTools
.closeDoc(xTextDoc
);
83 * Creating a TestEnvironment for the interfaces to be tested.
84 * Creates an instance of the service
85 * <code>com.sun.star.comp.Writer.XMLContentImporter</code><p>
87 * The text document is set as a target document for importer.
88 * Imported XML-data contains only content tags including test text.
89 * After import text getting from target document is checked.
90 * Object relations created :
92 * <li> <code>'XDocumentHandler.XMLData'</code> for
93 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
94 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
95 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
96 * <li> <code>'TargetDocument'</code> for
97 * {@link ifc.document._XImporter} interface </li>
101 public TestEnvironment
createTestEnvironment( TestParameters tParam
,
105 XInterface oObj
= null;
107 final String impText
= "XMLContentImporter test." ;
109 // creation of testobject here
110 // first we write what we are intend to do to log file
111 log
.println( "creating a test environment" );
113 XMultiServiceFactory xMSF
= tParam
.getMSF() ;
115 oInt
= xMSF
.createInstance
116 ("com.sun.star.comp.Writer.XMLContentImporter") ;
118 oObj
= (XInterface
) oInt
;
120 // create testobject here
121 log
.println( "creating a new environment for Paragraph object" );
122 TestEnvironment tEnv
= new TestEnvironment( oObj
);
125 tEnv
.addObjRelation("TargetDocument", xTextDoc
) ;
127 // adding relation for XDocumentHandler
128 String
[][] xml
= new String
[][] {
129 {"start", "office:document-content",
130 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
131 "xmlns:text", "CDATA", "http://openoffice.org/2000/text"
133 {"start", "office:body"},
137 {"end", "office:body"},
138 {"end", "office:document-content"}} ;
140 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
142 final XTextDocument textDoc
= UnoRuntime
.queryInterface
143 (XTextDocument
.class, xTextDoc
) ;
144 final PrintWriter fLog
= log
;
145 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
146 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
147 public boolean checkImport() {
148 String docText
= textDoc
.getText().getString() ;
149 fLog
.println("Document text returned = '" + docText
+ "'") ;
150 return impText
.equals(docText
) ;
155 } // finish method getTestEnvironment