// Path: spark-common/src/main/java/com/k15t/spark/base/util/NgTranslateMessageBundleProvider.java
// public class NgTranslateMessageBundleProvider implements MessageBundleProvider {
// 
//     private static final Logger logger = LoggerFactory.getLogger(NgTranslateMessageBundleProvider.class);
// 
//     private String msgBundleResourcePath;
// 
// 
//     public NgTranslateMessageBundleProvider(String msgBundleResourcePath) {
//         this.msgBundleResourcePath = msgBundleResourcePath;
//     }
// 
// 
//     @Override
//     public boolean isMessageBundle(RequestProperties props) {
// 
//         if (msgBundleResourcePath != null) {
//             return props.getLocalPath() != null && (this.msgBundleResourcePath).endsWith(props.getLocalPath());
//         }
// 
//         return false;
//     }
// 
// 
//     @Override
//     public String loadBundle(RequestProperties props) {
// 
//         ResourceBundle rb;
//         Locale locale = props.getLocale();
//         if (locale != null) {
//             logger.debug("Use local {} to load bundle from {}", locale, msgBundleResourcePath);
//             rb = ResourceBundle.getBundle(msgBundleResourcePath, locale, new ResourceBundle.Control() {
//                 @Override
//                 public Locale getFallbackLocale(String baseName, Locale locale) {
//                     return Locale.ROOT;
//                 }
//             });
//         } else {
//             logger.debug("Use local {} to load bundle from {}", Locale.getDefault(), msgBundleResourcePath);
//             rb = ResourceBundle.getBundle(msgBundleResourcePath);
//         }
//         ObjectMapper mapper = new ObjectMapper();
//         ObjectNode i18Properties = mapper.createObjectNode();
//         for (String key : rb.keySet()) {
//             i18Properties.put(key, convertValue(rb.getString(key)));
//         }
// 
//         return i18Properties.toString();
//     }
// 
// 
//     @Override
//     public String getContentType() {
//         return "application/json";
//     }
// 
// 
//     /**
//      * Converts the value to work with ng-translate. Overwrite this method to enforce a custom transformation.
//      */
//     protected String convertValue(String value) {
//         return value.replaceAll("\\{(\\d)\\}", "{{_$1}}").replaceAll("''", "'");
//     }
// 
// }


import com.k15t.spark.base.util.NgTranslateMessageBundleProvider;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
package com.k15t.spark.base;





/**
 * <p>Serves resources.</p>
 * <p>As an example, this servlet is supposed to be listening to the URL pattern <code>https://example.com/servlet/**</code>.
 * Inside the classpath, there is a directory <code>/webapp</code> that contains a web application. The file
 * <code>/scripts/test.js</code> from this directory can be accessed using the following two URLs:
 * <code>https://example.com/servlet/scripts/test.js</code> and
 * <code>https://example.com/servlet/_/&lt;deploymentNumber&gt;/&lt;localeKey&gt;/scripts/test.js</code>.</p>
 * <p>The following terminology will be used in this code:</p>
 * <ul>
 * <li><code>resourcePath</code> is <code>&quot;/webapp/&quot;</code></li>
 * <li><code>cacheKey</code> would be <code>&quot;_/&lt;deploymentNumber&gt;/&lt;localeKey&gt;/&quot;</code> in the
 * second URL</li>
 * <li><code>localPath</code> is <code>&quot;scripts/test.js</code></li>
 * <li><code>localUrlPart</code> is <code>&quot;/scripts/test.js</code> in the first example,
 * <code>/_/&lt;deploymentNumber&gt;/&lt;localeKey&gt;/scripts/test.js</code> in the second.</li>
 * </ul>
 */

public abstract class AppServlet extends HttpServlet {

    protected final Set<String> VELOCITY_TYPES = Collections.unmodifiableSet(new HashSet<String>() {{
        add("text/html");
    }});

    private MessageBundleProvider messageBundleProvider;

    private String resourcePath;


    @Override
    public void init() throws ServletException {
        resourcePath = getServletConfig().getInitParameter(Keys.RESOURCE_PATH);
        if (resourcePath == null) {
            throw new ServletException(Keys.RESOURCE_PATH + " parameter is not defined");
        }

        if (!"/".equals(resourcePath.substring(resourcePath.length() - 1))) {
            resourcePath = resourcePath + "/";
        }

        this.messageBundleProvider = initMessageBundleProvider();
    }


