Source Code Cross Referenced for BrowserProxyInfo.java in  » Portal » Open-Portal » com » sun » portal » netlet » client » applet » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.portal.netlet.client.applet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // @(#)BrowserProxyInfo.java 1.5     "@(#)BrowserProxyInfo.java	1.5 01/07/16 Sun Microsystems"
002:
003:        package com.sun.portal.netlet.client.applet;
004:
005:        import netscape.javascript.JSObject;
006:        import java.util.Enumeration;
007:        import java.util.StringTokenizer;
008:        import java.util.Vector;
009:
010:        import com.sun.portal.netlet.client.common.ProxyInfo;
011:        import com.sun.portal.netlet.client.common.BrowserType;
012:        import com.sun.portal.netlet.client.common.ClientUtil;
013:        import com.sun.portal.netlet.client.common.ResourceProperties;
014:
015:        public class BrowserProxyInfo {
016:
017:            JSObject window;
018:            String js_proxy_ssl;
019:            String proxy_ssl;
020:            String js_proxy_ssl_port;
021:            int proxy_ssl_port;
022:            String js_proxy_type;
023:            int proxy_type;
024:            String js_localhost;
025:            String localhost;
026:            String js_set_localhost;
027:
028:            String js_addlocal;
029:            String addlocal;
030:
031:            Vector noProxiesFor = new Vector();
032:
033:            private boolean privilegesGranted = false;
034:
035:            public BrowserProxyInfo(ProxyInfo pi) {
036:                //System.out.println("Netlet reading browser proxy configuration");
037:                BrowserType browser = BrowserType.getInstance();
038:
039:                if (browser.getNetscapeBrowser()
040:                        && browser.getJavaVMVersion() == 1) {
041:                    try {
042:                        BrowserType.SecurityCall sc = browser
043:                                .enablePermission(BrowserType.NETSCAPE_UNIVERSAL_PREFERENCES_READ);
044:                        sc.getMethod().invoke(null, sc.getArgs());
045:                        sc = browser
046:                                .enablePermission(BrowserType.NETSCAPE_UNIVERSAL_PREFERENCES_WRITE);
047:                        sc.getMethod().invoke(null, sc.getArgs());
048:                    } catch (Exception e) {
049:                        privilegesGranted = false;
050:                        return;
051:                    }
052:                    privilegesGranted = true;
053:                }
054:
055:                window = JSObject.getWindow(NetletApplet.getInstance());
056:                js_proxy_ssl = new String(
057:                        "netscape.security.PrivilegeManager.enablePrivilege(\"UniversalPreferencesRead\");navigator.preference(\"network.proxy.ssl\");");
058:
059:                js_proxy_ssl_port = new String(
060:                        "netscape.security.PrivilegeManager.enablePrivilege(\"UniversalPreferencesRead\");navigator.preference(\"network.proxy.ssl_port\");");
061:
062:                js_proxy_type = new String(
063:                        "netscape.security.PrivilegeManager.enablePrivilege(\"UniversalPreferencesRead\");navigator.preference(\"network.proxy.type\");");
064:
065:                proxy_ssl = (String) window.eval(js_proxy_ssl);
066:                proxy_ssl_port = ((Double) window.eval(js_proxy_ssl_port))
067:                        .intValue();
068:                proxy_type = ((Double) window.eval(js_proxy_type)).intValue();
069:
070:                if (proxy_type == 2) {
071:                    //automatic proxy
072:                    String autoProxyUrl = new String(
073:                            "netscape.security.PrivilegeManager.enablePrivilege(\"UniversalPreferencesRead\");navigator.preference(\"network.proxy.autoconfig_url\");");
074:                    String pacUrl = window.eval(autoProxyUrl).toString();
075:
076:                    //  As the applet can not connect to any server it is not downloaded from, get the Privilage to access the Proxy server to get the PAC file
077:                    try {
078:                        BrowserType.SecurityCall sc = browser
079:                                .enablePermission(BrowserType.NETSCAPE_UNIVERSAL_CONNECT);
080:                        sc.getMethod().invoke(null, sc.getArgs());
081:                        sc = browser
082:                                .enablePermission(BrowserType.NETSCAPE_UNIVERSAL_LISTEN);
083:                        sc.getMethod().invoke(null, sc.getArgs());
084:                        sc = browser
085:                                .enablePermission(BrowserType.NETSCAPE_UNIVERSAL_ACCEPT);
086:                        sc.getMethod().invoke(null, sc.getArgs());
087:                        sc = browser
088:                                .enablePermission(BrowserType.NETSCAPE_UNIVERSAL_FILE_ACCESS);
089:                        sc.getMethod().invoke(null, sc.getArgs());
090:                    } catch (Exception e) {
091:                        System.out
092:                                .println("SClient exception (start) (no privilege): "
093:                                        + e);
094:                    }
095:
096:                    String inputLine = ClientUtil.parsePACFile(pacUrl);
097:
098:                    if (inputLine.equalsIgnoreCase("DIRECT")) {
099:                        //no proxy required
100:                        proxy_type = 3;
101:                    } else {
102:                        if (inputLine.startsWith("PROXY")) {
103:                            /*
104:                             * @ modified by bshankar@sun.com for Bug - 4625682.
105:                             * Instead of taking the first proxy, use the first valid proxy
106:                             */
107:                            boolean isValid = false;
108:                            StringTokenizer tok = new StringTokenizer(
109:                                    inputLine, ";");
110:                            while (tok.hasMoreTokens() && !isValid) {
111:                                String str = tok.nextToken().trim();
112:                                String proxyString = (str.indexOf("PROXY") == 0) ? str
113:                                        .substring("PROXY".length()).trim()
114:                                        : str;
115:                                int index = proxyString.indexOf(":");
116:                                String proxyHost = null;
117:                                String proxyPort = null;
118:                                if (index == -1) {
119:                                    proxyHost = proxyString;
120:                                    proxyPort = new String("80");
121:                                } else {
122:                                    proxyHost = proxyString.substring(0, index);
123:                                    proxyPort = proxyString
124:                                            .substring(index + 1);
125:                                }
126:                                proxy_ssl = proxyHost.trim();
127:                                proxy_ssl_port = Integer.parseInt(proxyPort);
128:                                isValid = ClientUtil.isProxySettingsValid(
129:                                        proxy_ssl, proxy_ssl_port);
130:                                //isValid = isProxySettingsValid(proxy_ssl, proxy_ssl_port);
131:                            }
132:                            if (!isValid) {
133:                                pi.getProxyWarning()
134:                                        .setMessage(
135:                                                ResourceProperties
136:                                                        .getString("pwarn.4"));
137:                                proxy_ssl = "";
138:                                proxy_ssl_port = 0;
139:                            }
140:                        }
141:                    }
142:                    //else it would have failed, donot do anything so that it will show the dialog
143:                }
144:
145:                findLocalhostNoProxy();
146:            }
147:
148:            public void setLocalhostNoProxy() {
149:                js_set_localhost = new String(
150:                        "netscape.security.PrivilegeManager.enablePrivilege(\"UniversalPreferencesRead\");netscape.security.PrivilegeManager.enablePrivilege(\"UniversalPreferencesWrite\"); var addlocal = navigator.preference(\"network.proxy.no_proxies_on\"); myRe=/localhost/;if (!myRe.test(addlocal)) { navigator.preference(\"network.proxy.no_proxies_on\", addlocal + \", localhost\");}");
151:
152:                //System.out.println("js_set_localhost = " + js_set_localhost);
153:
154:                js_localhost = new String(
155:                        "netscape.security.PrivilegeManager.enablePrivilege(\"UniversalPreferencesRead\");navigator.preference(\"network.proxy.no_proxies_on\");");
156:
157:                //localhost = (String)window.eval(js_set_localhost);
158:                window.eval(js_set_localhost);
159:                //System.out.println("Netlet set localhost as no-proxy");
160:
161:                localhost = (String) window.eval(js_localhost);
162:                System.out.println("Netlet no-proxy hosts:" + localhost);
163:            }
164:
165:            public String getProxySSL() {
166:                return (proxy_ssl);
167:            }
168:
169:            public int getProxySSLPort() {
170:                return (proxy_ssl_port);
171:            }
172:
173:            public int getProxyType() {
174:                return (proxy_type);
175:            }
176:
177:            public String getLocalhostNoProxy() {
178:                return (addlocal);
179:            }
180:
181:            public boolean inLocalhostNoProxy(String host) {
182:                for (Enumeration e = noProxiesFor.elements(); e
183:                        .hasMoreElements();) {
184:                    String s = (String) e.nextElement();
185:                    if (host.toLowerCase().endsWith(s.toLowerCase())) {
186:                        return (true);
187:                    }
188:                }
189:                return (false);
190:            }
191:
192:            private void findLocalhostNoProxy() {
193:                String js_addlocal;
194:                String addlocal;
195:
196:                js_addlocal = new String(
197:                        "netscape.security.PrivilegeManager.enablePrivilege(\"UniversalPreferencesRead\");navigator.preference(\"network.proxy.no_proxies_on\");");
198:
199:                addlocal = (String) window.eval(js_addlocal);
200:
201:                //System.out.println("Netlet got no-proxy settings from browser:" + addlocal);
202:
203:                StringTokenizer nst = new StringTokenizer(addlocal, ",");
204:                while (nst.hasMoreTokens()) {
205:                    String s = nst.nextToken().toLowerCase().trim();
206:                    if (!s.equals("")) {
207:                        noProxiesFor.addElement(s);
208:                        //System.out.println("no proxy for putting " + s);
209:                    }
210:                }
211:            }
212:
213:            public boolean getPrivilegesGranted() {
214:                return privilegesGranted;
215:            }
216:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.