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._sw; 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.XMultiServiceFactory; 41 import com.sun.star.text.XTextDocument; 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.Writer.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 57 * </ul> 58 * @see com.sun.star.lang.XInitialization 59 * @see com.sun.star.document.XImporter 60 * @see com.sun.star.document.XFilter 61 * @see com.sun.star.document.ImportFilter 62 * @see com.sun.star.beans.XPropertySet 63 * @see com.sun.star.xml.sax.XDocumentHandler 64 * @see ifc.lang._XInitialization 65 * @see ifc.document._XImporter 66 * @see ifc.document._XFilter 67 * @see ifc.document._XExporter 68 * @see ifc.beans._XPropertySet 69 * @see ifc.xml.sax._XDocumentHandler 70 */ 71 public class XMLMetaImporter extends TestCase { 72 XTextDocument xTextDoc; 73 74 /** 75 * New text document created. 76 */ 77 protected void initialize( TestParameters tParam, PrintWriter log ) { 78 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 79 80 try { 81 log.println( "creating a textdocument" ); 82 xTextDoc = SOF.createTextDoc( null ); 83 } catch ( com.sun.star.uno.Exception e ) { 84 // Some exception occures.FAILED 85 e.printStackTrace( log ); 86 throw new StatusException( "Couldn't create document", e ); 87 } 88 } 89 90 /** 91 * Text document destroyed. 92 */ 93 protected void cleanup( TestParameters tParam, PrintWriter log ) { 94 log.println( " disposing xTextDoc " ); 95 util.DesktopTools.closeDoc(xTextDoc); 96 } 97 98 /** 99 * Creating a Testenvironment for the interfaces to be tested. 100 * Creates an instance of the service 101 * <code>com.sun.star.comp.Writer.XMLMetaImporter</code><p> 102 * 103 * The text document is set as a target document for importer. 104 * Imported XML-data contains only meta tags including 105 * title tag with test name. 106 * After import title name getting from target document is checked. 107 * Object relations created : 108 * <ul> 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> 115 * </ul> 116 */ 117 public synchronized TestEnvironment createTestEnvironment( TestParameters tParam, 118 PrintWriter log ) 119 throws StatusException { 120 121 XInterface oObj = null; 122 Object oInt = null ; 123 final String impTitle = "XMLMetaImporter 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.Writer.XMLMetaImporter") ; 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) ; 140 } 141 142 oObj = (XInterface) oInt ; 143 144 // create testobject here 145 log.println( "creating a new environment for Paragraph object" ); 146 TestEnvironment tEnv = new TestEnvironment( oObj ); 147 148 // adding relation 149 tEnv.addObjRelation("TargetDocument", xTextDoc) ; 150 151 // adding relation for XDocumentHandler 152 String[][] xml = new String[][] { 153 {"start", "office:document-meta" , 154 "xmlns:office", "CDATA", "http://openoffice.org/2000/office", 155 "xmlns:dc", "CDATA", "http://purl.org/dc/elements/1.1/"}, 156 {"start", "office:meta"} , 157 {"start", "dc:title"}, 158 {"chars", impTitle}, 159 {"end", "dc:title"}, 160 {"end", "office:meta"}, 161 {"end", "office:document-meta"}} ; 162 163 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ; 164 165 XDocumentInfoSupplier infoSup = (XDocumentInfoSupplier) UnoRuntime.queryInterface 166 (XDocumentInfoSupplier.class, xTextDoc) ; 167 final XPropertySet docInfo = (XPropertySet) UnoRuntime.queryInterface 168 (XPropertySet.class, infoSup.getDocumentInfo()) ; 169 final PrintWriter logF = log ; 170 171 tEnv.addObjRelation("XDocumentHandler.ImportChecker", 172 new ifc.xml.sax._XDocumentHandler.ImportChecker() { 173 public boolean checkImport() { 174 try { 175 String title = (String) 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