merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sw / XMLImporter.java
blob9c515bb056f83950f79f409b350ee059fc3b504c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: XMLImporter.java,v $
10 * $Revision: 1.7 $
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 ************************************************************************/
31 package mod._sw;
33 import java.io.PrintWriter;
35 import lib.StatusException;
36 import lib.TestCase;
37 import lib.TestEnvironment;
38 import lib.TestParameters;
39 import util.SOfficeFactory;
41 import com.sun.star.document.XImporter;
42 import com.sun.star.lang.XMultiServiceFactory;
43 import com.sun.star.text.XTextDocument;
44 import com.sun.star.uno.UnoRuntime;
45 import com.sun.star.uno.XInterface;
47 /**
48 * Test for object which is represented by service
49 * <code>com.sun.star.comp.Writer.XMLImporter</code>. <p>
50 * Object implements the following interfaces :
51 * <ul>
52 * <li><code>com::sun::star::lang::XInitialization</code></li>
53 * <li><code>com::sun::star::document::XImporter</code></li>
54 * <li><code>com::sun::star::document::XFilter</code></li>
55 * <li><code>com::sun::star::document::ImportFilter</code></li>
56 * <li><code>com::sun::star::beans::XPropertySet</code></li>
57 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
59 * </ul>
60 * @see com.sun.star.lang.XInitialization
61 * @see com.sun.star.document.XImporter
62 * @see com.sun.star.document.XFilter
63 * @see com.sun.star.document.ImportFilter
64 * @see com.sun.star.beans.XPropertySet
65 * @see com.sun.star.xml.sax.XDocumentHandler
66 * @see ifc.lang._XInitialization
67 * @see ifc.document._XImporter
68 * @see ifc.document._XFilter
69 * @see ifc.document._XExporter
70 * @see ifc.beans._XPropertySet
71 * @see ifc.xml.sax._XDocumentHandler
73 public class XMLImporter extends TestCase {
74 XTextDocument xTextDoc;
76 /**
77 * New text document created.
79 protected void initialize( TestParameters tParam, PrintWriter log ) {
80 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
82 try {
83 log.println( "creating a textdocument" );
84 xTextDoc = SOF.createTextDoc( null );
85 } catch ( com.sun.star.uno.Exception e ) {
86 // Some exception occures.FAILED
87 e.printStackTrace( log );
88 throw new StatusException( "Couldn't create document", e );
92 /**
93 * Text document destroyed.
95 protected void cleanup( TestParameters tParam, PrintWriter log ) {
96 log.println( " disposing xTextDoc " );
97 util.DesktopTools.closeDoc(xTextDoc);
101 * Creating a Testenvironment for the interfaces to be tested.
102 * Creates an instance of the service
103 * <code>com.sun.star.comp.Writer.XMLImporter</code><p>
105 * The text document is set as a target document for importer.
106 * Imported tags contain tag including tag with test text.
107 * After import text getting from target document is checked.
108 * Object relations created :
109 * <ul>
110 * <li> <code>'XDocumentHandler.XMLData'</code> for
111 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
112 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
113 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
114 * <li> <code>'TargetDocument'</code> for
115 * {@link ifc.document._XImporter} interface </li>
116 * </ul>
118 public synchronized TestEnvironment createTestEnvironment
119 ( TestParameters tParam, PrintWriter log) {
121 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ;
122 XInterface oObj = null;
124 try {
125 oObj = (XInterface) xMSF.createInstance
126 ("com.sun.star.comp.Writer.XMLImporter");
127 XImporter xIm = (XImporter) UnoRuntime.queryInterface
128 (XImporter.class,oObj);
129 xIm.setTargetDocument(xTextDoc);
130 } catch (com.sun.star.uno.Exception e) {
131 e.printStackTrace(log) ;
132 throw new StatusException("Can't create component.", e) ;
135 // create testobject here
136 log.println( "creating a new environment" );
137 TestEnvironment tEnv = new TestEnvironment( oObj );
139 final String impText = "XMLImporter test." ;
140 String[][] xml = new String[][] {
141 {"start", "office:document" ,
142 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
143 "office:class", "CDATA", "text",
144 "xmlns:text", "CDATA", "http://openoffice.org/2000/text"},
145 {"start", "office:body" },
146 {"start", "text:p" },
147 {"chars", impText},
148 {"end", "text:p"},
149 {"end", "office:body"},
150 {"end", "office:document"}} ;
152 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
154 tEnv.addObjRelation("TargetDocument",xTextDoc);
155 log.println("Implementation Name: "+util.utils.getImplName(oObj));
157 final XTextDocument textDoc = (XTextDocument) UnoRuntime.queryInterface
158 (XTextDocument.class, xTextDoc) ;
159 final PrintWriter fLog = log ;
160 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
161 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
162 public boolean checkImport() {
163 String docText = textDoc.getText().getString() ;
164 fLog.println("Document text returned = '" + docText + "'") ;
165 return impText.equals(docText) ;
167 }) ;
169 return tEnv;