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._scripting;
25 
26 import java.net.URLEncoder;
27 import java.io.PrintWriter;
28 
29 import lib.StatusException;
30 import lib.TestCase;
31 import lib.TestEnvironment;
32 import lib.TestParameters;
33 
34 import util.utils;
35 import util.SOfficeFactory;
36 
37 import com.sun.star.lang.XMultiServiceFactory;
38 import com.sun.star.lang.XComponent;
39 
40 import com.sun.star.uno.XInterface;
41 import com.sun.star.uno.UnoRuntime;
42 
43 import com.sun.star.frame.XModel;
44 import com.sun.star.frame.XFrame;
45 import com.sun.star.frame.XDesktop;
46 
47 
48 import com.sun.star.util.URL;
49 import com.sun.star.util.XURLTransformer;
50 
51 
52 
53 public class Dispatch extends TestCase {
54     //private String scriptURL = "script://MemoryUtils.MemUsage";
55     private String scriptURL = "script://HighlightText.showForm";
initialize( TestParameters tParam, PrintWriter log )56     public void initialize( TestParameters tParam, PrintWriter log ) {
57     }
58 
createTestEnvironment( TestParameters tParam, PrintWriter log )59     public synchronized TestEnvironment createTestEnvironment(
60         TestParameters tParam, PrintWriter log ) throws StatusException {
61 	log.println("creating test environment");
62         XInterface oObj = null;
63         URL dispatchURL = null;
64         try {
65 
66             XMultiServiceFactory xMSF = tParam.getMSF();
67             SOfficeFactory SOF = null;
68             SOF = SOfficeFactory.getFactory( xMSF );
69             String docPath = util.utils.getFullTestURL( "ExampleSpreadSheetLatest.sxc" );
70             XComponent doc = SOF.loadDocument( docPath );
71             XModel model = ( XModel ) UnoRuntime.queryInterface( XModel.class,
72                 doc );
73             XFrame frame = model.getCurrentController().getFrame();
74             oObj = ( XInterface )xMSF.createInstanceWithArguments( "com.sun.star.comp.ScriptProtocolHandler", new Object[] { frame } );
75 
76             XURLTransformer xParser=(XURLTransformer)
77                 UnoRuntime.queryInterface(XURLTransformer.class,
78                     tParam.getMSF().createInstance
79                         ("com.sun.star.util.URLTransformer"));
80             // Because it's an in/out parameter we must use an array of
81             // URL objects.
82             URL[] aParseURL = new URL[1];
83             aParseURL[0] = new URL();
84             aParseURL[0].Complete = scriptURL;
85             xParser.parseStrict(aParseURL);
86             dispatchURL = aParseURL[0];
87 
88         } catch (com.sun.star.uno.Exception e) {
89             e.printStackTrace();
90             throw new StatusException("Can't create object environment", e) ;
91         }
92 
93         TestEnvironment tEnv = new TestEnvironment(oObj) ;
94         tEnv.addObjRelation( "XDispatchProvider.URL", scriptURL );
95         tEnv.addObjRelation( "XDispatch.URL", dispatchURL );
96         return tEnv ;
97     }
98 
disposeTestEnvironment( TestEnvironment tEnv, TestParameters tParam)99     public synchronized void disposeTestEnvironment( TestEnvironment tEnv,
100             TestParameters tParam) {
101     }
102 }
103 
104 
105