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.Draw; 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.frame.XController; 36 import com.sun.star.frame.XModel; 37 import com.sun.star.lang.XComponent; 38 import com.sun.star.lang.XMultiServiceFactory; 39 import com.sun.star.uno.UnoRuntime; 40 import com.sun.star.uno.XInterface; 41 42 /** 43 * Test for object which is represented by service 44 * <code>com.sun.star.comp.Draw.XMLSettingsImporter</code>. <p> 45 * Object implements the following interfaces : 46 * <ul> 47 * <li><code>com::sun::star::lang::XInitialization</code></li> 48 * <li><code>com::sun::star::document::XImporter</code></li> 49 * <li><code>com::sun::star::document::XFilter</code></li> 50 * <li><code>com::sun::star::document::ImportFilter</code></li> 51 * <li><code>com::sun::star::beans::XPropertySet</code></li> 52 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li> 53 * </ul> 54 * @see com.sun.star.lang.XInitialization 55 * @see com.sun.star.document.XImporter 56 * @see com.sun.star.document.XFilter 57 * @see com.sun.star.document.ImportFilter 58 * @see com.sun.star.beans.XPropertySet 59 * @see com.sun.star.xml.sax.XDocumentHandler 60 * @see ifc.lang._XInitialization 61 * @see ifc.document._XImporter 62 * @see ifc.document._XFilter 63 * @see ifc.document._XExporter 64 * @see ifc.beans._XPropertySet 65 * @see ifc.xml.sax._XDocumentHandler 66 */ 67 public class XMLSettingsImporter extends TestCase { 68 XComponent xDrawDoc = null; 69 70 /** 71 * New draw document created. 72 */ initialize( TestParameters tParam, PrintWriter log )73 protected void initialize( TestParameters tParam, PrintWriter log ) { 74 75 // get a soffice factory object 76 SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF()); 77 78 try { 79 log.println( "creating a drawdocument" ); 80 xDrawDoc = SOF.createDrawDoc(null); 81 } catch ( Exception e ) { 82 // Some exception occures.FAILED 83 e.printStackTrace( log ); 84 throw new StatusException( "Couldn't create document", e ); 85 } 86 } 87 88 /** 89 * Text draw destroyed. 90 */ cleanup( TestParameters tParam, PrintWriter log )91 protected void cleanup( TestParameters tParam, PrintWriter log ) { 92 log.println( " disposing document " ); 93 xDrawDoc.dispose(); 94 } 95 96 /** 97 * Creating a Testenvironment for the interfaces to be tested. 98 * Creates an instance of the service 99 * <code>com.sun.star.comp.Draw.XMLSettingsImporter</code><p> 100 * 101 * The draw document is set as a target document for importer. 102 * Imported XML-data contains only settings tags including 103 * tag with property 'IsLayerMode'. 104 * After import property 'IsLayerMode' getting from target 105 * document is checked. 106 * Object relations created : 107 * <ul> 108 * <li> <code>'XDocumentHandler.XMLData'</code> for 109 * {@link ifc.xml.sax._XDocumentHandler} interface </li> 110 * <li> <code>'XDocumentHandler.ImportChecker'</code> for 111 * {@link ifc.xml.sax._XDocumentHandler} interface </li> 112 * <li> <code>'TargetDocument'</code> for 113 * {@link ifc.document._XImporter} interface </li> 114 * </ul> 115 */ createTestEnvironment(TestParameters tParam, PrintWriter log)116 public synchronized TestEnvironment createTestEnvironment 117 (TestParameters tParam, PrintWriter log) throws StatusException { 118 119 XInterface oObj = null; 120 Object oInt = null ; 121 122 // creation of testobject here 123 // first we write what we are intend to do to log file 124 log.println( "creating a test environment" ); 125 126 XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ; 127 128 try { 129 oInt = xMSF.createInstance 130 ("com.sun.star.comp.Draw.XMLSettingsImporter") ; 131 132 } catch (com.sun.star.uno.Exception e) { 133 e.printStackTrace(log) ; 134 throw new StatusException("Can't create component.", e) ; 135 } 136 137 oObj = (XInterface) oInt ; 138 139 // create testobject here 140 log.println( "creating a new environment for Paragraph object" ); 141 TestEnvironment tEnv = new TestEnvironment( oObj ); 142 143 // adding relation 144 tEnv.addObjRelation("TargetDocument", xDrawDoc) ; 145 146 // adding relation for XDocumentHandler 147 String[][] xml = new String[][] { 148 {"start", "office:document-settings", 149 "xmlns:office", "CDATA", "http://openoffice.org/2000/office", 150 "xmlns:config", "CDATA", "http://openoffice.org/2001/config"}, 151 {"start", "office:settings"}, 152 {"start", "config:config-item-set", 153 "config:name", "CDATA", "view-settings"}, 154 {"start", "config:config-item-map-indexed", 155 "config:name", "CDATA", "Views"}, 156 {"start", "config:config-item-map-entry"}, 157 {"start", "config:config-item", 158 "config:name", "CDATA", "IsLayerMode", 159 "config:type", "CDATA", "boolean"}, 160 {"chars", "true"}, 161 {"end", "config:config-item"}, 162 {"end", "config:config-item-map-entry"}, 163 {"end", "config:config-item-map-indexed"}, 164 {"end", "config:config-item-set"}, 165 {"end", "office:settings"}, 166 {"end", "office:document-settings"} }; 167 168 tEnv.addObjRelation("XDocumentHandler.XMLData", xml); 169 final PrintWriter logF = log; 170 XModel xDrawModel = (XModel) 171 UnoRuntime.queryInterface(XModel.class, xDrawDoc); 172 XController xController = xDrawModel.getCurrentController(); 173 final XPropertySet xPropSet = (XPropertySet) 174 UnoRuntime.queryInterface(XPropertySet.class, xController); 175 176 tEnv.addObjRelation("XDocumentHandler.ImportChecker", 177 new ifc.xml.sax._XDocumentHandler.ImportChecker() { 178 public boolean checkImport() { 179 try { 180 Boolean value = (Boolean) 181 xPropSet.getPropertyValue("IsLayerMode"); 182 logF.println("'IsLayerMode' property value is '" 183 + value + "'"); 184 return value.booleanValue() == true; 185 } catch (com.sun.star.uno.Exception e) { 186 logF.println("Exception while checking import :") ; 187 e.printStackTrace(logF) ; 188 return false ; 189 } 190 } 191 }) ; 192 193 return tEnv; 194 } // finish method getTestEnvironment 195 } 196