Class WebXml

java.lang.Object
org.apache.tomcat.util.descriptor.web.XmlEncodingBase
org.apache.tomcat.util.descriptor.web.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 Details

  • Constructor Details

    • WebXml

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

    • 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(String duplicate)
      Adds a duplicate fragment name.
      Parameters:
      duplicate - The duplicate fragment name
    • getDuplicates

      public List<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(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 Set<String> getAbsoluteOrdering()
      Returns the absolute ordering set.
      Returns:
      the absolute ordering
    • addAfterOrdering

      public void addAfterOrdering(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:
      IllegalArgumentException - If "others" is already in the before ordering
    • getAfterOrdering

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

      public void addBeforeOrdering(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:
      IllegalArgumentException - If "others" is already in the after ordering
    • getBeforeOrdering

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

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

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

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

      public void setPublicId(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 String getName()
      Returns the name of the web application.
      Returns:
      the name
    • setName

      public void setName(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 String getDisplayName()
      Returns the display name of the web application.
      Returns:
      the display name
    • setDisplayName

      public void setDisplayName(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(String param, String value)
      Adds a context parameter.
      Parameters:
      param - The parameter name
      value - The parameter value
    • getContextParams

      public Map<String,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:
      IllegalArgumentException - If a filter with the same name already exists
    • getFilters

      public Map<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 Set<FilterMap> getFilterMappings()
      Returns the filter mappings.
      Returns:
      the filter mappings
    • addListener

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

      public Set<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 Map<String, ServletDef> getServlets()
      Returns the servlet definitions.
      Returns:
      the servlet definitions
    • addServletMapping

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

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

      public Map<String,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(String extension, String mimeType)
      Adds a MIME mapping.
      Parameters:
      extension - The file extension
      mimeType - The MIME type
    • getMimeMappings

      public Map<String,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(String welcomeFile)
      Adds a welcome file.
      Parameters:
      welcomeFile - The welcome file name
    • getWelcomeFiles

      public Set<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 Map<String, ErrorPage> getErrorPages()
      Returns the error pages.
      Returns:
      the error pages
    • addTaglib

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

      public Map<String,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 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 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(String securityRole)
      Adds a security role.
      Parameters:
      securityRole - The security role name
    • getSecurityRoles

      public Set<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:
      IllegalArgumentException - If an entry with the same name already exists
    • getEnvEntries

      public Map<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 Map<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 Map<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 Map<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:
      IllegalArgumentException - If a reference with the same name already exists
    • getResourceRefs

      public Map<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:
      IllegalArgumentException - If a reference with the same name already exists
    • getResourceEnvRefs

      public Map<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:
      IllegalArgumentException - If a reference with the same name already exists
    • getMessageDestinationRefs

      public Map<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:
      IllegalArgumentException - If a destination with the same name already exists
    • getMessageDestinations

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

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

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

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

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

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

      public Map<String,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 String getRequestCharacterEncoding()
      Returns the request character encoding.
      Returns:
      the request character encoding
    • setRequestCharacterEncoding

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

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

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

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

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

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

      public 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 String toString()
      Overrides:
      toString in class Object
    • toXml

      public 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(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 Set<WebXml> orderWebFragments(WebXml application, Map<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