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