merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / mod / _sc / XMLMetaImporter.java
blobf2c61af2040b266ff971ab471054c7fa82527192
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: XMLMetaImporter.java,v $
10 * $Revision: 1.8 $
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._sc;
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.beans.XPropertySet;
42 import com.sun.star.document.XDocumentInfoSupplier;
43 import com.sun.star.document.XImporter;
44 import com.sun.star.lang.XComponent;
45 import com.sun.star.lang.XMultiServiceFactory;
46 import com.sun.star.sheet.XSpreadsheetDocument;
47 import com.sun.star.uno.UnoRuntime;
48 import com.sun.star.uno.XInterface;
50 /**
51 * Test for object which is represented by service
52 * <code>com.sun.star.comp.Calc.XMLMetaImporter</code>. <p>
53 * Object implements the following interfaces :
54 * <ul>
55 * <li><code>com::sun::star::lang::XInitialization</code></li>
56 * <li><code>com::sun::star::document::XImporter</code></li>
57 * <li><code>com::sun::star::document::XFilter</code></li>
58 * <li><code>com::sun::star::document::ImportFilter</code></li>
59 * <li><code>com::sun::star::beans::XPropertySet</code></li>
60 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
62 * </ul>
63 * @see com.sun.star.lang.XInitialization
64 * @see com.sun.star.document.XImporter
65 * @see com.sun.star.document.XFilter
66 * @see com.sun.star.document.ImportFilter
67 * @see com.sun.star.beans.XPropertySet
68 * @see com.sun.star.xml.sax.XDocumentHandler
69 * @see ifc.lang._XInitialization
70 * @see ifc.document._XImporter
71 * @see ifc.document._XFilter
72 * @see ifc.document._XExporter
73 * @see ifc.beans._XPropertySet
74 * @see ifc.xml.sax._XDocumentHandler
76 public class XMLMetaImporter extends TestCase {
77 static XSpreadsheetDocument xSheetDoc;
78 static XComponent comp ;
80 /**
81 * New spreadsheet document created.
83 protected void initialize( TestParameters tParam, PrintWriter log ) {
84 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() );
86 try {
87 log.println( "creating a Spreadsheet document" );
88 xSheetDoc = SOF.createCalcDoc( null );
89 comp = (XComponent) UnoRuntime.queryInterface
90 (XComponent.class, xSheetDoc) ;
91 } catch ( com.sun.star.uno.Exception e ) {
92 // Some exception occures.FAILED
93 e.printStackTrace( log );
94 throw new StatusException( "Couldn't create document", e );
98 /**
99 * Spreadsheet document destroyed.
101 protected void cleanup( TestParameters tParam, PrintWriter log ) {
102 log.println( " disposing document " );
103 util.DesktopTools.closeDoc(comp);
107 * Creating a Testenvironment for the interfaces to be tested.
108 * Creates an instance of the service
109 * <code>com.sun.star.comp.Calc.XMLMetaImporter</code><p>
111 * The calc document is set as a target document for importer.
112 * Imported XML-data contains only meta tags including title tag
113 * with test title name.
114 * After import title name getting from
115 * target document is checked.
116 * Object relations created :
117 * <ul>
118 * <li> <code>'XDocumentHandler.XMLData'</code> for
119 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
120 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
121 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
122 * <li> <code>'TargetDocument'</code> for
123 * {@link ifc.document._XImporter} interface </li>
124 * </ul>
126 public synchronized TestEnvironment createTestEnvironment( TestParameters tParam,
127 PrintWriter log )
128 throws StatusException {
130 XInterface oObj = null;
131 Object oInt = null ;
132 final String impTitle = "XMLMetaImporter" ;
134 // creation of testobject here
135 // first we write what we are intend to do to log file
136 log.println( "creating a test environment" );
138 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ;
140 try {
141 oInt = xMSF.createInstance
142 ("com.sun.star.comp.Calc.XMLMetaImporter") ;
143 XImporter imp = (XImporter) UnoRuntime.queryInterface
144 (XImporter.class, oInt) ;
145 imp.setTargetDocument(comp) ;
146 } catch (com.sun.star.uno.Exception e) {
147 e.printStackTrace(log) ;
148 throw new StatusException("Can't create component.", e) ;
151 oObj = (XInterface) oInt ;
153 // create testobject here
154 log.println( "creating a new environment for Paragraph object" );
155 TestEnvironment tEnv = new TestEnvironment( oObj );
157 // adding relation
158 tEnv.addObjRelation("TargetDocument", comp) ;
160 // adding relation for XDocumentHandler
161 String[][] xml = new String[][] {
162 {"start", "office:document-meta" ,
163 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
164 "xmlns:meta", "CDATA", "http://openoffice.org/2000/meta",
165 "xmlns:dc", "CDATA", "http://purl.org/dc/elements/1.1/"},
166 {"start", "office:meta"} ,
167 {"start", "dc:title"},
168 {"chars", impTitle},
169 {"end", "dc:title"},
170 {"end", "office:meta"},
171 {"end", "office:document-meta"}} ;
173 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
175 XDocumentInfoSupplier infoSup = (XDocumentInfoSupplier)
176 UnoRuntime.queryInterface(XDocumentInfoSupplier.class, xSheetDoc) ;
177 final XPropertySet docInfo = (XPropertySet) UnoRuntime.queryInterface
178 (XPropertySet.class, infoSup.getDocumentInfo()) ;
179 final PrintWriter logF = log ;
181 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
182 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
183 public boolean checkImport() {
184 try {
185 String title = (String) docInfo.getPropertyValue
186 ("Title") ;
187 logF.println("Title returned = '" + title + "'") ;
188 return impTitle.equals(title) ;
189 } catch (com.sun.star.uno.Exception e) {
190 logF.println("Exception occured while checking filter :") ;
191 e.printStackTrace(logF) ;
192 return false ;
195 }) ;
197 return tEnv;
198 } // finish method getTestEnvironment