Package freemarker.template

Examples of freemarker.template.Configuration


        settings.setProperty("tag_syntax", "auto_detect");

        Map vars = new HashMap();
        vars.put("name", "value");

        Configuration conf = FreemarkerTemplateEngine.createConfiguration(loader, settings, vars, null);

        TemplateLoader templateLoader = conf.getTemplateLoader();
        assertTrue(ResourceLoaderTemplateLoader.class.isInstance(templateLoader));
        ResourceLoaderTemplateLoader resourceLoaderTemplateLoader = (ResourceLoaderTemplateLoader) templateLoader;
        assertSame(loader, resourceLoaderTemplateLoader.getResourceLoader());

        assertEquals(6, conf.getSharedVariableNames().size());
        assertEquals("value", ((SimpleScalar) conf.getSharedVariable("name")).getAsString());

        assertEquals(Configuration.AUTO_DETECT_TAG_SYNTAX, conf.getTagSyntax());
    }
View Full Code Here


* @author Uri Boness
*/
public class FreemarkerTemplateTests extends TestCase {

    public void testGenerate() throws Exception {
        Configuration conf = new Configuration();
        Template template = new Template("name", new StringReader("${name}"), conf);
        FreemarkerTemplate ft = new FreemarkerTemplate(template);

        Map model = new HashMap();
        model.put("name", "Daan");
View Full Code Here

        settings.setProperty("tag_syntax", "auto_detect");

        Map vars = new HashMap();
        vars.put("name", "value");

        Configuration conf = FreemarkerTemplateEngine.createConfiguration(loader, settings, vars);

        TemplateLoader templateLoader = conf.getTemplateLoader();
        assertTrue(ResourceLoaderTemplateLoader.class.isInstance(templateLoader));
        ResourceLoaderTemplateLoader resourceLoaderTemplateLoader = (ResourceLoaderTemplateLoader) templateLoader;
        assertSame(loader, resourceLoaderTemplateLoader.getResourceLoader());

        assertEquals(6, conf.getSharedVariableNames().size());
        assertEquals("value", ((SimpleScalar) conf.getSharedVariable("name")).getAsString());

        assertEquals(Configuration.AUTO_DETECT_TAG_SYNTAX, conf.getTagSyntax());
    }
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

        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

            } else {
                try {
                    Reader templateReader = new InputStreamReader(templateUrl.openStream());

                    StringWriter outWriter = new StringWriter();
                    Configuration config = new Configuration();
                    config.setObjectWrapper(BeansWrapper.getDefaultInstance());
                    config.setSetting("datetime_format", "yyyy-MM-dd HH:mm:ss.SSS");

                    Template template = new Template("FMImportFilter", templateReader, config);
                    NodeModel nodeModel = NodeModel.wrap(this.rootNodeForTemplate);

                    Map<String, Object> context = FastMap.newInstance();
View Full Code Here

            StringWriter outWriter = new StringWriter();

            Template template = null;
            try {
                Configuration conf = org.ofbiz.base.util.template.FreeMarkerWorker.getDefaultOfbizConfig();
                template = new Template("FMImportFilter", templateReader, conf);
                Map<String, Object> fmcontext = FastMap.newInstance();

                InputSource ins = url != null ? new InputSource(url.openStream()) : new InputSource(new StringReader(fulltext));
                NodeModel nodeModel;
View Full Code Here

    public static UtilCache<String, Template> cachedTemplates = UtilCache.createUtilCache("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(StringUtil.INSTANCE, wrapper));
        newConfig.setTemplateLoader(new FlexibleTemplateLoader());
        newConfig.setAutoImports(UtilProperties.getProperties("freemarkerImports"));
        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

 
    public void init(File outputDirectory, String[] templatePaths) {
        this.outputDirectory = outputDirectory;
       
        context = new SimpleHash(ObjectWrapper.BEANS_WRAPPER);
      freeMarkerEngine = new Configuration();
       
        List loaders = new ArrayList();
       
        for (int i = 0; i < templatePaths.length; i++) {
          File file = new File(templatePaths[i]);
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.