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 import util.XMLTools; 38 39 import com.sun.star.beans.XPropertySet; 40 import com.sun.star.document.XExporter; 41 import com.sun.star.frame.XController; 42 import com.sun.star.frame.XModel; 43 import com.sun.star.lang.XComponent; 44 import com.sun.star.lang.XMultiServiceFactory; 45 import com.sun.star.uno.Any; 46 import com.sun.star.uno.Exception; 47 import com.sun.star.uno.Type; 48 import com.sun.star.uno.UnoRuntime; 49 import com.sun.star.uno.XInterface; 50 import com.sun.star.xml.sax.XDocumentHandler; 51 52 /** 53 * Test for object which is represented by service 54 * <code>com.sun.star.comp.Impress.XMLSettingsExporter</code>. <p> 55 * Object implements the following interfaces : 56 * <ul> 57 * <li><code>com::sun::star::lang::XInitialization</code></li> 58 * <li><code>com::sun::star::document::ExportFilter</code></li> 59 * <li><code>com::sun::star::document::XFilter</code></li> 60 * <li><code>com::sun::star::document::XExporter</code></li> 61 * <li><code>com::sun::star::beans::XPropertySet</code></li> 62 * </ul> 63 * @see com.sun.star.lang.XInitialization 64 * @see com.sun.star.document.ExportFilter 65 * @see com.sun.star.document.XFilter 66 * @see com.sun.star.document.XExporter 67 * @see com.sun.star.beans.XPropertySet 68 * @see ifc.lang._XInitialization 69 * @see ifc.document._ExportFilter 70 * @see ifc.document._XFilter 71 * @see ifc.document._XExporter 72 * @see ifc.beans._XPropertySet 73 */ 74 public class XMLSettingsExporter extends TestCase { 75 XComponent xImpressDoc = null; 76 77 /** 78 * New text document created. 79 */ 80 protected void initialize( TestParameters tParam, PrintWriter log ) { 81 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF()); 82 83 try { 84 log.println( "creating an impress document" ); 85 xImpressDoc = SOF.createImpressDoc(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 * Document disposed here. 95 */ 96 protected void cleanup( TestParameters tParam, PrintWriter log ) { 97 log.println( " disposing xImpressDoc " ); 98 xImpressDoc.dispose(); 99 } 100 101 /** 102 * Creating a Testenvironment for the interfaces to be tested. 103 * Creates an instance of the service 104 * <code>com.sun.star.comp.Impress.XMLSettingsExporter</code> with 105 * argument which is an implementation of <code>XDocumentHandler</code> 106 * and which can check if required tags and character data is 107 * exported. <p> 108 * The Impress document is set as a source document for exporter 109 * created. Then setting 'IsLayerMode' is changed to a new value. 110 * After this filter checks that value has changed in the XML output. 111 * Object relations created : 112 * <ul> 113 * <li> <code>'MediaDescriptor'</code> for 114 * {@link ifc.document._XFilter} interface </li> 115 * <li> <code>'XFilter.Checker'</code> for 116 * {@link ifc.document._XFilter} interface </li> 117 * <li> <code>'SourceDocument'</code> for 118 * {@link ifc.document._XExporter} interface </li> 119 * </ul> 120 */ 121 public synchronized TestEnvironment createTestEnvironment 122 (TestParameters tParam, PrintWriter log ) throws StatusException { 123 124 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF(); 125 XInterface oObj = null; 126 FilterChecker filter = new FilterChecker(log); 127 Any arg = new Any(new Type(XDocumentHandler.class),filter); 128 final boolean NewDataValue; 129 130 try { 131 oObj = (XInterface) xMSF.createInstanceWithArguments( 132 "com.sun.star.comp.Impress.XMLSettingsExporter", 133 new Object[] {arg}); 134 XExporter xEx = (XExporter) 135 UnoRuntime.queryInterface(XExporter.class,oObj); 136 xEx.setSourceDocument(xImpressDoc); 137 138 //set some settings 139 XModel xImpressModel = (XModel) 140 UnoRuntime.queryInterface(XModel.class, xImpressDoc); 141 XController xController = xImpressModel.getCurrentController(); 142 XPropertySet xPropSet = (XPropertySet) 143 UnoRuntime.queryInterface(XPropertySet.class, xController); 144 NewDataValue = ! ((Boolean) xPropSet.getPropertyValue 145 ("IsLayerMode")).booleanValue(); 146 xPropSet.setPropertyValue("IsLayerMode", 147 new Boolean (NewDataValue)); 148 149 /* XViewDataSupplier xViewDataSupp = (XViewDataSupplier) 150 UnoRuntime.queryInterface(XViewDataSupplier.class, xImpressDoc); 151 XIndexAccess xViewData = xViewDataSupp.getViewData(); 152 PropertyValue[] xData = (PropertyValue[]) xViewData.getByIndex(0); 153 NewDataValue = ! ((Boolean) xData[1].Value).booleanValue(); 154 xData[1].Value = new Boolean(NewDataValue); 155 XIndexReplace xViewDataReplacable = (XIndexReplace) 156 UnoRuntime.queryInterface(XIndexReplace.class, xViewData); 157 xViewDataReplacable.replaceByIndex(0,xData); 158 */ 159 160 } catch (com.sun.star.uno.Exception e) { 161 e.printStackTrace(log) ; 162 throw new StatusException("Can't create component.", e) ; 163 } 164 165 // Adding tags for checking existance of head tag and other tags 166 filter.addTagEnclosed(new XMLTools.Tag("office:settings"), 167 new XMLTools.Tag("office:document-settings")); 168 filter.addTagEnclosed(new XMLTools.Tag("config:config-item-set"), 169 new XMLTools.Tag("office:settings")); 170 filter.addTagEnclosed(new XMLTools.Tag("config:config-item-map-indexed"), 171 new XMLTools.Tag("config:config-item-set")); 172 filter.addTagEnclosed(new XMLTools.Tag("config:config-item-map-entry"), 173 new XMLTools.Tag("config:config-item-map-indexed")); 174 filter.addTagEnclosed(new XMLTools.Tag("config:config-item"), 175 new XMLTools.Tag("config:config-item-map-entry")); 176 filter.addCharactersEnclosed(String.valueOf(NewDataValue), 177 new XMLTools.Tag("config:config-item","config:name","IsLayerMode")); 178 179 // create testobject here 180 log.println( "creating a new environment" ); 181 TestEnvironment tEnv = new TestEnvironment( oObj ); 182 183 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor( 184 new String[] {"FilterName"}, 185 new Object[] {"simpress: StarOffice XML (Impress)"})); 186 tEnv.addObjRelation("SourceDocument",xImpressDoc); 187 tEnv.addObjRelation("XFilter.Checker", filter); 188 return tEnv; 189 } 190 191 /** 192 * This class checks the XML for tags and data required and returns 193 * checking result to <code>XFilter</code> interface test. All 194 * the information about errors occured in XML data is written 195 * to log specified. 196 * @see ifc.document._XFilter 197 */ 198 protected class FilterChecker extends XMLTools.XMLChecker 199 implements ifc.document._XFilter.FilterChecker { 200 201 /** 202 * Creates a class which will write information 203 * into log specified. 204 */ 205 public FilterChecker(PrintWriter log) { 206 super(log,false) ; 207 } 208 /** 209 * <code>_XFilter.FilterChecker</code> interface method 210 * which returns the result of XML checking. 211 * @return <code>true</code> if the XML data exported was 212 * valid (i.e. all necessary tags and character data exists), 213 * <code>false</code> if some errors occured. 214 */ 215 public boolean checkFilter() { 216 return check(); 217 } 218 } 219 } 220