private void createServletAndModifyWebXML( final IProject project, final IDataModel config, final IProgressMonitor monitor) { List<String> listOfMappings = Arrays.asList(servletInfoGroup.lstJAXRSServletURLPatterns.getItems()); if (JAXRSJEEUtils.isWebApp25orHigher(webAppObj)) { provider.modify( new UpdateWebXMLForJavaEE( project, initialInstallDelegateLibraryProviderID, servletInfoGroup.txtJAXRSServletName.getText(), servletInfoGroup.txtJAXRSServletClassName.getText(), listOfMappings), IModelProvider.FORCESAVE); } else // must be 2.3 or 2.4 { provider.modify( new UpdateWebXMLForJ2EE( project, this.j2eeServlet, this.j2eeServletMapping, servletInfoGroup.txtJAXRSServletName.getText(), servletInfoGroup.txtJAXRSServletClassName.getText(), listOfMappings), webXMLPath); } }
@SuppressWarnings({"unchecked", "rawtypes"}) protected void initializeValues() { List<ServletMapping> servletMappings = new ArrayList<ServletMapping>(); if (webAppObj != null) { servletInfoGroup.lstJAXRSServletURLPatterns.removeAll(); // set defaults- in the rare case we do not find the servlet we will create another servlet // entry String servletName = JAXRSUtils.JAXRS_DEFAULT_SERVLET_NAME; String servletClass = JAXRSUtils.JAXRS_SERVLET_CLASS; // get id ofthe library provider being used LibraryInstallDelegate installDelegate = super.getLibraryInstallDelegate(); ILibraryProvider libraryProvider = installDelegate.getLibraryProvider(); String id = ""; if (libraryProvider != null) id = libraryProvider.getId(); if (JAXRSJEEUtils.isWebApp25orHigher(webAppObj)) { WebApp webApp = (WebApp) webAppObj; Servlet servlet = JAXRSJEEUtils.findJAXRSServlet(webApp, id); if (servlet != null) { servletMappings = webApp.getServletMappings(); servletName = (servlet.getServletName() == null) ? servletName : servlet.getServletName(); servletClass = (servlet.getServletClass() == null) ? servletClass : servlet.getServletClass(); } else { // we did not find the servlet entry, set default value servletInfoGroup.lstJAXRSServletURLPatterns.add(JAXRSUtils.JAXRS_DEFAULT_URL_MAPPING); } } else { // 2.3 or 2.4 web app org.eclipse.jst.j2ee.webapplication.WebApp webApp = (org.eclipse.jst.j2ee.webapplication.WebApp) webAppObj; org.eclipse.jst.j2ee.webapplication.Servlet servlet = JAXRSJ2EEUtils.findJAXRSServlet(webApp, id); if (servlet != null) { this.j2eeServlet = servlet; servletMappings = webApp.getServletMappings(); servletName = (servlet.getServletName() == null) ? servletName : servlet.getServletName(); if (servlet.getServletClass() != null) { servletClass = (servlet.getServletClass().getQualifiedName() == null) ? servletClass : servlet.getServletClass().getQualifiedName(); } } else { // we did not find the servlet entry, set default value servletInfoGroup.lstJAXRSServletURLPatterns.add(JAXRSUtils.JAXRS_DEFAULT_URL_MAPPING); } } servletInfoGroup.txtJAXRSServletName.setText(servletName); servletInfoGroup.txtJAXRSServletClassName.setText(servletClass); // Find the servletMapping that corresponds to the servletName if (JAXRSJEEUtils.isWebApp25orHigher(webAppObj)) { for (Iterator<ServletMapping> i = servletMappings.iterator(); i.hasNext(); ) { Object o = i.next(); if (o instanceof ServletMapping) { // init the servletMapping ServletMapping next = (ServletMapping) o; if (servletName.equals(next.getServletName())) { for (Iterator p = next.getUrlPatterns().iterator(); p.hasNext(); ) { UrlPatternType pattern = (UrlPatternType) p.next(); servletInfoGroup.lstJAXRSServletURLPatterns.add(pattern.getValue()); } } } } } else { for (Iterator<ServletMapping> i = servletMappings.iterator(); i.hasNext(); ) { Object o = i.next(); if (o instanceof org.eclipse.jst.j2ee.webapplication.ServletMapping) { // init the servletMapping org.eclipse.jst.j2ee.webapplication.ServletMapping next = (org.eclipse.jst.j2ee.webapplication.ServletMapping) o; org.eclipse.jst.j2ee.webapplication.Servlet aServlet = next.getServlet(); // the servlet mapping may not have an associated servlet since the user could have // modified the file if (aServlet != null && servletName.equals(aServlet.getServletName())) { this.j2eeServletMapping = next; String pattern = next.getUrlPattern(); servletInfoGroup.lstJAXRSServletURLPatterns.add(new String(pattern)); } } } } } }