source: trunk/src/org/expeditee/settings/network/proxy/ProxySettings.java@ 919

Last change on this file since 919 was 919, checked in by jts21, 10 years ago

Added license headers to all files, added full GPL3 license file, moved license header generator script to dev/bin/scripts

File size: 4.2 KB
Line 
1/**
2 * ProxySettings.java
3 * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package org.expeditee.settings.network.proxy;
20
21import org.expeditee.gui.Browser;
22import org.expeditee.gui.MessageBay;
23import org.expeditee.items.Item;
24import org.expeditee.items.Text;
25import org.expeditee.items.widgets.InteractiveWidget;
26import org.expeditee.items.widgets.Password;
27import org.expeditee.items.widgets.WidgetCorner;
28import org.expeditee.items.widgets.WidgetEdge;
29import org.expeditee.setting.StringSetting;
30
31public abstract class ProxySettings {
32
33 private static boolean _warned = false;
34 public static final StringSetting Host = new StringSetting("The host for the proxy", null);
35 public static final StringSetting Port = new StringSetting("The port for the proxy (e.g. port 80)", "80");
36 public static final StringSetting User = new StringSetting("Your username for the proxy", null);
37 public static final StringSetting Pass = new StringSetting("Your password for the proxy", null);
38
39 public static void onParsed(Text text) {
40
41 // standard settings parsing won't find the password,
42 // so check if there's a password widget on the frame
43 Password passwordWidget = null;
44
45 for (Item i : text.getChild().getAllItems()) {
46 if (i instanceof Text) {
47 String str = i.getText().trim();
48 String strLower = str.toLowerCase();
49 if (strLower.startsWith("@iw:")) { // widget
50 // check if it's a password widget
51 if (strLower.substring(4).trim().startsWith("org.expeditee.items.widgets.password")) {
52 if (passwordWidget == null) {
53 try {
54 passwordWidget = (Password) InteractiveWidget.createWidget((Text) i);
55 if (Pass.get() != null) {
56 // MessageBay.displayMessage("pass was defined multiple times!", Color.ORANGE);
57 }
58 Pass.set(passwordWidget.getPassword());
59 } catch (Exception e) {
60 e.printStackTrace();
61 }
62 }
63 }
64 }
65 } else if(i instanceof WidgetCorner || i instanceof WidgetEdge) {
66 if(passwordWidget == null) {
67 InteractiveWidget iw;
68 if(i instanceof WidgetCorner) {
69 iw = ((WidgetCorner)i).getWidgetSource();
70 } else {
71 iw = ((WidgetEdge)i).getWidgetSource();
72 }
73 if(iw instanceof Password) {
74 passwordWidget = (Password) iw;
75 }
76 if(Pass.get() != null) {
77 // MessageBay.displayMessage("pass was defined multiple times!", Color.ORANGE);
78 }
79 Pass.set(passwordWidget.getPassword());
80 }
81 }
82 }
83
84 if(Host.get() == null) {
85 if(!_warned) {
86 MessageBay.warningMessage("@Settings: Network->Proxy->Host was not defined -- assuming direct Internet connection");
87 _warned = true;
88 }
89 return;
90 }
91 if(Port.get() == null) {
92 if(!_warned) {
93 MessageBay.warningMessage("@Settings: Network->Proxy->Port was not defined (defaulted to 80)");
94 _warned = true;
95 }
96 Port.set("80");
97 }
98 if(User.get() == null) {
99 if(!_warned) {
100 MessageBay.warningMessage("@Settings: Network->Proxy->User was not defined");
101 _warned = true;
102 }
103 return;
104 }
105 if(Pass.get() == null) {
106 if(!_warned) {
107 MessageBay.warningMessage("proxy pass was not defined");
108 _warned = true;
109 }
110 return;
111 }
112 // TODO: Is it possible to have different host/port for http/https protocols for a proxy server?
113 System.setProperty("http.proxyHost", Host.get());
114 System.setProperty("http.proxyPort", Port.get());
115 System.setProperty("https.proxyHost", Host.get());
116 System.setProperty("https.proxyPort", Port.get());
117 Browser.proxyAuth.setup(User.get(), Pass.get());
118
119 // System.out.println("proxy parsed");
120 }
121}
Note: See TracBrowser for help on using the repository browser.