Class WebXml

  • All Implemented Interfaces:
    DocumentProperties.Charset

    public class WebXml
    extends XmlEncodingBase
    implements DocumentProperties.Charset
    Representation of common elements of web.xml and web-fragment.xml. Provides a repository for parsed data before the elements are merged. Validation is spread between multiple classes: The digester checks for structural correctness (e.g. single login-config) This class checks for invalid duplicates (e.g. filter/servlet names) StandardContext will check validity of values (e.g. URL formats etc)
    • Field Detail

      • ORDER_OTHERS

        protected static final java.lang.String ORDER_OTHERS
        Marker for "others" in ordering.
        See Also:
        Constant Field Values
    • Constructor Detail

      • WebXml

        public WebXml()
        Constructs a new WebXml.
    • Method Detail

      • isOverridable

        public boolean isOverridable()
        Returns whether this web fragment is overridable.
        Returns:
        true if overridable
      • setOverridable

        public void setOverridable​(boolean overridable)
        Sets whether this web fragment is overridable.
        Parameters:
        overridable - The overridable flag
      • isDuplicated

        public boolean isDuplicated()
        Returns whether this web fragment has duplicate entries.
        Returns:
        true if duplicates exist
      • addDuplicate

        public void addDuplicate​(java.lang.String duplicate)
        Adds a duplicate fragment name.
        Parameters:
        duplicate - The duplicate fragment name
      • getDuplicates

        public java.util.List<java.lang.String> getDuplicates()
        Returns the list of duplicate fragment names.
        Returns:
        the duplicate fragment names
      • createAbsoluteOrdering

        public void createAbsoluteOrdering()
        Initializes the absolute ordering set if it has not been created yet.
      • addAbsoluteOrdering

        public void addAbsoluteOrdering​(java.lang.String fragmentName)
        Adds a fragment name to the absolute ordering.
        Parameters:
        fragmentName - The fragment name to add
      • addAbsoluteOrderingOthers

        public void addAbsoluteOrderingOthers()
        Adds "others" to the absolute ordering.
      • getAbsoluteOrdering

        public java.util.Set<java.lang.String> getAbsoluteOrdering()
        Returns the absolute ordering set.
        Returns:
        the absolute ordering
      • addAfterOrdering

        public void addAfterOrdering​(java.lang.String fragmentName)
        Adds a fragment name to the after ordering.
        Parameters:
        fragmentName - The fragment name to add
      • addAfterOrderingOthers

        public void addAfterOrderingOthers()
        Adds "others" to the after ordering.
        Throws:
        java.lang.IllegalArgumentException - If "others" is already in the before ordering
      • getAfterOrdering

        public java.util.Set<java.lang.String> getAfterOrdering()
        Returns the after ordering set.
        Returns:
        the after ordering
      • addBeforeOrdering

        public void addBeforeOrdering​(java.lang.String fragmentName)
        Adds a fragment name to the before ordering.
        Parameters:
        fragmentName - The fragment name to add
      • addBeforeOrderingOthers

        public void addBeforeOrderingOthers()
        Adds "others" to the before ordering.
        Throws:
        java.lang.IllegalArgumentException - If "others" is already in the after ordering
      • getBeforeOrdering

        public java.util.Set<java.lang.String> getBeforeOrdering()
        Returns the before ordering set.
        Returns:
        the before ordering
      • getVersion

        public java.lang.String getVersion()
        Returns the version of the web.xml.
        Returns:
        the version
      • setVersion

        public void setVersion​(java.lang.String version)
        Set the version for this web.xml file
        Parameters:
        version - Values of null will be ignored
      • getPublicId

        public java.lang.String getPublicId()
        Returns the public identifier.
        Returns:
        the public identifier
      • setPublicId

        public void setPublicId​(java.lang.String publicId)
        Sets the public identifier.
        Parameters:
        publicId - The public identifier
      • isMetadataComplete

        public boolean isMetadataComplete()
        Returns whether metadata is complete.
        Returns:
        true if metadata is complete
      • setMetadataComplete

        public void setMetadataComplete​(boolean metadataComplete)
        Sets whether metadata is complete.
        Parameters:
        metadataComplete - The metadata complete flag
      • getName

        public java.lang.String getName()
        Returns the name of the web application.
        Returns:
        the name
      • setName

        public void setName​(java.lang.String name)
        Sets the name of the web application.
        Parameters:
        name - The name
      • getMajorVersion

        public int getMajorVersion()
        Returns the major version number.
        Returns:
        the major version
      • getMinorVersion

        public int getMinorVersion()
        Returns the minor version number.
        Returns:
        the minor version
      • getDisplayName

        public java.lang.String getDisplayName()
        Returns the display name of the web application.
        Returns:
        the display name
      • setDisplayName

        public void setDisplayName​(java.lang.String displayName)
        Sets the display name.
        Parameters:
        displayName - The display name
      • isDistributable

        public boolean isDistributable()
        Returns whether the web application is distributable.
        Returns:
        true if distributable
      • setDistributable

        public void setDistributable​(boolean distributable)
        Sets whether the web application is distributable.
        Parameters:
        distributable - The distributable flag
      • getDenyUncoveredHttpMethods

        public boolean getDenyUncoveredHttpMethods()
        Returns whether uncovered HTTP methods are denied.
        Returns:
        true if uncovered HTTP methods are denied
      • setDenyUncoveredHttpMethods

        public void setDenyUncoveredHttpMethods​(boolean denyUncoveredHttpMethods)
        Sets whether uncovered HTTP methods are denied.
        Parameters:
        denyUncoveredHttpMethods - The deny uncovered HTTP methods flag
      • addContextParam

        public void addContextParam​(java.lang.String param,
                                    java.lang.String value)
        Adds a context parameter.
        Parameters:
        param - The parameter name
        value - The parameter value
      • getContextParams

        public java.util.Map<java.lang.String,​java.lang.String> getContextParams()
        Returns the context parameters.
        Returns:
        the context parameters
      • addFilter

        public void addFilter​(FilterDef filter)
        Adds a filter definition.
        Parameters:
        filter - The filter definition
        Throws:
        java.lang.IllegalArgumentException - If a filter with the same name already exists
      • getFilters

        public java.util.Map<java.lang.String,​FilterDef> getFilters()
        Returns the filter definitions.
        Returns:
        the filter definitions
      • addFilterMapping

        public void addFilterMapping​(FilterMap filterMap)
        Adds a filter mapping.
        Parameters:
        filterMap - The filter mapping
      • getFilterMappings

        public java.util.Set<FilterMap> getFilterMappings()
        Returns the filter mappings.
        Returns:
        the filter mappings
      • addListener

        public void addListener​(java.lang.String className)
        Adds a listener class.
        Parameters:
        className - The listener class name
      • getListeners

        public java.util.Set<java.lang.String> getListeners()
        Returns the listener class names.
        Returns:
        the listener class names
      • addServlet

        public void addServlet​(ServletDef servletDef)
        Adds a servlet definition.
        Parameters:
        servletDef - The servlet definition
      • getServlets

        public java.util.Map<java.lang.String,​ServletDef> getServlets()
        Returns the servlet definitions.
        Returns:
        the servlet definitions
      • addServletMapping

        public void addServletMapping​(java.lang.String urlPattern,
                                      java.lang.String servletName)
        Adds a servlet URL mapping.
        Parameters:
        urlPattern - The URL pattern
        servletName - The servlet name
      • addServletMappingDecoded

        public void addServletMappingDecoded​(java.lang.String urlPattern,
                                             java.lang.String servletName)
        Adds a servlet URL mapping (already decoded).
        Parameters:
        urlPattern - The URL pattern
        servletName - The servlet name
        Throws:
        java.lang.IllegalArgumentException - If a duplicate mapping exists
      • getServletMappings

        public java.util.Map<java.lang.String,​java.lang.String> getServletMappings()
        Returns the servlet URL mappings.
        Returns:
        the servlet mappings
      • setSessionConfig

        public void setSessionConfig​(SessionConfig sessionConfig)
        Sets the session configuration.
        Parameters:
        sessionConfig - The session configuration
      • getSessionConfig

        public SessionConfig getSessionConfig()
        Returns the session configuration.
        Returns:
        the session configuration
      • addMimeMapping

        public void addMimeMapping​(java.lang.String extension,
                                   java.lang.String mimeType)
        Adds a MIME mapping.
        Parameters:
        extension - The file extension
        mimeType - The MIME type
      • getMimeMappings

        public java.util.Map<java.lang.String,​java.lang.String> getMimeMappings()
        Returns the MIME mappings.
        Returns:
        the MIME mappings
      • setReplaceWelcomeFiles

        public void setReplaceWelcomeFiles​(boolean replaceWelcomeFiles)
        Sets whether welcome files should replace existing ones.
        Parameters:
        replaceWelcomeFiles - The replace welcome files flag
      • setAlwaysAddWelcomeFiles

        public void setAlwaysAddWelcomeFiles​(boolean alwaysAddWelcomeFiles)
        When merging from this web.xml, should the welcome files be added to the target web.xml even if it already contains welcome file definitions.
        Parameters:
        alwaysAddWelcomeFiles - true to add welcome files
      • addWelcomeFile

        public void addWelcomeFile​(java.lang.String welcomeFile)
        Adds a welcome file.
        Parameters:
        welcomeFile - The welcome file name
      • getWelcomeFiles

        public java.util.Set<java.lang.String> getWelcomeFiles()
        Returns the welcome files.
        Returns:
        the welcome files
      • addErrorPage

        public void addErrorPage​(ErrorPage errorPage)
        Adds an error page.
        Parameters:
        errorPage - The error page
      • getErrorPages

        public java.util.Map<java.lang.String,​ErrorPage> getErrorPages()
        Returns the error pages.
        Returns:
        the error pages
      • addTaglib

        public void addTaglib​(java.lang.String uri,
                              java.lang.String location)
        Adds a taglib mapping.
        Parameters:
        uri - The taglib URI
        location - The taglib location
      • getTaglibs

        public java.util.Map<java.lang.String,​java.lang.String> getTaglibs()
        Returns the taglib mappings.
        Returns:
        the taglib mappings
      • addJspPropertyGroup

        public void addJspPropertyGroup​(JspPropertyGroup propertyGroup)
        Adds a JSP property group.
        Parameters:
        propertyGroup - The JSP property group
      • getJspPropertyGroups

        public java.util.Set<JspPropertyGroup> getJspPropertyGroups()
        Returns the JSP property groups.
        Returns:
        the JSP property groups
      • addSecurityConstraint

        public void addSecurityConstraint​(SecurityConstraint securityConstraint)
        Adds a security constraint.
        Parameters:
        securityConstraint - The security constraint
      • getSecurityConstraints

        public java.util.Set<SecurityConstraint> getSecurityConstraints()
        Returns the security constraints.
        Returns:
        the security constraints
      • setLoginConfig

        public void setLoginConfig​(LoginConfig loginConfig)
        Sets the login configuration.
        Parameters:
        loginConfig - The login configuration
      • getLoginConfig

        public LoginConfig getLoginConfig()
        Returns the login configuration.
        Returns:
        the login configuration
      • addSecurityRole

        public void addSecurityRole​(java.lang.String securityRole)
        Adds a security role.
        Parameters:
        securityRole - The security role name
      • getSecurityRoles

        public java.util.Set<java.lang.String> getSecurityRoles()
        Returns the security roles.
        Returns:
        the security roles
      • addEnvEntry

        public void addEnvEntry​(ContextEnvironment envEntry)
        Adds an environment entry.
        Parameters:
        envEntry - The environment entry
        Throws:
        java.lang.IllegalArgumentException - If an entry with the same name already exists
      • getEnvEntries

        public java.util.Map<java.lang.String,​ContextEnvironment> getEnvEntries()
        Returns the environment entries.
        Returns:
        the environment entries
      • addEjbRef

        public void addEjbRef​(ContextEjb ejbRef)
        Adds an EJB reference.
        Parameters:
        ejbRef - The EJB reference
      • getEjbRefs

        public java.util.Map<java.lang.String,​ContextEjb> getEjbRefs()
        Returns the EJB references.
        Returns:
        the EJB references
      • addEjbLocalRef

        public void addEjbLocalRef​(ContextLocalEjb ejbLocalRef)
        Adds an EJB local reference.
        Parameters:
        ejbLocalRef - The EJB local reference
      • getEjbLocalRefs

        public java.util.Map<java.lang.String,​ContextLocalEjb> getEjbLocalRefs()
        Returns the EJB local references.
        Returns:
        the EJB local references
      • addServiceRef

        public void addServiceRef​(ContextService serviceRef)
        Adds a service reference.
        Parameters:
        serviceRef - The service reference
      • getServiceRefs

        public java.util.Map<java.lang.String,​ContextService> getServiceRefs()
        Returns the service references.
        Returns:
        the service references
      • addResourceRef

        public void addResourceRef​(ContextResource resourceRef)
        Adds a resource reference.
        Parameters:
        resourceRef - The resource reference
        Throws:
        java.lang.IllegalArgumentException - If a reference with the same name already exists
      • getResourceRefs

        public java.util.Map<java.lang.String,​ContextResource> getResourceRefs()
        Returns the resource references.
        Returns:
        the resource references
      • addResourceEnvRef

        public void addResourceEnvRef​(ContextResourceEnvRef resourceEnvRef)
        Adds a resource environment reference.
        Parameters:
        resourceEnvRef - The resource environment reference
        Throws:
        java.lang.IllegalArgumentException - If a reference with the same name already exists
      • getResourceEnvRefs

        public java.util.Map<java.lang.String,​ContextResourceEnvRef> getResourceEnvRefs()
        Returns the resource environment references.
        Returns:
        the resource environment references
      • addMessageDestinationRef

        public void addMessageDestinationRef​(MessageDestinationRef messageDestinationRef)
        Adds a message destination reference.
        Parameters:
        messageDestinationRef - The message destination reference
        Throws:
        java.lang.IllegalArgumentException - If a reference with the same name already exists
      • getMessageDestinationRefs

        public java.util.Map<java.lang.String,​MessageDestinationRef> getMessageDestinationRefs()
        Returns the message destination references.
        Returns:
        the message destination references
      • addMessageDestination

        public void addMessageDestination​(MessageDestination messageDestination)
        Adds a message destination.
        Parameters:
        messageDestination - The message destination
        Throws:
        java.lang.IllegalArgumentException - If a destination with the same name already exists
      • getMessageDestinations

        public java.util.Map<java.lang.String,​MessageDestination> getMessageDestinations()
        Returns the message destinations.
        Returns:
        the message destinations
      • addLocaleEncodingMapping

        public void addLocaleEncodingMapping​(java.lang.String locale,
                                             java.lang.String encoding)
        Adds a locale-encoding mapping.
        Parameters:
        locale - The locale
        encoding - The encoding
      • getLocaleEncodingMappings

        public java.util.Map<java.lang.String,​java.lang.String> getLocaleEncodingMappings()
        Returns the locale-encoding mappings.
        Returns:
        the locale-encoding mappings
      • addPostConstructMethods

        public void addPostConstructMethods​(java.lang.String clazz,
                                            java.lang.String method)
        Adds a post-construct method.
        Parameters:
        clazz - The class name
        method - The method name
      • getPostConstructMethods

        public java.util.Map<java.lang.String,​java.lang.String> getPostConstructMethods()
        Returns the post-construct methods.
        Returns:
        the post-construct methods
      • addPreDestroyMethods

        public void addPreDestroyMethods​(java.lang.String clazz,
                                         java.lang.String method)
        Adds a pre-destroy method.
        Parameters:
        clazz - The class name
        method - The method name
      • getPreDestroyMethods

        public java.util.Map<java.lang.String,​java.lang.String> getPreDestroyMethods()
        Returns the pre-destroy methods.
        Returns:
        the pre-destroy methods
      • getJspConfigDescriptor

        public JspConfigDescriptor getJspConfigDescriptor()
        Returns the JSP configuration descriptor.
        Returns:
        the JSP configuration descriptor
      • getRequestCharacterEncoding

        public java.lang.String getRequestCharacterEncoding()
        Returns the request character encoding.
        Returns:
        the request character encoding
      • setRequestCharacterEncoding

        public void setRequestCharacterEncoding​(java.lang.String requestCharacterEncoding)
        Sets the request character encoding.
        Parameters:
        requestCharacterEncoding - The request character encoding
      • getResponseCharacterEncoding

        public java.lang.String getResponseCharacterEncoding()
        Returns the response character encoding.
        Returns:
        the response character encoding
      • setResponseCharacterEncoding

        public void setResponseCharacterEncoding​(java.lang.String responseCharacterEncoding)
        Sets the response character encoding.
        Parameters:
        responseCharacterEncoding - The response character encoding
      • setURL

        public void setURL​(java.net.URL url)
        Sets the URL of the web.xml.
        Parameters:
        url - The URL
      • getURL

        public java.net.URL getURL()
        Returns the URL of the web.xml.
        Returns:
        the URL
      • setJarName

        public void setJarName​(java.lang.String jarName)
        Sets the JAR name for this web fragment.
        Parameters:
        jarName - The JAR name
      • getJarName

        public java.lang.String getJarName()
        Returns the JAR name for this web fragment.
        Returns:
        the JAR name
      • setWebappJar

        public void setWebappJar​(boolean webappJar)
        Sets whether this descriptor came from a webapp JAR.
        Parameters:
        webappJar - The webapp JAR flag
      • getWebappJar

        public boolean getWebappJar()
        Returns whether this descriptor came from a webapp JAR.
        Returns:
        true if from a webapp JAR
      • getDelegate

        public boolean getDelegate()
        Returns whether this web application delegates first for class loading.
        Returns:
        true if delegation is enabled
      • setDelegate

        public void setDelegate​(boolean delegate)
        Sets whether this web application delegates first for class loading.
        Parameters:
        delegate - The delegate flag
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • toXml

        public java.lang.String toXml()
        Generate a web.xml in String form that matches the representation stored in this object.
        Returns:
        The complete contents of web.xml as a String
      • merge

        public boolean merge​(java.util.Set<WebXml> fragments)
        Merge the supplied web fragments into this main web.xml.
        Parameters:
        fragments - The fragments to merge in
        Returns:
        true if merge is successful, else false
      • orderWebFragments

        public static java.util.Set<WebXml> orderWebFragments​(WebXml application,
                                                              java.util.Map<java.lang.String,​WebXml> fragments,
                                                              ServletContext servletContext)
        Generates the sub-set of the web-fragment.xml files to be processed in the order that the fragments must be processed as per the rules in the Servlet spec.
        Parameters:
        application - The application web.xml file
        fragments - The map of fragment names to web fragments
        servletContext - The servlet context the fragments are associated with
        Returns:
        Ordered list of web-fragment.xml files to process