FreemarkerTemplateLoader.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.IOException;
  22. import java.io.Reader;
  23. import java.io.StringReader;
  24. import java.util.Map;

  25. import freemarker.cache.TemplateLoader;

  26. /**
  27.  *  FreemarkerTemplateLoader
  28.  *
  29.  * @author Poli Andrea (apoli@link.it)
  30.  * @author $Author$
  31.  * @version $Rev$, $Date$
  32.  */
  33. public class FreemarkerTemplateLoader implements TemplateLoader {
  34.    
  35.     private Map<String, byte[]> templateIncludes;
  36.    
  37.     public FreemarkerTemplateLoader(Map<String, byte[]> templateIncludes) {
  38.         this.templateIncludes = templateIncludes;
  39.     }
  40.    
  41.     @Override
  42.     public Reader getReader(Object content, String name) throws IOException {
  43.         //System.out.println("READER ["+name+"]");
  44.         return new StringReader(new String((byte[])content));
  45.     }
  46.    
  47.     @Override
  48.     public long getLastModified(Object arg0) {
  49.         return 0;
  50.     }
  51.    
  52.     @Override
  53.     public Object findTemplateSource(String name) throws IOException {
  54.         //System.out.println("FIND ["+name+"]");
  55.         if(this.templateIncludes.containsKey(name)) {
  56.             //System.out.println("FIND ["+name+"] RETURN");
  57.             return this.templateIncludes.get(name);
  58.         }
  59.         return null;
  60.     }
  61.    
  62.     @Override
  63.     public void closeTemplateSource(Object name) throws IOException {
  64.        
  65.     }
  66.    
  67. }