edu.ucsb.nceas.metacat.util

## Class SystemUtil

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

-     public class SystemUtil
      extends java.lang.Object

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `LINUX_OS`
    `static int` | `MAC_OS`
    `static int` | `OTHER_OS`
    `static int` | `WIN_OS`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.lang.String` | `discoverApplicationContext(javax.servlet.ServletContext servletContext)` Attempt to discover the context for this application.
    `static java.lang.String` | `discoverDeployDir(javax.servlet.http.HttpServletRequest request)` Attempt to discover the deployment directory for this application.
    `static java.lang.String` | `discoverExternalDir()` Attempt to discover the external (to the metacat installation) directory where metacat will hold backup files.
    `static java.lang.String` | `discoverServerName(javax.servlet.http.HttpServletRequest request)` Attempt to discover the server name.
    `static java.lang.String` | `discoverServerPort(javax.servlet.http.HttpServletRequest request)` Attempt to discover the server port.
    `static java.lang.String` | `discoverServerSSLPort(javax.servlet.http.HttpServletRequest request)` Attempt to discover the server ssl port.
    `static java.lang.String` | `getCGI_URL()` Get the CGI URL which is made up of the server URL + file separator + the CGI directory
    `static java.lang.String` | `getContextDir()` Get the context directory.
    `static java.lang.String` | `getContextURL()` Get the server URL with the context.
    `static java.lang.String` | `getDefaultStyleURL()` Get the default style URL from metacat.properties.
    `static java.lang.String` | `getInternalContextURL()` Get the internal context url.
    `static java.lang.String` | `getInternalServerURL()` Get the internal server URL.
    `static java.lang.String` | `getMetacatReleaseInfo()` Gets a string that holds some description about the release.
    `static MetacatVersion` | `getMetacatVersion()` Get the metacat version by getting the string representation from metacat.properties and instantiating a MetacatVersion object.
    `static int` | `getOsClass()` Get the OS for this system.
    `static java.util.Vector<java.lang.String>` | `getPathsForIndexing()` Get a list of xml paths that need to be indexed
    `static java.lang.String` | `getSecureContextURL()` Get the secure server URL with the context.
    `static java.lang.String` | `getSecureServer()` Get the secure server which is made up of the server name + : + the https port number.
    `static java.lang.String` | `getSecureServerURL()` Get the secure server URL which is made up of the server name + : + the https port number.
    `static java.lang.String` | `getServerURL()` Get the server URL which is made up of the server name + : + the http port number.
    `static java.lang.String` | `getServletURL()` Get the servlet URL.
    `static java.lang.String` | `getSQLDir()` Get the SQL directory.
    `static java.lang.String` | `getStoredBackupDir()` Gets the stored backup location.
    `static java.lang.String` | `getStyleCommonURL()` Get the style common URL.
    `static java.lang.String` | `getStyleSkinsDir()` Get the style skins directory.
    `static java.lang.String` | `getStyleSkinsURL()` Get the style skins URL.
    `static java.lang.String` | `getUserHomeDir()` Get the current user's home directory
    `static java.lang.String` | `getUserManagementUrl()` Get the url pointing to the user management page.
    `static boolean` | `isInternalURLReplacedByExternal()` Check if the internal url has been replaced by external url.
    `static void` | `storeExternalDirLocation(java.lang.String externalDir)` Store the location of the backup file location into a file at //backup-location
    `static void` | `writeStoredBackupFile(java.lang.String backupPath)`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### 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 Detail

    - #### 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 java.lang.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

          public static java.lang.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 java.lang.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 prot 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 java.lang.String getServerURL()
                                               throws edu.ucsb.nceas.utilities.PropertyNotFoundException

      Get the server URL which is made up of the server name + : + the http port number. Note that if the port is 80, it is left off.
      Returns:
        string holding the server URL
      Throws:
        `edu.ucsb.nceas.utilities.PropertyNotFoundException`

    - #### getSecureServerURL

          public static java.lang.String getSecureServerURL()
                                                     throws edu.ucsb.nceas.utilities.PropertyNotFoundException

      Get the secure server URL which is made up of the server name + : + the https port number. Note that if the port is 443, it is left off.
      Returns:
        string holding the server URL
      Throws:
        `edu.ucsb.nceas.utilities.PropertyNotFoundException`

    - #### getSecureServer

          public static java.lang.String getSecureServer()
                                                  throws edu.ucsb.nceas.utilities.PropertyNotFoundException

      Get the secure server which is made up of the server name + : + the https port number. Note that if the port is 443, it is left off. NOTE: does NOT include "https://"
      Returns:
        string holding the secure server
      Throws:
        `edu.ucsb.nceas.utilities.PropertyNotFoundException`
      See Also:
        `getSecureServerURL()`

    - #### getCGI_URL

          public static java.lang.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 java.lang.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`

    - #### getSecureContextURL

          public static java.lang.String getSecureContextURL()
                                                      throws edu.ucsb.nceas.utilities.PropertyNotFoundException

      Get the secure server URL with the context. This is made up of the secure server URL + file separator + the context
      Returns:
        string holding the server URL with context
      Throws:
        `edu.ucsb.nceas.utilities.PropertyNotFoundException`

    - #### getServletURL

          public static java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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(java.lang.String backupPath)
                                            throws MetacatUtilException

      Throws:
        `MetacatUtilException`

    - #### discoverExternalDir

          public static java.lang.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(java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.String getUserHomeDir()

      Get the current user's home directory
      Returns:
        a string holding the home directory

    - #### getPathsForIndexing

          public static java.util.Vector<java.lang.String> getPathsForIndexing()
                                                                        throws MetacatUtilException

      Get a list of xml paths that need to be indexed
      Throws:
        `MetacatUtilException`

    - #### getUserManagementUrl

          public static java.lang.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`

Copyright © 2020 Regents of the University of California. All Rights Reserved.