Package freemarker.template

Examples of freemarker.template.Template


    {
        Configuration config = new Configuration();
        // config.setDebugMode(false);
        config.setClassicCompatible(false);
        config.setClassForTemplateLoading(PerformanceTest.class, "/freemarker/testcase");
        Template template = config.getTemplate("PerformanceTest.fm");
        boolean toFile = args.length > 0 && args[0].equals("file");
        File f = File.createTempFile("fmPerfTest", ".txt");
        f.deleteOnExit();
        OutputStream nullStream = new NullStream();
        SimpleHash h = new SimpleHash();
        h.put("ii", new TestSequence());
        h.put("j", new TestHash());
        h.put("k", new TestMethod());
       
        for(;;)
        {
            OutputStream stream = toFile ? new BufferedOutputStream(new FileOutputStream(f)) : nullStream;
            Writer writer = new OutputStreamWriter(stream, "UTF-8");
            try
            {
                template.process(h, writer);
            }
            finally
            {
                writer.close();
            }
View Full Code Here


        if( templateNameString == null ) {
            String msg = "Error " + getStartLocation()
                        + "The expression " + templateName + " is undefined.";
            throw new InvalidReferenceException(msg, env);
        }
        Template importedTemplate;
        try {
            if(!env.isClassicCompatible()) {
                if (templateNameString.indexOf("://") >0) {
                    ;
                }
View Full Code Here

                breakpoints.add(-pos - 1, breakpoint);
                // Inject the breakpoint into all templates with this name
                for (Iterator iter = tdi.templates.iterator(); iter.hasNext();)
                {
                    TemplateReference ref = (TemplateReference) iter.next();
                    Template t = ref.getTemplate();
                    if(t == null)
                    {
                        iter.remove();
                    }
                    else
View Full Code Here

                {
                    breakpoints.remove(pos);
                    for (Iterator iter = tdi.templates.iterator(); iter.hasNext();)
                    {
                        TemplateReference ref = (TemplateReference) iter.next();
                        Template t = ref.getTemplate();
                        if(t == null)
                        {
                            iter.remove();
                        }
                        else
View Full Code Here

    {
        tdi.breakpoints.clear();
        for (Iterator iter = tdi.templates.iterator(); iter.hasNext();)
        {
            TemplateReference ref = (TemplateReference) iter.next();
            Template t = ref.getTemplate();
            if(t == null)
            {
                iter.remove();
            }
            else
            {
                removeDebugBreaks(t.getRootTreeNode());
            }
        }
    }
View Full Code Here

    model.put("CoreServices", servicesStatic);
    Context currentContext = Context.getCurrentContext();
    if (currentContext != null) {
      model.put("CurrentContext", currentContext);
    }
    Template t = null;
    try {
      t = getConfig().getTemplate(
          new StringBuilder("/").append(templateId.replace('.', '/')).append(".ftl").toString());
    } catch (IOException e) {
      throw new TemplateNotFoundException();
    }
    Writer out = new StringWriter(1024);
    try {
      t.process(model, out);
    } catch (Exception e) {
      throw new JibeRuntimeException("There was an error processing template:" + templateId, e);
    }
    return out.toString();
  }
View Full Code Here

        // check for a cached template
        if (cache) {
            String disableCache = UtilProperties.getPropertyValue("content", "disable.ftl.template.cache");
            if (disableCache == null || !disableCache.equalsIgnoreCase("true")) {
                try {
                    Template cachedTemplate = FreeMarkerWorker.getTemplate("DataResource:" + dataResourceId);
                    if (cachedTemplate != null) {
                        String subContentId = (String) templateContext.get("subContentId");
                        if (UtilValidate.isNotEmpty(subContentId)) {
                            templateContext.put("contentId", subContentId);
                            templateContext.put("subContentId", null);
View Full Code Here

        this.node = node;
    }

    public String evalToString(String templateContent) throws Exception {
        StringReader reader = new StringReader(templateContent);
        Template template = new Template("test", reader, configuration);
       
        Map<String, TemplateModel> data = new HashMap<String, TemplateModel>();
        data.put("node", new NodeModel(node));

        StringWriter writer = new StringWriter();
        template.process(data, writer);
        return writer.toString();
    }
View Full Code Here

        }

        String scriptName = helper.getScript().getScriptResource().getPath();

        try {
            Template tmpl = new Template(scriptName, reader, configuration);
            bindings.put("currentNode", new NodeModel((Node) bindings.get("currentNode")));
            tmpl.process(bindings, scriptContext.getWriter());
        } catch (Throwable t) {
            log.error("Failure running Freemarker script.", t);
            throw new ScriptException("Failure running FreeMarker script "
                + scriptName);
        }
View Full Code Here

                    Map<String, Object> model = new HashMap<String, Object>();
                    model.put("inviter", invitation.getInviter());
                    model.put("randomkey", invitation.getRandomkey());
                    model.put("email", invitation.getEmail());

                    Template textTemplate = configurer.getConfiguration()
                            .getTemplate(invitationTemplate);
                    final StringWriter textWriter = new StringWriter();

                    textTemplate.process(model, textWriter);

                    message.setText(textWriter.toString(), true);

                    log.info("Inviting: " + invitation.getEmail());
                    log.debug("From: " + from);
View Full Code Here

TOP

Related Classes of freemarker.template.Template

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.