Class WebXmlUtils


  • public final class WebXmlUtils
    extends Object
    • Method Detail

      • getFilterNamesForClass

        public static List<String> getFilterNamesForClass​(WebXml webXml,
                                                          String className)
        Returns a list of names of filters that are mapped to the specified class.
        Parameters:
        webXml - The webXml file to use
        className - The fully qualified name of the filter class
        Returns:
        A list of the names of the filters mapped to the class
      • getFilterMappings

        public static List<String> getFilterMappings​(WebXml webXml,
                                                     String theFilterName)
        Returns the URL-patterns that the specified filter is mapped to in an ordered list. If there are no mappings for the specified filter, an empty list is returned.
        Parameters:
        webXml - The webXml file to use
        theFilterName - The name of the servlet filter of which the mappings should be retrieved
        Returns:
        An ordered list of the URL-patterns
      • getFilterDispatchers

        public static List<String> getFilterDispatchers​(WebXml webXml,
                                                        String theFilterName)
        Returns the dispatchers that the specified filter is mapped to in an ordered list. If there are no mappings for the specified filter, an empty list is returned.
        Parameters:
        webXml - The webXml file to use
        theFilterName - The name of the servlet filter of which the mappings should be retrieved
        Returns:
        An ordered list of the dispatchers
      • getFilterMappingElements

        public static List<FilterMapping> getFilterMappingElements​(WebXml webXml,
                                                                   String theFilterName)
        Returns the filter mappings that the specified filter is mapped to in an ordered list. If there are no mappings for the specified filter, an empty list is returned.
        Parameters:
        webXml - The webXml file to use
        theFilterName - The name of the servlet filter of which the mappings should be retrieved
        Returns:
        An ordered list of the filter elements
      • hasContextParam

        public static boolean hasContextParam​(WebXml webXml,
                                              String theParamName)
        Returns whether a context param by the specified name is defined in the deployment descriptor.
        Parameters:
        webXml - The webXml file to use
        theParamName - The name of the context param
        Returns:
        true if the context param is defined, false otherwise
      • getContextParam

        public static org.jdom2.Element getContextParam​(WebXml webXml,
                                                        String paramName)
        Returns the element that contains the definition of a specific context param, or null if a context param of the specified name is not defined in the descriptor.
        Parameters:
        webXml - The webXml file to use
        paramName - The context param name
        Returns:
        The DOM element representing the context param definition
      • hasFilter

        public static boolean hasFilter​(WebXml webXml,
                                        String theFilterName)
        Returns whether a servlet filter by the specified name is defined in the deployment descriptor.
        Parameters:
        webXml - The webXml file to use
        theFilterName - The name of the filter
        Returns:
        true if the filter is defined, false otherwise
      • getServletRunAsRoleName

        public static String getServletRunAsRoleName​(WebXml webXml,
                                                     String theServletName)
        For a named servlet, return the run-as role name.
        Parameters:
        webXml - The webXml file to use
        theServletName - the name of the servlet
        Returns:
        the run-as role name
      • addTagInitParam

        public static void addTagInitParam​(WebXmlElement itemElement,
                                           String name,
                                           String value)
        Add an init-param to the web xml.
        Parameters:
        itemElement - The the parent element to add to
        name - The name of the param
        value - The value for the param
      • getFilterInitParamNames

        public static List<String> getFilterInitParamNames​(WebXml webXml,
                                                           String name)
        Get the init parameter names for a filter.
        Parameters:
        webXml - The webXml file to use
        name - The name of the filter to use
        Returns:
        a list of the param names
      • addFilterInitParam

        public static void addFilterInitParam​(WebXml webXml,
                                              String name,
                                              String paramName,
                                              String paramValue)
        Add an init param to a filter.
        Parameters:
        webXml - The webXml file to use
        name - The name of the filter
        paramName - The name of the parameter
        paramValue - The value of the parameter
      • hasServlet

        public static boolean hasServlet​(WebXml webXml,
                                         String servletName)
        Does the web xml have a named servlet.
        Parameters:
        webXml - The webXml file to use
        servletName - The name of the servlet
        Returns:
        true if it does, false if not.
      • addServlet

        public static void addServlet​(WebXml webXml,
                                      String servletName,
                                      String servletClass)
        Add a servlet to the descriptor.
        Parameters:
        webXml - The webXml file to use
        servletName - The servlet name
        servletClass - The servlet class name
      • getServletNamesForClass

        public static List<String> getServletNamesForClass​(WebXml webXml,
                                                           String className)
        Get the names that this servlet uses.
        Parameters:
        webXml - The webXml file to use
        className - the name of the class
        Returns:
        a list of the servlet names
      • getServletNamesForJspFile

        public static List<String> getServletNamesForJspFile​(WebXml webXml,
                                                             String theJspFile)
        Returns a list of names of servlets that are mapped to the specified JSP file.
        Parameters:
        webXml - The webXml file to use
        theJspFile - The path to the JSP file, relative to the root of the web-application
        Returns:
        A list of the names of the servlets mapped to the JSP file
      • getServletNames

        public static List<String> getServletNames​(WebXml webXml)
        Get a list of the servlet names in the web xml.
        Parameters:
        webXml - The webXml file to use
        Returns:
        list of the servlet names in the web xml
      • getServletMappings

        public static List<String> getServletMappings​(WebXml webXml,
                                                      String theServletName)
        Get the servlet mappings to the named servlet.
        Parameters:
        webXml - The webXml file to use
        theServletName - The name of the servlet
        Returns:
        A list of the mappings
      • getServletMappingElements

        public static List<ServletMapping> getServletMappingElements​(WebXml webXml,
                                                                     String theServletName)
        Returns the servlet mappings that the specified servlet is mapped to in an ordered list. If there are no mappings for the specified servlet, an empty list is returned.
        Parameters:
        webXml - The webXml file to use
        theServletName - The name of the servlet of which the mappings should be retrieved
        Returns:
        An ordered list of the servlet elements
      • addServlet

        public static void addServlet​(WebXml webXml,
                                      Servlet element)
        Add a servlet to the web xml.
        Parameters:
        webXml - The webXml file to use
        element - The servlet element
      • addServletInitParam

        public static void addServletInitParam​(WebXml webXml,
                                               String theServletName,
                                               String name,
                                               String value)
        Add an init param to a servlet.
        Parameters:
        webXml - The webXml file to use
        theServletName - The name of the servlet
        name - The name of the init param
        value - The value for the init param
      • getServletInitParamNames

        public static List<String> getServletInitParamNames​(WebXml webXml,
                                                            String theServletName)
        Get the names of all the servlet init parameters.
        Parameters:
        webXml - The webXml file to use
        theServletName - The name of the servlet
        Returns:
        A list of the parameter names
      • addSecurityConstraint

        public static void addSecurityConstraint​(WebXml webXml,
                                                 String theWebResourceName,
                                                 String theUrlPattern,
                                                 List<String> theRoles)
        Add a security constraint.
        Parameters:
        webXml - The webXml file to use
        theWebResourceName - The name of the web resource
        theUrlPattern - The URL Pattern
        theRoles - the Roles to Allow
      • addJspFile

        public static void addJspFile​(WebXml webXml,
                                      String theServletName,
                                      String theJspFile)
        Add a JSP file.
        Parameters:
        webXml - The webXml file to use
        theServletName - The name of the servlet
        theJspFile - The name of the JSP file
      • hasSecurityConstraint

        public static boolean hasSecurityConstraint​(WebXml webXml,
                                                    String theUrlPattern)
        Does the descriptor have a security constraint for a URL?
        Parameters:
        webXml - The webXml file to use
        theUrlPattern - The URL pattern to query
        Returns:
        boolean
      • hasLoginConfig

        public static boolean hasLoginConfig​(WebXml webXml)
        Does the descriptor have a login config?
        Parameters:
        webXml - The webXml file to use
        Returns:
        boolean
      • setLoginConfig

        public static void setLoginConfig​(WebXml webXml,
                                          String theAuthMethod,
                                          String theRealmName)
        Set the login config.
        Parameters:
        webXml - The webXml file to use
        theAuthMethod - The authorization method
        theRealmName - The realm name
      • getLoginConfigAuthMethod

        public static String getLoginConfigAuthMethod​(WebXml webXml)
        Get the login config authorization method.
        Parameters:
        webXml - The webXml file to use
        Returns:
        the auth method
      • getSecurityConstraint

        public static SecurityConstraint getSecurityConstraint​(WebXml webXml,
                                                               String theUrlPattern)
        Get a security constraint by URL.
        Parameters:
        webXml - The webXml file to use
        theUrlPattern - The URL Pattern
        Returns:
        Security Constraint
      • hasSecurityRole

        public static boolean hasSecurityRole​(WebXml webXml,
                                              String theRoleName)
        Does the role have a security definition?
        Parameters:
        webXml - The webXml file to use
        theRoleName - The name of the role
        Returns:
        boolean
      • getSecurityRoleNames

        public static List<String> getSecurityRoleNames​(WebXml webXml)
        Get the security role names.
        Parameters:
        webXml - The webXml file to use
        Returns:
        a list of the role names
      • getSecurityRole

        public static org.jdom2.Element getSecurityRole​(WebXml webXml,
                                                        String theRoleName)
        Get the security role by name.
        Parameters:
        webXml - The webXml file to use
        theRoleName - The name of the role
        Returns:
        Element containing the security role
      • addEjbRef

        public static void addEjbRef​(WebXml webXml,
                                     EjbRef ref)
        Add an EJB Reference.
        Parameters:
        webXml - The webXml file to use
        ref - the EJB Reference element to add
      • addSecurityRole

        public static void addSecurityRole​(WebXml webXml,
                                           String theRoleName)
        Parameters:
        webXml - The webXml file to use
        theRoleName - The role name to use
      • getServlet

        public static Servlet getServlet​(WebXml theWebXml,
                                         String servletName)
        Parameters:
        theWebXml - The webXml file to use
        servletName - The name of the servlet to get
        Returns:
        the servlet
      • getFilterNames

        public static List<String> getFilterNames​(WebXml webXml)
        Parameters:
        webXml - The webXml file to use
        Returns:
        filter names
      • getFilter

        public static Filter getFilter​(WebXml theWebXml,
                                       String filterName)
        Parameters:
        theWebXml - The webXml file to use
        filterName - The name of the filter
        Returns:
        Filter
      • addFilterMapping

        public static void addFilterMapping​(WebXml webXml,
                                            String theFilterName,
                                            String theUrlPattern)
        Parameters:
        webXml - The webXml file to use
        theFilterName - The name of the filter
        theUrlPattern - the URL Pattern to add
      • addFilterDispatcher

        public static void addFilterDispatcher​(WebXml webXml,
                                               String theFilterName,
                                               String theDispatcher)
        Parameters:
        webXml - The webXml file to use
        theFilterName - The name of the filter
        theDispatcher - the dispatcher to add
      • getServletInitParam

        public static String getServletInitParam​(WebXml theWebXml,
                                                 String servletName,
                                                 String paramName)
        Parameters:
        theWebXml - The webXml file to use
        servletName - The servlet name
        paramName - The parameter Name
        Returns:
        The value of the init param
      • addServletRunAsRoleName

        public static void addServletRunAsRoleName​(WebXml webXml,
                                                   String theServletName,
                                                   String theRoleName)
        Parameters:
        webXml - The webXml file to use
        theServletName - The name of the servlet
        theRoleName - The role name to add
      • addServletMapping

        public static void addServletMapping​(WebXml webXml,
                                             String theServletName,
                                             String theUrlPattern)
        Parameters:
        webXml - The webXml file to use
        theServletName - The name of the servlet
        theUrlPattern - the URL Pattern to add
      • getFilterInitParam

        public static String getFilterInitParam​(WebXml theWebXml,
                                                String filterName,
                                                String paramName)
        Parameters:
        theWebXml - The webXml file to use
        filterName - The name of the filter
        paramName - The name of the parameter
        Returns:
        the init parameter value
      • addFilter

        public static void addFilter​(WebXml webXml,
                                     Filter filter)
        Parameters:
        webXml - The webXml file to use
        filter - The filter to add
      • addFilter

        public static void addFilter​(WebXml webXml,
                                     String filterName,
                                     String filterClass)
        Add a filter to the descriptor.
        Parameters:
        webXml - The webXml file to use
        filterName - The servlet name
        filterClass - The servlet class name
      • addContextParam

        public static void addContextParam​(WebXml webXml,
                                           String name,
                                           String value)
        Adds a new context-param element to the descriptor.
        Parameters:
        webXml - The webXml containing the descriptor
        name - The context name
        value - The context value