1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package mod._sw; 25 26 import java.io.PrintWriter; 27 28 import lib.StatusException; 29 import lib.TestCase; 30 import lib.TestEnvironment; 31 import lib.TestParameters; 32 import util.SOfficeFactory; 33 34 import com.sun.star.beans.XPropertySet; 35 import com.sun.star.frame.XController; 36 import com.sun.star.lang.XMultiServiceFactory; 37 import com.sun.star.text.XTextDocument; 38 import com.sun.star.uno.UnoRuntime; 39 import com.sun.star.uno.XInterface; 40 import com.sun.star.view.XViewSettingsSupplier; 41 42 /** 43 * Test for object which is represented by service 44 * <code>com.sun.star.comp.Writer.XMLSettingsImporter</code>. <p> 45 * Object implements the following interfaces : 46 * <ul> 47 * <li><code>com::sun::star::lang::XInitialization</code></li> 48 * <li><code>com::sun::star::document::XImporter</code></li> 49 * <li><code>com::sun::star::document::XFilter</code></li> 50 * <li><code>com::sun::star::document::ImportFilter</code></li> 51 * <li><code>com::sun::star::beans::XPropertySet</code></li> 52 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li> 53 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 XMLSettingsImporter extends TestCase { 69 XTextDocument xTextDoc; 70 71 /** 72 * New text document created. 73 */ initialize( TestParameters tParam, PrintWriter log )74 protected void initialize( TestParameters tParam, PrintWriter log ) { 75 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 76 77 try { 78 log.println( "creating a textdocument" ); 79 xTextDoc = SOF.createTextDoc( null ); 80 } catch ( com.sun.star.uno.Exception e ) { 81 // Some exception occured.FAILED 82 e.printStackTrace( log ); 83 throw new StatusException( "Couldn't create document", e ); 84 } 85 } 86 87 /** 88 * Text document destroyed. 89 */ cleanup( TestParameters tParam, PrintWriter log )90 protected void cleanup( TestParameters tParam, PrintWriter log ) { 91 log.println( " disposing xTextDoc " ); 92 util.DesktopTools.closeDoc(xTextDoc); 93 } 94 95 /** 96 * Creating a Testenvironment for the interfaces to be tested. 97 * Creates an instance of the service 98 * <code>com.sun.star.comp.Writer.XMLSettingsImporter</code><p> 99 * 100 * The text document is set as a target document for importer. 101 * Imported XML-data contains only settings tags including 102 * title tag with test zoom factor. 103 * After import zoom factor getting from target document is checked. 104 * Object relations created : 105 * <ul> 106 * <li> <code>'XDocumentHandler.XMLData'</code> for 107 * {@link ifc.xml.sax._XDocumentHandler} interface </li> 108 * <li> <code>'XDocumentHandler.ImportChecker'</code> for 109 * {@link ifc.xml.sax._XDocumentHandler} interface </li> 110 * <li> <code>'TargetDocument'</code> for 111 * {@link ifc.document._XImporter} interface </li> 112 * </ul> 113 */ createTestEnvironment(TestParameters tParam, PrintWriter log )114 public synchronized TestEnvironment createTestEnvironment 115 (TestParameters tParam, PrintWriter log ) throws StatusException { 116 117 XInterface oObj = null; 118 Object oInt = null ; 119 final short impZoom = 50 ; 120 121 // creation of testobject here 122 // first we write what we are intend to do to log file 123 log.println( "creating a test environment" ); 124 125 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ; 126 127 try { 128 oInt = xMSF.createInstance 129 ("com.sun.star.comp.Writer.XMLSettingsImporter") ; 130 131 } catch (com.sun.star.uno.Exception e) { 132 e.printStackTrace(log) ; 133 throw new StatusException("Can't create component.", e) ; 134 } 135 136 137 oObj = (XInterface) oInt ; 138 139 // create testobject here 140 log.println( "creating a new environment for Paragraph object" ); 141 TestEnvironment tEnv = new TestEnvironment( oObj ); 142 143 // adding relation 144 tEnv.addObjRelation("TargetDocument", xTextDoc) ; 145 146 // adding relation for XDocumentHandler 147 String[][] xml = new String[][] { 148 {"start", "office:document-settings", 149 "xmlns:office", "CDATA", "http://openoffice.org/2000/office", 150 "xmlns:config", "CDATA", "http://openoffice.org/2001/config", 151 "xmlns:xlink", "CDATA", "http://www.w3.org/1999/xlink", 152 }, 153 {"start", "office:settings"}, 154 {"start", "config:config-item-set", 155 "config:name", "CDATA", "view-settings" 156 }, 157 {"start", "config:config-item-map-indexed", 158 "config:name", "CDATA", "Views"}, 159 {"start", "config:config-item-map-entry"}, 160 {"start", "config:config-item", 161 "config:name", "CDATA", "ZoomFactor", 162 "config:type", "CDATA", "short" 163 }, 164 {"chars", String.valueOf(impZoom)}, 165 {"end", "config:config-item"}, 166 {"start", "config:config-item", 167 "config:name", "CDATA", "ZoomType", 168 "config:type", "CDATA", "short" 169 }, 170 {"chars", "0"}, 171 {"end", "config:config-item"}, 172 {"end", "config:config-item-map-entry"}, 173 {"end", "config:config-item-map-indexed"}, 174 {"end", "config:config-item-set"}, 175 {"end", "office:settings"}, 176 {"end", "office:document-settings"}} ; 177 178 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ; 179 180 final PrintWriter logF = log ; 181 XController xController = xTextDoc.getCurrentController(); 182 XViewSettingsSupplier xViewSetSup = (XViewSettingsSupplier) 183 UnoRuntime.queryInterface(XViewSettingsSupplier.class, xController); 184 final XPropertySet xPropSet = xViewSetSup.getViewSettings(); 185 tEnv.addObjRelation("XDocumentHandler.ImportChecker", 186 new ifc.xml.sax._XDocumentHandler.ImportChecker() { 187 public boolean checkImport() { 188 try { 189 Short gValue = (Short) 190 xPropSet.getPropertyValue("ZoomValue"); 191 logF.println("ZoomValue property value = " + gValue) ; 192 return impZoom == gValue.shortValue() ; 193 } catch (com.sun.star.uno.Exception e) { 194 logF.println("Exception while checking import :") ; 195 e.printStackTrace(logF) ; 196 return false ; 197 } 198 } 199 }) ; 200 201 return tEnv; 202 } // finish method getTestEnvironment 203 } 204 205