Package freemarker.template

Examples of freemarker.template.Configuration


      }
    }
  }

  private Configuration newFreeMarkerConfiguration() throws IOException {
    final Configuration config = new Configuration();

    final FileTemplateLoader[] templateLoaders = new FileTemplateLoader[templateRootDirs.size()];
    for(int i = 0; i < templateRootDirs.size(); i++) {
      templateLoaders[i] = new FileTemplateLoader((File)templateRootDirs.get(i));
    }
    final MultiTemplateLoader multiTemplateLoader = new MultiTemplateLoader(templateLoaders);

    config.setTemplateLoader(multiTemplateLoader);
    config.setNumberFormat("###############");
    config.setBooleanFormat("true,false");
    config.setDefaultEncoding(encoding);
    return config;
  }
View Full Code Here


     * Load and process the repository configuration templates.
     */
    public String processTemplate(String name,
                                  Map<String, Object> data) {
        try {
            Configuration configuration = new Configuration();
            configuration.setObjectWrapper( new DefaultObjectWrapper() );
            configuration.setTemplateUpdateDelay( 0 );

            Template template = new Template( name,
                                              new InputStreamReader( ServiceImplementation.class.getResourceAsStream( "/repoconfig/" + name + ".xml" ) ),
                                              configuration );
            StringWriter stringwriter = new StringWriter();
View Full Code Here

    }

    // returns the FTL Template object
    // Note: the template will not be cached
    protected Template getTemplate(URL templateUrl) {
        Configuration config = FreeMarkerWorker.getDefaultOfbizConfig();

        Template template = null;
        try {
            InputStream templateStream = templateUrl.openStream();
            InputStreamReader templateReader = new InputStreamReader(templateStream);
View Full Code Here

    // set template config
    File templatePath = new File(Espeon.templatePath);
   
    if(templatePath.isDirectory())
    {
      this.cfg = new Configuration();

      this.cfg.setDirectoryForTemplateLoading(new File(Espeon.templatePath));

      this.cfg.setObjectWrapper(new DefaultObjectWrapper());
    }
View Full Code Here

        AssertArgument.isNotNullAndNotEmpty(templateText, "templateText");
        Reader templateReader = new StringReader(templateText);

        try {
            try {
                template = new Template("free-marker-template", templateReader, new Configuration());
            } finally {
                templateReader.close();
            }
        } catch (IOException e) {
            throw new IllegalStateException("Unexpected IOException.", e);
View Full Code Here

    public FreeMarkerTemplate(String templatePath, Class basePath) {
        AssertArgument.isNotNullAndNotEmpty(templatePath, "templatePath");
        this.templateText = templatePath;

        try {
            Configuration configuration = new Configuration();

            if(basePath != null) {
                configuration.setClassForTemplateLoading(basePath, "");
            }
            template = configuration.getTemplate(templatePath);
        } catch (IOException e) {
            throw new IllegalStateException("Unexpected IOException.", e);
        }
    }
View Full Code Here

        URL screenFileUrl = FlexibleLocation.resolveLocation(fileUrl, null);
        String urlStr = screenFileUrl.toString();
        URI uri = new URI(urlStr);
        File f = new File(uri);
        FileReader templateReader = new FileReader(f);
        Configuration conf = makeDefaultOfbizConfig();
        template = new Template("FMImportFilter", templateReader, conf);
        return template;
    }
View Full Code Here

        template = new Template("FMImportFilter", templateReader, conf);
        return template;
    }

    public static Configuration makeDefaultOfbizConfig() throws TemplateException, IOException {
        Configuration config = new Configuration();
        config.setObjectWrapper(BeansWrapper.getDefaultInstance());
        config.setSetting("datetime_format", "yyyy-MM-dd HH:mm:ss.SSS");
        Configuration defaultOfbizConfig = config;
        return defaultOfbizConfig;
    }
View Full Code Here

    public static UtilCache<String, Template> cachedTemplates = new UtilCache<String, Template>("template.ftl.general", 0, 0, false);
    protected static BeansWrapper defaultOfbizWrapper = BeansWrapper.getDefaultInstance();
    protected static Configuration defaultOfbizConfig = makeConfiguration(defaultOfbizWrapper);

    public static Configuration makeConfiguration(BeansWrapper wrapper) {
        Configuration newConfig = new Configuration();

        newConfig.setObjectWrapper(wrapper);
        newConfig.setSharedVariable("Static", wrapper.getStaticModels());
        newConfig.setLocalizedLookup(false);
        newConfig.setSharedVariable("StringUtil", new BeanModel(new StringUtil(), wrapper));
        newConfig.setTemplateLoader(new FlexibleTemplateLoader());
        newConfig.setTemplateExceptionHandler(new FreeMarkerWorker.OFBizTemplateExceptionHandler());
        try {
            newConfig.setSetting("datetime_format", "yyyy-MM-dd HH:mm:ss.SSS");
            newConfig.setSetting("number_format", "0.##########");
        } catch (TemplateException e) {
            Debug.logError("Unable to set date/time and number formats in FreeMarker: " + e, module);
        }
        // Transforms properties file set up as key=transform name, property=transform class name
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
View Full Code Here

     * </ul>
     *
     * @param servletContext
     */
    protected Configuration createConfiguration(ServletContext servletContext) throws TemplateException {
        Configuration configuration = new Configuration();

        configuration.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);

        if (mruMaxStrongSize > 0) {
            configuration.setSetting(Configuration.CACHE_STORAGE_KEY, "strong:" + mruMaxStrongSize);
        }
        if (templateUpdateDelay != null) {
            configuration.setSetting(Configuration.TEMPLATE_UPDATE_DELAY_KEY, templateUpdateDelay);
        }
        if (encoding != null) {
            configuration.setDefaultEncoding(encoding);
        }


        configuration.setWhitespaceStripping(true);

        return configuration;
    }
View Full Code Here

TOP

Related Classes of freemarker.template.Configuration

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.