<commit_before>/*
 * Copyright 2005 The eFaps Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package org.efaps.servlet;

import java.io.ByteArrayInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.logging.LogManager;
import java.util.Map;
import java.util.Stack;

import java.text.FieldPosition;
import java.text.SimpleDateFormat;

import javax.naming.InitialContext;
import javax.sql.DataSource;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.efaps.admin.user.Person;
import org.efaps.db.Cache;
import org.efaps.db.Context;
import org.efaps.util.EFapsException;

/**
 *
 */
public class RequestHandler extends AbstractServlet  {

  /**
   * Parameter name for absolut url of login without protocol and host name.
   */
  final private static String INITPARAM_URL_LOGIN_PAGE =      "urlLoginPage";

  /**
   * Parameter name for the logging properties.
   */
  final private static String INITPARAM_LOGGING = "logging";

  /**
   *
   */
  final private static String SESSIONPARAM_LOGIN_TARGET = "login.target";

  /**
   *
   */
  final private static String SESSIONPARAM_ERROR =        "error";

  /**
   *
   */
  final private static String POSTPARAM_USERNAME =        "name";

  /**
   *
   */
  final private static String POSTPARAM_PASSWORD =        "password";



final private static String URL_LOGOUT =  "/Logout";
final private static String URL_LOGIN =  "/Login";

  /////////////////////////////////////////////////////////////////////////////


  /**
   * @param _config
   */
  public void init(ServletConfig _config) throws ServletException  {
    super.init(_config);



    initReplacableMacros("/"+_config.getServletContext().getServletContextName()+"/");

this.pathLoginPage = replaceMacrosInUrl(_config.getInitParameter(INITPARAM_URL_LOGIN_PAGE));


try {

String loggingProperties = _config.getInitParameter(INITPARAM_LOGGING);
if (loggingProperties!=null && loggingProperties.length()>0)  {
  ByteArrayInputStream ins = new ByteArrayInputStream(loggingProperties.getBytes());
  LogManager.getLogManager().readConfiguration(ins);
}



InitialContext initCtx = new InitialContext();
javax.naming.Context envCtx = (javax.naming.Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/eFaps");<commit_msg>add parameter dbType to initialise parameters<commit_after>/*
 * Copyright 2005 The eFaps Team
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package org.efaps.servlet;

import java.io.ByteArrayInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.logging.LogManager;
import java.util.Map;
import java.util.Stack;

import java.text.FieldPosition;
import java.text.SimpleDateFormat;

import javax.naming.InitialContext;
import javax.sql.DataSource;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.efaps.admin.user.Person;
import org.efaps.db.Cache;
import org.efaps.db.Context;
import org.efaps.util.EFapsException;

/**
 *
 */
public class RequestHandler extends AbstractServlet  {

  /**
   * Parameter name for absolut url of login without protocol and host name.
   */
  final private static String INITPARAM_URL_LOGIN_PAGE =      "urlLoginPage";

  /**
   * Parameter name for the logging properties.
   */
  final private static String INITPARAM_LOGGING = "logging";

  /**
   * Parameter name for the database type.
   */
  final private static String INITPARAM_DBTYPE = "dbType";

  /**
   *
   */
  final private static String SESSIONPARAM_LOGIN_TARGET = "login.target";

  /**
   *
   */
  final private static String SESSIONPARAM_ERROR =        "error";

  /**
   *
   */
  final private static String POSTPARAM_USERNAME =        "name";

  /**
   *
   */
  final private static String POSTPARAM_PASSWORD =        "password";



final private static String URL_LOGOUT =  "/Logout";
final private static String URL_LOGIN =  "/Login";

  /////////////////////////////////////////////////////////////////////////////


  /**
   * @param _config
   */
  public void init(ServletConfig _config) throws ServletException  {
    super.init(_config);



    initReplacableMacros("/"+_config.getServletContext().getServletContextName()+"/");

this.pathLoginPage = replaceMacrosInUrl(_config.getInitParameter(INITPARAM_URL_LOGIN_PAGE));


try {

String loggingProperties = _config.getInitParameter(INITPARAM_LOGGING);
if (loggingProperties!=null && loggingProperties.length()>0)  {
  ByteArrayInputStream ins = new ByteArrayInputStream(loggingProperties.getBytes());
  LogManager.getLogManager().readConfiguration(ins);
}

String dbType = _config.getInitParameter(INITPARAM_DBTYPE);
if (dbType!=null)  {
  if ("Derby".equals(dbType.toString()))  {
    Context.setDbType(Context.DbType.Derby);
  } else if ("Oracle".equals(dbType.toString()))  {
    Context.setDbType(Context.DbType.Oracle);
  } else  {
    throw new ServletException("unknown database type '" + dbType + "'!");
  }
} else  {
  throw new ServletException("no database type defined!");
}


InitialContext initCtx = new InitialContext();
javax.naming.Context envCtx = (javax.naming.Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/eFaps");
{'fraction_non_alphanumeric': 0.1237491190979563, 'fraction_numerical': 0.002536997885835095, 'mean_word_length': 3.8636052090472925, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '6717832', 'n_tokens_mistral': 2029, 'n_tokens_neox': 2002, 'n_words': 540}