Ejemplo n.º 1
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  protected void setupWebXML() {
    WebResourcesFacet web = this.project.getFacet(WebResourcesFacet.class);
    ServletFacet servlet = this.project.getFacet(ServletFacet.class);
    WebAppCommonDescriptor servletConfig = (WebAppCommonDescriptor) servlet.getConfig();
    Node root = ((NodeDescriptor) servletConfig).getRootNode();
    removeConflictingErrorPages(root);

    // (prefer /faces/error.xhtml)

    List<String> webPaths = getAccessStrategy().getWebPaths(web.getWebResource(ERROR_XHTML));
    String errorLocation = webPaths.size() > 1 ? webPaths.get(1) : "/faces/error.xhtml";
    createErrorPageEntry(servletConfig, errorLocation, "404");
    createErrorPageEntry(servletConfig, errorLocation, "500");

    // Use the server timezone since we accept dates in that timezone, and it makes sense to display
    // them in the
    // same
    boolean found = false;
    List<ParamValueCommonType<?>> allContextParam = servletConfig.getAllContextParam();
    for (ParamValueCommonType<?> contextParam : allContextParam) {
      if (contextParam
          .getParamName()
          .equals("javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE")) {
        found = true;
      }
    }
    if (!found) {
      servletConfig
          .createContextParam()
          .paramName("javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE")
          .paramValue("true");
    }
    servlet.saveConfig(servletConfig);
  }
Ejemplo n.º 2
0
  @SuppressWarnings("rawtypes")
  protected List<Resource<?>> generateIndex(String targetDir, final Resource<?> template) {
    List<Resource<?>> result = new ArrayList<>();
    WebResourcesFacet web = this.project.getFacet(WebResourcesFacet.class);

    ServletFacet servlet = this.project.getFacet(ServletFacet.class);
    if (servlet instanceof ServletFacet_3_0) {
      WebAppDescriptor servletConfig = (WebAppDescriptor) servlet.getConfig();
      servletConfig.getOrCreateWelcomeFileList().welcomeFile(INDEX_HTML);
    } else if (servlet instanceof ServletFacet_3_1) {
      org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor servletConfig =
          (org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor) servlet.getConfig();
      servletConfig.getOrCreateWelcomeFileList().welcomeFile(INDEX_HTML);
    }
    loadTemplates();

    generateTemplates(targetDir);
    HashMap<Object, Object> context = getTemplateContext(targetDir, template);

    // Basic pages

    result.add(
        ScaffoldUtil.createOrOverwrite(
            web.getWebResource(targetDir + INDEX_HTML),
            FreemarkerTemplateProcessor.processTemplate(context, indexWelcomeTemplate)));

    result.add(
        ScaffoldUtil.createOrOverwrite(
            web.getWebResource(targetDir + INDEX_XHTML),
            FreemarkerTemplateProcessor.processTemplate(context, indexTemplate)));

    result.add(
        ScaffoldUtil.createOrOverwrite(
            web.getWebResource(ERROR_XHTML),
            FreemarkerTemplateProcessor.processTemplate(context, errorTemplate)));

    // Static resources

    result.add(
        ScaffoldUtil.createOrOverwrite(
            web.getWebResource(ADD_PNG), getClass().getResourceAsStream(SCAFFOLD_ADD_PNG)));

    result.add(
        ScaffoldUtil.createOrOverwrite(
            web.getWebResource(BOOTSTRAP_CSS),
            getClass().getResourceAsStream(SCAFFOLD_BOOTSTRAP_CSS)));

    result.add(
        ScaffoldUtil.createOrOverwrite(
            web.getWebResource(FALSE_PNG), getClass().getResourceAsStream(SCAFFOLD_FALSE_PNG)));

    result.add(
        ScaffoldUtil.createOrOverwrite(
            web.getWebResource(FAVICON_ICO), getClass().getResourceAsStream(SCAFFOLD_FAVICON_ICO)));

    result.add(
        ScaffoldUtil.createOrOverwrite(
            web.getWebResource(FORGE_LOGO_PNG),
            getClass().getResourceAsStream(SCAFFOLD_FORGE_LOGO_PNG)));

    result.add(
        ScaffoldUtil.createOrOverwrite(
            web.getWebResource(FORGE_STYLE_CSS),
            getClass().getResourceAsStream(SCAFFOLD_FORGE_STYLE_CSS)));

    result.add(
        ScaffoldUtil.createOrOverwrite(
            web.getWebResource(REMOVE_PNG), getClass().getResourceAsStream(SCAFFOLD_REMOVE_PNG)));

    result.add(
        ScaffoldUtil.createOrOverwrite(
            web.getWebResource(SEARCH_PNG), getClass().getResourceAsStream(SCAFFOLD_SEARCH_PNG)));

    result.add(
        ScaffoldUtil.createOrOverwrite(
            web.getWebResource(TRUE_PNG), getClass().getResourceAsStream(SCAFFOLD_TRUE_PNG)));

    result.add(
        ScaffoldUtil.createOrOverwrite(
            web.getWebResource(JBOSS_COMMUNITY_PNG),
            getClass().getResourceAsStream(SCAFFOLD_JBOSS_COMMUNITY_PNG)));

    return result;
  }
