Exemple #1
0
  @Override
  public List<String> getFacesServletMappings() {
    List<String> results = new ArrayList<String>();
    ServletFacet facet = project.getFacet(ServletFacet.class);
    WebAppDescriptor webXml = facet.getConfig();

    // TODO should probably take into account facelets view mappings
    // facelets.VIEW_MAPPINGS

    if (webXml.hasFacesServlet()) {
      List<ServletDef> servlets = webXml.getServlets();
      for (ServletDef servlet : servlets) {
        if ("javax.faces.webapp.FacesServlet".equals(servlet.getServletClass())) {
          List<ServletMappingDef> mappings = servlet.getMappings();
          for (ServletMappingDef mapping : mappings) {
            results.addAll(mapping.getUrlPatterns());
          }
        }
      }
    } else {
      if (webXml.getVersion().startsWith("3")) {
        results.add("*.jsf");
        results.add("/faces/*");
      } else
        ShellMessages.info(
            out,
            "FacesServlet not found in web.xml and Servlet "
                + "Version not >= 3.0, could not discover FacesServlet mappings");
    }
    return results;
  }
  @Test
  public void shouldBeAbleToConstructDescriptorFromString() throws Exception {
    final WebAppDescriptor web =
        Descriptors.importAs(WebAppDescriptor.class)
            .from(new ByteArrayInputStream(source.getBytes()));

    Assert.assertNotNull(web);

    Assert.assertEquals(1, web.getFilters().size());
    Assert.assertEquals(1, web.getFilterMappings().size());
  }
Exemple #3
0
 private List<String> getExplicitFacesServletMappings(final WebAppDescriptor webXml) {
   List<ServletDef> servlets = webXml.getServlets();
   List<String> results = new ArrayList<String>();
   for (ServletDef servlet : servlets) {
     if ("javax.faces.webapp.FacesServlet".equals(servlet.getServletClass())) {
       List<ServletMappingDef> mappings = servlet.getMappings();
       for (ServletMappingDef mapping : mappings) {
         results.addAll(mapping.getUrlPatterns());
       }
     }
   }
   return results;
 }
Exemple #4
0
  @Override
  public List<String> getEffectiveFacesServletMappings() {
    List<String> results = new ArrayList<String>();
    ServletFacet facet = project.getFacet(ServletFacet.class);
    WebAppDescriptor webXml = facet.getConfig();

    // TODO should probably take into account facelets view mappings
    // facelets.VIEW_MAPPINGS

    if (webXml.hasFacesServlet()) {
      results.addAll(getExplicitFacesServletMappings(webXml));
    } else {
      if (webXml.getVersion().startsWith("3")) {
        results.add("*.jsf");
        results.add("/faces/*");
      } else
        ShellMessages.info(
            out,
            "FacesServlet not found in web.xml and Servlet "
                + "Version not >= 3.0, could not discover FacesServlet mappings");
    }
    return results;
  }
  @Test
  public void testInstallAfterOtherServletMapping() throws Exception {
    Project project = getProject();

    assertFalse(project.hasFacet(RestFacet.class));

    queueInputLines("");
    getShell().execute("setup servlet");
    ServletFacet web = project.getFacet(ServletFacet.class);
    WebAppDescriptor config = web.getConfig();
    config.facesServlet();
    web.saveConfig(config);

    org.jboss.forge.parser.xml.Node webXml = XMLParser.parse(web.getConfig().exportAsString());
    assertEquals(1, webXml.get("servlet-mapping").size());

    assertTrue(config.exportAsString().contains("servlet-mapping"));

    setupRest();

    assertTrue(project.hasFacet(RestFacet.class));
    assertTrue(
        project
            .getFacet(DependencyFacet.class)
            .hasEffectiveDependency(
                DependencyBuilder.create("org.jboss.spec.javax.ws.rs:jboss-jaxrs-api_1.1_spec")));

    RestFacet restFacet = project.getFacet(RestFacet.class);
    assertEquals("/rest", restFacet.getApplicationPath());

    assertTrue(project.hasFacet(RestWebXmlFacet.class));
    RestWebXmlFacet restWebXmlFacet = project.getFacet(RestWebXmlFacet.class);
    assertEquals("/rest/*", restWebXmlFacet.getServletPath());

    webXml = XMLParser.parse(web.getConfig().exportAsString());
    assertEquals(2, webXml.get("servlet-mapping").size());
  }
Exemple #6
0
  @Override
  public boolean install() {
    if (!isInstalled()) {
      String projectName = project.getFacet(MetadataFacet.class).getProjectName();

      project.getFacet(DependencyFacet.class).addDependency(dep);

      DirectoryResource webRoot = project.getFacet(WebResourceFacet.class).getWebRootDirectory();
      if (!webRoot.exists()) {
        webRoot.mkdirs();
      }

      FileResource<?> descriptor = getConfigFile();
      if (!descriptor.exists()) {
        WebAppDescriptor unit =
            Descriptors.create(WebAppDescriptor.class)
                .displayName(projectName)
                .sessionTimeout(30)
                .welcomeFile("/index.html");

        descriptor.setContents(unit.exportAsString());
      }

      FileResource<?> welcomePage = (FileResource<?>) webRoot.getChild("index.html");
      welcomePage.setContents(
          "<html><head><title>Welcome to Seam Forge</title></head>"
              + "<body>"
              + "<h1> ["
              + projectName
              + "] is Online</h1>"
              + "Powered by <a href=\"http://bit.ly/seamforge\">Seam Forge</a>"
              + "</body>"
              + "</html>");
    }
    return true;
  }
Exemple #7
0
 @Override
 public List<String> getFaceletsViewMapping() {
   ServletFacet facet = project.getFacet(ServletFacet.class);
   WebAppDescriptor webXml = facet.getConfig();
   return webXml.getFaceletsViewMappings();
 }
Exemple #8
0
 @Override
 public List<String> getFaceletsDefaultSuffixes() {
   ServletFacet facet = project.getFacet(ServletFacet.class);
   WebAppDescriptor webXml = facet.getConfig();
   return webXml.getFaceletsDefaultSuffixes();
 }
Exemple #9
0
 @Override
 public FacesProjectStage getProjectStage() {
   ServletFacet facet = project.getFacet(ServletFacet.class);
   WebAppDescriptor config = facet.getConfig();
   return config.getFacesProjectStage();
 }
Exemple #10
0
 public void saveConfig(final WebAppDescriptor descriptor) {
   String output = descriptor.exportAsString();
   getConfigFile().setContents(output);
 }