    protected MessageBundleProvider initMessageBundleProvider() {
        String msgBundleResourcePath = getServletConfig().getInitParameter(Keys.NG_TRANS_MSG_BUNDLE);
        if (msgBundleResourcePath != null) {
            return new NgTranslateMessageBundleProvider(msgBundleResourcePath);
        }
        return null;
    }


// Path: spark-common/src/main/java/com/k15t/spark/base/util/NgTranslateMessageBundleProvider.java
// public class NgTranslateMessageBundleProvider implements MessageBundleProvider {
// 
//     private static final Logger logger = LoggerFactory.getLogger(NgTranslateMessageBundleProvider.class);
// 
//     private String msgBundleResourcePath;
// 
// 
//     public NgTranslateMessageBundleProvider(String msgBundleResourcePath) {
//         this.msgBundleResourcePath = msgBundleResourcePath;
//     }
// 
// 
//     @Override
//     public boolean isMessageBundle(RequestProperties props) {
// 
//         if (msgBundleResourcePath != null) {
//             return props.getLocalPath() != null && (this.msgBundleResourcePath).endsWith(props.getLocalPath());
//         }
// 
//         return false;
//     }
// 
// 
//     @Override
//     public String loadBundle(RequestProperties props) {
// 
//         ResourceBundle rb;
//         Locale locale = props.getLocale();
//         if (locale != null) {
//             logger.debug("Use local {} to load bundle from {}", locale, msgBundleResourcePath);
//             rb = ResourceBundle.getBundle(msgBundleResourcePath, locale, new ResourceBundle.Control() {
//                 @Override
//                 public Locale getFallbackLocale(String baseName, Locale locale) {
//                     return Locale.ROOT;
//                 }
//             });
//         } else {
//             logger.debug("Use local {} to load bundle from {}", Locale.getDefault(), msgBundleResourcePath);
//             rb = ResourceBundle.getBundle(msgBundleResourcePath);
//         }
//         ObjectMapper mapper = new ObjectMapper();
//         ObjectNode i18Properties = mapper.createObjectNode();
//         for (String key : rb.keySet()) {
//             i18Properties.put(key, convertValue(rb.getString(key)));
//         }
// 
//         return i18Properties.toString();
//     }
// 
// 
//     @Override
//     public String getContentType() {
//         return "application/json";
//     }
// 
// 
//     /**
//      * Converts the value to work with ng-translate. Overwrite this method to enforce a custom transformation.
//      */
//     protected String convertValue(String value) {
//         return value.replaceAll("\\{(\\d)\\}", "{{_$1}}").replaceAll("''", "'");
//     }
// 
// }


// Path: spark-common/src/main/java/com/k15t/spark/base/AppServlet.java
import com.k15t.spark.base.util.NgTranslateMessageBundleProvider;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

package com.k15t.spark.base;





/**
 * <p>Serves resources.</p>
 * <p>As an example, this servlet is supposed to be listening to the URL pattern <code>https://example.com/servlet/**</code>.
 * Inside the classpath, there is a directory <code>/webapp</code> that contains a web application. The file
 * <code>/scripts/test.js</code> from this directory can be accessed using the following two URLs:
 * <code>https://example.com/servlet/scripts/test.js</code> and
 * <code>https://example.com/servlet/_/&lt;deploymentNumber&gt;/&lt;localeKey&gt;/scripts/test.js</code>.</p>
 * <p>The following terminology will be used in this code:</p>
 * <ul>
 * <li><code>resourcePath</code> is <code>&quot;/webapp/&quot;</code></li>
 * <li><code>cacheKey</code> would be <code>&quot;_/&lt;deploymentNumber&gt;/&lt;localeKey&gt;/&quot;</code> in the
 * second URL</li>
 * <li><code>localPath</code> is <code>&quot;scripts/test.js</code></li>
 * <li><code>localUrlPart</code> is <code>&quot;/scripts/test.js</code> in the first example,
 * <code>/_/&lt;deploymentNumber&gt;/&lt;localeKey&gt;/scripts/test.js</code> in the second.</li>
 * </ul>
 */

public abstract class AppServlet extends HttpServlet {

    protected final Set<String> VELOCITY_TYPES = Collections.unmodifiableSet(new HashSet<String>() {{
        add("text/html");
    }});

    private MessageBundleProvider messageBundleProvider;

    private String resourcePath;


    @Override
    public void init() throws ServletException {
        resourcePath = getServletConfig().getInitParameter(Keys.RESOURCE_PATH);
        if (resourcePath == null) {
            throw new ServletException(Keys.RESOURCE_PATH + " parameter is not defined");
        }

        if (!"/".equals(resourcePath.substring(resourcePath.length() - 1))) {
            resourcePath = resourcePath + "/";
        }

        this.messageBundleProvider = initMessageBundleProvider();
    }


    protected MessageBundleProvider initMessageBundleProvider() {
        String msgBundleResourcePath = getServletConfig().getInitParameter(Keys.NG_TRANS_MSG_BUNDLE);
        if (msgBundleResourcePath != null) {
            return new NgTranslateMessageBundleProvider(msgBundleResourcePath);
        }
        return null;
    }


    @Override