Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/applet/AppletProps.java
38829 views
/*1* Copyright (c) 1995, 2003, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.applet;2627import java.awt.*;28import java.io.*;29import java.util.Properties;30import sun.net.www.http.HttpClient;31import sun.net.ftp.FtpClient;32import java.security.AccessController;33import java.security.PrivilegedAction;34import java.security.PrivilegedExceptionAction;35import java.security.PrivilegedActionException;3637import sun.security.action.*;3839class AppletProps extends Frame {4041TextField proxyHost;42TextField proxyPort;43Choice accessMode;4445AppletProps() {46setTitle(amh.getMessage("title"));47Panel p = new Panel();48p.setLayout(new GridLayout(0, 2));4950p.add(new Label(amh.getMessage("label.http.server", "Http proxy server:")));51p.add(proxyHost = new TextField());5253p.add(new Label(amh.getMessage("label.http.proxy")));54p.add(proxyPort = new TextField());5556p.add(new Label(amh.getMessage("label.class")));57p.add(accessMode = new Choice());58accessMode.addItem(amh.getMessage("choice.class.item.restricted"));59accessMode.addItem(amh.getMessage("choice.class.item.unrestricted"));6061add("Center", p);62p = new Panel();63p.add(new Button(amh.getMessage("button.apply")));64p.add(new Button(amh.getMessage("button.reset")));65p.add(new Button(amh.getMessage("button.cancel")));66add("South", p);67move(200, 150);68pack();69reset();70}7172void reset() {73AppletSecurity security = (AppletSecurity) System.getSecurityManager();74if (security != null)75security.reset();7677String proxyhost = (String) AccessController.doPrivileged(78new GetPropertyAction("http.proxyHost"));79String proxyport = (String) AccessController.doPrivileged(80new GetPropertyAction("http.proxyPort"));8182Boolean tmp = (Boolean) AccessController.doPrivileged(83new GetBooleanAction("package.restrict.access.sun"));8485boolean packageRestrict = tmp.booleanValue();86if (packageRestrict) {87accessMode.select(amh.getMessage("choice.class.item.restricted"));88} else {89accessMode.select(amh.getMessage("choice.class.item.unrestricted"));90}9192if (proxyhost != null) {93proxyHost.setText(proxyhost);94proxyPort.setText(proxyport);95} else {96proxyHost.setText("");97proxyPort.setText("");98}99}100101void apply() {102String proxyHostValue = proxyHost.getText().trim();103String proxyPortValue = proxyPort.getText().trim();104105// Get properties106final Properties props = (Properties) AccessController.doPrivileged(107new PrivilegedAction() {108public Object run() {109return System.getProperties();110}111});112113if (proxyHostValue.length() != 0) {114/* 4066402 */115/* Check for parsable value in proxy port number field before */116/* applying. Display warning to user until parsable value is */117/* entered. */118int proxyPortNumber = 0;119try {120proxyPortNumber = Integer.parseInt(proxyPortValue);121} catch (NumberFormatException e) {}122123if (proxyPortNumber <= 0) {124proxyPort.selectAll();125proxyPort.requestFocus();126(new AppletPropsErrorDialog(this,127amh.getMessage("title.invalidproxy"),128amh.getMessage("label.invalidproxy"),129amh.getMessage("button.ok"))).show();130return;131}132/* end 4066402 */133134props.put("http.proxyHost", proxyHostValue);135props.put("http.proxyPort", proxyPortValue);136} else {137props.put("http.proxyHost", "");138}139140if (amh.getMessage("choice.class.item.restricted").equals(accessMode.getSelectedItem())) {141props.put("package.restrict.access.sun", "true");142} else {143props.put("package.restrict.access.sun", "false");144}145146// Save properties147try {148reset();149AccessController.doPrivileged(new PrivilegedExceptionAction() {150public Object run() throws IOException {151File dotAV = Main.theUserPropertiesFile;152FileOutputStream out = new FileOutputStream(dotAV);153Properties avProps = new Properties();154for (int i = 0; i < Main.avDefaultUserProps.length; i++) {155String avKey = Main.avDefaultUserProps[i][0];156avProps.setProperty(avKey, props.getProperty(avKey));157}158avProps.store(out, amh.getMessage("prop.store"));159out.close();160return null;161}162});163hide();164} catch (java.security.PrivilegedActionException e) {165System.out.println(amh.getMessage("apply.exception",166e.getException()));167// XXX what's the general feeling on stack traces to System.out?168e.printStackTrace();169reset();170}171}172173public boolean action(Event evt, Object obj) {174if (amh.getMessage("button.apply").equals(obj)) {175apply();176return true;177}178if (amh.getMessage("button.reset").equals(obj)) {179reset();180return true;181}182if (amh.getMessage("button.cancel").equals(obj)) {183reset();184hide();185return true;186}187return false;188}189190private static AppletMessageHandler amh = new AppletMessageHandler("appletprops");191192}193194/* 4066432 */195/* Dialog class to display property-related errors to user */196197class AppletPropsErrorDialog extends Dialog {198public AppletPropsErrorDialog(Frame parent, String title, String message,199String buttonText) {200super(parent, title, true);201Panel p = new Panel();202add("Center", new Label(message));203p.add(new Button(buttonText));204add("South", p);205pack();206207Dimension dDim = size();208Rectangle fRect = parent.bounds();209move(fRect.x + ((fRect.width - dDim.width) / 2),210fRect.y + ((fRect.height - dDim.height) / 2));211}212213public boolean action(Event event, Object object) {214hide();215dispose();216return true;217}218}219220/* end 4066432 */221222223