Package freemarker.template

Examples of freemarker.template.Configuration


  {
    /* request 정보 호출 */
    log.info(request.toString());
   
    /* freemarker configuration */
    Configuration cfg = new Configuration();
   
    /* freemarker path */
    String   ftlPath = null;
   
    try
    {
      /* template call */
      ftlPath  = appendExt(path);
      Template template = cfg.getTemplate(ftlPath);
     
      /* write */
      Writer out = response.getWriter();
     
      /* freemaker call */
 
View Full Code Here


      throw new IllegalArgumentException("'outFile' is missing");
  }

  private void saveTemplates() {
    // freemarker configuration
    Configuration config = new Configuration();
    config.setClassForTemplateLoading(getClass(), "");
    config.setObjectWrapper(new DefaultObjectWrapper());

    try {
      // load template
      Template template = config.getTemplate("tag.ftl");
      String rootDir = (new File(getOption("outTemplatesDir"))).getAbsolutePath();
      File rootFile = new File(rootDir);
      rootFile.mkdirs();
      for (Tag tag : tags.values()) {
        if (tag.isInclude()) {
View Full Code Here

     * to custom-configure the configuration object in a subclass.
     * The default implementation returns a new {@link Configuration}
     * instance.
     */
    protected Configuration createConfiguration() {
        return new Configuration();
    }
View Full Code Here

        model.put("user", new User("liangfei", "admin"));
        model.put("books", books);
       
     // freemark
        StringWriter writer = new StringWriter();
        Configuration configuration = new Configuration();
        configuration.setTemplateLoader(new ClassTemplateLoader(PerformanceTest.class, "/"));
        Template template = configuration.getTemplate("books.ftl");
        template.process(context, writer);
//        byte[] ret = null;
        long start = System.currentTimeMillis();
        for (int i = 0; i < times; i++) {
          writer = new StringWriter();
View Full Code Here

        } else if (logService instanceof JdkLogService) {
            Logger.selectLoggerLibrary(Logger.LIBRARY_JAVA);
        }

        configuration = new Configuration();

        // Templates are stored in the / directory of the Web app.
        WebappTemplateLoader webloader = new WebappTemplateLoader(servletContext);

        // Templates are stored in the root of the classpath.
View Full Code Here

    protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception {
        FreemarkerEndpoint endpoint = new FreemarkerEndpoint(uri, this, remaining, parameters);

        // should we use regular configuration or no cache (content cache is default true)
        Configuration config;
        boolean cache = (Boolean) getAndRemoveParameter(parameters, "contentCache", Boolean.class, Boolean.TRUE);
        if (cache) {
            config = getConfiguraiton();
        } else {
            config = getNoCacheConfiguration();
View Full Code Here

        return endpoint;
    }

    public synchronized Configuration getConfiguraiton() {
        if (configuraiton == null) {
            configuraiton = new Configuration();
            // use class template loader using Spring Resource class and / as root in classpath
            configuraiton.setTemplateLoader(new ClassTemplateLoader(Resource.class, "/"));
        }
        return (Configuration) configuraiton.clone();
    }
View Full Code Here

        ServletContext servletContext = (ServletContext) context.get(ServletActionContext.SERVLET_CONTEXT);
        HttpServletRequest req = (HttpServletRequest) context.get(ServletActionContext.HTTP_REQUEST);
        HttpServletResponse res = (HttpServletResponse) context.get(ServletActionContext.HTTP_RESPONSE);

        // prepare freemarker
        Configuration config = freemarkerManager.getConfiguration(servletContext);

        // get the list of templates we can use
        List<Template> templates = templateContext.getTemplate().getPossibleTemplates(this);

        // find the right template
        freemarker.template.Template template = null;
        String templateName = null;
        Exception exception = null;
        for (Template t : templates) {
            templateName = getFinalTemplateName(t);
                try {
                    // try to load, and if it works, stop at the first one
                    template = config.getTemplate(templateName);
                    break;
                } catch (ParseException e) {
                    // template was found but was invalid - always report this.
                    exception = e;
                    break;
                } catch (IOException e) {
                    // FileNotFoundException is anticipated - report the first IOException if no template found
                    if (exception == null) {
                        exception = e;
                    }
                }
        }

        if (template == null) {
            if (LOG.isErrorEnabled()) {
                LOG.error("Could not load the FreeMarker template named '" + templateContext.getTemplate().getName() +"':");
                for (Template t : templates) {
                    LOG.error("Attempted: " + getFinalTemplateName(t));
                }
                LOG.error("The TemplateLoader provided by the FreeMarker Configuration was a: "+config.getTemplateLoader().getClass().getName());
            }
            if (exception != null) {
                throw exception;
            } else {
                return;
            }
        }

        if (LOG.isDebugEnabled()) {
            LOG.debug("Rendering template " + templateName);
        }

        ActionInvocation ai = ActionContext.getContext().getActionInvocation();

        Object action = (ai == null) ? null : ai.getAction();
        SimpleHash model = freemarkerManager.buildTemplateModel(stack, action, servletContext, req, res, config.getObjectWrapper());

        model.put("tag", templateContext.getTag());
        model.put("themeProperties", getThemeProps(templateContext.getTemplate()));

        // the BodyContent JSP writer doesn't like it when FM flushes automatically --
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.setLocalizedLookup(false);
        configuration.setWhitespaceStripping(true);

        return configuration;
    }
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

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.