Package org.jboss.forge.addon.projects.facets

Examples of org.jboss.forge.addon.projects.facets.WebResourcesFacet


      {
         if (template.exists())
         {
            Map<Object, Object> attributeMap = context.getUIContext().getAttributeMap();
            Project project = (Project) attributeMap.get(Project.class);
            WebResourcesFacet web = project.getFacet(WebResourcesFacet.class);
            boolean isValidTemplate = false;
            for (DirectoryResource dir : web.getWebRootDirectories())
            {
               if (ResourceUtil.isChildOf(dir, template))
               {
                  isValidTemplate = true;
               }
View Full Code Here


   }

   @Override
   public String getReferencePath(final Resource<?> template)
   {
      WebResourcesFacet web = this.project.getFacet(WebResourcesFacet.class);
      for (DirectoryResource dir : web.getWebRootDirectories()) {
         if (ResourceUtil.isChildOf(dir, template))
         {
            String relativePath = template.getFullyQualifiedName().substring(dir.getFullyQualifiedName().length());
            return relativePath;
         }
View Full Code Here

   }

   @Override
   public FileResource<?> getDefaultTemplate()
   {
      WebResourcesFacet web = this.project.getFacet(WebResourcesFacet.class);
      return web.getWebResource(SCAFFOLD_FORGE_TEMPLATE);
   }
View Full Code Here

      String targetDir = setupContext.getTargetDirectory();
      targetDir = targetDir == null ? "" : targetDir;
      if (project.hasAllFacets(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)
         {
View Full Code Here

   }

   protected List<Resource<?>> generateIndex(String targetDir, final Resource<?> template)
   {
      List<Resource<?>> result = new ArrayList<Resource<?>>();
      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),
               this.templateProcessor.processTemplate(context, indexWelcomeTemplate)));

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

      result.add(ScaffoldUtil.createOrOverwrite(web.getWebResource(ERROR_XHTML),
               this.templateProcessor.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;
   }
View Full Code Here

   {
      List<Resource<?>> result = new ArrayList<Resource<?>>();

      try
      {
         WebResourcesFacet web = this.project.getFacet(WebResourcesFacet.class);

         result.add(ScaffoldUtil.createOrOverwrite(web.getWebResource(PAGINATOR),
                  getClass().getResourceAsStream(SCAFFOLD_PAGINATOR)));

         result.add(generateNavigation(targetDir));
      }
      catch (Exception e)
View Full Code Here

      return context;
   }

   protected void setupWebXML()
   {
      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();
         Node root = ((NodeDescriptor) servletConfig).getRootNode();
         removeConflictingErrorPages(root);

         // (prefer /faces/error.xhtml)

         String errorLocation = getAccessStrategy().getWebPaths(web.getWebResource(ERROR_XHTML)).get(1);
         servletConfig.createErrorPage().errorCode("404").location(errorLocation);
         servletConfig.createErrorPage().errorCode("500").location(errorLocation);

         // Use the server timezone since we accept dates in that timezone, and it makes sense to display them in the
         // same
         boolean found = false;
         for (ParamValueType<WebAppDescriptor> contextParam : servletConfig.getAllContextParam())
         {
            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);
      }
      else if (servlet instanceof ServletFacet_3_1)
      {
         org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor servletConfig = (org.jboss.shrinkwrap.descriptor.api.webapp31.WebAppDescriptor) servlet
                  .getConfig();
         // (prefer /faces/error.xhtml)

         String errorLocation = getAccessStrategy().getWebPaths(web.getWebResource(ERROR_XHTML)).get(1);
         servletConfig.createErrorPage().errorCode("404").location(errorLocation);
         servletConfig.createErrorPage().errorCode("500").location(errorLocation);

         // Use the server timezone since we accept dates in that timezone, and it makes sense to display them in the
         // same
View Full Code Here

    */

   protected Resource<?> generateNavigation(final String targetDir)
            throws IOException
   {
      WebResourcesFacet web = this.project.getFacet(WebResourcesFacet.class);
      HtmlTag unorderedList = new HtmlTag("ul");

      ResourceFilter filter = new ResourceFilter()
      {
         @Override
         public boolean accept(Resource<?> resource)
         {
            FileResource<?> file = (FileResource<?>) resource;

            if (!file.isDirectory()
                     || file.getName().equals("resources")
                     || file.getName().equals("WEB-INF")
                     || file.getName().equals("META-INF"))
            {
               return false;
            }

            return true;
         }
      };

      for (Resource<?> resource : web.getWebResource(targetDir + "/").listResources(filter))
      {
         HtmlOutcomeTargetLink outcomeTargetLink = new HtmlOutcomeTargetLink();
         String outcome = targetDir.isEmpty() || targetDir.startsWith("/") ? targetDir : "/" + targetDir;
         outcomeTargetLink.putAttribute("outcome", outcome + "/" + resource.getName() + "/search");
         outcomeTargetLink.setValue(StringUtils.uncamelCase(resource.getName()));
View Full Code Here

      List<Resource<?>> result = new ArrayList<Resource<?>>();
      try
      {
         JavaSourceFacet java = this.project.getFacet(JavaSourceFacet.class);
         WebResourcesFacet web = this.project.getFacet(WebResourcesFacet.class);
         JPAFacet<PersistenceCommonDescriptor> jpa = this.project.getFacet(JPAFacet.class);

         loadTemplates();
         Map<Object, Object> context = CollectionUtils.newHashMap();
         context.put("entity", entity);
         String ccEntity = StringUtils.decapitalize(entity.getName());
         context.put("ccEntity", ccEntity);
         context.put("rmEntity", ccEntity + "ToDelete");
         setPrimaryKeyMetaData(context, entity);

         // Prepare qbeMetawidget
         this.qbeMetawidget.setPath(entity.getQualifiedName());
         StringWriter stringWriter = new StringWriter();
         this.qbeMetawidget.write(stringWriter, this.backingBeanTemplateQbeMetawidgetIndent);
         context.put("qbeMetawidget", stringWriter.toString().trim());

         // Prepare removeEntityMetawidget
         this.rmEntityMetawidget.setPath(entity.getQualifiedName());
         stringWriter = new StringWriter();
         this.rmEntityMetawidget.write(stringWriter, this.backingBeanTemplateRmEntityMetawidgetIndent);
         context.put("rmEntityMetawidget", stringWriter.toString().trim());

         // Prepare Java imports
         Set<String> qbeMetawidgetImports = this.qbeMetawidget.getImports();
         Set<String> rmEntityMetawidgetImports = this.rmEntityMetawidget.getImports();
         Set<String> metawidgetImports = CollectionUtils.newHashSet();
         metawidgetImports.addAll(qbeMetawidgetImports);
         metawidgetImports.addAll(rmEntityMetawidgetImports);
         metawidgetImports.remove(entity.getQualifiedName());
         context.put("metawidgetImports",
                  CollectionUtils.toString(metawidgetImports, ";\r\nimport ", true, false));

         // Prepare JPA Persistence Unit
         context.put("persistenceUnitName", jpa.getConfig().getOrCreatePersistenceUnit().getName());

         // Create the Backing Bean for this entity
         JavaClassSource viewBean = Roaster.parse(JavaClassSource.class,
                  this.templateProcessor.processTemplate(context, this.backingBeanTemplate));
         viewBean.setPackage(java.getBasePackage() + ".view");
         result.add(ScaffoldUtil.createOrOverwrite(java.getJavaResource(viewBean), viewBean.toString()));

         // Set new context for view generation
         context = getTemplateContext(targetDir, template);
         String beanName = StringUtils.decapitalize(viewBean.getName());
         context.put("beanName", beanName);
         context.put("ccEntity", ccEntity);
         context.put("entityName", StringUtils.uncamelCase(entity.getName()));
         setPrimaryKeyMetaData(context, entity);

         // Prepare entityMetawidget
         this.entityMetawidget.setValue(StaticFacesUtils.wrapExpression(beanName + "." + ccEntity));
         this.entityMetawidget.setPath(entity.getQualifiedName());
         this.entityMetawidget.setReadOnly(false);
         this.entityMetawidget.setStyle(null);

         // Generate create
         writeEntityMetawidget(context, this.createTemplateEntityMetawidgetIndent, this.createTemplateNamespaces);

         result.add(ScaffoldUtil.createOrOverwrite(
                  web.getWebResource(targetDir + "/" + ccEntity + "/create.xhtml"),
                  this.templateProcessor.processTemplate(context, this.createTemplate)));

         // Generate view
         this.entityMetawidget.setReadOnly(true);
         writeEntityMetawidget(context, this.viewTemplateEntityMetawidgetIndent, this.viewTemplateNamespaces);

         result.add(ScaffoldUtil.createOrOverwrite(
                  web.getWebResource(targetDir + "/" + ccEntity + "/view.xhtml"),
                  this.templateProcessor.processTemplate(context, this.viewTemplate)));

         // Generate search
         this.searchMetawidget.setValue(StaticFacesUtils.wrapExpression(beanName + ".example"));
         this.searchMetawidget.setPath(entity.getQualifiedName());
         this.beanMetawidget.setValue(StaticFacesUtils.wrapExpression(beanName + ".pageItems"));
         this.beanMetawidget.setPath(viewBean.getQualifiedName() + "/pageItems");
         writeSearchAndBeanMetawidget(context, this.searchTemplateSearchMetawidgetIndent,
                  this.searchTemplateBeanMetawidgetIndent, this.searchTemplateNamespaces);

         result.add(ScaffoldUtil.createOrOverwrite(
                  web.getWebResource(targetDir + "/" + ccEntity + "/search.xhtml"),
                  this.templateProcessor.processTemplate(context, this.searchTemplate)));

         // Generate navigation
         result.add(generateNavigation(targetDir));

         // Need ViewUtils and forge.taglib.xml for forgeview:asList
         JavaClassSource viewUtils = Roaster.parse(JavaClassSource.class,
                  this.templateProcessor.processTemplate(context, this.viewUtilsTemplate));
         viewUtils.setPackage(viewBean.getPackage());
         result.add(ScaffoldUtil.createOrOverwrite(java.getJavaResource(viewUtils), viewUtils.toString()));

         context.put("viewPackage", viewBean.getPackage());
         result.add(ScaffoldUtil.createOrOverwrite(
                  web.getWebResource("WEB-INF/classes/META-INF/forge.taglib.xml"),
                  this.templateProcessor.processTemplate(context, this.taglibTemplate)));

         createInitializers(entity);
      }
      catch (Exception e)
View Full Code Here

      String targetDir = setupContext.getTargetDirectory();
      targetDir = (targetDir == null) ? "" : targetDir;

      // Setup static resources.
      ArrayList<Resource<?>> result = new ArrayList<>();
      WebResourcesFacet web = project.getFacet(WebResourcesFacet.class);
      ProcessingStrategy strategy = new CopyResourcesStrategy(web);
      for (ScaffoldResource scaffoldResource : getStatics(targetDir, strategy)) {
         result.add(scaffoldResource.generate());
      }
View Full Code Here

TOP

Related Classes of org.jboss.forge.addon.projects.facets.WebResourcesFacet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.