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.Chart;
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.chart.XChartDocument;
35 import com.sun.star.lang.XComponent;
36 import com.sun.star.lang.XMultiServiceFactory;
37 import com.sun.star.uno.XInterface;
38 
39 /**
40  * Test for object which is represented by service
41  * <code>com.sun.star.comp.Chart.XMLStylesImporter</code>. <p>
42  * Object implements the following interfaces :
43  * <ul>
44  *  <li><code>com::sun::star::lang::XInitialization</code></li>
45  *  <li><code>com::sun::star::document::XImporter</code></li>
46  *  <li><code>com::sun::star::document::XFilter</code></li>
47  *  <li><code>com::sun::star::document::ImportFilter</code></li>
48  *  <li><code>com::sun::star::beans::XPropertySet</code></li>
49  *  <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
50  * </ul>
51  * @see com.sun.star.lang.XInitialization
52  * @see com.sun.star.document.XImporter
53  * @see com.sun.star.document.XFilter
54  * @see com.sun.star.document.ImportFilter
55  * @see com.sun.star.beans.XPropertySet
56  * @see com.sun.star.xml.sax.XDocumentHandler
57  * @see ifc.lang._XInitialization
58  * @see ifc.document._XImporter
59  * @see ifc.document._XFilter
60  * @see ifc.document._XExporter
61  * @see ifc.beans._XPropertySet
62  * @see ifc.xml.sax._XDocumentHandler
63  */
64 public class XMLStylesImporter extends TestCase {
65     XComponent comp ;
66     XChartDocument xChartDoc = null;
67 
68     /**
69     * New chart document created.
70     */
initialize( TestParameters tParam, PrintWriter log )71     protected void initialize( TestParameters tParam, PrintWriter log ) {
72         // get a soffice factory object
73         SOfficeFactory SOF = SOfficeFactory.getFactory( (XMultiServiceFactory)tParam.getMSF());
74 
75         try {
76             log.println( "creating a chartdocument" );
77             xChartDoc = SOF.createChartDoc(null);
78         } catch ( Exception e ) {
79             // Some exception occures.FAILED
80             e.printStackTrace( log );
81             throw new StatusException( "Couldn't create document", e );
82         }
83 
84         comp = xChartDoc;
85     }
86 
87    /**
88      * Close document
89      */
cleanup( TestParameters tParam, PrintWriter log )90     protected void cleanup( TestParameters tParam, PrintWriter log ) {
91         if( xChartDoc!=null ) {
92             log.println( "    closing xChartDoc" );
93             util.DesktopTools.closeDoc(xChartDoc);
94             xChartDoc = null;
95             comp = null;
96         }
97     }
98 
99     /**
100     * Creating a Testenvironment for the interfaces to be tested.
101     * Creates an instance of the service
102     * <code>com.sun.star.comp.Chart.XMLStylesImporter</code><p>
103     *
104     * The chart document is set as a target document for importer.
105     *     Object relations created :
106     * <ul>
107     *  <li> <code>'XDocumentHandler.XMLData'</code> for
108     *      {@link ifc.xml.sax._XDocumentHandler} interface </li>
109     *  <li> <code>'XDocumentHandler.ImportChecker'</code> for
110     *      {@link ifc.xml.sax._XDocumentHandler} interface </li>
111     *  <li> <code>'TargetDocument'</code> for
112     *      {@link ifc.document._XImporter} interface </li>
113     * </ul>
114     */
createTestEnvironment(TestParameters tParam, PrintWriter log)115     public synchronized TestEnvironment createTestEnvironment
116             (TestParameters tParam, PrintWriter log) {
117 
118         XInterface oObj = null;
119         Object oInt = null ;
120 
121         // creation of testobject here
122         // first we write what we are intend to do to log file
123         log.println( "creating a test environment" );
124 
125         XMultiServiceFactory xMSF = (XMultiServiceFactory)tParam.getMSF() ;
126 
127         try {
128             oInt = xMSF.createInstance
129                 ("com.sun.star.comp.Chart.XMLStylesImporter") ;
130 
131         } catch (com.sun.star.uno.Exception e) {
132             e.printStackTrace(log) ;
133             throw new StatusException("Can't create component.", e) ;
134         }
135 
136         oObj = (XInterface) oInt ;
137 
138         // create testobject here
139         log.println( "creating a new environment for Paragraph object" );
140         TestEnvironment tEnv = new TestEnvironment( oObj );
141 
142         // adding relation
143         tEnv.addObjRelation("TargetDocument", comp) ;
144 
145         // adding relation for XDocumentHandler
146         String[][] xml = new String[][] {
147             {"start", "office:document-styles",
148                 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
149                 "xmlns:text", "CDATA", "http://openoffice.org/2000/text",
150                 "xmlns:chart", "CDATA", "http://openoffice.org/2000/chart",
151                 "xmlns:style", "CDATA", "http://openoffice.org/2000/style",
152                 "xmlns:svg", "CDATA", "http://openoffice.org/2000/svg",
153                 "office:class", "CDATA", "chart",
154                 "office:version", "CDATA", "1.0"
155                 },
156             {"start", "office:styles"},
157             {"end", "office:styles"},
158             {"end", "office:document-styles"}} ;
159 
160         tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
161 
162         final PrintWriter logF = log ;
163 
164         tEnv.addObjRelation("XDocumentHandler.ImportChecker",
165             new ifc.xml.sax._XDocumentHandler.ImportChecker() {
166                 public boolean checkImport() {
167                         logF.println("No ways to check styles import were not found.");
168                         logF.println(" TRUE returned.");
169                         return true ;
170 /*                    } catch (com.sun.star.uno.Exception e) {
171                         logF.println("Exception occured while checking filter :") ;
172                         e.printStackTrace(logF) ;
173                         return false ;
174                     }
175 */                }
176             }) ;
177 
178 
179         return tEnv;
180     } // finish method getTestEnvironment
181 }
182