home *** CD-ROM | disk | FTP | other *** search
/ PC for Alla 2003 April / PFA0304.iso / fullversioner / ImageZoom / InstData / WebInst.cab / com / zerog / ia / download / utility / Gestalt.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-10-10  |  5.3 KB  |  333 lines

  1. package com.zerog.ia.download.utility;
  2.  
  3. import com.zerog.ia.download.utility.nativelib.unix.Environment;
  4. import java.io.File;
  5. import java.util.StringTokenizer;
  6. import netscape.security.PrivilegeManager;
  7.  
  8. public class Gestalt {
  9.    public static String NETSCAPE_VM = "netscape";
  10.    public static String MICROSOFT_VM = "microsoft";
  11.    public static String SUN_VM = "sun";
  12.    public static String APPLE_VM = "apple";
  13.    public static String IBM_VM = "ibm";
  14.    public static String WINDOWS_PLATFORM = "windows";
  15.    public static String MAC_OS_PLATFORM = "mac os";
  16.    public static String MAC_OS_X_PLATFORM = "mac os x";
  17.    public static String SOLARIS_PLATFORM = "solaris";
  18.    public static String HPUX_PLATFORM = "hp-ux";
  19.    public static String LINUX_PLATFORM = "linux";
  20.    public static String DGUX_PLATFORM = "dg-ux";
  21.    public static String IRIX_PLATFORM = "irix";
  22.    public static String AIX_PLATFORM = "aix";
  23.    public static String OS2_PLATFORM = "os/2";
  24.    public static String NETSCAPE_FILE_ACCESS = "UniversalFileAccess";
  25.    public static String NETSCAPE_EXEC_ACCESS = "UniversalExecAccess";
  26.    public static String NETSCAPE_PROPERTY_READ = "UniversalPropertyRead";
  27.    private static String vmVendor;
  28.    private static String platform;
  29.    private static String vmVersion;
  30.    private static String mrjVersion;
  31.    private static boolean determinedAbleToCreateFiles = false;
  32.    private static boolean determinedAbleToExecuteFiles = false;
  33.    private static boolean determinedAbleToReadSystemProperties = false;
  34.    private static boolean ableToCreateFiles = false;
  35.    private static boolean ableToExecuteFiles = false;
  36.    private static boolean ableToReadSystemProperties = false;
  37.    private static boolean ableToBeSuperUser = false;
  38.    private static boolean pathChecked;
  39.    private static boolean checkPathResult;
  40.  
  41.    public static String getVMVendor() {
  42.       if (vmVendor == null) {
  43.          String var0 = System.getProperty("java.vendor").toLowerCase();
  44.          if (var0.indexOf("netscape") >= 0) {
  45.             vmVendor = NETSCAPE_VM;
  46.          } else if (var0.indexOf("microsoft") >= 0) {
  47.             vmVendor = MICROSOFT_VM;
  48.          } else if (var0.indexOf("sun") < 0 && var0.indexOf("java") < 0) {
  49.             if (var0.indexOf("apple") < 0 && var0.indexOf("mac") < 0) {
  50.                if (var0.indexOf("ibm") >= 0) {
  51.                   vmVendor = IBM_VM;
  52.                } else {
  53.                   vmVendor = var0.toLowerCase();
  54.                }
  55.             } else {
  56.                vmVendor = APPLE_VM;
  57.             }
  58.          } else {
  59.             vmVendor = SUN_VM;
  60.          }
  61.       }
  62.  
  63.       return vmVendor;
  64.    }
  65.  
  66.    public static String getVMVersion() {
  67.       if (vmVersion == null) {
  68.          vmVersion = System.getProperty("java.version").toLowerCase();
  69.       }
  70.  
  71.       return vmVersion;
  72.    }
  73.  
  74.    public static String getMRJVersion() {
  75.       if (mrjVersion == null) {
  76.          mrjVersion = System.getProperty("mrj.version").toLowerCase();
  77.       }
  78.  
  79.       return mrjVersion;
  80.    }
  81.  
  82.    public static String getPlatform() {
  83.       if (platform == null) {
  84.          String var0 = System.getProperty("os.name").toLowerCase();
  85.          if (var0.indexOf("win") != -1) {
  86.             platform = WINDOWS_PLATFORM;
  87.          } else if (var0.indexOf("apple") == -1 && var0.indexOf("mac") == -1) {
  88.             if (var0.indexOf("sun") == -1 && var0.indexOf("solaris") == -1) {
  89.                if (var0.indexOf("linux") != -1) {
  90.                   platform = LINUX_PLATFORM;
  91.                } else if (var0.indexOf("hp") != -1) {
  92.                   platform = HPUX_PLATFORM;
  93.                } else if (var0.indexOf("aix") != -1) {
  94.                   platform = AIX_PLATFORM;
  95.                } else {
  96.                   platform = var0.toLowerCase();
  97.                }
  98.             } else {
  99.                platform = SOLARIS_PLATFORM;
  100.             }
  101.          } else if (var0.indexOf("x") != -1) {
  102.             platform = MAC_OS_X_PLATFORM;
  103.          } else {
  104.             platform = MAC_OS_PLATFORM;
  105.          }
  106.       }
  107.  
  108.       return platform;
  109.    }
  110.  
  111.    public static boolean isThisPlatformUnix() {
  112.       if (getPlatform().equals(SOLARIS_PLATFORM)) {
  113.          return true;
  114.       } else if (getPlatform().equals(HPUX_PLATFORM)) {
  115.          return true;
  116.       } else if (getPlatform().equals(LINUX_PLATFORM)) {
  117.          return true;
  118.       } else if (getPlatform().equals(IRIX_PLATFORM)) {
  119.          return true;
  120.       } else if (getPlatform().equals(AIX_PLATFORM)) {
  121.          return true;
  122.       } else if (getPlatform().equals(DGUX_PLATFORM)) {
  123.          return true;
  124.       } else if (getPlatform().equals(MAC_OS_X_PLATFORM)) {
  125.          return true;
  126.       } else {
  127.          return getPlatform().indexOf("unix") >= 0;
  128.       }
  129.    }
  130.  
  131.    public static boolean isSupportedVM() {
  132.       if (getPlatform().equals(MAC_OS_PLATFORM)) {
  133.          if (getVMVendor().equals(MICROSOFT_VM) && getVMVersion().equals("1.1.4")) {
  134.             return false;
  135.          }
  136.       } else if (getPlatform().equals(SOLARIS_PLATFORM)) {
  137.          if (getVMVendor().equals(NETSCAPE_VM) && getVMVersion().equals("1.02")) {
  138.             return false;
  139.          }
  140.       } else if (getPlatform().equals(OS2_PLATFORM)) {
  141.          if (getVMVendor().equals(IBM_VM) && getVMVersion().equals("1.1.6")) {
  142.             return false;
  143.          }
  144.       } else if (getPlatform().equals(MAC_OS_X_PLATFORM) && getMRJVersion().equals("3.0")) {
  145.          return false;
  146.       }
  147.  
  148.       return true;
  149.    }
  150.  
  151.    public static boolean isNetscapeSecurityModelAvailable() {
  152.       if (getVMVendor().equals(NETSCAPE_VM)) {
  153.          return !getPlatform().equals(MAC_OS_PLATFORM);
  154.       } else {
  155.          return false;
  156.       }
  157.    }
  158.  
  159.    public static boolean vmCanSupportUnsecureActivities() {
  160.       if (getVMVendor().equals(MICROSOFT_VM)) {
  161.          return getPlatform().equals(WINDOWS_PLATFORM);
  162.       } else {
  163.          if (getVMVendor().equals(NETSCAPE_VM)) {
  164.             if (getPlatform().equals(WINDOWS_PLATFORM)) {
  165.                return true;
  166.             }
  167.  
  168.             if (getPlatform().equals(SOLARIS_PLATFORM)) {
  169.                return true;
  170.             }
  171.          } else if (getVMVendor().equals(APPLE_VM)) {
  172.             return getPlatform().equals(MAC_OS_PLATFORM) || getPlatform().equals(MAC_OS_X_PLATFORM);
  173.          }
  174.  
  175.          return false;
  176.       }
  177.    }
  178.  
  179.    public static boolean isAbleToReadSystemProperties() {
  180.       if (!determinedAbleToReadSystemProperties) {
  181.          if (isNetscapeSecurityModelAvailable()) {
  182.             try {
  183.                PrivilegeManager.enablePrivilege("UniversalPropertyAccess");
  184.                ableToReadSystemProperties = true;
  185.             } catch (Exception var2) {
  186.                ableToReadSystemProperties = false;
  187.             }
  188.          } else if (getVMVendor().equals(MICROSOFT_VM) || getVMVendor().equals(APPLE_VM)) {
  189.             try {
  190.                String var0 = System.getProperty("user.home");
  191.                ableToReadSystemProperties = true;
  192.             } catch (Throwable var1) {
  193.                ableToReadSystemProperties = false;
  194.             }
  195.          }
  196.  
  197.          determinedAbleToReadSystemProperties = true;
  198.       }
  199.  
  200.       return ableToReadSystemProperties;
  201.    }
  202.  
  203.    public static boolean isAbleToSendEmail() {
  204.       return getVMVendor() != NETSCAPE_VM;
  205.    }
  206.  
  207.    public static boolean checkPathForVM() {
  208.       if (getPlatform() == MAC_OS_X_PLATFORM) {
  209.          pathChecked = true;
  210.          checkPathResult = true;
  211.       }
  212.  
  213.       if (!pathChecked && isThisPlatformUnix()) {
  214.          pathChecked = true;
  215.  
  216.          try {
  217.             PrivilegeManager.getPrivilegeManager();
  218.             PrivilegeManager.enablePrivilege(NETSCAPE_FILE_ACCESS);
  219.          } catch (Throwable var8) {
  220.             System.err.println("Not permitted to access system files:\n   " + var8);
  221.             checkPathResult = false;
  222.             return checkPathResult;
  223.          }
  224.  
  225.          try {
  226.             PrivilegeManager.getPrivilegeManager();
  227.             PrivilegeManager.enablePrivilege(NETSCAPE_EXEC_ACCESS);
  228.          } catch (Throwable var7) {
  229.             System.err.println("Not permitted to exec files:\n   " + var7);
  230.             checkPathResult = false;
  231.             return checkPathResult;
  232.          }
  233.  
  234.          Object var0 = null;
  235.          boolean var1 = false;
  236.  
  237.          try {
  238.             var9 = Environment.getInstance().getValue("PATH");
  239.          } catch (Throwable var6) {
  240.             System.err.println("Unable to verify system PATH:\n   " + var6);
  241.             checkPathResult = false;
  242.             return checkPathResult;
  243.          }
  244.  
  245.          if (var9 == null || var9.trim().equals("")) {
  246.             return false;
  247.          }
  248.  
  249.          System.err.println("PATH = " + var9);
  250.          StringTokenizer var2 = new StringTokenizer(var9, ":");
  251.  
  252.          while(!checkPathResult && var2.hasMoreTokens()) {
  253.             String var3 = var2.nextToken();
  254.             File var4 = new File(var3, "jre");
  255.             File var5 = new File(var3, "java");
  256.             if (var4.exists() || var5.exists()) {
  257.                System.err.println("Java has been found on the system PATH");
  258.                checkPathResult = true;
  259.             }
  260.          }
  261.  
  262.          if (!checkPathResult) {
  263.             System.err.println("Java could not be found on the system PATH");
  264.          }
  265.       }
  266.  
  267.       return checkPathResult;
  268.    }
  269.  
  270.    public static boolean isAbleToCreateFiles() {
  271.       if (!determinedAbleToCreateFiles) {
  272.          if (isNetscapeSecurityModelAvailable()) {
  273.             try {
  274.                PrivilegeManager.enablePrivilege(NETSCAPE_FILE_ACCESS);
  275.                ableToCreateFiles = true;
  276.             } catch (Exception var2) {
  277.                ableToCreateFiles = false;
  278.             }
  279.          } else if (getVMVendor().equals(MICROSOFT_VM) || getVMVendor().equals(APPLE_VM)) {
  280.             try {
  281.                String var0 = System.getProperty("user.home");
  282.                ableToCreateFiles = true;
  283.             } catch (Throwable var1) {
  284.                ableToCreateFiles = false;
  285.             }
  286.          }
  287.  
  288.          determinedAbleToCreateFiles = true;
  289.       }
  290.  
  291.       return ableToCreateFiles;
  292.    }
  293.  
  294.    public static boolean isAbleToExecuteFiles() {
  295.       if (!determinedAbleToExecuteFiles) {
  296.          if (isNetscapeSecurityModelAvailable()) {
  297.             try {
  298.                PrivilegeManager.enablePrivilege(NETSCAPE_EXEC_ACCESS);
  299.                ableToExecuteFiles = true;
  300.             } catch (Exception var2) {
  301.                ableToExecuteFiles = false;
  302.             }
  303.          } else if (!getVMVendor().equals(MICROSOFT_VM) && !getVMVendor().equals(APPLE_VM)) {
  304.             if (getVMVendor().equals(SUN_VM)) {
  305.                ableToExecuteFiles = true;
  306.             }
  307.          } else {
  308.             try {
  309.                String var0 = System.getProperty("user.home");
  310.                ableToExecuteFiles = true;
  311.             } catch (Throwable var1) {
  312.                ableToExecuteFiles = false;
  313.             }
  314.          }
  315.  
  316.          determinedAbleToExecuteFiles = true;
  317.       }
  318.  
  319.       return ableToExecuteFiles;
  320.    }
  321.  
  322.    static {
  323.       if (isNetscapeSecurityModelAvailable()) {
  324.          isAbleToExecuteFiles();
  325.          isAbleToCreateFiles();
  326.          isAbleToReadSystemProperties();
  327.       }
  328.  
  329.       pathChecked = false;
  330.       checkPathResult = false;
  331.    }
  332. }
  333.