Package org.jivesoftware.util
Class WebXmlUtils
java.lang.Object
org.jivesoftware.util.WebXmlUtils
Utilities to extract data from a web.xml file.
- Author:
- Guus der Kinderen, guus.der.kinderen@gmail.com
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.dom4j.Document
asDocument
(File webXML) static String
getFilterClassName
(org.dom4j.Document webXml, String filterName) Retrieves the class name for a particular filter from a web.xml document.getFilterInitParams
(org.dom4j.Document webXml, String filterName) Retrieves a map of init param/values for a particular filter from a web.xml document.getFilterNames
(org.dom4j.Document webXml) Retrieves the names of all filters from a web.xml document.getFilterUrlPatterns
(org.dom4j.Document webXml, String filterName) Retrieves all URL patterns that apply to a specific filter.static String
getServletClassName
(org.dom4j.Document webXml, String servletName) Retrieves the class name for a particular servlet from a web.xml document.getServletInitParams
(org.dom4j.Document webXml, String servletName) Retrieves a map of init param/values for a particular servlet from a web.xml document.getServletNames
(org.dom4j.Document webXml) Retrieves the names of all servlets from a web.xml document.getServletUrlPatterns
(org.dom4j.Document webXml, String servletName) Retrieves all URL patterns that apply to a specific servlet.
-
Constructor Details
-
WebXmlUtils
public WebXmlUtils()
-
-
Method Details
-
asDocument
public static org.dom4j.Document asDocument(File webXML) throws org.dom4j.DocumentException, SAXException - Throws:
org.dom4j.DocumentException
SAXException
-
getServletNames
Retrieves the names of all servlets from a web.xml document. Returns a list that contains 'sessioncreate' and 'sessiondestroy' from this web.xml document: <servlet> <servlet-name>sessioncreate</servlet-name> <servlet-class>SessionCreateServlet</servlet-class> </servlet> <servlet> <servlet-name>sessiondestroy</servlet-name> <servlet-class>SessionDestroyServlet</servlet-class> </servlet>- Parameters:
webXml
- web.xml document, parsed as XML (cannot be null)- Returns:
- The name of the filter class, or null when no such class was defined.
-
getFilterNames
Retrieves the names of all filters from a web.xml document. Returns a list that contains 'message' from this web.xml document: <filter> <filter-name>message</filter-name> <filter-class>com.acme.filter.MessageFilter</filter-class> </filter>- Parameters:
webXml
- web.xml document, parsed as XML (cannot be null)- Returns:
- The name of the filter class, or null when no such class was defined.
-
getServletClassName
Retrieves the class name for a particular servlet from a web.xml document. Returns 'SessionCreateServlet' for 'sessioncreate' of this web.xml document: <servlet> <servlet-name>sessioncreate</servlet-name> <servlet-class>SessionCreateServlet</servlet-class> </servlet> <servlet> <servlet-name>sessiondestroy</servlet-name> <servlet-class>SessionDestroyServlet</servlet-class> </servlet>- Parameters:
webXml
- web.xml document, parsed as XML (cannot be null)servletName
- The name of the servlet (cannot be null or empty).- Returns:
- The name of the filter class, or null when no such class was defined.
-
getFilterClassName
Retrieves the class name for a particular filter from a web.xml document. Returns 'com.acme.filter.MessageFilter' for 'message' of this web.xml document: <filter> <filter-name>message</filter-name> <filter-class>com.acme.filter.MessageFilter</filter-class> </filter>- Parameters:
webXml
- web.xml document, parsed as XML (cannot be null)filterName
- The name of the filter (cannot be null or empty).- Returns:
- The name of the filter class, or null when no such class was defined.
-
getServletInitParams
public static Map<String,String> getServletInitParams(org.dom4j.Document webXml, String servletName) Retrieves a map of init param/values for a particular servlet from a web.xml document. For filter 'message' of this web.xml document, returns a map with two entries: foo-> bar, test->value. <servlet> <servlet-name>sessioncreate</servlet-name> <servlet-class>SessionCreateServlet</servlet-class> <init-param> <param-name>foo</param-name> <param-value>bar</param-value> </init-param> <init-param> <param-name>test</param-name> <param-value>value</param-value> </init-param> </servlet> Parameters with no or empty name are ignored. When multiple parameters have the same name, only one of them is returned.- Parameters:
webXml
- web.xml document, parsed as XML (cannot be null)servletName
- The name of the servlet (cannot be null or empty).- Returns:
- A map (possibly empty, but never null).
-
getFilterInitParams
Retrieves a map of init param/values for a particular filter from a web.xml document. For filter 'message' of this web.xml document, returns a map with two entries: foo-> bar, test->value. <filter> <filter-name>message</filter-name> <filter-class>com.acme.filter.MessageFilter</filter-class> <init-param> <param-name>foo</param-name> <param-value>bar</param-value> </init-param> <init-param> <param-name>test</param-name> <param-value>value</param-value> </init-param> </filter> Parameters with no or empty name are ignored. When multiple parameters have the same name, only one of them is returned.- Parameters:
webXml
- web.xml document, parsed as XML (cannot be null)filterName
- The name of the filter (cannot be null or empty).- Returns:
- A map (possibly empty, but never null).
-
getServletUrlPatterns
Retrieves all URL patterns that apply to a specific servlet.- Parameters:
webXml
- web.xml document, parsed as XML (cannot be null)servletName
- The name of the servlet (cannot be null or empty).- Returns:
- A collection (possibly empty, but never null).
-
getFilterUrlPatterns
Retrieves all URL patterns that apply to a specific filter.- Parameters:
webXml
- web.xml document, parsed as XML (cannot be null)filterName
- The name of the filter (cannot be null or empty).- Returns:
- A collection (possibly empty, but never null).
-