org.omnifaces.config
Enum WebXml

java.lang.Object
  extended by java.lang.Enum<WebXml>
      extended by org.omnifaces.config.WebXml
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<WebXml>

public enum WebXml
extends java.lang.Enum<WebXml>

This configuration enum parses the /WEB-INF/web.xml and all /META-INF/web-fragment files found in the classpath and offers methods to obtain information from them which is not available by the standard Servlet API.

Since:
1.2
Author:
Bauke Scholtz

Enum Constant Summary
INSTANCE
          Returns the lazily loaded enum singleton instance.
 
Method Summary
 java.lang.String findErrorPageLocation(java.lang.Throwable exception)
          Find for the given exception the right error page location as per Servlet 3.0 specification 10.9.2: Make a first pass through all specific exception types.
 java.util.Map<java.lang.Class<java.lang.Throwable>,java.lang.String> getErrorPageLocations()
          Returns a mapping of all error page locations by exception type.
 java.lang.String getFormLoginPage()
          Returns the location of the FORM authentication login page, or null if it is not defined.
 java.util.Map<java.lang.String,java.util.Set<java.lang.String>> getSecurityConstraints()
          Returns a mapping of all security constraint URL patterns and the associated roles in the declared order.
 java.util.List<java.lang.String> getWelcomeFiles()
          Returns a list of all welcome files.
 WebXml init(javax.servlet.ServletContext servletContext)
          Perform manual initialization with the given servlet context, if not already initialized yet.
 boolean isAccessAllowed(java.lang.String url, java.lang.String role)
          Returns true if access to the given URL is allowed for the given role.
static WebXml valueOf(java.lang.String name)
          Returns the enum constant of this type with the specified name.
static WebXml[] values()
          Returns an array containing the constants of this enum type, in the order they are declared.
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

INSTANCE

public static final WebXml INSTANCE
Returns the lazily loaded enum singleton instance.

Note: if this is needed in e.g. a Filter which is called before the FacesServlet is invoked, then it won't work if the INSTANCE hasn't been referenced before. Since JSF installs a special "init" FacesContext during startup, one option for doing this initial referencing is in a ServletContextListener. The data this enum encapsulates will then be available even where there is no FacesContext available. If there's no other option, then you need to manually invoke init(ServletContext) whereby you pass the desired ServletContext.

Method Detail

values

public static WebXml[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
for (WebXml c : WebXml.values())
    System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they are declared

valueOf

public static WebXml valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
java.lang.NullPointerException - if the argument is null

init

public WebXml init(javax.servlet.ServletContext servletContext)
Perform manual initialization with the given servlet context, if not already initialized yet.

Parameters:
servletContext - The servlet context to obtain the web.xml from.
Returns:
The current WebXml instance, initialized and all.

findErrorPageLocation

public java.lang.String findErrorPageLocation(java.lang.Throwable exception)
Find for the given exception the right error page location as per Servlet 3.0 specification 10.9.2:

Parameters:
exception - The exception to find the error page location for.
Returns:
The right error page location for the given exception.

isAccessAllowed

public boolean isAccessAllowed(java.lang.String url,
                               java.lang.String role)
Returns true if access to the given URL is allowed for the given role. URL patterns are matched as per Servlet 3.0 specification 12.1:

Parameters:
url - URL to be checked for access by the given role. It must start with '/' and be context-relative.
role - Role to be checked for access to the given URL.
Returns:
true if access to the given URL is allowed for the given role, otherwise false.
Throws:
java.lang.NullPointerException - If given URL is null.
java.lang.IllegalArgumentException - If given URL does not start with '/'.
Since:
1.4

getWelcomeFiles

public java.util.List<java.lang.String> getWelcomeFiles()
Returns a list of all welcome files.

Returns:
A list of all welcome files.
Since:
1.4

getErrorPageLocations

public java.util.Map<java.lang.Class<java.lang.Throwable>,java.lang.String> getErrorPageLocations()
Returns a mapping of all error page locations by exception type. The default location is identified by null key.

Returns:
A mapping of all error page locations by exception type.

getFormLoginPage

public java.lang.String getFormLoginPage()
Returns the location of the FORM authentication login page, or null if it is not defined.

Returns:
The location of the FORM authentication login page, or null if it is not defined.

getSecurityConstraints

public java.util.Map<java.lang.String,java.util.Set<java.lang.String>> getSecurityConstraints()
Returns a mapping of all security constraint URL patterns and the associated roles in the declared order. If the roles is null, then it means that no auth constraint is been set (i.e. the resource is publicly accessible). If the roles is empty, then it means that an empty auth constraint is been set (i.e. the resource is in no way accessible).

Returns:
A mapping of all security constraint URL patterns and the associated roles in the declared order.
Since:
1.4