1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLContentImporter.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 import java
.io
.PrintWriter
;
35 import lib
.StatusException
;
37 import lib
.TestEnvironment
;
38 import lib
.TestParameters
;
39 import util
.SOfficeFactory
;
41 import com
.sun
.star
.lang
.XMultiServiceFactory
;
42 import com
.sun
.star
.text
.XTextDocument
;
43 import com
.sun
.star
.uno
.UnoRuntime
;
44 import com
.sun
.star
.uno
.XInterface
;
47 * Test for object which is represented by service
48 * <code>com.sun.star.comp.Writer.XMLContentImporter</code>. <p>
49 * Object implements the following interfaces :
51 * <li><code>com::sun::star::lang::XInitialization</code></li>
52 * <li><code>com::sun::star::document::XImporter</code></li>
53 * <li><code>com::sun::star::document::XFilter</code></li>
54 * <li><code>com::sun::star::document::ImportFilter</code></li>
55 * <li><code>com::sun::star::beans::XPropertySet</code></li>
56 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
59 * @see com.sun.star.lang.XInitialization
60 * @see com.sun.star.document.XImporter
61 * @see com.sun.star.document.XFilter
62 * @see com.sun.star.document.ImportFilter
63 * @see com.sun.star.beans.XPropertySet
64 * @see com.sun.star.xml.sax.XDocumentHandler
65 * @see ifc.lang._XInitialization
66 * @see ifc.document._XImporter
67 * @see ifc.document._XFilter
68 * @see ifc.document._XExporter
69 * @see ifc.beans._XPropertySet
70 * @see ifc.xml.sax._XDocumentHandler
72 public class XMLContentImporter
extends TestCase
{
73 XTextDocument xTextDoc
;
76 * New text document created.
78 protected void initialize( TestParameters tParam
, PrintWriter log
) {
79 SOfficeFactory SOF
= SOfficeFactory
.getFactory( (XMultiServiceFactory
)tParam
.getMSF() );
82 log
.println( "creating a textdocument" );
83 xTextDoc
= SOF
.createTextDoc( null );
84 } catch ( com
.sun
.star
.uno
.Exception e
) {
85 // Some exception occures.FAILED
86 e
.printStackTrace( log
);
87 throw new StatusException( "Couldn't create document", e
);
92 * Text document destroyed.
94 protected void cleanup( TestParameters tParam
, PrintWriter log
) {
95 log
.println( " disposing xTextDoc " );
96 util
.DesktopTools
.closeDoc(xTextDoc
);
100 * Creating a Testenvironment for the interfaces to be tested.
101 * Creates an instance of the service
102 * <code>com.sun.star.comp.Writer.XMLContentImporter</code><p>
104 * The text document is set as a target document for importer.
105 * Imported XML-data contains only content tags including test text.
106 * After import text getting from target document is checked.
107 * Object relations created :
109 * <li> <code>'XDocumentHandler.XMLData'</code> for
110 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
111 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
112 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
113 * <li> <code>'TargetDocument'</code> for
114 * {@link ifc.document._XImporter} interface </li>
117 public synchronized TestEnvironment
createTestEnvironment( TestParameters tParam
,
119 throws StatusException
{
121 XInterface oObj
= null;
123 final String impText
= "XMLContentImporter test." ;
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
= (XMultiServiceFactory
)tParam
.getMSF() ;
132 oInt
= xMSF
.createInstance
133 ("com.sun.star.comp.Writer.XMLContentImporter") ;
134 //XImporter imp = (XImporter) UnoRuntime.queryInterface
135 // (XImporter.class, oInt) ;
136 //imp.setTargetDocument(xTextDoc) ;
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", xTextDoc
) ;
151 // adding relation for XDocumentHandler
152 String
[][] xml
= new String
[][] {
153 {"start", "office:document-content",
154 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
155 "xmlns:text", "CDATA", "http://openoffice.org/2000/text"
157 {"start", "office:body"},
161 {"end", "office:body"},
162 {"end", "office:document-content"}} ;
164 tEnv
.addObjRelation("XDocumentHandler.XMLData", xml
) ;
166 final XTextDocument textDoc
= (XTextDocument
) UnoRuntime
.queryInterface
167 (XTextDocument
.class, xTextDoc
) ;
168 final PrintWriter fLog
= log
;
169 tEnv
.addObjRelation("XDocumentHandler.ImportChecker",
170 new ifc
.xml
.sax
._XDocumentHandler
.ImportChecker() {
171 public boolean checkImport() {
172 String docText
= textDoc
.getText().getString() ;
173 fLog
.println("Document text returned = '" + docText
+ "'") ;
174 return impText
.equals(docText
) ;
179 } // finish method getTestEnvironment