コード例 #1
0
  private void updateTemplates() {
    LOG.info("Updating template cache...");
    StringResourceRepository repo = StringResourceLoader.getRepository();
    URI uri = path.toUri();
    if (uri == null) {
      LOG.error("Could not locate templates folder!");
      return;
    }

    File dir = new File(uri);

    File[] templates =
        dir.listFiles(
            new FilenameFilter() {
              @Override
              public boolean accept(File arg0, String arg1) {
                boolean isTemplateFile = arg1 != null && arg1.endsWith(".tpl");
                if (!isTemplateFile) {
                  return false;
                }

                return fileHasBeenModified(new File(arg0, arg1));
              }
            });

    if (templates != null && templates.length > 0) {
      for (File template : templates) {
        repo.putStringResource(template.getName(), getTemplateFromResource(template.getName()));
      }
    }
  }
コード例 #2
0
  /**
   * This method will return a {@link Template} object containing the requested template. This
   * method will also throw a {@link RuntimeException} if the template could not be loaded, in which
   * case you probably specified the wrong file.
   *
   * @param templatePath The template file to load.
   * @return The loaded {@link Template} object.
   */
  public Template getTemplate(final String templatePath) {
    synchronized (engine) {
      if (!engine.resourceExists(templatePath)) {
        StringResourceRepository repo = StringResourceLoader.getRepository();
        repo.putStringResource(templatePath, getTemplateFromResource(templatePath));
      }

      try {
        return engine.getTemplate(templatePath);
      } catch (Exception e) {
        LOG.error(e.getLocalizedMessage(), e);
        throw new DevHubException(e);
      }
    }
  }
コード例 #3
0
 private Template createTemplate(TemplateDescription templateDescription, VelocityEngine ve) {
   StringResourceRepository repo = StringResourceLoader.getRepository();
   repo.putStringResource(TEMPLATE_NAME, templateDescription.getTemplate());
   return ve.getTemplate(TEMPLATE_NAME, DEFAULT_ENCODING);
 }