Package freemarker.template

Examples of freemarker.template.Template


      config.setLocalizedLookup(false);
    }
  }

  private Template loadTemplate(String templateName) throws Exception {
    Template template = null;
    String curTemplate = templateName;
    while (null == template) {
      try {
        template = config.getTemplate(curTemplate);
      } catch (ParseException e) {
View Full Code Here


      stack.getContext().put(UI_ENV_CACHE, envs);
    }
    Environment env = envs.get(templateName);
    if (null == env) {
      try {
        Template template = loadTemplate(templateName);
        env = template.createProcessingEnvironment(model, writer);
        envs.put(templateName, env);
      } catch (ParseException pe) {
        throw pe;
      }
    } else {
View Full Code Here

        new MockHttpServletRequest(), new MockHttpServletResponse()));
    datas.put("s", new StrutsModels(ActionContext.getContext().getValueStack(),
        new MockHttpServletRequest(), new MockHttpServletResponse()));
    datas.put("watch", new StopWatch());
    StringWriter writer = new StringWriter();
    Template template = cfg.getTemplate("comp.ftl");
    // template.process(datas, writer);
  }
View Full Code Here

        if (debug) {
            log("Requested template: " + StringUtil.jQuoteNoXSS(path));
        }

        Template template = null;
        try {
            template = config.getTemplate(
                    path,
                    deduceLocale(path, request, response));
        } catch (FileNotFoundException e) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
       
        Object attrContentType = template.getCustomAttribute("content_type");
        if(attrContentType != null) {
            response.setContentType(attrContentType.toString());
        }
        else {
            if (noCharsetInContentType) {
                response.setContentType(
                        contentType + "; charset=" + template.getEncoding());
            } else {
                response.setContentType(contentType);
            }
        }

        // Set cache policy
        setBrowserCachingPolicy(response);

        ServletContext servletContext = getServletContext();
        try {
            TemplateModel model = createModel(wrapper, servletContext, request, response);

            // Give subclasses a chance to hook into preprocessing
            if (preTemplateProcess(request, response, template, model)) {
                try {
                    // Process the template
                    template.process(model, response.getWriter());
                } finally {
                    // Give subclasses a chance to hook into postprocessing
                    postTemplateProcess(request, response, template, model);
                }
            }
View Full Code Here

        }
        name = normalizeName(name);
        if(name == null) {
            return null;
        }
        Template result = null;
        if (mainLoader != null) {
            result = getTemplate(mainLoader, name, locale, encoding, parse);
        }
        /** DD: [noFallback]
        if (result == null && name.toLowerCase().endsWith(".ftl")) {
View Full Code Here

                logger.debug("Compiling FreeMarker template " +
                    debugName + " from " + StringUtil.jQuoteNoXSS(newlyFoundSource));
            }
            // If we get here, then we need to (re)load the template
            Object source = cachedTemplate.source;
            Template t = loadTemplate(loader, name, locale, encoding, parse, source);
            cachedTemplate.templateOrException = t;
            cachedTemplate.lastModified =
                lastModified == Long.MIN_VALUE
                    ? loader.getLastModified(source)
                    : lastModified;
View Full Code Here

    private Template loadTemplate(TemplateLoader loader, String name, Locale locale, String encoding,
                                   boolean parse, Object source)
    throws IOException
    {
        Template template;
        Reader reader = loader.getReader(source, encoding);
        try
        {
            if(parse)
            {
                try {
                    template = new Template(name, reader, config, encoding);
                }
                catch (Template.WrongEncodingException wee) {
                    encoding = wee.specifiedEncoding;
                    reader = loader.getReader(source, encoding);
                    template = new Template(name, reader, config, encoding);
                }
                template.setLocale(locale);
            }
            else
            {
                // Read the contents into a StringWriter, then construct a single-textblock
                // template from it.
                StringWriter sw = new StringWriter();
                char[] buf = new char[4096];
                for(;;)
                {
                    int charsRead = reader.read(buf);
                    if (charsRead > 0)
                    {
                        sw.write(buf, 0, charsRead);
                    }
                    else if(charsRead == -1)
                    {
                        break;
                    }
                }
                template = Template.getPlainTextTemplate(name, sw.toString(), config);
                template.setLocale(locale);
            }
            template.setEncoding(encoding);
        }
        finally
        {
            reader.close();
        }
View Full Code Here

        org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder();
        Document document = builder.build(System.in);
        SimpleHash model = new SimpleHash();
        model.put("document", new NodeListModel(document));
        FileReader fr = new FileReader(args[0]);
        Template template = new Template(args[0], fr);
        Writer w = new java.io.OutputStreamWriter(System.out);
        template.process(model, w);
        w.flush();
        w.close();
    }
View Full Code Here

       
        if (view.getContentType() != null){
            response.setContentType(view.getContentType());
        }
       
        Template t = cfg.getTemplate(path, request.getLocale());
        t.process(view.getAttributes(), response.getWriter());
    }
View Full Code Here

        if (args.length == 0) {
            usage();
            return;
        }
        String filename = args[0];
        Template t = null;
        try {
            t = new Template(filename, new FileReader(filename));
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }
        showTree(t);
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.