Ejemplo n.º 3
0
 @SuppressWarnings("rawtypes")
 @Override
 public boolean isSetup(ScaffoldSetupContext setupContext) {
   Project project = setupContext.getProject();
   setProject(project);
   String targetDir = setupContext.getTargetDirectory();
   targetDir = targetDir == null ? "" : targetDir;
   if (project.hasAllFacets(
       Arrays.asList(
           WebResourcesFacet.class,
           DependencyFacet.class,
           JPAFacet.class,
           EJBFacet.class,
           CDIFacet.class,
           ServletFacet.class,
           FacesFacet.class))) {
     WebResourcesFacet web = project.getFacet(WebResourcesFacet.class);
     boolean areResourcesInstalled =
         web.getWebResource(targetDir + INDEX_HTML).exists()
             && web.getWebResource(targetDir + INDEX_XHTML).exists()
             && web.getWebResource(ERROR_XHTML).exists()
             && web.getWebResource(ADD_PNG).exists()
             && web.getWebResource(BOOTSTRAP_CSS).exists()
             && web.getWebResource(FALSE_PNG).exists()
             && web.getWebResource(FAVICON_ICO).exists()
             && web.getWebResource(FORGE_LOGO_PNG).exists()
             && web.getWebResource(FORGE_STYLE_CSS).exists()
             && web.getWebResource(REMOVE_PNG).exists()
             && web.getWebResource(SEARCH_PNG).exists()
             && web.getWebResource(TRUE_PNG).exists()
             && web.getWebResource(JBOSS_COMMUNITY_PNG).exists()
             && web.getWebResource(PAGINATOR).exists()
             && getTemplateStrategy().getDefaultTemplate().exists();
     ServletFacet servlet = project.getFacet(ServletFacet.class);
     boolean isWelcomeFileListed = false;
     if (servlet instanceof ServletFacet_3_0) {
       WebAppDescriptor servletConfig = (WebAppDescriptor) servlet.getConfig();
       for (WelcomeFileListType<WebAppDescriptor> welcomeFileList :
           servletConfig.getAllWelcomeFileList()) {
         for (String welcomeFile : welcomeFileList.getAllWelcomeFile()) {
           if (welcomeFile.equals(INDEX_HTML)) {
             isWelcomeFileListed = true;
             break;
           }
         }
       }
     } else if (servlet instanceof ServletFacet_3_1) {
       org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor servletConfig =
           (org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor) servlet.getConfig();
       for (org.jboss.shrinkwrap.descriptor.api.webcommon31.WelcomeFileListType<
               org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor>
           welcomeFileList : servletConfig.getAllWelcomeFileList()) {
         for (String welcomeFile : welcomeFileList.getAllWelcomeFile()) {
           if (welcomeFile.equals(INDEX_HTML)) {
             isWelcomeFileListed = true;
             break;
           }
         }
       }
     }
     return areResourcesInstalled && isWelcomeFileListed;
   }
   return false;
 }