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 
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.Impress.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 
54  * </ul>
55  * @see com.sun.star.lang.XInitialization
56  * @see com.sun.star.document.XImporter
57  * @see com.sun.star.document.XFilter
58  * @see com.sun.star.document.ImportFilter
59  * @see com.sun.star.beans.XPropertySet
60  * @see com.sun.star.xml.sax.XDocumentHandler
61  * @see ifc.lang._XInitialization
62  * @see ifc.document._XImporter
63  * @see ifc.document._XFilter
64  * @see ifc.document._XExporter
65  * @see ifc.beans._XPropertySet
66  * @see ifc.xml.sax._XDocumentHandler
67  */
68 public class XMLSettingsImporter extends TestCase {
69     XComponent xImpressDoc = null;
70 
71     /**
72     * New impress document created.
73     */
initialize( TestParameters tParam, PrintWriter log )74     protected void initialize( TestParameters tParam, PrintWriter log ) {
75 
76         // get a soffice factory object
77         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
78 
79         try {
80             log.println( "creating an impress document" );
81             xImpressDoc = SOF.createImpressDoc(null);
82         } catch ( Exception e ) {
83             // Some exception occured.FAILED
84             e.printStackTrace( log );
85             throw new StatusException( "Couldn't create document", e );
86         }
87     }
88 
89     /**
90     * Impress document destroyed.
91     */
cleanup( TestParameters tParam, PrintWriter log )92     protected void cleanup( TestParameters tParam, PrintWriter log ) {
93         log.println( "    disposing document " );
94         xImpressDoc.dispose();
95     }
96 
97     /**
98     * Creating a Testenvironment for the interfaces to be tested.
99     * Creates an instance of the service
100     * <code>com.sun.star.comp.Impress.XMLStylesImporter</code><p>
101     *
102     * The Impress document is set as a target document for importer.
103     * Value of a property "IsLayerMode" has imported as 'true' to a target
104     * document. After import property value getting from target document
105     *  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.Impress.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", xImpressDoc) ;
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:xlink", "CDATA", "http://www.w3.org/1999/xlink",
151                 "xmlns:presentation", "CDATA",
152                     "http://openoffice.org/2000/presentation",
153                 "xmlns:config", "CDATA", "http://openoffice.org/2001/config",
154                 "office:version", "CDATA", "1.0"},
155             {"start", "office:settings"},
156             {"start", "config:config-item-map-indexed", "config:name",
157                 "CDATA", "Views"},
158             {"start", "config:config-item-map-entry"},
159             {"start","config:config-item", "config:name", "CDATA",
160                 "IsLayerMode"},
161             {"chars", "true"},
162             {"end", "config:config-item"},
163             {"end", "config:config-item-map-entry"},
164             {"end", "config:config-item-map-indexed"},
165             {"end", "office:settings"},
166             {"end", "office:document-settings"}} ;
167 
168         tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
169 
170         // get property before import
171         XModel xImpressModel = (XModel)
172             UnoRuntime.queryInterface(XModel.class, xImpressDoc);
173         XController xController = xImpressModel.getCurrentController();
174         final XPropertySet xPropSet = (XPropertySet)
175             UnoRuntime.queryInterface(XPropertySet.class, xController);
176         try {
177             log.println("Property \"IsLayerMode\" before import is " +
178                 xPropSet.getPropertyValue("IsLayerMode"));
179         } catch (com.sun.star.uno.Exception e) {
180             e.printStackTrace(log);
181             throw new StatusException("Can't create component.", e);
182         }
183         final PrintWriter logF = log;
184         tEnv.addObjRelation("XDocumentHandler.ImportChecker",
185             new ifc.xml.sax._XDocumentHandler.ImportChecker() {
186                 public boolean checkImport() {
187                     Boolean propValue;
188                     try {
189                         propValue = (Boolean) xPropSet.getPropertyValue
190                             ("IsLayerMode");
191                     } catch (com.sun.star.uno.Exception e) {
192                         e.printStackTrace(logF);
193                         throw new StatusException
194                             ("Can't get property value.", e);
195                     }
196                     logF.println("Property \"IsLayerMode\" after import is "
197                         + propValue);
198                     if ( propValue.booleanValue() == true ) {
199                         return true;
200                     } else {
201                         return false;
202                     }
203                 }
204             });
205 
206         return tEnv;
207     } // end of getTestEnvironment
208 
209 }
210