FreemarkerTemplateUtils.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */

  20. package org.openspcoop2.utils.resources;

  21. import java.io.File;
  22. import java.io.IOException;
  23. import java.util.Map;

  24. import freemarker.cache.TemplateLoader;
  25. import freemarker.template.Configuration;
  26. import freemarker.template.ObjectWrapper;
  27. import freemarker.template.Template;
  28. import freemarker.template.TemplateException;

  29. /**
  30.  *  FreemarkerTemplateUtils
  31.  *  
  32.  *  utilizza TemplateUtils per retrocompatibilità
  33.  *
  34.  * @author Poli Andrea (apoli@link.it)
  35.  * @author $Author$
  36.  * @version $Rev$, $Date$
  37.  */
  38. public class FreemarkerTemplateUtils {

  39.    
  40.     /** -------- Utility per la creazione delle configurazioni ------------- */
  41.    
  42.     public static Configuration newTemplateEngine() {
  43.         return TemplateUtils.newTemplateEngine(TemplateUtils.class,"", null,null);
  44.     }
  45.     public static Configuration newTemplateEngine(String prefix) {
  46.         return TemplateUtils.newTemplateEngine(TemplateUtils.class,prefix, null,null);
  47.     }
  48.     public static Configuration newTemplateEngine(Class<?> c) {
  49.         return TemplateUtils.newTemplateEngine(c,"", null,null);
  50.     }
  51.     public static Configuration newTemplateEngine(Class<?> c,String prefix) {
  52.         return TemplateUtils.newTemplateEngine(c, prefix, null,null);
  53.     }
  54.     public static Configuration newTemplateEngine(Class<?> c,String prefix,ObjectWrapper wrapper) {
  55.         return TemplateUtils.newTemplateEngine(c, prefix, wrapper, null);
  56.     }
  57.     public static Configuration newTemplateEngine(Class<?> c,String prefix,ObjectWrapper wrapper,TemplateLoader templateLoader) {
  58.        return TemplateUtils.newTemplateEngine(c, prefix, wrapper, templateLoader);
  59.     }
  60.    
  61.    
  62.    
  63.     /** -------- Utility per la creazione dei template ------------- */
  64.    
  65.     public static Template getTemplate(Configuration cfg,String templateName) throws IOException{
  66.         return TemplateUtils.getTemplate(cfg, templateName);
  67.     }
  68.    
  69.     public static Template getTemplate(String templateName) throws IOException{
  70.         return TemplateUtils.getTemplate(templateName);
  71.     }
  72.     public static Template getTemplate(String prefix,String templateName) throws IOException{
  73.         return TemplateUtils.getTemplate(prefix, templateName);
  74.     }
  75.     public static Template getTemplate(Class<?> c,String prefix,String templateName) throws IOException{
  76.         return TemplateUtils.getTemplate(c, prefix, templateName);
  77.     }
  78.     public static Template getTemplate(Class<?> c,String prefix,ObjectWrapper wrapper,String templateName) throws IOException{
  79.         return TemplateUtils.getTemplate(c, prefix, wrapper, templateName);
  80.     }
  81.    
  82.     public static Template buildTemplate(String name,byte[] bytes) throws IOException{
  83.         return TemplateUtils.buildTemplate(name, bytes);
  84.     }
  85.     public static Template buildTemplate(Configuration cfg,String name,byte[] bytes) throws IOException{
  86.         return TemplateUtils.buildTemplate(cfg, name, bytes);
  87.     }
  88.    
  89.    
  90.    
  91.     /** -------- Trasformazioni dei template ------------- */
  92.        
  93.     public static byte[] toByteArray(Template template,Map<?, ?> map) throws IOException,TemplateException{
  94.         return TemplateUtils.toByteArray(template, map);
  95.     }
  96.     public static String toString(Template template,Map<?, ?> map) throws IOException,TemplateException{
  97.         return TemplateUtils.toString(template, map);
  98.     }
  99.     public static void writeFile(Template template,Map<?, ?> map,File file,boolean overwrite) throws Exception{
  100.         TemplateUtils.writeFile(template, map, file, overwrite);
  101.     }
  102.    

  103.    
  104. }