Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2013 Red Hat, Inc. and/or its affiliates. Licensed under the Eclipse Public License version 1.0, available at http://www.eclipse.org/legal/epl-v10.html
 
 
 package org.jboss.forge.addon.javaee.rest.config;
 
import  org.jboss.forge.addon.projects.Project;
import  org.jboss.forge.furnace.util.Assert;
Configures the Rest facet through the web.xml

Author(s):
George Gastaldi
   public static final String JAXRS_SERVLET = "javax.ws.rs.core.Application";
   private final String path;
   {
      Assert.notNull(path"Path cannot be null");
      this. = path;
   }
   @Override
   public String getApplicationPath()
   {
      return ;
   }
   @Override
   public void install(Project project)
   {
      if (!installedInWebXML(project))
      {
         ServletFacet_3_0 servlet = project.getFacet(ServletFacet_3_0.class);
         WebAppDescriptor config = servlet.getConfig();
         config.createServlet().servletName().loadOnStartup(1);
         String urlPattern = ;
         if (urlPattern.endsWith("/"))
         {
            urlPattern = urlPattern.substring(0, urlPattern.length() - 1);
         }
         config.createServletMapping().servletName().urlPattern(urlPattern);
         servlet.saveConfig(config);
      }
   }
   private boolean installedInWebXML(Project project)
   {
      return getServletPath(project) != null;
   }
   static String getServletPath(Project project)
   {
      String servletPath = null;
      if (project.hasFacet(ServletFacet_3_0.class))
      {
         ServletFacet_3_0 servlet = project.getFacet(ServletFacet_3_0.class);
         WebAppDescriptor config = servlet.getConfig();
         List<ServletMappingType<WebAppDescriptor>> allServletMapping = config.getAllServletMapping();
         for (ServletMappingType<WebAppDescriptorservletMappingType : allServletMapping)
         {
            if (.equals(servletMappingType.getServletName()))
            {
               List<StringallUrlPattern = servletMappingType.getAllUrlPattern();
               for (String urlPattern : allUrlPattern)
               {
                  servletPath = urlPattern;
               }
            }
         }
      }
      return servletPath;
   }
   @Override
   public void uninstall(Project project)
   {
      // TODO Auto-generated method stub
   }
New to GrepCode? Check out our FAQ X