home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 1999 March / maximum-cd-1999-03.iso / Feature / Lotus / ORGANIZE / COMPNENT / LTOUIN21.ZIP / sun / activator / panel / ConfigurationInfo.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-03-12  |  8.3 KB  |  373 lines

  1. package sun.activator.panel;
  2.  
  3. import java.io.BufferedInputStream;
  4. import java.io.File;
  5. import java.io.FileInputStream;
  6. import java.io.FileOutputStream;
  7. import java.io.IOException;
  8. import java.util.Observable;
  9. import java.util.Properties;
  10. import sun.activator.AppletMessageHandler;
  11. import sun.activator.AppletViewer;
  12.  
  13. public class ConfigurationInfo extends Observable {
  14.    private static File theUserPropertiesFile;
  15.    private Properties props;
  16.    private String[] networkAccessTable = new String[3];
  17.    private String[] classAccessTable = new String[2];
  18.    private String[] unsignedAppletTable = new String[2];
  19.    private boolean debugMode;
  20.    private boolean activatorEnabled;
  21.    private boolean showConsole;
  22.    private boolean useJIT = false;
  23.    private String JITPath;
  24.    private int networkMode;
  25.    private int classAccess;
  26.    private int unsignedAccess;
  27.    private String debugPort;
  28.    private String[] installedJavaVersion;
  29.    private String jdk;
  30.    private boolean useDefaultProxy;
  31.    private boolean useSameProxy;
  32.    private String proxySettings;
  33.    private static final String networkKey = "appletviewer.security.mode";
  34.    static final int NETWORK_NONE = 0;
  35.    static final int NETWORK_HOST = 1;
  36.    static final int NETWORK_UNRESTRICTED = 2;
  37.    private static final String classKey = "package.restrict.access.netscape";
  38.    private static final int CLASS_ACCESS_RESTRICTED = 0;
  39.    private static final int CLASS_ACCESS_UNRESTRICTED = 1;
  40.    private static final String unsignedKey = "appletviewer.security.allowUnsigned";
  41.    private static final int UNSIGNED_ACCESS_NO = 0;
  42.    private static final int UNSIGNED_ACCESS_YES = 1;
  43.    private static AppletMessageHandler amh = new AppletMessageHandler("appletprops");
  44.  
  45.    public ConfigurationInfo() {
  46.       if (theUserPropertiesFile == null) {
  47.          String var1 = File.separator;
  48.          theUserPropertiesFile = new File(System.getProperty("user.home") + var1 + ".java" + var1 + "properties");
  49.          (new File(theUserPropertiesFile.getParent())).mkdirs();
  50.       }
  51.  
  52.       this.initialize();
  53.       this.reset();
  54.    }
  55.  
  56.    public void applyChanges() {
  57.       this.props.put("activator.version", AppletViewer.theVersion);
  58.       this.props.put("activator.console", this.showConsole ? "true" : "false");
  59.       this.props.put("activator.enabled", this.activatorEnabled ? "true" : "false");
  60.       if (this.classAccess == 0) {
  61.          this.props.put("package.restrict.access.sun", "true");
  62.          this.props.put("package.restrict.access.netscape", "true");
  63.       } else {
  64.          this.props.put("package.restrict.access.sun", "false");
  65.          this.props.put("package.restrict.access.netscape", "false");
  66.       }
  67.  
  68.       if (this.networkMode == 0) {
  69.          this.props.put("appletviewer.security.mode", "none");
  70.       } else if (this.networkMode == 2) {
  71.          this.props.put("appletviewer.security.mode", "unrestricted");
  72.       } else {
  73.          this.props.put("appletviewer.security.mode", "host");
  74.       }
  75.  
  76.       if (this.unsignedAccess == 0) {
  77.          this.props.put("appletviewer.security.allowUnsigned", "false");
  78.       } else {
  79.          this.props.put("appletviewer.security.allowUnsigned", "true");
  80.       }
  81.  
  82.       if (this.debugMode) {
  83.          this.props.put("activator.debug.mode", "true");
  84.          this.props.put("activator.debug.port", this.debugPort);
  85.       } else {
  86.          this.props.put("activator.debug.mode", "false");
  87.       }
  88.  
  89.       if (this.useDefaultProxy) {
  90.          this.props.put("activator.proxy.usebrowsersettings", "true");
  91.       } else {
  92.          this.props.put("activator.proxy.usebrowsersettings", "false");
  93.       }
  94.  
  95.       if (this.proxySettings != null) {
  96.          this.props.put("activator.proxy.settings", this.proxySettings);
  97.       } else {
  98.          this.props.remove("activator.proxy.settings");
  99.       }
  100.  
  101.       if (this.useSameProxy) {
  102.          this.props.put("activator.proxy.forallprotocols", "true");
  103.       } else {
  104.          this.props.put("activator.proxy.forallprotocols", "false");
  105.       }
  106.  
  107.       if (this.jdk != null) {
  108.          this.props.put("activator.jre.path", this.jdk);
  109.       } else {
  110.          this.props.remove("activator.jre.path");
  111.       }
  112.  
  113.       try {
  114.          FileOutputStream var1 = new FileOutputStream(theUserPropertiesFile);
  115.          this.props.save(var1, " Java Properties");
  116.          var1.close();
  117.       } catch (IOException var2) {
  118.          System.out.println(amh.getMessage("apply.exception", var2));
  119.          ((Throwable)var2).printStackTrace();
  120.       }
  121.  
  122.    }
  123.  
  124.    public String getClassAcccessLabel() {
  125.       return amh.getMessage("label.class");
  126.    }
  127.  
  128.    public int getClassAccessLevel() {
  129.       return this.classAccess;
  130.    }
  131.  
  132.    public String[] getClassAccessLevels() {
  133.       return this.classAccessTable;
  134.    }
  135.  
  136.    public String getDebugPort() {
  137.       return this.debugPort;
  138.    }
  139.  
  140.    public String[] getInstalledJavaList() {
  141.       return this.installedJavaVersion;
  142.    }
  143.  
  144.    public String getJDK() {
  145.       return this.jdk;
  146.    }
  147.  
  148.    public String getJITPath() {
  149.       return this.JITPath;
  150.    }
  151.  
  152.    public String getMessage(String var1) {
  153.       return amh.getMessage(var1);
  154.    }
  155.  
  156.    public String getNetworkAccessLabel() {
  157.       return amh.getMessage("label.network");
  158.    }
  159.  
  160.    public int getNetworkAccessLevel() {
  161.       return this.networkMode;
  162.    }
  163.  
  164.    public String[] getNetworkAccessLevels() {
  165.       return this.networkAccessTable;
  166.    }
  167.  
  168.    public String getProxySettingsString() {
  169.       return this.proxySettings;
  170.    }
  171.  
  172.    public String[] getSupportedVersionList() {
  173.       String[] var1 = new String[]{"1.1", "1.2"};
  174.       return var1;
  175.    }
  176.  
  177.    public int getUnsignedAccessLevel() {
  178.       return this.unsignedAccess;
  179.    }
  180.  
  181.    public String[] getUnsignedAccessLevels() {
  182.       return this.unsignedAppletTable;
  183.    }
  184.  
  185.    public String getUnsignedAppletChoice() {
  186.       return amh.getMessage("label.unsignedapplet");
  187.    }
  188.  
  189.    private void initialize() {
  190.       this.networkAccessTable[0] = amh.getMessage("choice.network.item.none");
  191.       this.networkAccessTable[1] = amh.getMessage("choice.network.item.applethost");
  192.       this.networkAccessTable[2] = amh.getMessage("choice.network.item.unrestricted");
  193.       this.classAccessTable[0] = amh.getMessage("choice.class.item.restricted");
  194.       this.classAccessTable[1] = amh.getMessage("choice.class.item.unrestricted");
  195.       this.unsignedAppletTable[0] = amh.getMessage("choice.unsignedapplet.no");
  196.       this.unsignedAppletTable[1] = amh.getMessage("choice.unsignedapplet.yes");
  197.    }
  198.  
  199.    public boolean isConsoleEnabled() {
  200.       return this.showConsole;
  201.    }
  202.  
  203.    public boolean isDebugEnabled() {
  204.       return this.debugMode;
  205.    }
  206.  
  207.    public boolean isJITEnabled() {
  208.       return this.useJIT;
  209.    }
  210.  
  211.    public boolean isJavaEnabled() {
  212.       return this.activatorEnabled;
  213.    }
  214.  
  215.    public void reset() {
  216.       this.setChanged("All");
  217.       this.props = new Properties();
  218.  
  219.       try {
  220.          FileInputStream var1 = new FileInputStream(theUserPropertiesFile);
  221.          this.props.load(new BufferedInputStream(var1));
  222.          var1.close();
  223.       } catch (Exception var2) {
  224.          System.out.println("[no properties loaded, using defaults]");
  225.       }
  226.  
  227.       String var3 = this.props.getProperty("activator.console");
  228.       if (var3 != null && var3.equals("true")) {
  229.          this.showConsole = true;
  230.       } else {
  231.          this.showConsole = false;
  232.       }
  233.  
  234.       var3 = this.props.getProperty("activator.enabled");
  235.       if (var3 != null && !var3.equals("true")) {
  236.          this.activatorEnabled = false;
  237.       } else {
  238.          this.activatorEnabled = true;
  239.       }
  240.  
  241.       var3 = this.props.getProperty("appletviewer.security.mode");
  242.       if (var3 == null) {
  243.          this.setNetworkAccessLevel(1);
  244.       } else if (var3.equals("none")) {
  245.          this.setNetworkAccessLevel(0);
  246.       } else if (var3.equals("unrestricted")) {
  247.          this.setNetworkAccessLevel(2);
  248.       } else {
  249.          this.setNetworkAccessLevel(1);
  250.       }
  251.  
  252.       var3 = this.props.getProperty("package.restrict.access.netscape");
  253.       if (var3 != null && !var3.equals("true")) {
  254.          this.setClassAccessLevel(1);
  255.       } else {
  256.          this.setClassAccessLevel(0);
  257.       }
  258.  
  259.       var3 = this.props.getProperty("appletviewer.security.allowUnsigned");
  260.       if (var3 != null && !var3.equals("true")) {
  261.          this.setUnsignedAccessLevel(0);
  262.       } else {
  263.          this.setUnsignedAccessLevel(1);
  264.       }
  265.  
  266.       var3 = this.props.getProperty("activator.debug.mode");
  267.       if (var3 != null && var3.equals("true")) {
  268.          this.debugMode = true;
  269.       } else {
  270.          this.debugMode = false;
  271.       }
  272.  
  273.       this.debugPort = this.props.getProperty("activator.debug.port");
  274.       if (this.debugPort == null) {
  275.          this.debugPort = "2502";
  276.       }
  277.  
  278.       var3 = this.props.getProperty("activator.proxy.usebrowsersettings");
  279.       if (var3 != null && !var3.equals("true")) {
  280.          this.useDefaultProxy = false;
  281.       } else {
  282.          this.useDefaultProxy = true;
  283.       }
  284.  
  285.       this.proxySettings = this.props.getProperty("activator.proxy.settings");
  286.       var3 = this.props.getProperty("activator.proxy.forallprotocols");
  287.       this.useSameProxy = "true".equals(var3);
  288.       this.jdk = this.props.getProperty("activator.jre.path");
  289.    }
  290.  
  291.    protected void setChanged(String var1) {
  292.       super.setChanged();
  293.       ((Observable)this).notifyObservers(var1);
  294.    }
  295.  
  296.    public void setClassAccessLevel(int var1) {
  297.       this.classAccess = var1;
  298.       this.setChanged("Class Access");
  299.    }
  300.  
  301.    public void setConsoleEnabled(boolean var1) {
  302.       this.showConsole = var1;
  303.       this.setChanged("Show Console");
  304.    }
  305.  
  306.    public void setDebugEnabled(boolean var1) {
  307.       this.debugMode = var1;
  308.       this.setChanged("Debug Mode");
  309.    }
  310.  
  311.    public void setDebugPort(String var1) {
  312.       this.debugPort = var1;
  313.       this.setChanged("Debug Port");
  314.    }
  315.  
  316.    public void setDefaultProxySettings(boolean var1) {
  317.       this.useDefaultProxy = var1;
  318.       this.setChanged("Default Proxy Settings");
  319.    }
  320.  
  321.    public void setInstalledJavaList(String[] var1) {
  322.       this.installedJavaVersion = var1;
  323.    }
  324.  
  325.    public void setJDK(String var1) {
  326.       this.jdk = var1;
  327.       this.setChanged("JDK");
  328.    }
  329.  
  330.    public void setJITEnabled(boolean var1) {
  331.       this.useJIT = var1;
  332.       this.setChanged("Use JIT");
  333.    }
  334.  
  335.    public void setJITPath(String var1) {
  336.       this.JITPath = var1;
  337.       this.setChanged("JIT Path");
  338.    }
  339.  
  340.    public void setJavaEnabled(boolean var1) {
  341.       this.activatorEnabled = var1;
  342.       this.setChanged("Java Enabled");
  343.    }
  344.  
  345.    public void setNetworkAccessLevel(int var1) {
  346.       this.networkMode = var1;
  347.       this.setChanged("Network Access");
  348.    }
  349.  
  350.    public void setProxySettingsString(String var1) {
  351.       this.proxySettings = var1;
  352.       this.setChanged("Proxy String");
  353.    }
  354.  
  355.    public void setUnsignedAccessLevel(int var1) {
  356.       this.unsignedAccess = var1;
  357.       this.setChanged("Unsigned Access");
  358.    }
  359.  
  360.    public void setUseSameProxy(boolean var1) {
  361.       this.useSameProxy = var1;
  362.       this.setChanged("Same Proxy Settings");
  363.    }
  364.  
  365.    public boolean useDefaultProxy() {
  366.       return this.useDefaultProxy;
  367.    }
  368.  
  369.    public boolean useSameProxy() {
  370.       return this.useSameProxy;
  371.    }
  372. }
  373.