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 38 import com.sun.star.beans.XPropertySet; 39 import com.sun.star.frame.XController; 40 import com.sun.star.frame.XModel; 41 import com.sun.star.lang.XComponent; 42 import com.sun.star.lang.XMultiServiceFactory; 43 import com.sun.star.uno.UnoRuntime; 44 import com.sun.star.uno.XInterface; 45 46 /** 47 * Test for object which is represented by service 48 * <code>com.sun.star.comp.Impress.XMLSettingsImporter</code>. <p> 49 * Object implements the following interfaces : 50 * <ul> 51 * <li><code>com::sun::star::lang::XInitialization</code></li> 52 * <li><code>com::sun::star::document::XImporter</code></li> 53 * <li><code>com::sun::star::document::XFilter</code></li> 54 * <li><code>com::sun::star::document::ImportFilter</code></li> 55 * <li><code>com::sun::star::beans::XPropertySet</code></li> 56 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li> 57 58 * </ul> 59 * @see com.sun.star.lang.XInitialization 60 * @see com.sun.star.document.XImporter 61 * @see com.sun.star.document.XFilter 62 * @see com.sun.star.document.ImportFilter 63 * @see com.sun.star.beans.XPropertySet 64 * @see com.sun.star.xml.sax.XDocumentHandler 65 * @see ifc.lang._XInitialization 66 * @see ifc.document._XImporter 67 * @see ifc.document._XFilter 68 * @see ifc.document._XExporter 69 * @see ifc.beans._XPropertySet 70 * @see ifc.xml.sax._XDocumentHandler 71 */ 72 public class XMLSettingsImporter extends TestCase { 73 XComponent xImpressDoc = null; 74 75 /** 76 * New impress 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 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 * Impress document destroyed. 95 */ 96 protected void cleanup( TestParameters tParam, PrintWriter log ) { 97 log.println( " disposing document " ); 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.XMLStylesImporter</code><p> 105 * 106 * The Impress document is set as a target document for importer. 107 * Value of a property "IsLayerMode" has imported as 'true' to a target 108 * document. After import property value getting from target document 109 * is checked. 110 * Object relations created : 111 * <ul> 112 * <li> <code>'XDocumentHandler.XMLData'</code> for 113 * {@link ifc.xml.sax._XDocumentHandler} interface </li> 114 * <li> <code>'XDocumentHandler.ImportChecker'</code> for 115 * {@link ifc.xml.sax._XDocumentHandler} interface </li> 116 * <li> <code>'TargetDocument'</code> for 117 * {@link ifc.document._XImporter} interface </li> 118 * </ul> 119 */ 120 public synchronized TestEnvironment createTestEnvironment 121 (TestParameters tParam, PrintWriter log ) throws StatusException { 122 123 XInterface oObj = null; 124 Object oInt = null ; 125 126 // creation of testobject here 127 // first we write what we are intend to do to log file 128 log.println( "creating a test environment" ); 129 130 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ; 131 132 try { 133 oInt = xMSF.createInstance 134 ("com.sun.star.comp.Impress.XMLSettingsImporter") ; 135 136 } catch (com.sun.star.uno.Exception e) { 137 e.printStackTrace(log) ; 138 throw new StatusException("Can't create component.", e) ; 139 } 140 141 oObj = (XInterface) oInt ; 142 143 // create testobject here 144 log.println( "creating a new environment for Paragraph object" ); 145 TestEnvironment tEnv = new TestEnvironment( oObj ); 146 147 // adding relation 148 tEnv.addObjRelation("TargetDocument", xImpressDoc) ; 149 150 // adding relation for XDocumentHandler 151 String[][] xml = new String[][] { 152 {"start", "office:document-settings", 153 "xmlns:office", "CDATA", "http://openoffice.org/2000/office", 154 "xmlns:xlink", "CDATA", "http://www.w3.org/1999/xlink", 155 "xmlns:presentation", "CDATA", 156 "http://openoffice.org/2000/presentation", 157 "xmlns:config", "CDATA", "http://openoffice.org/2001/config", 158 "office:version", "CDATA", "1.0"}, 159 {"start", "office:settings"}, 160 {"start", "config:config-item-map-indexed", "config:name", 161 "CDATA", "Views"}, 162 {"start", "config:config-item-map-entry"}, 163 {"start","config:config-item", "config:name", "CDATA", 164 "IsLayerMode"}, 165 {"chars", "true"}, 166 {"end", "config:config-item"}, 167 {"end", "config:config-item-map-entry"}, 168 {"end", "config:config-item-map-indexed"}, 169 {"end", "office:settings"}, 170 {"end", "office:document-settings"}} ; 171 172 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ; 173 174 // get property before import 175 XModel xImpressModel = (XModel) 176 UnoRuntime.queryInterface(XModel.class, xImpressDoc); 177 XController xController = xImpressModel.getCurrentController(); 178 final XPropertySet xPropSet = (XPropertySet) 179 UnoRuntime.queryInterface(XPropertySet.class, xController); 180 try { 181 log.println("Property \"IsLayerMode\" before import is " + 182 xPropSet.getPropertyValue("IsLayerMode")); 183 } catch (com.sun.star.uno.Exception e) { 184 e.printStackTrace(log); 185 throw new StatusException("Can't create component.", e); 186 } 187 final PrintWriter logF = log; 188 tEnv.addObjRelation("XDocumentHandler.ImportChecker", 189 new ifc.xml.sax._XDocumentHandler.ImportChecker() { 190 public boolean checkImport() { 191 Boolean propValue; 192 try { 193 propValue = (Boolean) xPropSet.getPropertyValue 194 ("IsLayerMode"); 195 } catch (com.sun.star.uno.Exception e) { 196 e.printStackTrace(logF); 197 throw new StatusException 198 ("Can't get property value.", e); 199 } 200 logF.println("Property \"IsLayerMode\" after import is " 201 + propValue); 202 if ( propValue.booleanValue() == true ) { 203 return true; 204 } else { 205 return false; 206 } 207 } 208 }); 209 210 return tEnv; 211 } // end of getTestEnvironment 212 213 } 214