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.XMLExporter</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 XMLExporter 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.XMLExporter</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 formula inserted into document. This made 103 * for checking if this formula is successfully exported within 104 * the document content. 105 * Object relations created : 106 * <ul> 107 * <li> <code>'MediaDescriptor'</code> for 108 * {@link ifc.document._XFilter} interface </li> 109 * <li> <code>'XFilter.Checker'</code> for 110 * {@link ifc.document._XFilter} interface </li> 111 * <li> <code>'SourceDocument'</code> for 112 * {@link ifc.document._XExporter} interface </li> 113 * </ul> 114 */ 115 protected TestEnvironment createTestEnvironment 116 (TestParameters tParam, PrintWriter log) { 117 118 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ; 119 XInterface oObj = null; 120 final String expFormula = "a - b" ; 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.XMLExporter", new Object[] {arg}); 128 XExporter xEx = (XExporter) UnoRuntime.queryInterface 129 (XExporter.class,oObj); 130 xEx.setSourceDocument(xMathDoc); 131 132 // setting a formula in document 133 XPropertySet xPS = (XPropertySet) UnoRuntime.queryInterface 134 (XPropertySet.class, xMathDoc) ; 135 xPS.setPropertyValue("Formula", expFormula) ; 136 } catch (com.sun.star.uno.Exception e) { 137 e.printStackTrace(log) ; 138 throw new StatusException("Can't create component.", e) ; 139 } 140 141 // checking tags required 142 filter.addTag(new XMLTools.Tag("math:math")) ; 143 filter.addTagEnclosed(new XMLTools.Tag("math:annotation"), 144 new XMLTools.Tag("math:semantics")) ; 145 filter.addCharactersEnclosed(expFormula, 146 new XMLTools.Tag("math:annotation")) ; 147 148 // create testobject here 149 log.println( "creating a new environment" ); 150 TestEnvironment tEnv = new TestEnvironment( oObj ); 151 152 tEnv.addObjRelation("MediaDescriptor", XMLTools.createMediaDescriptor( 153 new String[] {"FilterName"}, 154 new Object[] {"smath: StarOffice XML (Math)"})); 155 tEnv.addObjRelation("SourceDocument",xMathDoc); 156 tEnv.addObjRelation("XFilter.Checker", filter) ; 157 158 log.println("Implementation Name: "+util.utils.getImplName(oObj)); 159 160 return tEnv; 161 } 162 163 /** 164 * This class checks the XML for tags and data required and returns 165 * checking result to <code>XFilter</code> interface test. All 166 * the information about errors occured in XML data is written 167 * to log specified. 168 * @see ifc.document._XFilter 169 */ 170 protected class FilterChecker extends XMLTools.XMLChecker 171 implements ifc.document._XFilter.FilterChecker { 172 173 /** 174 * Creates a class which will write information 175 * into log specified. 176 */ 177 public FilterChecker(PrintWriter log) { 178 super(log, true) ; 179 } 180 /** 181 * <code>_XFilter.FilterChecker</code> interface method 182 * which returns the result of XML checking. 183 * @return <code>true</code> if the XML data exported was 184 * valid (i.e. all necessary tags and character data exists), 185 * <code>false</code> if some errors occured. 186 */ 187 public boolean checkFilter() { 188 return check(); 189 } 190 } 191 192 } // finish class TestCase 193 194