public boolean install()
{
if (!installedInWebXML())
{
// TODO this needs to be fixed in desciptors (allow creation of servlet mapping)
ServletFacet servlet = project.getFacet(ServletFacet.class);
WebAppDescriptorImpl web = (WebAppDescriptorImpl) servlet.getConfig();
Node node = web.getRootNode();
Node servletClass = node.getSingle("servlet/servlet-name=" + JAXRS_SERVLET);
Node servletMapping = node.getSingle("servlet-mapping/servlet-name=" + JAXRS_SERVLET);
if (servletClass == null)
{
Node mapping = node.createChild("servlet");
mapping.createChild("servlet-name").text(JAXRS_SERVLET);
mapping.createChild("load-on-startup").text("1");
}
if (servletMapping == null)
{
Node mapping = node.createChild("servlet-mapping");
mapping.createChild("servlet-name").text(JAXRS_SERVLET);
String urlPattern = getProjectConfiguration().getString(RestFacet.ROOTPATH);
if (urlPattern.endsWith("/"))
{
urlPattern = urlPattern.substring(0, urlPattern.length() - 1);
}
mapping.createChild("url-pattern").text(urlPattern + "/*");
}
servlet.saveConfig(web);
}
return true;
}