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.document.XImporter; 35 import com.sun.star.lang.XMultiServiceFactory; 36 import com.sun.star.text.XTextDocument; 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.Writer.XMLImporter</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 52 * </ul> 53 * @see com.sun.star.lang.XInitialization 54 * @see com.sun.star.document.XImporter 55 * @see com.sun.star.document.XFilter 56 * @see com.sun.star.document.ImportFilter 57 * @see com.sun.star.beans.XPropertySet 58 * @see com.sun.star.xml.sax.XDocumentHandler 59 * @see ifc.lang._XInitialization 60 * @see ifc.document._XImporter 61 * @see ifc.document._XFilter 62 * @see ifc.document._XExporter 63 * @see ifc.beans._XPropertySet 64 * @see ifc.xml.sax._XDocumentHandler 65 */ 66 public class XMLImporter extends TestCase { 67 XTextDocument xTextDoc; 68 69 /** 70 * New text document created. 71 */ initialize( TestParameters tParam, PrintWriter log )72 protected void initialize( TestParameters tParam, PrintWriter log ) { 73 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF() ); 74 75 try { 76 log.println( "creating a textdocument" ); 77 xTextDoc = SOF.createTextDoc( null ); 78 } catch ( com.sun.star.uno.Exception e ) { 79 // Some exception occures.FAILED 80 e.printStackTrace( log ); 81 throw new StatusException( "Couldn't create document", e ); 82 } 83 } 84 85 /** 86 * Text document destroyed. 87 */ cleanup( TestParameters tParam, PrintWriter log )88 protected void cleanup( TestParameters tParam, PrintWriter log ) { 89 log.println( " disposing xTextDoc " ); 90 util.DesktopTools.closeDoc(xTextDoc); 91 } 92 93 /** 94 * Creating a Testenvironment for the interfaces to be tested. 95 * Creates an instance of the service 96 * <code>com.sun.star.comp.Writer.XMLImporter</code><p> 97 * 98 * The text document is set as a target document for importer. 99 * Imported tags contain tag including tag with test text. 100 * After import text getting from target document is checked. 101 * Object relations created : 102 * <ul> 103 * <li> <code>'XDocumentHandler.XMLData'</code> for 104 * {@link ifc.xml.sax._XDocumentHandler} interface </li> 105 * <li> <code>'XDocumentHandler.ImportChecker'</code> for 106 * {@link ifc.xml.sax._XDocumentHandler} interface </li> 107 * <li> <code>'TargetDocument'</code> for 108 * {@link ifc.document._XImporter} interface </li> 109 * </ul> 110 */ createTestEnvironment( TestParameters tParam, PrintWriter log)111 public synchronized TestEnvironment createTestEnvironment 112 ( TestParameters tParam, PrintWriter log) { 113 114 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ; 115 XInterface oObj = null; 116 117 try { 118 oObj = (XInterface) xMSF.createInstance 119 ("com.sun.star.comp.Writer.XMLImporter"); 120 XImporter xIm = (XImporter) UnoRuntime.queryInterface 121 (XImporter.class,oObj); 122 xIm.setTargetDocument(xTextDoc); 123 } catch (com.sun.star.uno.Exception e) { 124 e.printStackTrace(log) ; 125 throw new StatusException("Can't create component.", e) ; 126 } 127 128 // create testobject here 129 log.println( "creating a new environment" ); 130 TestEnvironment tEnv = new TestEnvironment( oObj ); 131 132 final String impText = "XMLImporter test." ; 133 String[][] xml = new String[][] { 134 {"start", "office:document" , 135 "xmlns:office", "CDATA", "http://openoffice.org/2000/office", 136 "office:class", "CDATA", "text", 137 "xmlns:text", "CDATA", "http://openoffice.org/2000/text"}, 138 {"start", "office:body" }, 139 {"start", "text:p" }, 140 {"chars", impText}, 141 {"end", "text:p"}, 142 {"end", "office:body"}, 143 {"end", "office:document"}} ; 144 145 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ; 146 147 tEnv.addObjRelation("TargetDocument",xTextDoc); 148 log.println("Implementation Name: "+util.utils.getImplName(oObj)); 149 150 final XTextDocument textDoc = (XTextDocument) UnoRuntime.queryInterface 151 (XTextDocument.class, xTextDoc) ; 152 final PrintWriter fLog = log ; 153 tEnv.addObjRelation("XDocumentHandler.ImportChecker", 154 new ifc.xml.sax._XDocumentHandler.ImportChecker() { 155 public boolean checkImport() { 156 String docText = textDoc.getText().getString() ; 157 fLog.println("Document text returned = '" + docText + "'") ; 158 return impText.equals(docText) ; 159 } 160 }) ; 161 162 return tEnv; 163 164 } 165 166 } 167 168