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.chart.XChartDocument; 39 import com.sun.star.lang.XComponent; 40 import com.sun.star.lang.XMultiServiceFactory; 41 import com.sun.star.uno.XInterface; 42 43 /** 44 * Test for object which is represented by service 45 * <code>com.sun.star.comp.Chart.XMLStylesImporter</code>. <p> 46 * Object implements the following interfaces : 47 * <ul> 48 * <li><code>com::sun::star::lang::XInitialization</code></li> 49 * <li><code>com::sun::star::document::XImporter</code></li> 50 * <li><code>com::sun::star::document::XFilter</code></li> 51 * <li><code>com::sun::star::document::ImportFilter</code></li> 52 * <li><code>com::sun::star::beans::XPropertySet</code></li> 53 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li> 54 * </ul> 55 * @see com.sun.star.lang.XInitialization 56 * @see com.sun.star.document.XImporter 57 * @see com.sun.star.document.XFilter 58 * @see com.sun.star.document.ImportFilter 59 * @see com.sun.star.beans.XPropertySet 60 * @see com.sun.star.xml.sax.XDocumentHandler 61 * @see ifc.lang._XInitialization 62 * @see ifc.document._XImporter 63 * @see ifc.document._XFilter 64 * @see ifc.document._XExporter 65 * @see ifc.beans._XPropertySet 66 * @see ifc.xml.sax._XDocumentHandler 67 */ 68 public class XMLStylesImporter extends TestCase { 69 XComponent comp ; 70 XChartDocument xChartDoc = null; 71 72 /** 73 * New chart document created. 74 */ 75 protected void initialize( TestParameters tParam, PrintWriter log ) { 76 // get a soffice factory object 77 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF()); 78 79 try { 80 log.println( "creating a chartdocument" ); 81 xChartDoc = SOF.createChartDoc(null); 82 } catch ( Exception e ) { 83 // Some exception occures.FAILED 84 e.printStackTrace( log ); 85 throw new StatusException( "Couldn't create document", e ); 86 } 87 88 comp = xChartDoc; 89 } 90 91 /** 92 * Close document 93 */ 94 protected void cleanup( TestParameters tParam, PrintWriter log ) { 95 if( xChartDoc!=null ) { 96 log.println( " closing xChartDoc" ); 97 util.DesktopTools.closeDoc(xChartDoc); 98 xChartDoc = null; 99 comp = null; 100 } 101 } 102 103 /** 104 * Creating a Testenvironment for the interfaces to be tested. 105 * Creates an instance of the service 106 * <code>com.sun.star.comp.Chart.XMLStylesImporter</code><p> 107 * 108 * The chart document is set as a target document for importer. 109 * Object relations created : 110 * <ul> 111 * <li> <code>'XDocumentHandler.XMLData'</code> for 112 * {@link ifc.xml.sax._XDocumentHandler} interface </li> 113 * <li> <code>'XDocumentHandler.ImportChecker'</code> for 114 * {@link ifc.xml.sax._XDocumentHandler} interface </li> 115 * <li> <code>'TargetDocument'</code> for 116 * {@link ifc.document._XImporter} interface </li> 117 * </ul> 118 */ 119 public synchronized TestEnvironment createTestEnvironment 120 (TestParameters tParam, PrintWriter log) { 121 122 XInterface oObj = null; 123 Object oInt = null ; 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.Chart.XMLStylesImporter") ; 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", comp) ; 148 149 // adding relation for XDocumentHandler 150 String[][] xml = new String[][] { 151 {"start", "office:document-styles", 152 "xmlns:office", "CDATA", "http://openoffice.org/2000/office", 153 "xmlns:text", "CDATA", "http://openoffice.org/2000/text", 154 "xmlns:chart", "CDATA", "http://openoffice.org/2000/chart", 155 "xmlns:style", "CDATA", "http://openoffice.org/2000/style", 156 "xmlns:svg", "CDATA", "http://openoffice.org/2000/svg", 157 "office:class", "CDATA", "chart", 158 "office:version", "CDATA", "1.0" 159 }, 160 {"start", "office:styles"}, 161 {"end", "office:styles"}, 162 {"end", "office:document-styles"}} ; 163 164 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ; 165 166 final PrintWriter logF = log ; 167 168 tEnv.addObjRelation("XDocumentHandler.ImportChecker", 169 new ifc.xml.sax._XDocumentHandler.ImportChecker() { 170 public boolean checkImport() { 171 logF.println("No ways to check styles import were not found."); 172 logF.println(" TRUE returned."); 173 return true ; 174 /* } catch (com.sun.star.uno.Exception e) { 175 logF.println("Exception occured while checking filter :") ; 176 e.printStackTrace(logF) ; 177 return false ; 178 } 179 */ } 180 }) ; 181 182 183 return tEnv; 184 } // finish method getTestEnvironment 185 } 186