// Path: src/com/seller/trade/core/Configuration.java
// public final class Configuration {
// 
//     private static final Logger LOG = Lumberjack.getLogger(Configuration.class);
// 
//     private static final String ST_CONF_ENV = "ST_CONF";
// 
//     private final Properties properties;
// 
//     public Configuration(String filename) {
//         properties = new Properties();
// 
//         try {
//             properties.load(new FileInputStream(filename));
//         } catch (Throwable e) {
//             throw new RuntimeException("Can't run without configuration", e);
//         }
//     }
// 
//     public Configuration() {
//         this(System.getenv(ST_CONF_ENV));
//     }
// 
//     public String getString(String key) {
//         String r = "";
//         
//         try{
//             r = properties.getProperty(key);
//         } catch (Throwable e) {
//             LOG.log(Level.SEVERE, String.format("Error reading configuration key %s", key), e);
//         }
//         
//         return r;
//     }
// 
//     public int getInt(String key) {
//         int r = 0;
// 
//         try {
//             r = Integer.parseInt(properties.getProperty(key));
//         } catch (Throwable e) {
//             LOG.log(Level.SEVERE, String.format("Error reading configuration key %s", key), e);
//         }
// 
//         return r;
//     }
//     
//     public float getFloat(String key) {
//         float r = 0f;
// 
//         try {
//             r = Float.parseFloat(properties.getProperty(key));
//         } catch (Throwable e) {
//             LOG.log(Level.SEVERE, String.format("Error reading configuration key %s", key), e);
//         }
// 
//         return r;
//     }
// 
//     public boolean getBoolean(String key) {
//         boolean r = false;
// 
//         try {
//             r = Boolean.parseBoolean(properties.getProperty(key));
//         } catch (Throwable e) {
//             LOG.log(Level.SEVERE, String.format("Error reading configuration key %s", key), e);
//         }
// 
//         return r;
//     }
// 
//     public List<String> getList(String key) {
// 
//         List<String> results = new ArrayList<>();
//         String property = null;
//         String[] split = null;
// 
//         try {
//             property = properties.getProperty(key);
//             
//             if (property == null) {
//                 return null;
//             }
//             
//             split = property.split(",");
//             results = Arrays.asList(split);
//         } catch (Exception e) {
//             LOG.log(Level.SEVERE, String.format("Error reading configuration key %s", key), e);
//         }
// 
//         return results;
//     }
// 
//     public long getLong(String key) {
//         long r = 0;
// 
//         try {
//             r = Long.parseLong(properties.getProperty(key));
//         } catch (Throwable e) {
//             LOG.log(Level.SEVERE, String.format("Error reading configuration key %s", key), e);
//         }
// 
//         return r;
//     }
// }
// 
// Path: src/com/seller/trade/core/ConfigurationKeys.java
// public class ConfigurationKeys {
//     public static final String ST_VERSION = "st.version";
//     public static final String ST_SERVER_PORT = "st.server_port";
//     public static final String ST_SITE_NAME = "st.site_name";
//     public static final String ST_TEMPLATES_FOLDER = "st.templates.folder";
//     public static final String ST_SITE_SLOGAN = "st.site_slogan";
//     public static final String ST_SITE_DESCRIPTION = "st.site_description";
//     public static final String ST_SITE_KEYWORDS = "st.site_keywords";
//     public static final String ST_SHIPPING_FROM = "st.shipping_from";
//     public static final String ST_HOSTNAME = "st.hostname";
//     public static final String ST_SERVER_IP = "st.server_ip";
//     public static final String ST_IS_LOBBY_SERVER = "st.is_lobby_server";
//     public static final String ST_USE_LAN_MAPPINGS= "st.use_lan_mappings";
//     public static final String ST_SEND_ACCESS_CONTROL_ALLOW_ORIGIN = "st.send_access_control_allow_origin";
//     public static final String ST_SEARCH_HOPS = "st.search.hops";
//     public static final String ST_PRODUCTS_SET = "st.products_set";
//     public static final String ST_QUERY_NODE_TIMEOUT_MS = "st.query_node_timeout_ms";
// 
//     protected ConfigurationKeys() {
//     }
// }


import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
import java.io.Writer;
import java.util.Properties;
import com.seller.trade.core.Configuration;
import com.seller.trade.core.ConfigurationKeys;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.context.Context;
/**
 * The MIT License
 ===============

 Copyright (C) 2015 SellerTrade Developers

 Permission is hereby granted, free of charge, to any person obtaining
 a copy of this software and associated documentation files (the
 "Software"), to deal in the Software without restriction, including
 without limitation the rights to use, copy, modify, merge, publish,
 distribute, sublicense, and/or sell copies of the Software, and to
 permit persons to whom the Software is furnished to do so, subject
 to the following conditions:

 The above copyright notice and this permission notice shall be
 included in all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package com.seller.trade.services;



/**
 * Created by gubatron on 1/10/15.
 */
public class TemplateService {
    private final Configuration configuration;
    private final VelocityEngine templateEngine;

