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 import util.XMLTools; 38 39 import com.sun.star.beans.XPropertySet; 40 import com.sun.star.chart.XChartDocument; 41 import com.sun.star.document.XExporter; 42 import com.sun.star.lang.XMultiServiceFactory; 43 import com.sun.star.uno.Any; 44 import com.sun.star.uno.Exception; 45 import com.sun.star.uno.Type; 46 import com.sun.star.uno.UnoRuntime; 47 import com.sun.star.uno.XInterface; 48 import com.sun.star.xml.sax.XDocumentHandler; 49 50 /** 51 * Test for object which is represented by service 52 * <code>com.sun.star.comp.Chart.XMLContentExporter</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::ExportFilter</code></li> 57 * <li><code>com::sun::star::document::XFilter</code></li> 58 * <li><code>com::sun::star::document::XExporter</code></li> 59 * <li><code>com::sun::star::beans::XPropertySet</code></li> 60 * </ul> 61 * @see com.sun.star.lang.XInitialization 62 * @see com.sun.star.document.ExportFilter 63 * @see com.sun.star.document.XFilter 64 * @see com.sun.star.document.XExporter 65 * @see com.sun.star.beans.XPropertySet 66 * @see ifc.lang._XInitialization 67 * @see ifc.document._ExportFilter 68 * @see ifc.document._XFilter 69 * @see ifc.document._XExporter 70 * @see ifc.beans._XPropertySet 71 */ 72 public class XMLContentExporter extends TestCase { 73 XChartDocument xChartDoc = null; 74 75 /** 76 * New text document created. 77 */ 78 protected void initialize( TestParameters tParam, PrintWriter log ) { 79 80 // get a soffice factory object 81 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF()); 82 83 try { 84 log.println( "creating a chartdocument" ); 85 xChartDoc = SOF.createChartDoc(null);; 86 } catch ( Exception e ) { 87 // Some exception occures.FAILED 88 e.printStackTrace( log ); 89 throw new StatusException( "Couldn't create document", e ); 90 } 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 } 102 } 103 104 /** 105 * Creating a Testenvironment for the interfaces to be tested. 106 * Creates an instance of the service 107 * <code>com.sun.star.comp.Chart.XMLContentExporter</code> with 108 * argument which is an implementation of <code>XDocumentHandler</code> 109 * and which can check if required tags and character data is 110 * exported. <p> 111 * The chart document is set as a source document for exporter 112 * created. A new 'main title' is set for chart. This made 113 * for checking if this title is successfully exported within 114 * the document content. 115 * Object relations created : 116 * <ul> 117 * <li> <code>'MediaDescriptor'</code> for 118 * {@link ifc.document._XFilter} interface </li> 119 * <li> <code>'XFilter.Checker'</code> for 120 * {@link ifc.document._XFilter} interface </li> 121 * <li> <code>'SourceDocument'</code> for 122 * {@link ifc.document._XExporter} interface </li> 123 * </ul> 124 */ 125 protected synchronized TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) { 126 127 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ; 128 XInterface oObj = null; 129 final String exportStr = "XMLContentExporter" ; 130 131 FilterChecker filter = new FilterChecker(log); 132 Any arg = new Any(new Type(XDocumentHandler.class),filter); 133 134 try { 135 oObj = (XInterface) xMSF.createInstanceWithArguments( 136 "com.sun.star.comp.Chart.XMLContentExporter", 137 new Object[] {arg}); 138 XExporter xEx = (XExporter) 139 UnoRuntime.queryInterface(XExporter.class,oObj); 140 xEx.setSourceDocument(xChartDoc); 141 142 Object oTitle = xChartDoc.getTitle() ; 143 XPropertySet xTitleProp = (XPropertySet) UnoRuntime.queryInterface 144 (XPropertySet.class, oTitle) ; 145 xTitleProp.setPropertyValue("String", exportStr) ; 146 } catch (com.sun.star.uno.Exception e) { 147 e.printStackTrace(log) ; 148 throw new StatusException("Can't create component.", e) ; 149 } 150 151 filter.addTag(new XMLTools.Tag("office:document-content")) ; 152 filter.addTagEnclosed(new XMLTools.Tag("office:body"), 153 new XMLTools.Tag("office:document-content")); 154 filter.addCharactersEnclosed(exportStr, 155 new XMLTools.Tag("chart:title")) ; 156 157 158 // create testobject here 159 log.println( "creating a new environment" ); 160 TestEnvironment tEnv = new TestEnvironment( oObj ); 161 162 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor( 163 new String[] {"FilterName"}, 164 new Object[] {"schart: StarOffice XML (Chart)"})); 165 tEnv.addObjRelation("SourceDocument",xChartDoc); 166 tEnv.addObjRelation("XFilter.Checker", filter) ; 167 log.println("Implementation Name: "+util.utils.getImplName(oObj)); 168 169 return tEnv; 170 171 } 172 173 /** 174 * This class checks the XML for tags and data required and returns 175 * checking result to <code>XFilter</code> interface test. All 176 * the information about errors occured in XML data is written 177 * to log specified. 178 * @see ifc.document._XFilter 179 */ 180 protected class FilterChecker extends XMLTools.XMLChecker 181 implements ifc.document._XFilter.FilterChecker { 182 183 /** 184 * Creates a class which will write information 185 * into log specified. 186 */ 187 public FilterChecker(PrintWriter log) { 188 super(log, true) ; 189 } 190 /** 191 * <code>_XFilter.FilterChecker</code> interface method 192 * which returns the result of XML checking. 193 * @return <code>true</code> if the XML data exported was 194 * valid (i.e. all necessary tags and character data exists), 195 * <code>false</code> if some errors occured. 196 */ 197 public boolean checkFilter() { 198 return check() ; 199 } 200 } 201 } 202