325N/A/*
325N/A * Copyright (c) 1995, 2003, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage sun.applet;
325N/A
325N/Aimport java.awt.*;
325N/Aimport java.io.*;
325N/Aimport java.util.Properties;
325N/Aimport sun.net.www.http.HttpClient;
325N/Aimport sun.net.ftp.FtpClient;
325N/Aimport java.security.AccessController;
325N/Aimport java.security.PrivilegedAction;
325N/Aimport java.security.PrivilegedExceptionAction;
325N/Aimport java.security.PrivilegedActionException;
325N/A
325N/Aimport sun.security.action.*;
325N/A
325N/Aclass AppletProps extends Frame {
325N/A
325N/A TextField proxyHost;
325N/A TextField proxyPort;
325N/A Choice accessMode;
325N/A
325N/A AppletProps() {
325N/A setTitle(amh.getMessage("title"));
325N/A Panel p = new Panel();
325N/A p.setLayout(new GridLayout(0, 2));
325N/A
325N/A p.add(new Label(amh.getMessage("label.http.server", "Http proxy server:")));
325N/A p.add(proxyHost = new TextField());
325N/A
325N/A p.add(new Label(amh.getMessage("label.http.proxy")));
325N/A p.add(proxyPort = new TextField());
325N/A
325N/A p.add(new Label(amh.getMessage("label.class")));
325N/A p.add(accessMode = new Choice());
325N/A accessMode.addItem(amh.getMessage("choice.class.item.restricted"));
325N/A accessMode.addItem(amh.getMessage("choice.class.item.unrestricted"));
325N/A
325N/A add("Center", p);
325N/A p = new Panel();
325N/A p.add(new Button(amh.getMessage("button.apply")));
325N/A p.add(new Button(amh.getMessage("button.reset")));
325N/A p.add(new Button(amh.getMessage("button.cancel")));
325N/A add("South", p);
325N/A move(200, 150);
325N/A pack();
325N/A reset();
325N/A }
325N/A
325N/A void reset() {
325N/A AppletSecurity security = (AppletSecurity) System.getSecurityManager();
325N/A if (security != null)
325N/A security.reset();
325N/A
325N/A String proxyhost = (String) AccessController.doPrivileged(
325N/A new GetPropertyAction("http.proxyHost"));
325N/A String proxyport = (String) AccessController.doPrivileged(
325N/A new GetPropertyAction("http.proxyPort"));
325N/A
325N/A Boolean tmp = (Boolean) AccessController.doPrivileged(
325N/A new GetBooleanAction("package.restrict.access.sun"));
325N/A
325N/A boolean packageRestrict = tmp.booleanValue();
325N/A if (packageRestrict) {
325N/A accessMode.select(amh.getMessage("choice.class.item.restricted"));
325N/A } else {
325N/A accessMode.select(amh.getMessage("choice.class.item.unrestricted"));
325N/A }
325N/A
325N/A if (proxyhost != null) {
325N/A proxyHost.setText(proxyhost);
325N/A proxyPort.setText(proxyport);
325N/A } else {
325N/A proxyHost.setText("");
325N/A proxyPort.setText("");
325N/A }
325N/A }
325N/A
325N/A void apply() {
325N/A String proxyHostValue = proxyHost.getText().trim();
325N/A String proxyPortValue = proxyPort.getText().trim();
325N/A
325N/A // Get properties
325N/A final Properties props = (Properties) AccessController.doPrivileged(
325N/A new PrivilegedAction() {
325N/A public Object run() {
325N/A return System.getProperties();
325N/A }
325N/A });
325N/A
325N/A if (proxyHostValue.length() != 0) {
325N/A /* 4066402 */
325N/A /* Check for parsable value in proxy port number field before */
325N/A /* applying. Display warning to user until parsable value is */
325N/A /* entered. */
325N/A int proxyPortNumber = 0;
325N/A try {
325N/A proxyPortNumber = Integer.parseInt(proxyPortValue);
} catch (NumberFormatException e) {}
if (proxyPortNumber <= 0) {
proxyPort.selectAll();
proxyPort.requestFocus();
(new AppletPropsErrorDialog(this,
amh.getMessage("title.invalidproxy"),
amh.getMessage("label.invalidproxy"),
amh.getMessage("button.ok"))).show();
return;
}
/* end 4066402 */
props.put("http.proxyHost", proxyHostValue);
props.put("http.proxyPort", proxyPortValue);
} else {
props.put("http.proxyHost", "");
}
if (amh.getMessage("choice.class.item.restricted").equals(accessMode.getSelectedItem())) {
props.put("package.restrict.access.sun", "true");
} else {
props.put("package.restrict.access.sun", "false");
}
// Save properties
try {
reset();
AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws IOException {
File dotAV = Main.theUserPropertiesFile;
FileOutputStream out = new FileOutputStream(dotAV);
Properties avProps = new Properties();
for (int i = 0; i < Main.avDefaultUserProps.length; i++) {
String avKey = Main.avDefaultUserProps[i][0];
avProps.setProperty(avKey, props.getProperty(avKey));
}
avProps.store(out, amh.getMessage("prop.store"));
out.close();
return null;
}
});
hide();
} catch (java.security.PrivilegedActionException e) {
System.out.println(amh.getMessage("apply.exception",
e.getException()));
// XXX what's the general feeling on stack traces to System.out?
e.printStackTrace();
reset();
}
}
public boolean action(Event evt, Object obj) {
if (amh.getMessage("button.apply").equals(obj)) {
apply();
return true;
}
if (amh.getMessage("button.reset").equals(obj)) {
reset();
return true;
}
if (amh.getMessage("button.cancel").equals(obj)) {
reset();
hide();
return true;
}
return false;
}
private static AppletMessageHandler amh = new AppletMessageHandler("appletprops");
}
/* 4066432 */
/* Dialog class to display property-related errors to user */
class AppletPropsErrorDialog extends Dialog {
public AppletPropsErrorDialog(Frame parent, String title, String message,
String buttonText) {
super(parent, title, true);
Panel p = new Panel();
add("Center", new Label(message));
p.add(new Button(buttonText));
add("South", p);
pack();
Dimension dDim = size();
Rectangle fRect = parent.bounds();
move(fRect.x + ((fRect.width - dDim.width) / 2),
fRect.y + ((fRect.height - dDim.height) / 2));
}
public boolean action(Event event, Object object) {
hide();
dispose();
return true;
}
}
/* end 4066432 */