    public TemplateService(Configuration configuration) {
        this.configuration = configuration;
// Path: src/com/seller/trade/core/Configuration.java
// public final class Configuration {
// 
//     private static final Logger LOG = Lumberjack.getLogger(Configuration.class);
// 
//     private static final String ST_CONF_ENV = "ST_CONF";
// 
//     private final Properties properties;
// 
//     public Configuration(String filename) {
//         properties = new Properties();
// 
//         try {
//             properties.load(new FileInputStream(filename));
//         } catch (Throwable e) {
//             throw new RuntimeException("Can't run without configuration", e);
//         }
//     }
// 
//     public Configuration() {
//         this(System.getenv(ST_CONF_ENV));
//     }
// 
//     public String getString(String key) {
//         String r = "";
//         
//         try{
//             r = properties.getProperty(key);
//         } catch (Throwable e) {
//             LOG.log(Level.SEVERE, String.format("Error reading configuration key %s", key), e);
//         }
//         
//         return r;
//     }
// 
//     public int getInt(String key) {
//         int r = 0;
// 
//         try {
//             r = Integer.parseInt(properties.getProperty(key));
//         } catch (Throwable e) {
//             LOG.log(Level.SEVERE, String.format("Error reading configuration key %s", key), e);
//         }
// 
//         return r;
//     }
//     
//     public float getFloat(String key) {
//         float r = 0f;
// 
//         try {
//             r = Float.parseFloat(properties.getProperty(key));
//         } catch (Throwable e) {
//             LOG.log(Level.SEVERE, String.format("Error reading configuration key %s", key), e);
//         }
// 
//         return r;
//     }
// 
//     public boolean getBoolean(String key) {
//         boolean r = false;
// 
//         try {
//             r = Boolean.parseBoolean(properties.getProperty(key));
//         } catch (Throwable e) {
//             LOG.log(Level.SEVERE, String.format("Error reading configuration key %s", key), e);
//         }
// 
//         return r;
//     }
// 
//     public List<String> getList(String key) {
// 
//         List<String> results = new ArrayList<>();
//         String property = null;
//         String[] split = null;
// 
//         try {
//             property = properties.getProperty(key);
//             
//             if (property == null) {
//                 return null;
//             }
//             
//             split = property.split(",");
//             results = Arrays.asList(split);
//         } catch (Exception e) {
//             LOG.log(Level.SEVERE, String.format("Error reading configuration key %s", key), e);
//         }
// 
//         return results;
//     }
// 
//     public long getLong(String key) {
//         long r = 0;
// 
//         try {
//             r = Long.parseLong(properties.getProperty(key));
//         } catch (Throwable e) {
//             LOG.log(Level.SEVERE, String.format("Error reading configuration key %s", key), e);
//         }
// 
//         return r;
//     }
// }
// 
// Path: src/com/seller/trade/core/ConfigurationKeys.java
// public class ConfigurationKeys {
//     public static final String ST_VERSION = "st.version";
//     public static final String ST_SERVER_PORT = "st.server_port";
//     public static final String ST_SITE_NAME = "st.site_name";
//     public static final String ST_TEMPLATES_FOLDER = "st.templates.folder";
//     public static final String ST_SITE_SLOGAN = "st.site_slogan";
//     public static final String ST_SITE_DESCRIPTION = "st.site_description";
//     public static final String ST_SITE_KEYWORDS = "st.site_keywords";
//     public static final String ST_SHIPPING_FROM = "st.shipping_from";
//     public static final String ST_HOSTNAME = "st.hostname";
//     public static final String ST_SERVER_IP = "st.server_ip";
//     public static final String ST_IS_LOBBY_SERVER = "st.is_lobby_server";
//     public static final String ST_USE_LAN_MAPPINGS= "st.use_lan_mappings";
//     public static final String ST_SEND_ACCESS_CONTROL_ALLOW_ORIGIN = "st.send_access_control_allow_origin";
//     public static final String ST_SEARCH_HOPS = "st.search.hops";
//     public static final String ST_PRODUCTS_SET = "st.products_set";
//     public static final String ST_QUERY_NODE_TIMEOUT_MS = "st.query_node_timeout_ms";
// 
//     protected ConfigurationKeys() {
//     }
// }


// Path: src/com/seller/trade/services/TemplateService.java
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
import java.io.Writer;
import java.util.Properties;
import com.seller.trade.core.Configuration;
import com.seller.trade.core.ConfigurationKeys;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.context.Context;

/**
 * The MIT License
 ===============

 Copyright (C) 2015 SellerTrade Developers

 Permission is hereby granted, free of charge, to any person obtaining
 a copy of this software and associated documentation files (the
 "Software"), to deal in the Software without restriction, including
 without limitation the rights to use, copy, modify, merge, publish,
 distribute, sublicense, and/or sell copies of the Software, and to
 permit persons to whom the Software is furnished to do so, subject
 to the following conditions:

 The above copyright notice and this permission notice shall be
 included in all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

package com.seller.trade.services;



/**
 * Created by gubatron on 1/10/15.
 */
public class TemplateService {
    private final Configuration configuration;
    private final VelocityEngine templateEngine;

    public TemplateService(Configuration configuration) {
        this.configuration = configuration;
        final String templatesFolder = configuration.getString(ConfigurationKeys.ST_TEMPLATES_FOLDER);