Evan Knowles
Evan Knowles

Reputation: 7501

Access the value of welcome-file-list in web.xml

Is there any way of accessing the welcome-file-list element in the web.xml without having to re-parse the web.xml itself?

Upvotes: 1

Views: 232

Answers (1)

BalusC
BalusC

Reputation: 1108742

No. There's no public JSF or Servlet API for that.

Best what you can do is to grab JAXP+XPath.

InputStream input = FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream("/WEB-INF/web.xml");
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(input);
XPathExpression xpath = XPathFactory.newInstance().newXPath().compile("web-app/welcome-file-list/welcome-file");
NodeList nodes = (NodeList) xpath.evaluate(document, XPathConstants.NODESET);

for (int i = 0; i < nodes.getLength(); i++) {
    String welcomeFile = nodes.item(i).getFirstChild().getNodeValue().trim();
    // ...
}

If you happen to use JSF utility library OmniFaces, you can use its WebXml utility class.

List<String> welcomeFiles = WebXml.INSTANCE.getWelcomeFiles();

See also:

Upvotes: 1

Related Questions