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.Chart; 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.chart.XChartDocument; 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.Chart.XMLImporter</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 XMLImporter extends TestCase { 71 XComponent comp ; 72 XChartDocument xChartDoc = null; 73 74 /** 75 * New chart document created. 76 */ 77 protected void initialize( TestParameters tParam, PrintWriter log ) { 78 // get a soffice factory object 79 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF()); 80 81 try { 82 log.println( "creating a chartdocument" ); 83 xChartDoc = SOF.createChartDoc(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 comp = xChartDoc; 91 } 92 93 /** 94 * Close document 95 */ 96 protected void cleanup( TestParameters tParam, PrintWriter log ) { 97 if( xChartDoc!=null ) { 98 log.println( " closing xChartDoc" ); 99 util.DesktopTools.closeDoc(xChartDoc); 100 xChartDoc = null; 101 comp = null; 102 } 103 } 104 105 /** 106 * Creating a Testenvironment for the interfaces to be tested. 107 * Creates an instance of the service 108 * <code>com.sun.star.comp.Chart.XMLImporter</code><p> 109 * 110 * The chart document is set as a target document for importer. 111 * Imported XML-data contains the tag which specifies the title 112 * of a chart. 113 * After import title name getting from target document is checked. 114 * Object relations created : 115 * <ul> 116 * <li> <code>'XDocumentHandler.XMLData'</code> for 117 * {@link ifc.xml.sax._XDocumentHandler} interface </li> 118 * <li> <code>'XDocumentHandler.ImportChecker'</code> for 119 * {@link ifc.xml.sax._XDocumentHandler} interface </li> 120 * <li> <code>'TargetDocument'</code> for 121 * {@link ifc.document._XImporter} interface </li> 122 * </ul> 123 */ 124 public synchronized TestEnvironment createTestEnvironment 125 (TestParameters tParam, PrintWriter log) { 126 127 XInterface oObj = null; 128 Object oInt = null ; 129 final String impValue = "XMLImporter_test" ; 130 131 // creation of testobject here 132 // first we write what we are intend to do to log file 133 log.println( "creating a test environment" ); 134 135 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ; 136 137 final XPropertySet xTitleProp ; 138 try { 139 oInt = xMSF.createInstance("com.sun.star.comp.Chart.XMLImporter") ; 140 141 Object oTitle = xChartDoc.getTitle() ; 142 xTitleProp = (XPropertySet) UnoRuntime.queryInterface 143 (XPropertySet.class, oTitle) ; 144 } catch (com.sun.star.uno.Exception e) { 145 e.printStackTrace(log) ; 146 throw new StatusException("Can't create component.", e) ; 147 } 148 149 oObj = (XInterface) oInt ; 150 151 // create testobject here 152 log.println( "creating a new environment for Paragraph object" ); 153 TestEnvironment tEnv = new TestEnvironment( oObj ); 154 155 // adding relation 156 tEnv.addObjRelation("TargetDocument", comp) ; 157 158 // adding relation for XDocumentHandler 159 String[][] xml = new String[][] { 160 {"start", "office:document", 161 "xmlns:office", "CDATA", "http://openoffice.org/2000/office", 162 "xmlns:text", "CDATA", "http://openoffice.org/2000/text", 163 "xmlns:chart", "CDATA", "http://openoffice.org/2000/chart", 164 "xmlns:table", "CDATA", "http://openoffice.org/2000/table", 165 "xmlns:svg", "CDATA", "http://openoffice.org/2000/svg", 166 "office:class", "CDATA", "chart" 167 ,"office:version", "CDATA", "1.0" 168 }, 169 {"start", "office:body"}, 170 {"start", "chart:chart"}, 171 {"start", "chart:title"}, 172 {"start", "text:p"}, 173 {"chars", impValue}, 174 {"end", "text:p"}, 175 {"end", "chart:title"}, 176 {"end", "chart:chart"}, 177 {"end", "office:body"}, 178 {"end", "office:document-content"}} ; 179 180 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ; 181 182 final PrintWriter logF = log ; 183 184 tEnv.addObjRelation("XDocumentHandler.ImportChecker", 185 new ifc.xml.sax._XDocumentHandler.ImportChecker() { 186 public boolean checkImport() { 187 try { 188 String title = (String) 189 xTitleProp.getPropertyValue("String") ; 190 logF.println("Title returned = '" + title + "'") ; 191 return impValue.equals(title) ; 192 } catch (com.sun.star.uno.Exception e) { 193 logF.println 194 ("Exception occured while checking filter :") ; 195 e.printStackTrace(logF) ; 196 return false ; 197 } 198 } 199 }) ; 200 201 202 return tEnv; 203 } // finish method getTestEnvironment 204 } 205