Class AppPathService
java.lang.Object
fr.paris.lutece.portal.service.util.AppPathService
this class provides services for locate repository or url
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic UrlItembuildRedirectUrlItem(String strRootUrl, String strUrlPropertySuffixKey) Build the url item to use for a url that includes the redirection parameter for reconnection.static StringgetAbsolutePathFromRelativePath(String strDirectory) Returns the absolute path of a repository from a relative pathstatic StringgetAbsoluteUrl(jakarta.servlet.http.HttpServletRequest request, String strUrl) Returns the absolute url corresponding to the given one, if the later was found to be relative.static StringReturns the admin menu page relative url (jsp/admin/site/AdminMenu.jsp) defined in lutece.propertiesstatic StringReturns the admin portal page relative url (jsp/admin/site/AdminSite.jsp) defined in lutece.propertiesstatic ReferenceListGets available virtual hosts defined in the config.propertiesstatic StringDeprecated.static StringgetBaseUrl(jakarta.servlet.http.HttpServletRequest request) Return the url of the webapp, built from the requeststatic StringReturns the lutece global export path, defined in lutece.export.path property: an absolute path, a path starting with java.io.tmpdir (located in the temporary directory of the JVM), or no value for the temporary directory itself.getlistFilesFromRelativePath(String relativePath) Retrieves a list of files for a given relative path within the web application.static fr.paris.lutece.plugins.resource.LuteceResourcegetLuteceResource(String relativePath) Retrieves a Lutece resource based on its relative path.static StringReturns the absolute path of a repository from a relative definition in properties filestatic StringReturns the absolute path of file from its relative definition in properties file.static StringReturns the portal page relative url (jsp/site/Portal.jsp) defined in lutece.propertiesstatic StringgetProdUrl(jakarta.servlet.http.HttpServletRequest request) Return the webapp prod url (or the base url if no prod url has been definied).static StringgetProdUrl(String strBaseUrl) Return the webapp prod url.static StringgetRequestedPath(jakarta.servlet.http.HttpServletRequest request) Return the path requested inside the webapp (servlet path followed by the path info), without its leading slash, so that it can be appended togetBaseUrl(HttpServletRequest).static FileInputStreamgetResourceAsStream(String strPath, String strFilename) Deprecated.getResourcesPathsFromRelativePath(String relativePath) Retrieves the resource paths for a given relative path within the web application.static InputStreamgetResourceStream(String strFilename) Retrieves an input stream for a resource based solely on its relative path.static InputStreamgetResourceStream(String strPath, String strFilename) Retrieves an input stream for a resource based on a path and a file name.Retrieves the resource paths as a Setfrom a given directory. static StringReturns the forward URL for webapp's root path.static StringReturns the Site Message relative url (jsp/site/SiteMessage.jsp) defined in lutece.propertiesstatic StringgetSiteMessageUrl(jakarta.servlet.http.HttpServletRequest request) Return the url of the webapp, built from the requeststatic StringgetVirtualHostKey(jakarta.servlet.http.HttpServletRequest request) Gets a Virtual Host Key if the request contains a virtual host keystatic StringGets the webapp instance defined in the config.properties file with the key lutece.webapp.instancestatic StringReturns the webapp path from the properties filestatic voidinit(jakarta.servlet.ServletContext context) Initialize The path servicestatic voidInitialize The webapppathstatic voidstatic booleanReturns whether the current instance is the default webapp instancestatic UrlItemresolveRedirectUrl(jakarta.servlet.http.HttpServletRequest request, String strDefaultRedirectUrl) Retrieve the url to redirect to after login.static StringresolveTemporaryDirectory(String strPath) Resolves a configured path starting with java.io.tmpdir to the temporary directory of the JVM (java.io.tmpdir/index becomes /tmp/index).
-
Field Details
-
SESSION_BASE_URL
- See Also:
-
-
Method Details
-
init
public static void init(jakarta.servlet.ServletContext context) Initialize The path service- Parameters:
context- The servlet context
-
initResourceManager
public static void initResourceManager() -
init
Initialize The webapppath- Parameters:
strWebAppPath- The Webapp path
-
getWebAppPath
Returns the webapp path from the properties file- Returns:
- the webapp path
-
getPath
Returns the absolute path of a repository from a relative definition in properties file- Parameters:
strKey- the repository key definied in properties file- Returns:
- the repository absolute path else return null
- Throws:
PathNotFoundException- if the resource cannot be found
-
getPath
Returns the absolute path of file from its relative definition in properties file.- Parameters:
strKey- the repository key defined in properties filestrFilename- The name of file- Returns:
- the absolute path of file else null if file not found
- Throws:
fr.paris.lutece.plugins.resource.loader.ResourceNotFoundException- if the resource cannot be found
-
getAbsolutePathFromRelativePath
Returns the absolute path of a repository from a relative path- Parameters:
strDirectory- the relative path- Returns:
- the repository absolute path
- Throws:
fr.paris.lutece.plugins.resource.loader.ResourceNotFoundException- if the resource cannot be found
-
getResourcesPathsFromRelativePath
public static Set<String> getResourcesPathsFromRelativePath(String relativePath) throws fr.paris.lutece.plugins.resource.loader.ResourceNotFoundException Retrieves the resource paths for a given relative path within the web application.The path provided should be relative to the web application's root, and the method will return a set of resource paths matching that location.
- Parameters:
relativePath- The relative path to the resource(s) within the web application.- Returns:
- A set of resource paths as strings, or an empty set if no resources are found.
- Throws:
fr.paris.lutece.plugins.resource.loader.ResourceNotFoundException- if the resource cannot be found
-
getResourceURLFromRelativePath
public static Set<URL> getResourceURLFromRelativePath(String path) throws fr.paris.lutece.plugins.resource.loader.ResourceNotFoundException Retrieves the resource paths as a Setfrom a given directory. This method reads the files in the specified directory, converts their paths to URLs, and returns them in a Set. If no resources are found, a ResourceNotFoundExceptionwill be thrown.- Parameters:
path- The base path in the file system, which can be either relative or absolute. This path is used to locate the directory containing the resources. The path must start with a "/".- Returns:
- A Set containing the URLs of the resources found in the directory.
- Throws:
fr.paris.lutece.plugins.resource.loader.ResourceNotFoundException- If no resources are found or if an error occurs while reading the directory or converting paths to URLs.
-
getlistFilesFromRelativePath
public static Set<File> getlistFilesFromRelativePath(String relativePath) throws fr.paris.lutece.plugins.resource.loader.ResourceNotFoundException Retrieves a list of files for a given relative path within the web application.This method constructs the full path to each file based on the relative path provided, and adds the corresponding files to a set. It assumes that the resources are accessible via the servlet context and converts them to file objects.
Note: The paths used in this method are relative to the web application, and the method processes the paths using the servlet context.
- Parameters:
relativePath- The relative path to the resources within the web application.- Returns:
- A set of
Fileobjects corresponding to the resources found at the specified path. - Throws:
fr.paris.lutece.plugins.resource.loader.ResourceNotFoundException- if the resource cannot be found
-
getResourceAsStream
Deprecated.Gets a file as stream This method is deprecated usegetResourceStream(String, String)- Parameters:
strPath- the pathstrFilename- The name of file- Returns:
- a FileInput Stream object
- Throws:
fr.paris.lutece.plugins.resource.loader.ResourceNotFoundException- if the resource cannot be found
-
getResourceStream
public static InputStream getResourceStream(String strPath, String strFilename) throws fr.paris.lutece.plugins.resource.loader.ResourceNotFoundException Retrieves an input stream for a resource based on a path and a file name.- Parameters:
strPath- the relative path to the directory containing the resourcestrFilename- the name of the file to load- Returns:
- an input stream representing the requested resource
- Throws:
fr.paris.lutece.plugins.resource.loader.ResourceNotFoundException- if the resource cannot be found
-
getResourceStream
public static InputStream getResourceStream(String strFilename) throws fr.paris.lutece.plugins.resource.loader.ResourceNotFoundException Retrieves an input stream for a resource based solely on its relative path.- Parameters:
strFilename- the relative path of the file to load- Returns:
- an input stream representing the requested resource
- Throws:
fr.paris.lutece.plugins.resource.loader.ResourceNotFoundException- if the resource cannot be found
-
getLuteceResource
public static fr.paris.lutece.plugins.resource.LuteceResource getLuteceResource(String relativePath) throws fr.paris.lutece.plugins.resource.loader.ResourceNotFoundException Retrieves a Lutece resource based on its relative path.- Parameters:
relativePath- the relative path of the resource to retrieve- Returns:
- an instance of
LuteceResourcerepresenting the resource - Throws:
fr.paris.lutece.plugins.resource.loader.ResourceNotFoundException- if the resource cannot be found
-
getRequestedPath
Return the path requested inside the webapp (servlet path followed by the path info), without its leading slash, so that it can be appended togetBaseUrl(HttpServletRequest). Never fails when the container reports an empty servlet path (root request or "/*" servlet mapping).- Parameters:
request- The HttpServletRequest- Returns:
- the requested path relative to the webapp root, empty if none
-
getBaseUrl
Return the url of the webapp, built from the request- Parameters:
request- The HttpServletRequest- Returns:
- strBase the webapp url
-
getBaseUrl
Deprecated.UsegetBaseUrl(HttpServletRequest)insteadReturn the url of the webapp. The method should only be used out of request context (by daemons for example). If there is a request context, usegetBaseUrl(HttpServletRequest)instead.- Returns:
- The webapp url, or null if the 'lutece.base.url' property has not been set.
-
getProdUrl
Return the webapp prod url (or the base url if no prod url has been definied).- Parameters:
request- The HTTP request- Returns:
- The prod url
-
getProdUrl
Return the webapp prod url. If no prod URL has been defined, then the base URL is returned- Parameters:
strBaseUrl- The base URL- Returns:
- The prod url
-
getSiteMessageUrl
Return the url of the webapp, built from the request- Parameters:
request- The HttpServletRequest- Returns:
- strBase the webapp url
-
getPortalUrl
Returns the portal page relative url (jsp/site/Portal.jsp) defined in lutece.properties- Returns:
- the Portal Url
-
getRootForwardUrl
Returns the forward URL for webapp's root path. Default is (jsp/site/Portal.jsp) defined in lutece.properties- Returns:
- the Portal Root forward Url
-
getSiteMessageUrl
Returns the Site Message relative url (jsp/site/SiteMessage.jsp) defined in lutece.properties- Returns:
- the SiteMessage Url
-
getAdminPortalUrl
Returns the admin portal page relative url (jsp/admin/site/AdminSite.jsp) defined in lutece.properties- Returns:
- the Portal Url
-
getAdminMenuUrl
Returns the admin menu page relative url (jsp/admin/site/AdminMenu.jsp) defined in lutece.properties- Returns:
- the Admin Menu Url
-
getAvailableVirtualHosts
Gets available virtual hosts defined in the config.properties- Returns:
- A reference list containing the key and the description of each virtual host configuration. The list is empty if there is no configuration defined.
-
getVirtualHostKey
Gets a Virtual Host Key if the request contains a virtual host key- Parameters:
request- The HTTP request- Returns:
- A Virtual Host Key if present, otherwise null.
-
buildRedirectUrlItem
Build the url item to use for a url that includes the redirection parameter for reconnection.- Parameters:
strRootUrl- the root part of the url, to build an absolute urlstrUrlPropertySuffixKey- The property suffix to retrieve the url- Returns:
- an absolute url, completed with the redirectUrl parameter (contains the relative part of the url), as an UrlItem
-
resolveRedirectUrl
public static UrlItem resolveRedirectUrl(jakarta.servlet.http.HttpServletRequest request, String strDefaultRedirectUrl) Retrieve the url to redirect to after login. It is given by the redirectUrl parameter if found. The request parameters are copied (except the login and acces code and token). This is to be used by the doLogin method of AdminLoginJspBean.- Parameters:
request- the http requeststrDefaultRedirectUrl- the default url to go to after login- Returns:
- an UrlItem corresponding to the url to redirect to after login.
-
getAbsoluteUrl
Returns the absolute url corresponding to the given one, if the later was found to be relative. An url starting with "http://" is absolute. A relative url should be given relatively to the webapp root.- Parameters:
request- the http request (provides the base path if needed)strUrl- the url to transform- Returns:
- the corresonding absolute url
-
getWebappInstance
Gets the webapp instance defined in the config.properties file with the key lutece.webapp.instance- Returns:
- The instance name
- Since:
- 4.1
-
isDefaultWebappInstance
public static boolean isDefaultWebappInstance()Returns whether the current instance is the default webapp instance- Returns:
- true if default, otherwise false
-
resolveTemporaryDirectory
Resolves a configured path starting with java.io.tmpdir to the temporary directory of the JVM (java.io.tmpdir/index becomes /tmp/index). Any other path is returned unchanged.- Parameters:
strPath- the configured path- Returns:
- the resolved path
-
getExportPath
Returns the lutece global export path, defined in lutece.export.path property: an absolute path, a path starting with java.io.tmpdir (located in the temporary directory of the JVM), or no value for the temporary directory itself. The directory is created when missing.- Returns:
- The export path
-
getBaseUrl(HttpServletRequest)instead