Class WebXml
java.lang.Object
org.apache.tomcat.util.descriptor.web.XmlEncodingBase
org.apache.tomcat.util.descriptor.web.WebXml
- All Implemented Interfaces:
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAbsoluteOrdering(String fragmentName) Adds a fragment name to the absolute ordering.voidAdds "others" to the absolute ordering.voidaddAfterOrdering(String fragmentName) Adds a fragment name to the after ordering.voidAdds "others" to the after ordering.voidaddBeforeOrdering(String fragmentName) Adds a fragment name to the before ordering.voidAdds "others" to the before ordering.voidaddContextParam(String param, String value) Adds a context parameter.voidaddDuplicate(String duplicate) Adds a duplicate fragment name.voidaddEjbLocalRef(ContextLocalEjb ejbLocalRef) Adds an EJB local reference.voidaddEjbRef(ContextEjb ejbRef) Adds an EJB reference.voidaddEnvEntry(ContextEnvironment envEntry) Adds an environment entry.voidaddErrorPage(ErrorPage errorPage) Adds an error page.voidAdds a filter definition.voidaddFilterMapping(FilterMap filterMap) Adds a filter mapping.voidaddJspPropertyGroup(JspPropertyGroup propertyGroup) Adds a JSP property group.voidaddListener(String className) Adds a listener class.voidaddLocaleEncodingMapping(String locale, String encoding) Adds a locale-encoding mapping.voidaddMessageDestination(MessageDestination messageDestination) Adds a message destination.voidaddMessageDestinationRef(MessageDestinationRef messageDestinationRef) Adds a message destination reference.voidaddMimeMapping(String extension, String mimeType) Adds a MIME mapping.voidaddPostConstructMethods(String clazz, String method) Adds a post-construct method.voidaddPreDestroyMethods(String clazz, String method) Adds a pre-destroy method.voidaddResourceEnvRef(ContextResourceEnvRef resourceEnvRef) Adds a resource environment reference.voidaddResourceRef(ContextResource resourceRef) Adds a resource reference.voidaddSecurityConstraint(SecurityConstraint securityConstraint) Adds a security constraint.voidaddSecurityRole(String securityRole) Adds a security role.voidaddServiceRef(ContextService serviceRef) Adds a service reference.voidaddServlet(ServletDef servletDef) Adds a servlet definition.voidaddServletMapping(String urlPattern, String servletName) Adds a servlet URL mapping.voidaddServletMappingDecoded(String urlPattern, String servletName) Adds a servlet URL mapping (already decoded).voidAdds a taglib mapping.voidaddWelcomeFile(String welcomeFile) Adds a welcome file.voidInitializes the absolute ordering set if it has not been created yet.Returns the absolute ordering set.Returns the after ordering set.Returns the before ordering set.Returns the context parameters.booleanReturns whether this web application delegates first for class loading.booleanReturns whether uncovered HTTP methods are denied.Returns the display name of the web application.Returns the list of duplicate fragment names.Returns the EJB local references.Returns the EJB references.Returns the environment entries.Returns the error pages.Returns the filter mappings.Returns the filter definitions.Returns the JAR name for this web fragment.Returns the JSP configuration descriptor.Returns the JSP property groups.Returns the listener class names.Returns the locale-encoding mappings.Returns the login configuration.intReturns the major version number.Returns the message destination references.Returns the message destinations.Returns the MIME mappings.intReturns the minor version number.getName()Returns the name of the web application.Returns the post-construct methods.Returns the pre-destroy methods.Returns the public identifier.Returns the request character encoding.Returns the resource environment references.Returns the resource references.Returns the response character encoding.Returns the security constraints.Returns the security roles.Returns the service references.Returns the servlet URL mappings.Returns the servlet definitions.Returns the session configuration.Returns the taglib mappings.getURL()Returns the URL of the web.xml.Returns the version of the web.xml.booleanReturns whether this descriptor came from a webapp JAR.Returns the welcome files.booleanReturns whether the web application is distributable.booleanReturns whether this web fragment has duplicate entries.booleanReturns whether metadata is complete.booleanReturns whether this web fragment is overridable.booleanMerge the supplied web fragments into this main web.xml.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.voidsetAlwaysAddWelcomeFiles(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.voidsetDelegate(boolean delegate) Sets whether this web application delegates first for class loading.voidsetDenyUncoveredHttpMethods(boolean denyUncoveredHttpMethods) Sets whether uncovered HTTP methods are denied.voidsetDisplayName(String displayName) Sets the display name.voidsetDistributable(boolean distributable) Sets whether the web application is distributable.voidsetJarName(String jarName) Sets the JAR name for this web fragment.voidsetLoginConfig(LoginConfig loginConfig) Sets the login configuration.voidsetMetadataComplete(boolean metadataComplete) Sets whether metadata is complete.voidSets the name of the web application.voidsetOverridable(boolean overridable) Sets whether this web fragment is overridable.voidsetPublicId(String publicId) Sets the public identifier.voidsetReplaceWelcomeFiles(boolean replaceWelcomeFiles) Sets whether welcome files should replace existing ones.voidsetRequestCharacterEncoding(String requestCharacterEncoding) Sets the request character encoding.voidsetResponseCharacterEncoding(String responseCharacterEncoding) Sets the response character encoding.voidsetSessionConfig(SessionConfig sessionConfig) Sets the session configuration.voidSets the URL of the web.xml.voidsetVersion(String version) Set the version for this web.xml filevoidsetWebappJar(boolean webappJar) Sets whether this descriptor came from a webapp JAR.toString()toXml()Generate a web.xml in String form that matches the representation stored in this object.Methods inherited from class org.apache.tomcat.util.descriptor.web.XmlEncodingBase
getCharset, setCharsetMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.tomcat.util.digester.DocumentProperties.Charset
setCharset
-
Field Details
-
ORDER_OTHERS
Marker for "others" in ordering.- See Also:
-
-
Constructor Details
-
WebXml
public WebXml()Constructs a new WebXml.
-
-
Method Details
-
isOverridable
public boolean isOverridable()Returns whether this web fragment is overridable.- Returns:
trueif 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:
trueif duplicates exist
-
addDuplicate
Adds a duplicate fragment name.- Parameters:
duplicate- The duplicate fragment name
-
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
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
Returns the absolute ordering set.- Returns:
- the absolute ordering
-
addAfterOrdering
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
Returns the after ordering set.- Returns:
- the after ordering
-
addBeforeOrdering
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
Returns the before ordering set.- Returns:
- the before ordering
-
getVersion
Returns the version of the web.xml.- Returns:
- the version
-
setVersion
Set the version for this web.xml file- Parameters:
version- Values ofnullwill be ignored
-
getPublicId
Returns the public identifier.- Returns:
- the public identifier
-
setPublicId
Sets the public identifier.- Parameters:
publicId- The public identifier
-
isMetadataComplete
public boolean isMetadataComplete()Returns whether metadata is complete.- Returns:
trueif metadata is complete
-
setMetadataComplete
public void setMetadataComplete(boolean metadataComplete) Sets whether metadata is complete.- Parameters:
metadataComplete- The metadata complete flag
-
getName
Returns the name of the web application.- Returns:
- the name
-
setName
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
Returns the display name of the web application.- Returns:
- the display name
-
setDisplayName
Sets the display name.- Parameters:
displayName- The display name
-
isDistributable
public boolean isDistributable()Returns whether the web application is distributable.- Returns:
trueif 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:
trueif 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
Adds a context parameter.- Parameters:
param- The parameter namevalue- The parameter value
-
getContextParams
Returns the context parameters.- Returns:
- the context parameters
-
addFilter
Adds a filter definition.- Parameters:
filter- The filter definition- Throws:
IllegalArgumentException- If a filter with the same name already exists
-
getFilters
Returns the filter definitions.- Returns:
- the filter definitions
-
addFilterMapping
Adds a filter mapping.- Parameters:
filterMap- The filter mapping
-
getFilterMappings
Returns the filter mappings.- Returns:
- the filter mappings
-
addListener
Adds a listener class.- Parameters:
className- The listener class name
-
getListeners
Returns the listener class names.- Returns:
- the listener class names
-
addServlet
Adds a servlet definition.- Parameters:
servletDef- The servlet definition
-
getServlets
Returns the servlet definitions.- Returns:
- the servlet definitions
-
addServletMapping
Adds a servlet URL mapping.- Parameters:
urlPattern- The URL patternservletName- The servlet name
-
addServletMappingDecoded
Adds a servlet URL mapping (already decoded).- Parameters:
urlPattern- The URL patternservletName- The servlet name- Throws:
IllegalArgumentException- If a duplicate mapping exists
-
getServletMappings
Returns the servlet URL mappings.- Returns:
- the servlet mappings
-
setSessionConfig
Sets the session configuration.- Parameters:
sessionConfig- The session configuration
-
getSessionConfig
Returns the session configuration.- Returns:
- the session configuration
-
addMimeMapping
Adds a MIME mapping.- Parameters:
extension- The file extensionmimeType- The MIME type
-
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-trueto add welcome files
-
addWelcomeFile
Adds a welcome file.- Parameters:
welcomeFile- The welcome file name
-
getWelcomeFiles
Returns the welcome files.- Returns:
- the welcome files
-
addErrorPage
Adds an error page.- Parameters:
errorPage- The error page
-
getErrorPages
Returns the error pages.- Returns:
- the error pages
-
addTaglib
Adds a taglib mapping.- Parameters:
uri- The taglib URIlocation- The taglib location
-
getTaglibs
Returns the taglib mappings.- Returns:
- the taglib mappings
-
addJspPropertyGroup
Adds a JSP property group.- Parameters:
propertyGroup- The JSP property group
-
getJspPropertyGroups
Returns the JSP property groups.- Returns:
- the JSP property groups
-
addSecurityConstraint
Adds a security constraint.- Parameters:
securityConstraint- The security constraint
-
getSecurityConstraints
Returns the security constraints.- Returns:
- the security constraints
-
setLoginConfig
Sets the login configuration.- Parameters:
loginConfig- The login configuration
-
getLoginConfig
Returns the login configuration.- Returns:
- the login configuration
-
addSecurityRole
Adds a security role.- Parameters:
securityRole- The security role name
-
getSecurityRoles
Returns the security roles.- Returns:
- the security roles
-
addEnvEntry
Adds an environment entry.- Parameters:
envEntry- The environment entry- Throws:
IllegalArgumentException- If an entry with the same name already exists
-
getEnvEntries
Returns the environment entries.- Returns:
- the environment entries
-
addEjbRef
Adds an EJB reference.- Parameters:
ejbRef- The EJB reference
-
getEjbRefs
Returns the EJB references.- Returns:
- the EJB references
-
addEjbLocalRef
Adds an EJB local reference.- Parameters:
ejbLocalRef- The EJB local reference
-
getEjbLocalRefs
Returns the EJB local references.- Returns:
- the EJB local references
-
addServiceRef
Adds a service reference.- Parameters:
serviceRef- The service reference
-
getServiceRefs
Returns the service references.- Returns:
- the service references
-
addResourceRef
Adds a resource reference.- Parameters:
resourceRef- The resource reference- Throws:
IllegalArgumentException- If a reference with the same name already exists
-
getResourceRefs
Returns the resource references.- Returns:
- the resource references
-
addResourceEnvRef
Adds a resource environment reference.- Parameters:
resourceEnvRef- The resource environment reference- Throws:
IllegalArgumentException- If a reference with the same name already exists
-
getResourceEnvRefs
Returns the resource environment references.- Returns:
- the resource environment references
-
addMessageDestinationRef
Adds a message destination reference.- Parameters:
messageDestinationRef- The message destination reference- Throws:
IllegalArgumentException- If a reference with the same name already exists
-
getMessageDestinationRefs
Returns the message destination references.- Returns:
- the message destination references
-
addMessageDestination
Adds a message destination.- Parameters:
messageDestination- The message destination- Throws:
IllegalArgumentException- If a destination with the same name already exists
-
getMessageDestinations
Returns the message destinations.- Returns:
- the message destinations
-
addLocaleEncodingMapping
Adds a locale-encoding mapping.- Parameters:
locale- The localeencoding- The encoding
-
getLocaleEncodingMappings
Returns the locale-encoding mappings.- Returns:
- the locale-encoding mappings
-
addPostConstructMethods
Adds a post-construct method.- Parameters:
clazz- The class namemethod- The method name
-
getPostConstructMethods
Returns the post-construct methods.- Returns:
- the post-construct methods
-
addPreDestroyMethods
Adds a pre-destroy method.- Parameters:
clazz- The class namemethod- The method name
-
getPreDestroyMethods
Returns the pre-destroy methods.- Returns:
- the pre-destroy methods
-
getJspConfigDescriptor
Returns the JSP configuration descriptor.- Returns:
- the JSP configuration descriptor
-
getRequestCharacterEncoding
Returns the request character encoding.- Returns:
- the request character encoding
-
setRequestCharacterEncoding
Sets the request character encoding.- Parameters:
requestCharacterEncoding- The request character encoding
-
getResponseCharacterEncoding
Returns the response character encoding.- Returns:
- the response character encoding
-
setResponseCharacterEncoding
Sets the response character encoding.- Parameters:
responseCharacterEncoding- The response character encoding
-
setURL
Sets the URL of the web.xml.- Parameters:
url- The URL
-
getURL
Returns the URL of the web.xml.- Returns:
- the URL
-
setJarName
Sets the JAR name for this web fragment.- Parameters:
jarName- The JAR name
-
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:
trueif from a webapp JAR
-
getDelegate
public boolean getDelegate()Returns whether this web application delegates first for class loading.- Returns:
trueif 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
-
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
Merge the supplied web fragments into this main web.xml.- Parameters:
fragments- The fragments to merge in- Returns:
trueif merge is successful, elsefalse
-
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 filefragments- The map of fragment names to web fragmentsservletContext- The servlet context the fragments are associated with- Returns:
- Ordered list of web-fragment.xml files to process
-