xref: /AOO41X/main/qadevOOo/tests/java/mod/_xmloff/Draw/XMLSettingsImporter.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package mod._xmloff.Draw;
29 
30 import java.io.PrintWriter;
31 
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.SOfficeFactory;
37 
38 import com.sun.star.beans.XPropertySet;
39 import com.sun.star.frame.XController;
40 import com.sun.star.frame.XModel;
41 import com.sun.star.lang.XComponent;
42 import com.sun.star.lang.XMultiServiceFactory;
43 import com.sun.star.uno.UnoRuntime;
44 import com.sun.star.uno.XInterface;
45 
46 /**
47  * Test for object which is represented by service
48  * <code>com.sun.star.comp.Draw.XMLSettingsImporter</code>. <p>
49  * Object implements the following interfaces :
50  * <ul>
51  *  <li><code>com::sun::star::lang::XInitialization</code></li>
52  *  <li><code>com::sun::star::document::XImporter</code></li>
53  *  <li><code>com::sun::star::document::XFilter</code></li>
54  *  <li><code>com::sun::star::document::ImportFilter</code></li>
55  *  <li><code>com::sun::star::beans::XPropertySet</code></li>
56  *  <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
57  * </ul>
58  * @see com.sun.star.lang.XInitialization
59  * @see com.sun.star.document.XImporter
60  * @see com.sun.star.document.XFilter
61  * @see com.sun.star.document.ImportFilter
62  * @see com.sun.star.beans.XPropertySet
63  * @see com.sun.star.xml.sax.XDocumentHandler
64  * @see ifc.lang._XInitialization
65  * @see ifc.document._XImporter
66  * @see ifc.document._XFilter
67  * @see ifc.document._XExporter
68  * @see ifc.beans._XPropertySet
69  * @see ifc.xml.sax._XDocumentHandler
70  */
71 public class XMLSettingsImporter extends TestCase {
72     XComponent xDrawDoc = null;
73 
74     /**
75     * New draw document created.
76     */
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 a drawdocument" );
84             xDrawDoc = SOF.createDrawDoc(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     * Text draw destroyed.
94     */
95     protected void cleanup( TestParameters tParam, PrintWriter log ) {
96         log.println( "    disposing document " );
97         xDrawDoc.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.Draw.XMLSettingsImporter</code><p>
104     *
105     * The draw document is set as a target document for importer.
106     * Imported XML-data contains only settings tags including
107     * tag with property 'IsLayerMode'.
108     * After import property 'IsLayerMode' getting from target
109     * document is checked.
110     *     Object relations created :
111     * <ul>
112     *  <li> <code>'XDocumentHandler.XMLData'</code> for
113     *      {@link ifc.xml.sax._XDocumentHandler} interface </li>
114     *  <li> <code>'XDocumentHandler.ImportChecker'</code> for
115     *      {@link ifc.xml.sax._XDocumentHandler} interface </li>
116     *  <li> <code>'TargetDocument'</code> for
117     *      {@link ifc.document._XImporter} interface </li>
118     * </ul>
119     */
120     public synchronized TestEnvironment createTestEnvironment
121             (TestParameters tParam, PrintWriter log) throws StatusException {
122 
123         XInterface oObj = null;
124         Object oInt = null ;
125 
126         // creation of testobject here
127         // first we write what we are intend to do to log file
128         log.println( "creating a test environment" );
129 
130         XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ;
131 
132         try {
133             oInt = xMSF.createInstance
134                 ("com.sun.star.comp.Draw.XMLSettingsImporter") ;
135 
136         } catch (com.sun.star.uno.Exception e) {
137             e.printStackTrace(log) ;
138             throw new StatusException("Can't create component.", e) ;
139         }
140 
141         oObj = (XInterface) oInt ;
142 
143         // create testobject here
144         log.println( "creating a new environment for Paragraph object" );
145         TestEnvironment tEnv = new TestEnvironment( oObj );
146 
147         // adding relation
148         tEnv.addObjRelation("TargetDocument", xDrawDoc) ;
149 
150         // adding relation for XDocumentHandler
151         String[][] xml = new String[][] {
152             {"start", "office:document-settings",
153                 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
154                 "xmlns:config", "CDATA", "http://openoffice.org/2001/config"},
155                 {"start", "office:settings"},
156                     {"start", "config:config-item-set",
157                         "config:name", "CDATA", "view-settings"},
158                         {"start", "config:config-item-map-indexed",
159                             "config:name", "CDATA", "Views"},
160                             {"start", "config:config-item-map-entry"},
161                                 {"start", "config:config-item",
162                                     "config:name", "CDATA", "IsLayerMode",
163                                     "config:type", "CDATA", "boolean"},
164                                 {"chars", "true"},
165                                 {"end", "config:config-item"},
166                             {"end", "config:config-item-map-entry"},
167                         {"end", "config:config-item-map-indexed"},
168                     {"end", "config:config-item-set"},
169                 {"end", "office:settings"},
170             {"end", "office:document-settings"} };
171 
172         tEnv.addObjRelation("XDocumentHandler.XMLData", xml);
173         final PrintWriter logF = log;
174         XModel xDrawModel = (XModel)
175             UnoRuntime.queryInterface(XModel.class, xDrawDoc);
176         XController xController = xDrawModel.getCurrentController();
177         final XPropertySet xPropSet = (XPropertySet)
178             UnoRuntime.queryInterface(XPropertySet.class, xController);
179 
180         tEnv.addObjRelation("XDocumentHandler.ImportChecker",
181             new ifc.xml.sax._XDocumentHandler.ImportChecker() {
182                 public boolean checkImport() {
183                     try {
184                         Boolean value = (Boolean)
185                             xPropSet.getPropertyValue("IsLayerMode");
186                         logF.println("'IsLayerMode' property value is '"
187                             + value + "'");
188                         return value.booleanValue() == true;
189                     } catch (com.sun.star.uno.Exception e) {
190                         logF.println("Exception while checking import :") ;
191                         e.printStackTrace(logF) ;
192                         return false ;
193                     }
194                 }
195             }) ;
196 
197         return tEnv;
198     } // finish method getTestEnvironment
199 }
200