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