Package freemarker.cache

Examples of freemarker.cache.FileTemplateLoader


     * <p/>
     * The WebappTemplateLoader attempts to resolve templates relative to the web root folder
     */
    protected TemplateLoader getTemplateLoader(ServletContext servletContext) {
        // construct a FileTemplateLoader for the init-param 'TemplatePath'
        FileTemplateLoader templatePathLoader = null;

        String templatePath = servletContext.getInitParameter("TemplatePath");
        if (templatePath == null) {
            templatePath = servletContext.getInitParameter("templatePath");
        }

        if (templatePath != null) {
            try {
                templatePathLoader = new FileTemplateLoader(new File(templatePath));
            } catch (IOException e) {
                LOG.error("Invalid template path specified: " + e.getMessage(), e);
            }
        }

View Full Code Here


         try {
             if (templatePath.startsWith("class://")) {
                 // substring(7) is intentional as we "reuse" the last slash
                 templatePathLoader = new ClassTemplateLoader(getClass(), templatePath.substring(7));
             } else if (templatePath.startsWith("file://")) {
                 templatePathLoader = new FileTemplateLoader(new File(templatePath));
             }
         } catch (IOException e) {
             LOG.error("Invalid template path specified: " + e.getMessage(), e);
         }
View Full Code Here

    public static Configuration newFreeMarkerConfiguration(List<File> templateRootDirs,String defaultEncoding,String templateName) throws IOException {
        Configuration conf = new Configuration();
     
      FileTemplateLoader[] templateLoaders = new FileTemplateLoader[templateRootDirs.size()];
      for(int i = 0; i < templateRootDirs.size(); i++) {
        templateLoaders[i] = new FileTemplateLoader((File)templateRootDirs.get(i));
      }
      MultiTemplateLoader multiTemplateLoader = new MultiTemplateLoader(templateLoaders);
     
      conf.setTemplateLoader(multiTemplateLoader);
      conf.setNumberFormat("###############");
View Full Code Here

    }
  }
 
  private TemplateLoader buildTemplateLoader(List<TemplateLoader> loaders){
    try {
      FileTemplateLoader loader1 = new FileTemplateLoader(workingTemplateDir);
      FileTemplateLoader loader2 = new FileTemplateLoader(templateDir);
      ClassTemplateLoader loader3 = new ClassTemplateLoader(RendererImpl.class, "/org/opoo/press/templates");
       
      if(loaders == null){
        loaders = new ArrayList<TemplateLoader>();
      }
View Full Code Here

                if (servletContext != null) {
                    loaders.add(new WebappTemplateLoader(servletContext));
                }
                loaders.add(new ClassTemplateLoader(FreemarkerViewProcessor.class, "/"));
                try {
                    loaders.add(new FileTemplateLoader(new File("/")));
                } catch (IOException e) {
                    // NOOP
                }

                // Create Factory.
View Full Code Here

        try {
             if (templatePath.startsWith("class://")) {
                 // substring(7) is intentional as we "reuse" the last slash
                 templatePathLoader = new ClassTemplateLoader(getClass(), templatePath.substring(7));
             } else if (templatePath.startsWith("file://")) {
                 templatePathLoader = new FileTemplateLoader(new File(URI.create(templatePath)));
             }
         } catch (IOException e) {
             LOG.error("Invalid template path specified: " + e.getMessage(), e);
         }
View Full Code Here

             if(templatePath!=null){
                 if (templatePath.startsWith("class://")) {
                     // substring(7) is intentional as we "reuse" the last slash
                     templatePathLoader = new ClassTemplateLoader(getClass(), templatePath.substring(7));
                 } else if (templatePath.startsWith("file://")) {
                     templatePathLoader = new FileTemplateLoader(new File(templatePath.substring(7)));
                 }
             }
         } catch (IOException e) {
             if (LOG.isErrorEnabled()) {
                LOG.error("Invalid template path specified: #0", e, e.getMessage());
View Full Code Here

    final IPathFinder pathFinder = Activator.getDefault().getPathFinder();
    if(pathFinder == null)
      throw new IllegalStateException("Cannot find templates to render because path finder service is not available");
    final File templateDirectory = new File(pathFinder.getDataDirectory(), "templates");
    try {
      return new FileTemplateLoader(templateDirectory);
    } catch (IOException e) {
      logger.log(Level.WARNING, "Failed to open template directory: "+ e.getMessage());
      return null;
    }
   
View Full Code Here

        File file = path.getFile()// will fail if not resolvable in the file system
        if (logger.isDebugEnabled()) {
          logger.debug(
              "Template loader path [" + path + "] resolved to file path [" + file.getAbsolutePath() + "]");
        }
        return new FileTemplateLoader(file);
      }
      catch (IOException ex) {
        if (logger.isDebugEnabled()) {
          logger.debug("Cannot resolve template loader path [" + templateLoaderPath +
              "] to [java.io.File]: using SpringTemplateLoader as fallback", ex);
View Full Code Here

        if (ninjaProperties.isDev()
                && new File(srcDir).exists()) {
           
            try {
                // the src dir of user's project.
                FileTemplateLoader fileTemplateLoader = new FileTemplateLoader(new File(srcDir));
                // then ftl.html files from the classpath (eg. from inherited modules
                // or the ninja core module)
                ClassTemplateLoader classTemplateLoader = new ClassTemplateLoader(this.getClass(), "/");
               
                TemplateLoader [] templateLoader = new TemplateLoader[] {
View Full Code Here

TOP

Related Classes of freemarker.cache.FileTemplateLoader

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.