Class SystemUtil

java.lang.Object
edu.ucsb.nceas.metacat.util.SystemUtil

public class SystemUtil extends Object
  • Field Details

    • WIN_OS

      public static int WIN_OS
    • LINUX_OS

      public static int LINUX_OS
    • MAC_OS

      public static int MAC_OS
    • OTHER_OS

      public static int OTHER_OS
  • Method Details

    • getOsClass

      public static int getOsClass()
      Get the OS for this system.
      Returns:
      an integer representing the class of OS. Possibilities are: WIN_OS = 1; LINUX_OS = 2; MAC_OS = 3; OTHER_OS = 4;
    • discoverServerName

      public static String discoverServerName(javax.servlet.http.HttpServletRequest request)
      Attempt to discover the server name. The name is retrieved from the http servlet request. This is used by configuration routines before the port has been populated in metacat.properties. it is possible the port that the user configures might be different than the name we get here. You should use getServerPort() instead of this method whenever possible.
      Parameters:
      request - the http servlet request we will use to find the server name
      Returns:
      a string holding the server name
    • discoverServerPort

      protected static String discoverServerPort(javax.servlet.http.HttpServletRequest request)
      Attempt to discover the server port. The port is retrieved from the http servlet request. This is used by configuration routines before the port has been populated in metacat.properties. it is possible the port that the user configures might be different than the port we get here. You should use getServerPort() instead of this method whenever possible.
      Parameters:
      request - the http servlet request we will use to find the server port
      Returns:
      a string holding the server port
    • discoverServerSSLPort

      public static String discoverServerSSLPort(javax.servlet.http.HttpServletRequest request)
      Attempt to discover the server ssl port. The ssl port is assumed using the standard port. This is used by configuration routines before the port has been populated in metacat.properties. it is possible the port that the user configures might be different than the port we get here. You should use getServerSSLPort() instead of this method whenever possible.
      Parameters:
      request - the http servlet request we will use to find the server port
      Returns:
      a string holding the server ssl port
    • getServerURL

      public static String getServerURL() throws edu.ucsb.nceas.utilities.PropertyNotFoundException
      Get the server URL which is made up of the http or https + :// + the server name + : + the port number. Note that if the port is 80 or 443, it is left off.
      Returns:
      string holding the server URL
      Throws:
      edu.ucsb.nceas.utilities.PropertyNotFoundException
    • getServer

      public static String getServer() throws edu.ucsb.nceas.utilities.PropertyNotFoundException
      Get the server which is made up of the server name + : + the port number. Note that if the port is 443 or 80, it is left off. NOTE: does NOT include "https://"
      Returns:
      String representation of the server host:port
      Throws:
      edu.ucsb.nceas.utilities.PropertyNotFoundException
    • getCGI_URL

      public static String getCGI_URL() throws edu.ucsb.nceas.utilities.PropertyNotFoundException
      Get the CGI URL which is made up of the server URL + file separator + the CGI directory
      Returns:
      string holding the server URL
      Throws:
      edu.ucsb.nceas.utilities.PropertyNotFoundException
    • getContextURL

      public static String getContextURL() throws edu.ucsb.nceas.utilities.PropertyNotFoundException
      Get the server URL with the context. This is made up of the server URL + file separator + the context
      Returns:
      string holding the server URL with context
      Throws:
      edu.ucsb.nceas.utilities.PropertyNotFoundException
    • getServletURL

      public static String getServletURL() throws edu.ucsb.nceas.utilities.PropertyNotFoundException
      Get the servlet URL. This is made up of the server URL with context + file separator + the metacat servlet name
      Returns:
      string holding the servlet URL
      Throws:
      edu.ucsb.nceas.utilities.PropertyNotFoundException
    • getInternalContextURL

      public static String getInternalContextURL() throws edu.ucsb.nceas.utilities.PropertyNotFoundException
      Get the internal context url. If the internal server url is not accessible, it falls back to the external context url.
      Returns:
      the url of the internal Metacat context
      Throws:
      edu.ucsb.nceas.utilities.PropertyNotFoundException
    • getInternalServerURL

      public static String getInternalServerURL() throws edu.ucsb.nceas.utilities.PropertyNotFoundException
      Get the internal server URL. If the internal server url is not accessible, it falls back to the external url
      Returns:
      the url of the internal server
      Throws:
      edu.ucsb.nceas.utilities.PropertyNotFoundException
    • isInternalURLReplacedByExternal

      public static boolean isInternalURLReplacedByExternal()
      Check if the internal url has been replaced by external url.
      Returns:
      true if the url has been replaced; otherwise false;
    • getStyleSkinsURL

      public static String getStyleSkinsURL() throws edu.ucsb.nceas.utilities.PropertyNotFoundException
      Get the style skins URL. This is made up of the server URL with context + file separator + "style" + file separator + "skins"
      Returns:
      string holding the style skins URL
      Throws:
      edu.ucsb.nceas.utilities.PropertyNotFoundException
    • getStyleCommonURL

      public static String getStyleCommonURL() throws edu.ucsb.nceas.utilities.PropertyNotFoundException
      Get the style common URL. This is made up of the server URL with context + file separator + "style" + file separator + "common"
      Returns:
      string holding the style common URL
      Throws:
      edu.ucsb.nceas.utilities.PropertyNotFoundException
    • getMetacatVersion

      public static MetacatVersion getMetacatVersion() throws edu.ucsb.nceas.utilities.PropertyNotFoundException
      Get the metacat version by getting the string representation from metacat.properties and instantiating a MetacatVersion object. The info is set in build.properties and then populated into metacat.properties at build time using Ant token replacement.
      Returns:
      a MetacatVersion object holding metacat version information
      Throws:
      edu.ucsb.nceas.utilities.PropertyNotFoundException
    • getMetacatReleaseInfo

      public static String getMetacatReleaseInfo() throws edu.ucsb.nceas.utilities.PropertyNotFoundException
      Gets a string that holds some description about the release. Typically this is used during release candidates for display purposes and might hold something like "Release Candidate 1". Normally it is empty for final production release. The info is set in build.properties and then populated into metacat.properties at build time using Ant token replacement.
      Returns:
      a MetacatVersion object holding metacat version information
      Throws:
      edu.ucsb.nceas.utilities.PropertyNotFoundException
    • getContextDir

      public static String getContextDir() throws edu.ucsb.nceas.utilities.PropertyNotFoundException
      Get the context directory. This is made up of the deployment directory + file separator + context
      Returns:
      string holding the context directory
      Throws:
      edu.ucsb.nceas.utilities.PropertyNotFoundException
    • discoverApplicationContext

      public static String discoverApplicationContext(javax.servlet.ServletContext servletContext)
      Attempt to discover the context for this application. This is a best guess scenario. It is used by configuration routines before the context has been populated in metacat.properties. You should always use getApplicationContext() instead of this method if possible.
      Parameters:
      servletContext - the servlet context we will use to find the application context
      Returns:
      a string holding the context
    • getStoredBackupDir

      public static String getStoredBackupDir() throws MetacatUtilException
      Gets the stored backup location. This location is held in a file at /./backup-location
      Returns:
      a string holding the backup location. Null if none could be found.
      Throws:
      MetacatUtilException
    • writeStoredBackupFile

      public static void writeStoredBackupFile(String backupPath) throws MetacatUtilException
      Throws:
      MetacatUtilException
    • discoverExternalDir

      public static String discoverExternalDir() throws MetacatUtilException
      Attempt to discover the external (to the metacat installation) directory where metacat will hold backup files. This functionality is used to populate the configuration utility initially. The user can change the directory manually, so you can't rely on this method to give you the actual directory. Here are the steps taken to discover the directory: -- 1) Look for an existing hidden (.) directory in a default system directory. Get the default base directory for the OS. (See application.windowsBackupBaseDir and application.linuxBackupBaseDir in metacat.properties.) If a directory called /metacat/. exists, return /metacat -- 2) Otherwise, look for an existing hidden (.metacat) directory in the user directory. If a directory called /metacat/. exists for the user that started tomcat, return /metacat. -- 3) Otherwise, look for an existing metacat directory in a default system directory. Get the default base directory for the OS. (See application.windowsBackupBaseDir and application.linuxBackupBaseDir in metacat.properties.) If a directory called /metacat exists, return /metacat. -- 4) Otherwise, look for an existing metacat directory in the user directory. If a directory called /metacat/ exists for the user that started tomcat, return /metacat. -- 5) Otherwise, is the writable by the user that started tomcat? If so, return /metacat -- 6) Does the exist? If so, return /metacat -- 7) Otherwise, return null
      Returns:
      a string holding the backup directory path
      Throws:
      MetacatUtilException
    • storeExternalDirLocation

      public static void storeExternalDirLocation(String externalDir)
      Store the location of the backup file location into a file at //backup-location
      Parameters:
      externalDir - the backup file location.
    • getStyleSkinsDir

      public static String getStyleSkinsDir() throws edu.ucsb.nceas.utilities.PropertyNotFoundException
      Get the style skins directory. This is made up of the tomcat directory with context + file separator + "style" + file separator + "skins"
      Returns:
      string holding the style skins directory
      Throws:
      edu.ucsb.nceas.utilities.PropertyNotFoundException
    • getSQLDir

      public static String getSQLDir() throws edu.ucsb.nceas.utilities.PropertyNotFoundException
      Get the SQL directory. This is made up of the context directory + file separator + sql
      Returns:
      string holding the sql directory
      Throws:
      edu.ucsb.nceas.utilities.PropertyNotFoundException
    • getDefaultStyleURL

      public static String getDefaultStyleURL() throws edu.ucsb.nceas.utilities.PropertyNotFoundException
      Get the default style URL from metacat.properties.
      Returns:
      string holding the default style URL
      Throws:
      edu.ucsb.nceas.utilities.PropertyNotFoundException
    • discoverDeployDir

      public static String discoverDeployDir(javax.servlet.http.HttpServletRequest request)
      Attempt to discover the deployment directory for this application. This is a best guess scenario. It is used by configuration routines before the deployment directory has been populated in metacat.properties.
      Parameters:
      request - the http servlet request we will use to find the tomcat directory
      Returns:
      a string holding the web application directory
    • getUserHomeDir

      public static String getUserHomeDir()
      Get the current user's home directory
      Returns:
      a string holding the home directory
    • getUserManagementUrl

      public static String getUserManagementUrl() throws edu.ucsb.nceas.utilities.PropertyNotFoundException
      Get the url pointing to the user management page.
      Returns:
      the url.
      Throws:
      edu.ucsb.nceas.utilities.PropertyNotFoundException
    • getCommonSkinsDir

      public static String getCommonSkinsDir() throws edu.ucsb.nceas.utilities.PropertyNotFoundException
      Get the style skins directory. This is made up of the tomcat directory with context + file separator + "style" + file separator + "skins"
      Returns:
      string holding the style skins directory
      Throws:
      edu.ucsb.nceas.utilities.PropertyNotFoundException