Package freemarker.cache

Examples of freemarker.cache.StringTemplateLoader$StringTemplateSource


        super("freemarker");
        // initialize the template engine, this is static to maintain a cache
        // over instantiations of kml writer
        templateConfig = new Configuration();
        templateConfig.setObjectWrapper(new FeatureWrapper());
        templateLoader = new StringTemplateLoader();
        templateConfig.setTemplateLoader(templateLoader);
    }
View Full Code Here


        assertTrue(errMsg.contains("WEB-INF/templates"));
    }

    @Test
    public void testStringTemplateLoader() throws IOException {
        StringTemplateLoader tl = new StringTemplateLoader();
        tl.putTemplate("aaa", "A");
        tl.putTemplate("bbb", "B");
        tl.putTemplate("ccc", "C");
        final String errMsg = failWith(tl);
        showErrorMessage(errMsg);
        assertTrue(errMsg.contains("StringTemplateLoader"));
        assertTrue(errMsg.contains("aaa"));
        assertTrue(errMsg.contains("bbb"));
View Full Code Here

        cfg.setObjectWrapper(new SimpleObjectWrapper());
        cfg.setIncompatibleImprovements(oldVersion);
        assertSame(SimpleObjectWrapper.class, cfg.getObjectWrapper().getClass());
        assertUsesLegacyTemplateLoader(cfg);
       
        cfg.setTemplateLoader(new StringTemplateLoader());
        cfg.setIncompatibleImprovements(newVersion);
        assertSame(SimpleObjectWrapper.class, cfg.getObjectWrapper().getClass());
        assertSame(StringTemplateLoader.class, cfg.getTemplateLoader().getClass());
       
        cfg.setIncompatibleImprovements(oldVersion);
View Full Code Here

        assertEquals(ftlV, t.getTemplateLanguageVersion());
    }
   
    private Configuration createConfiguration(Version version) {
        Configuration cfg = new Configuration(version);
        StringTemplateLoader stl = new StringTemplateLoader();
        stl.putTemplate("test.ftl", "foo");
        cfg.setTemplateLoader(stl);
        return cfg;
    }
View Full Code Here

        super(name);
    }
   
    public void test() throws IOException, TemplateException {
        Configuration cfg = new Configuration();
        StringTemplateLoader tl = new StringTemplateLoader();
        tl.putTemplate("i.ftl", "[i]");
        tl.putTemplate("sub/i.ftl", "[sub/i]");
        tl.putTemplate("import.ftl", "<#assign x = 1>");
        cfg.setTemplateLoader(tl);
       
        Template t = new Template(null, new StringReader(
                    "<#include 'i.ftl'>\n"
                    + "<#include '/i.ftl'>\n"
View Full Code Here

    }

    protected Template getTemplate() {
        try {
            String templateContent = IOUtils.toString(reportTemplate.getDocumentContent());
            StringTemplateLoader stringLoader = new StringTemplateLoader();
            stringLoader.putTemplate(reportTemplate.getDocumentName(), templateContent);

            Configuration fmConfiguration = new Configuration();
            fmConfiguration.setTemplateLoader(stringLoader);
            fmConfiguration.setDefaultEncoding("UTF-8");
View Full Code Here

  public static String processTemplate(Map<String, Object> map,String templateContent,Locale locale,String encoding) throws IOException, TemplateException{
    Configuration cfg = new Configuration();
    cfg.setEncoding(locale, encoding);
    cfg.setWhitespaceStripping(true);
    cfg.setTagSyntax(Configuration.AUTO_DETECT_TAG_SYNTAX);
    StringTemplateLoader stringLoader = new StringTemplateLoader();
    stringLoader.putTemplate(STRINGTEMPLATENAME, templateContent);
    cfg.setTemplateLoader(stringLoader);
    Template template = cfg.getTemplate(STRINGTEMPLATENAME, locale, encoding);
    StringWriter sw = new StringWriter();
    template.process(map, sw);
    return sw.toString();
View Full Code Here

    public byte[] readFor(final Optional<? extends Request> request) {
        if (!request.isPresent()) {
            throw new IllegalArgumentException("Request is required to read template");
        }

        StringTemplateLoader templateLoader = new StringTemplateLoader();
        String templateSource = new String(this.template.readFor(request));
        templateLoader.putTemplate(TEMPLATE_NAME, templateSource);
        Configuration cfg = createConfiguration(templateLoader);

        try {
            Template template = cfg.getTemplate(TEMPLATE_NAME);
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
View Full Code Here

    _sqlPool = new HashMap<String, SQLBean>();

    try {
      ClassLoader classLoader = getClass().getClassLoader();
      configuration = new Configuration()
      stringTemplateLoader = new StringTemplateLoader();
          configuration.setDefaultEncoding("UTF-8")

      String[] configs = getConfigs();
      for (String _config : configs) {
        read(classLoader, _config);
View Full Code Here

TOP

Related Classes of freemarker.cache.StringTemplateLoader$StringTemplateSource

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.