1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package mod._xmloff.Impress; 29 30 import java.io.PrintWriter; 31 32 import lib.StatusException; 33 import lib.TestCase; 34 import lib.TestEnvironment; 35 import lib.TestParameters; 36 import util.SOfficeFactory; 37 38 import com.sun.star.beans.XPropertySet; 39 import com.sun.star.document.XDocumentInfoSupplier; 40 import com.sun.star.lang.XComponent; 41 import com.sun.star.lang.XMultiServiceFactory; 42 import com.sun.star.uno.UnoRuntime; 43 import com.sun.star.uno.XInterface; 44 45 /** 46 * Test for object which is represented by service 47 * <code>com.sun.star.comp.Impress.XMLMetaImporter</code>. <p> 48 * Object implements the following interfaces : 49 * <ul> 50 * <li><code>com::sun::star::lang::XInitialization</code></li> 51 * <li><code>com::sun::star::document::XImporter</code></li> 52 * <li><code>com::sun::star::document::XFilter</code></li> 53 * <li><code>com::sun::star::document::ImportFilter</code></li> 54 * <li><code>com::sun::star::beans::XPropertySet</code></li> 55 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li> 56 * </ul> 57 * @see com.sun.star.lang.XInitialization 58 * @see com.sun.star.document.XImporter 59 * @see com.sun.star.document.XFilter 60 * @see com.sun.star.document.ImportFilter 61 * @see com.sun.star.beans.XPropertySet 62 * @see com.sun.star.xml.sax.XDocumentHandler 63 * @see ifc.lang._XInitialization 64 * @see ifc.document._XImporter 65 * @see ifc.document._XFilter 66 * @see ifc.document._XExporter 67 * @see ifc.beans._XPropertySet 68 * @see ifc.xml.sax._XDocumentHandler 69 */ 70 public class XMLMetaImporter extends TestCase { 71 XComponent xImpressDoc = null; 72 73 /** 74 * New impress document created. 75 */ 76 protected void initialize( TestParameters tParam, PrintWriter log ) { 77 78 // get a soffice factory object 79 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF()); 80 81 try { 82 log.println( "creating an impress document" ); 83 xImpressDoc = SOF.createImpressDoc(null);; 84 } catch ( Exception e ) { 85 // Some exception occures.FAILED 86 e.printStackTrace( log ); 87 throw new StatusException( "Couldn't create document", e ); 88 } 89 } 90 91 /** 92 * Impress document destroyed. 93 */ 94 protected void cleanup( TestParameters tParam, PrintWriter log ) { 95 log.println( " disposing document " ); 96 xImpressDoc.dispose(); 97 } 98 99 /** 100 * Creating a Testenvironment for the interfaces to be tested. 101 * Creates an instance of the service 102 * <code>com.sun.star.comp.Impress.XMLMetaImporter</code><p> 103 * 104 * The impress document is set as a target document for importer. 105 * Imported XML-data contains only meta tags including title tag 106 * with test title name. After import title name getting from 107 * 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> 117 */ 118 public synchronized TestEnvironment createTestEnvironment 119 (TestParameters tParam,PrintWriter log ) throws StatusException { 120 121 XInterface oObj = null; 122 Object oInt = null ; 123 final String impTitle = "XMLImporter_test" ; 124 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" ); 128 129 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ; 130 131 try { 132 oInt = xMSF.createInstance 133 ("com.sun.star.comp.Impress.XMLMetaImporter") ; 134 135 } catch (com.sun.star.uno.Exception e) { 136 e.printStackTrace(log) ; 137 throw new StatusException("Can't create component.", e) ; 138 } 139 140 oObj = (XInterface) oInt ; 141 142 // create testobject here 143 log.println( "creating a new environment for Paragraph object" ); 144 TestEnvironment tEnv = new TestEnvironment( oObj ); 145 146 // adding relation 147 tEnv.addObjRelation("TargetDocument", xImpressDoc) ; 148 149 // adding relation for XDocumentHandler 150 String[][] xml = new String[][] { 151 {"start", "office:document-meta" , 152 "xmlns:office", "CDATA", "http://openoffice.org/2000/office", 153 "xmlns:dc", "CDATA", "http://purl.org/dc/elements/1.1/"}, 154 {"start", "office:meta"} , 155 {"start", "dc:title"}, 156 {"chars", impTitle}, 157 {"end", "dc:title"}, 158 {"end", "office:meta"}, 159 {"end", "office:document-meta"}} ; 160 161 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ; 162 163 XDocumentInfoSupplier infoSup = (XDocumentInfoSupplier) 164 UnoRuntime.queryInterface 165 (XDocumentInfoSupplier.class, xImpressDoc) ; 166 final XPropertySet docInfo = (XPropertySet) UnoRuntime.queryInterface 167 (XPropertySet.class, infoSup.getDocumentInfo()) ; 168 final PrintWriter logF = log ; 169 170 tEnv.addObjRelation("XDocumentHandler.ImportChecker", 171 new ifc.xml.sax._XDocumentHandler.ImportChecker() { 172 public boolean checkImport() { 173 try { 174 String title = (String) 175 docInfo.getPropertyValue("Title") ; 176 logF.println("Title returned = '" + title + "'") ; 177 return impTitle.equals(title) ; 178 } catch (com.sun.star.uno.Exception e) { 179 logF.println("Exception occured while checking filter :") ; 180 e.printStackTrace(logF) ; 181 return false ; 182 } 183 } 184 } ); 185 186 return tEnv; 187 } // finish method getTestEnvironment 188 189 } 190