< prev index next >

src/java.desktop/share/classes/sun/applet/AppletProps.java

Print this page




  27 
  28 import java.awt.*;
  29 import java.io.*;
  30 import java.util.Properties;
  31 import sun.net.www.http.HttpClient;
  32 import sun.net.ftp.FtpClient;
  33 import java.security.AccessController;
  34 import java.security.PrivilegedAction;
  35 import java.security.PrivilegedExceptionAction;
  36 import java.security.PrivilegedActionException;
  37 
  38 import sun.security.action.*;
  39 
  40 @SuppressWarnings("serial") // JDK implementation class
  41 class AppletProps extends Frame {
  42 
  43     TextField proxyHost;
  44     TextField proxyPort;
  45     Choice accessMode;
  46 

  47     AppletProps() {
  48         setTitle(amh.getMessage("title"));
  49         Panel p = new Panel();
  50         p.setLayout(new GridLayout(0, 2));
  51 
  52         p.add(new Label(amh.getMessage("label.http.server", "Http proxy server:")));
  53         p.add(proxyHost = new TextField());
  54 
  55         p.add(new Label(amh.getMessage("label.http.proxy")));
  56         p.add(proxyPort = new TextField());
  57 
  58         p.add(new Label(amh.getMessage("label.class")));
  59         p.add(accessMode = new Choice());
  60         accessMode.addItem(amh.getMessage("choice.class.item.restricted"));
  61         accessMode.addItem(amh.getMessage("choice.class.item.unrestricted"));
  62 
  63         add("Center", p);
  64         p = new Panel();
  65         p.add(new Button(amh.getMessage("button.apply")));
  66         p.add(new Button(amh.getMessage("button.reset")));


  83 
  84         Boolean tmp = AccessController.doPrivileged(
  85                 new GetBooleanAction("package.restrict.access.sun"));
  86 
  87         boolean packageRestrict = tmp.booleanValue();
  88         if (packageRestrict) {
  89            accessMode.select(amh.getMessage("choice.class.item.restricted"));
  90         } else {
  91            accessMode.select(amh.getMessage("choice.class.item.unrestricted"));
  92         }
  93 
  94         if (proxyhost != null) {
  95             proxyHost.setText(proxyhost);
  96             proxyPort.setText(proxyport);
  97         } else {
  98             proxyHost.setText("");
  99             proxyPort.setText("");
 100         }
 101     }
 102 

 103     void apply() {
 104         String proxyHostValue = proxyHost.getText().trim();
 105         String proxyPortValue = proxyPort.getText().trim();
 106 
 107         // Get properties
 108         final Properties props = AccessController.doPrivileged(
 109              new PrivilegedAction<Properties>() {
 110                  public Properties run() {
 111                      return System.getProperties();
 112                  }
 113         });
 114 
 115         if (proxyHostValue.length() != 0) {
 116             /* 4066402 */
 117             /* Check for parsable value in proxy port number field before */
 118             /* applying. Display warning to user until parsable value is  */
 119             /* entered. */
 120             int proxyPortNumber = 0;
 121             try {
 122                 proxyPortNumber = Integer.parseInt(proxyPortValue);


 155                     Properties avProps = new Properties();
 156                     for (int i = 0; i < Main.avDefaultUserProps.length; i++) {
 157                         String avKey = Main.avDefaultUserProps[i][0];
 158                         avProps.setProperty(avKey, props.getProperty(avKey));
 159                     }
 160                     avProps.store(out, amh.getMessage("prop.store"));
 161                     out.close();
 162                     return null;
 163                 }
 164             });
 165             hide();
 166         } catch (java.security.PrivilegedActionException e) {
 167             System.out.println(amh.getMessage("apply.exception",
 168                                               e.getException()));
 169             // XXX what's the general feeling on stack traces to System.out?
 170             e.printStackTrace();
 171             reset();
 172         }
 173     }
 174 

 175     public boolean action(Event evt, Object obj) {
 176         if (amh.getMessage("button.apply").equals(obj)) {
 177             apply();
 178             return true;
 179         }
 180         if (amh.getMessage("button.reset").equals(obj)) {
 181             reset();
 182             return true;
 183         }
 184         if (amh.getMessage("button.cancel").equals(obj)) {
 185             reset();
 186             hide();
 187             return true;
 188         }
 189         return false;
 190     }
 191 
 192     private static AppletMessageHandler amh = new AppletMessageHandler("appletprops");
 193 
 194 }
 195 
 196 /* 4066432 */
 197 /* Dialog class to display property-related errors to user */
 198 @SuppressWarnings("serial") // JDK implementation class
 199 class AppletPropsErrorDialog extends Dialog {

 200     public AppletPropsErrorDialog(Frame parent, String title, String message,
 201                 String buttonText) {
 202         super(parent, title, true);
 203         Panel p = new Panel();
 204         add("Center", new Label(message));
 205         p.add(new Button(buttonText));
 206         add("South", p);
 207         pack();
 208 
 209         Dimension dDim = size();
 210         Rectangle fRect = parent.bounds();
 211         move(fRect.x + ((fRect.width - dDim.width) / 2),
 212              fRect.y + ((fRect.height - dDim.height) / 2));
 213     }
 214 

 215     public boolean action(Event event, Object object) {
 216         hide();
 217         dispose();
 218         return true;
 219     }
 220 }
 221 
 222 /* end 4066432 */


  27 
  28 import java.awt.*;
  29 import java.io.*;
  30 import java.util.Properties;
  31 import sun.net.www.http.HttpClient;
  32 import sun.net.ftp.FtpClient;
  33 import java.security.AccessController;
  34 import java.security.PrivilegedAction;
  35 import java.security.PrivilegedExceptionAction;
  36 import java.security.PrivilegedActionException;
  37 
  38 import sun.security.action.*;
  39 
  40 @SuppressWarnings("serial") // JDK implementation class
  41 class AppletProps extends Frame {
  42 
  43     TextField proxyHost;
  44     TextField proxyPort;
  45     Choice accessMode;
  46 
  47     @SuppressWarnings("deprecation")
  48     AppletProps() {
  49         setTitle(amh.getMessage("title"));
  50         Panel p = new Panel();
  51         p.setLayout(new GridLayout(0, 2));
  52 
  53         p.add(new Label(amh.getMessage("label.http.server", "Http proxy server:")));
  54         p.add(proxyHost = new TextField());
  55 
  56         p.add(new Label(amh.getMessage("label.http.proxy")));
  57         p.add(proxyPort = new TextField());
  58 
  59         p.add(new Label(amh.getMessage("label.class")));
  60         p.add(accessMode = new Choice());
  61         accessMode.addItem(amh.getMessage("choice.class.item.restricted"));
  62         accessMode.addItem(amh.getMessage("choice.class.item.unrestricted"));
  63 
  64         add("Center", p);
  65         p = new Panel();
  66         p.add(new Button(amh.getMessage("button.apply")));
  67         p.add(new Button(amh.getMessage("button.reset")));


  84 
  85         Boolean tmp = AccessController.doPrivileged(
  86                 new GetBooleanAction("package.restrict.access.sun"));
  87 
  88         boolean packageRestrict = tmp.booleanValue();
  89         if (packageRestrict) {
  90            accessMode.select(amh.getMessage("choice.class.item.restricted"));
  91         } else {
  92            accessMode.select(amh.getMessage("choice.class.item.unrestricted"));
  93         }
  94 
  95         if (proxyhost != null) {
  96             proxyHost.setText(proxyhost);
  97             proxyPort.setText(proxyport);
  98         } else {
  99             proxyHost.setText("");
 100             proxyPort.setText("");
 101         }
 102     }
 103 
 104     @SuppressWarnings("deprecation")
 105     void apply() {
 106         String proxyHostValue = proxyHost.getText().trim();
 107         String proxyPortValue = proxyPort.getText().trim();
 108 
 109         // Get properties
 110         final Properties props = AccessController.doPrivileged(
 111              new PrivilegedAction<Properties>() {
 112                  public Properties run() {
 113                      return System.getProperties();
 114                  }
 115         });
 116 
 117         if (proxyHostValue.length() != 0) {
 118             /* 4066402 */
 119             /* Check for parsable value in proxy port number field before */
 120             /* applying. Display warning to user until parsable value is  */
 121             /* entered. */
 122             int proxyPortNumber = 0;
 123             try {
 124                 proxyPortNumber = Integer.parseInt(proxyPortValue);


 157                     Properties avProps = new Properties();
 158                     for (int i = 0; i < Main.avDefaultUserProps.length; i++) {
 159                         String avKey = Main.avDefaultUserProps[i][0];
 160                         avProps.setProperty(avKey, props.getProperty(avKey));
 161                     }
 162                     avProps.store(out, amh.getMessage("prop.store"));
 163                     out.close();
 164                     return null;
 165                 }
 166             });
 167             hide();
 168         } catch (java.security.PrivilegedActionException e) {
 169             System.out.println(amh.getMessage("apply.exception",
 170                                               e.getException()));
 171             // XXX what's the general feeling on stack traces to System.out?
 172             e.printStackTrace();
 173             reset();
 174         }
 175     }
 176 
 177     @SuppressWarnings("deprecation")
 178     public boolean action(Event evt, Object obj) {
 179         if (amh.getMessage("button.apply").equals(obj)) {
 180             apply();
 181             return true;
 182         }
 183         if (amh.getMessage("button.reset").equals(obj)) {
 184             reset();
 185             return true;
 186         }
 187         if (amh.getMessage("button.cancel").equals(obj)) {
 188             reset();
 189             hide();
 190             return true;
 191         }
 192         return false;
 193     }
 194 
 195     private static AppletMessageHandler amh = new AppletMessageHandler("appletprops");
 196 
 197 }
 198 
 199 /* 4066432 */
 200 /* Dialog class to display property-related errors to user */
 201 @SuppressWarnings("serial") // JDK implementation class
 202 class AppletPropsErrorDialog extends Dialog {
 203     @SuppressWarnings("deprecation")
 204     public AppletPropsErrorDialog(Frame parent, String title, String message,
 205                 String buttonText) {
 206         super(parent, title, true);
 207         Panel p = new Panel();
 208         add("Center", new Label(message));
 209         p.add(new Button(buttonText));
 210         add("South", p);
 211         pack();
 212 
 213         Dimension dDim = size();
 214         Rectangle fRect = parent.bounds();
 215         move(fRect.x + ((fRect.width - dDim.width) / 2),
 216              fRect.y + ((fRect.height - dDim.height) / 2));
 217     }
 218 
 219     @SuppressWarnings("deprecation")
 220     public boolean action(Event event, Object object) {
 221         hide();
 222         dispose();
 223         return true;
 224     }
 225 }
 226 
 227 /* end 4066432 */
< prev index next >