Package edu.ucsb.nceas.metacat.util
Class SystemUtil
java.lang.Object
edu.ucsb.nceas.metacat.util.SystemUtil
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
discoverApplicationContext
(javax.servlet.ServletContext servletContext) Attempt to discover the context for this application.static String
discoverDeployDir
(javax.servlet.http.HttpServletRequest request) Attempt to discover the deployment directory for this application.static String
Attempt to discover the external (to the metacat installation) directory where metacat will hold backup files.static String
discoverServerName
(javax.servlet.http.HttpServletRequest request) Attempt to discover the server name.protected static String
discoverServerPort
(javax.servlet.http.HttpServletRequest request) Attempt to discover the server port.static String
discoverServerSSLPort
(javax.servlet.http.HttpServletRequest request) Attempt to discover the server ssl port.static String
Get the CGI URL which is made up of the server URL + file separator + the CGI directorystatic String
Get the style skins directory.static String
Get the context directory.static String
Get the server URL with the context.static String
Get the default style URL from metacat.properties.static String
Get the internal context url.static String
Get the internal server URL.static String
Gets a string that holds some description about the release.static MetacatVersion
Get the metacat version by getting the string representation from metacat.properties and instantiating a MetacatVersion object.static int
Get the OS for this system.static String
Get the server which is made up of the server name + : + the port number.static String
Get the server URL which is made up of the http or https + :// + the server name + : + the port number.static String
Get the servlet URL.static String
Get the SQL directory.static String
Gets the stored backup location.static String
Get the style common URL.static String
Get the style skins directory.static String
Get the style skins URL.static String
Get the current user's home directorystatic String
Get the url pointing to the user management page.static boolean
Check if the internal url has been replaced by external url.static void
storeExternalDirLocation
(String externalDir) Store the location of the backup file location into a file at/ /backup-location static void
writeStoredBackupFile
(String backupPath)
-
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
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
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
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
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
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
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
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
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.PropertyNotFoundExceptionGet 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.PropertyNotFoundExceptionGet 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
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
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.PropertyNotFoundExceptionGet 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.PropertyNotFoundExceptionGets 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
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
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
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
- Throws:
MetacatUtilException
-
discoverExternalDir
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
Store the location of the backup file location into a file at/ /backup-location - Parameters:
externalDir
- the backup file location.
-
getStyleSkinsDir
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
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
Get the default style URL from metacat.properties.- Returns:
- string holding the default style URL
- Throws:
edu.ucsb.nceas.utilities.PropertyNotFoundException
-
discoverDeployDir
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
Get the current user's home directory- Returns:
- a string holding the home directory
-
getUserManagementUrl
public static String getUserManagementUrl() throws edu.ucsb.nceas.utilities.PropertyNotFoundExceptionGet the url pointing to the user management page.- Returns:
- the url.
- Throws:
edu.ucsb.nceas.utilities.PropertyNotFoundException
-
getCommonSkinsDir
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
-