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 package helper;
24 
25 import com.sun.star.beans.PropertyValue;
26 import com.sun.star.beans.XPropertySet;
27 import com.sun.star.lang.XMultiServiceFactory;
28 import com.sun.star.uno.UnoRuntime;
29 
30 // access the implementations via names
31 import com.sun.star.util.XChangesBatch;
32 
33 import lib.TestParameters;
34 
35 
36 public class InetTools {
37     /**
38      * Helper method: sets the HTTP-Proxy to values from
39      * <code>lib.TestParameters</code>
40      */
setHTTPProxy(TestParameters param)41     public static boolean setHTTPProxy(TestParameters param){
42         XMultiServiceFactory xMSF = (XMultiServiceFactory) param.getMSF();
43         PropertyValue[] ProvArgs = new PropertyValue[1];
44         PropertyValue Arg = new PropertyValue();
45         Arg.Name = "nodepath";
46         Arg.Value = "/org.openoffice.Inet/Settings";
47         ProvArgs[0] = Arg;
48 
49         try {
50             Object oProvider = xMSF.createInstance(
51                                        "com.sun.star.configuration.ConfigurationProvider");
52 
53             XMultiServiceFactory oProviderMSF = (XMultiServiceFactory) UnoRuntime.queryInterface(
54                                                         XMultiServiceFactory.class,
55                                                         oProvider);
56 
57             Object oInet = oProviderMSF.createInstanceWithArguments(
58                                    "com.sun.star.configuration.ConfigurationUpdateAccess",
59                                    ProvArgs);
60 
61             XPropertySet oInetProps = (XPropertySet) UnoRuntime.queryInterface(
62                                               XPropertySet.class, oInet);
63 
64             String HTTPProxyName = (String)param.get("HTTPProxyName");
65             String HTTPProxyPort = (String)param.get("HTTPProxyPort");
66 
67             if ((HTTPProxyName == null) || (HTTPProxyPort == null)) {
68                 return false;
69             }
70 
71             oInetProps.setPropertyValue("ooInetHTTPProxyName", HTTPProxyName);
72             oInetProps.setPropertyValue("ooInetHTTPProxyPort", HTTPProxyPort);
73             oInetProps.setPropertyValue("ooInetProxyType", new Long(2));
74 
75             XChangesBatch oSecureChange = (XChangesBatch) UnoRuntime.queryInterface(
76                                                   XChangesBatch.class, oInet);
77             oSecureChange.commitChanges();
78         }
79         catch(com.sun.star.uno.Exception e) {
80             e.printStackTrace();
81         }
82         return true;
83     }
84 }
85