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._sm; 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.lang.XComponent; 36 import com.sun.star.lang.XMultiServiceFactory; 37 import com.sun.star.uno.UnoRuntime; 38 import com.sun.star.uno.XInterface; 39 40 /** 41 * Test for object which is represented by service 42 * <code>com.sun.star.comp.Math.XMLSettingsImporter</code>. <p> 43 * Object implements the following interfaces : 44 * <ul> 45 * <li><code>com::sun::star::lang::XInitialization</code></li> 46 * <li><code>com::sun::star::document::XImporter</code></li> 47 * <li><code>com::sun::star::document::XFilter</code></li> 48 * <li><code>com::sun::star::document::ImportFilter</code></li> 49 * <li><code>com::sun::star::beans::XPropertySet</code></li> 50 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li> 51 * </ul> 52 * @see com.sun.star.lang.XInitialization 53 * @see com.sun.star.document.XImporter 54 * @see com.sun.star.document.XFilter 55 * @see com.sun.star.document.ImportFilter 56 * @see com.sun.star.beans.XPropertySet 57 * @see com.sun.star.xml.sax.XDocumentHandler 58 * @see ifc.lang._XInitialization 59 * @see ifc.document._XImporter 60 * @see ifc.document._XFilter 61 * @see ifc.document._XExporter 62 * @see ifc.beans._XPropertySet 63 * @see ifc.xml.sax._XDocumentHandler 64 */ 65 public class XMLSettingsImporter extends TestCase { 66 XComponent xMathDoc; 67 68 /** 69 * New math document created. 70 */ initialize( TestParameters tParam, PrintWriter log )71 protected void initialize( TestParameters tParam, PrintWriter log ) { 72 73 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 74 try { 75 xMathDoc = SOF.openDoc("smath","_blank"); 76 } catch (com.sun.star.uno.Exception ex) { 77 ex.printStackTrace( log ); 78 throw new StatusException( "Couldn't create document", ex ); 79 } 80 } 81 82 /** 83 * Disposes document. 84 */ cleanup( TestParameters tParam, PrintWriter log )85 protected void cleanup( TestParameters tParam, PrintWriter log ) { 86 log.println( " disposing xMathDoc " ); 87 xMathDoc.dispose(); 88 } 89 90 /** 91 * Creating a Testenvironment for the interfaces to be tested. 92 * Creates an instance of the service 93 * <code>com.sun.star.comp.Math.XMLSettingsImporter</code><p> 94 * 95 * The math document is set as a target document for importer. 96 * Imported XML-data contains the tag which specifies new 97 * 'TopMargin' property value. 98 * After import 'TopMargin' property value of target document 99 * is checked. 100 * Object relations created : 101 * <ul> 102 * <li> <code>'XDocumentHandler.XMLData'</code> for 103 * {@link ifc.xml.sax._XDocumentHandler} interface </li> 104 * <li> <code>'XDocumentHandler.ImportChecker'</code> for 105 * {@link ifc.xml.sax._XDocumentHandler} interface </li> 106 * <li> <code>'TargetDocument'</code> for 107 * {@link ifc.document._XImporter} interface </li> 108 * </ul> 109 */ createTestEnvironment( TestParameters Param, PrintWriter log )110 public synchronized TestEnvironment createTestEnvironment 111 ( TestParameters Param, PrintWriter log ) 112 throws StatusException { 113 114 XMultiServiceFactory xMSF = (XMultiServiceFactory)Param.getMSF(); 115 XInterface oObj = null; 116 final short impMargin = 67 ; 117 118 try { 119 oObj = (XInterface)xMSF.createInstance( 120 "com.sun.star.comp.Math.XMLSettingsImporter"); 121 122 } catch (com.sun.star.uno.Exception e) { 123 e.printStackTrace(log); 124 throw new StatusException("Unexpected exception", e); 125 } 126 127 TestEnvironment tEnv = new TestEnvironment(oObj); 128 129 tEnv.addObjRelation("TargetDocument",xMathDoc); 130 131 String[][] xml = new String[][] { 132 {"start", "office:document-settings", 133 "xmlns:office", "CDATA", "http://openoffice.org/2000/office", 134 "xmlns:config", "CDATA", "http://openoffice.org/2001/config", 135 "xmlns:xlink", "CDATA", "http://www.w3.org/1999/xlink", 136 "office:version", "CDATA", "1.0" 137 }, 138 {"start", "office:settings"}, 139 {"start", "config:config-item-set", 140 "config:name", "CDATA", "configuration-settings"}, 141 142 {"start", "config:config-item", 143 "config:name", "CDATA", "TopMargin", 144 "config:type", "CDATA", "short"}, 145 {"chars", String.valueOf(impMargin)}, 146 {"end", "config:config-item"}, 147 {"end", "config:config-item-set"}, 148 {"end", "office:settings"}, 149 {"end", "office:document-settings"}} ; 150 151 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ; 152 153 final PrintWriter logF = log ; 154 final XPropertySet xPS = (XPropertySet) UnoRuntime.queryInterface 155 (XPropertySet.class, xMathDoc) ; 156 157 tEnv.addObjRelation("XDocumentHandler.ImportChecker", 158 new ifc.xml.sax._XDocumentHandler.ImportChecker() { 159 public boolean checkImport() { 160 try { 161 Short gMargin = (Short) xPS.getPropertyValue 162 ("TopMargin") ; 163 logF.println("Margin returned: " + gMargin); 164 return impMargin == gMargin.shortValue() ; 165 } catch (com.sun.star.uno.Exception e) { 166 logF.println("Exception occurred while checking filter :") ; 167 e.printStackTrace(logF) ; 168 return false ; 169 } 170 } 171 }) ; 172 173 return tEnv; 174 } 175 } 176 177