Object
Utility methods for applications.
Object
ApplicationHelper
Constructor Summary |
Method Summary |
public static |
|
public static |
|
public static |
|
public static |
|
public static |
|
public static |
|
public static boolean |
|
Methods from class java.lang. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ApplicationHelper()
Method Detail |
public staticGet name of the current application. This name is unique among applications deployed to the domain, and thus can be useful for naming resources to be scoped to the application.String
getApplicationName()
throwsIllegalStateException
This method must be called from an application context. That is, some component (EJB, Servlet, etc.) deployed as part of an application (ear), or code called from such a component. The result will be specific to the application containing that component.
The Application Name is the deployed name of the application, and is often the name of the EAR jar file or directory, although this is not always the case.
IllegalStateException
public staticRetrieve the context root for a webapp. The context root can be used to build a URL to access that webapp. The context root is specified in either the application's or the webapp's deployment descriptors.String
getContextRoot(String
applicationName,String
webAppName)
throwsInstanceNotFoundException
This can be used when a webapp needs to build an absolute URL to itself, or a URL to some other webapp.
InstanceNotFoundException
Related Topics
ApplicationHelper.getApplicationName()
ApplicationHelper.getWebAppName(ServletContext)
ApplicationHelper.getWebAppName(HttpServletRequest)
ApplicationHelper.getWebAppUri(String, String)
public staticRead a resource (file) from the current application.InputStream
getResourceAsStream(String
uri)
throwsIOException
This method must be called from an application context. That is, some component (EJB, Servlet, etc.) deployed as part of an application (ear), or code called from such a component. The result will be specific to the application containing that component.
This will fail (log and throw an IOException) if the file does
not exist. Use resourceExists()
to test existence and prevent
the exception being logged.
IOException
Related Topics
ApplicationHelper.resourceExists(String)
public staticGet name of the current WebApp module for the given context.String
getWebAppName(ServletContext
theContext)
This method is intended to be called from a WebApp component (Servlet) that wants to know its own deployed name. The name is the deployed name of the webapp, and is often (by convention) given the name of the war file or directory, or the webapp's context root, although this is not always the case. This name is unique among webapps in the application, and thus can be useful for naming resources to be scoped to the webapp. Note, however, that the name is not unique within a server or domain, as webapps with the same name may be deployed in other applications.
Related Topics
ApplicationHelper.getApplicationName()
ApplicationHelper.getWebAppName(HttpServletRequest)
ApplicationHelper.getContextRoot(String, String)
ApplicationHelper.getWebAppUri(String, String)
public staticGet name of the current WebApp module running the given HTTP Request.String
getWebAppName(HttpServletRequest
theRequest)
This method is intended to be called from a WebApp component (Servlet) that wants to know its own deployed name. The name is the deployed name of the webapp, and is often (by convention) given the name of the war file or directory, or the webapp's context root, although this is not always the case. This name is unique among webapps in the application, and thus can be useful for naming resources to be scoped to the webapp. Note, however, that the name is not unique within a server or domain, as webapps with the same name may be deployed in other applications.
Related Topics
ApplicationHelper.getApplicationName()
ApplicationHelper.getWebAppName(ServletContext)
ApplicationHelper.getContextRoot(String, String)
ApplicationHelper.getWebAppUri(String, String)
public staticRetrieve the URI where the webapp is deployed. The URI is the directory or war file name of the deployed webapp, relative to the application root. The returned uri might be a directory or a war file.String
getWebAppUri(String
applicationName,String
webAppName)
throwsInstanceNotFoundException
This uri can be used with getResourceAsStream to retrieve files from a
webapp, for example, when ServletContext.getResourceAsStream()
will not work. Usually this will be in the case of one webapp "managing"
another webapp.
InstanceNotFoundException
Related Topics
ApplicationHelper.getApplicationName()
ApplicationHelper.getWebAppName(ServletContext)
ApplicationHelper.getWebAppName(HttpServletRequest)
ApplicationHelper.getContextRoot(String, String)
public static boolean resourceExists(Test if a resource (file) exists in the app.String
uri)
throwsIOException
This method must be called from an application context. That is, some component (EJB, Servlet, etc.) deployed as part of an application (ear), or code called from such a component. The result will be specific to the application containing that component.
This will fail (log and throw an IOException) if the parent directory does not exist.
If you are intending to test for a directory, the uri must end with a "/", or it won't match.
IOException