<commit_before>/**
 * Copyright 2015 creditease Inc. All rights reserved.
 * @description Marmot template
 * @author evan2x(<EMAIL>/<EMAIL>)
 * @date  2015/07/27
 */
import * as _ from './helper';

/**
 * 生成freemarker的配置
 * @param  {Object} params
 * @return {String}
 */
function freemarker(params) {
  return _.serializeXMLParams({
    tag_syntax: params.tagSyntax,
    TemplatePath: params.template,
    template_update_delay: 0,
    NoCache: true,
    default_encoding: 'UTF-8'
  });
}

/**
 * 生成velocity配置
 * @param  {Object} params
 * @return {String}
 */
export function velocity(params) {

  return (
`input.encoding = UTF-8
output.encoding = UTF-8
resource.loader = webapp
webapp.resource.loader.class = org.apache.velocity.tools.view.servlet.WebappLoader
webapp.resource.loader.path = /${params.template}
webapp.resource.loader.cache = false
webapp.resource.loader.modificationCheckInterval = 0
tools.view.servlet.layout.directory = /`
  );

}

/**
 * 路由配置示例
 * @type {String}
 */
export let router = (
  `<?xml version="1.0" encoding="UTF-8"?>
  <router>
    <router-map>
      <!-- 路由配置，uri：访问地址，target：目标文件 -->
      <!-- <route uri="/" target="/index.vm"/> -->
    </router-map>
    <!-- 使用import 引入其他的router file -->
    <!-- <import src="product.xml"/> -->
  </router>`
);

/**
 * 生成一个tomcat service
 * @param  {Object} conf 配置文件
 * @return {String}
 */
export function service(conf) {
  return (
    `<Service name="${conf.name}">
       <Connector port="${conf.port}" protocol="HTTP/1.1"
                   connectionTimeout="20000"
                   redirectPort="8443"
                   compression="on"
                   compressionMinSize="2048"
                   compressableMimeType="text/html,text/xml,text/css,text/plain,text/javascript,application/javascript" />
       <Engine name="${conf.name}" defaultHost="localhost">
         <Host name="localhost"  appBase="${conf.dir}" unpackWARs="true" autoDeploy="true">
           <Context path="" docBase="${conf.name}" />
           <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" />
         </Host>
       </Engine>
    </Service>`
  );
}

/**
 * 生成servlet配置<commit_msg>update template<commit_after>/**
 * Copyright 2015 creditease Inc. All rights reserved.
 * @description Marmot template
 * @author evan2x(<EMAIL>/<EMAIL>)
 * @date  2015/07/27
 */
import * as _ from './helper';

/**
 * 生成freemarker的配置
 * @param  {Object} params
 * @return {String}
 */
function freemarker(params) {
  return _.serializeXMLParams({
    tag_syntax: params.tagSyntax,
    TemplatePath: params.template,
    template_update_delay: 0,
    NoCache: true,
    default_encoding: 'UTF-8'
  });
}

/**
 * 生成velocity配置
 * @param  {Object} params
 * @return {String}
 */
export function velocity(params) {

  return (
`input.encoding = UTF-8
output.encoding = UTF-8
resource.loader = webapp
webapp.resource.loader.class = org.apache.velocity.tools.view.servlet.WebappLoader
webapp.resource.loader.path = /${params.template}
webapp.resource.loader.cache = false
webapp.resource.loader.modificationCheckInterval = 0
tools.view.servlet.layout.directory = /`
  );

}

/**
 * 路由配置示例
 * @type {String}
 */
export let router = (
  `<?xml version="1.0" encoding="UTF-8"?>
  <router>
    <route-map>
      <!-- 路由配置，uri：访问地址，target：目标文件 -->
      <!-- <route uri="/" target="/index.vm"/> -->
    </route-map>
    <!-- 使用import 引入其他的router file -->
    <!-- <import src="product.xml"/> -->
  </router>`
);

/**
 * 生成一个tomcat service
 * @param  {Object} conf 配置文件
 * @return {String}
 */
export function service(conf) {
  return (
    `<Service name="${conf.name}">
       <Connector port="${conf.port}" protocol="HTTP/1.1"
                   connectionTimeout="20000"
                   redirectPort="8443"
                   compression="on"
                   compressionMinSize="2048"
                   compressableMimeType="text/html,text/xml,text/css,text/plain,text/javascript,application/javascript" />
       <Engine name="${conf.name}" defaultHost="localhost">
         <Host name="localhost"  appBase="${conf.dir}" unpackWARs="true" autoDeploy="true">
           <Context path="" docBase="${conf.name}" />
           <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" />
         </Host>
       </Engine>
    </Service>`
  );
}

/**
 * 生成servlet配置
{'fraction_non_alphanumeric': 0.17115130127922365, 'fraction_numerical': 0.015880017644464048, 'mean_word_length': 3.020390070921986, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 2, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2442886', 'n_tokens_mistral': 1564, 'n_tokens_neox': 1497, 'n_words': 270}