package com.ngMAT.appl.genericservlet; import java.sql.Connection; import java.util.Vector; import javax.servlet.http.Cookie; import javax.servlet.http.HttpSession; import com.ngMAT.Common.DBConnection; import com.ngMAT.Common.Log; import com.ngMAT.HTML.HTMLTemplate; import com.ngMAT.servlet.EZServletContext; import com.ngMAT.appl.GenericObjectFunction; import com.ngMAT.appl.GenericConstants; import com.ngMAT.appl.DBApplicationContext; //import com.ngMAT.appl.data.session.LoginSessionManagerData; //import com.ngMAT.appl.data.session.RequestDataStore; import com.ngMAT.appl.data.util.StringConverter; //import com.ngMAT.appl.etc.HttpLog; public class GenericServletContext extends EZServletContext implements DBApplicationContext, GenericObjectFunction { public void init() { not_ready_page_url = ((GenericServletConfig)super.config).not_ready_page_url; if (req != null) { // HttpLog httplog = HttpLog.getInstance (this); // httplog.printLog (req); } } private Connection con = null; public String not_ready_page_url = null; /** * 現在このコンテキストに割り当てられているDB接続オブジェクトを取得する。 */ public Connection getConnection () {return con;} /** * デフォルトのDB接続設定ファイルを使用して、DB接続をコンテキストに割り当てる。 */ public void assignConnection() { assignConnection (((GenericServletConfig)config).db_connection_name); } /** * 指定されたDB接続設定ファイルを使用して、DB接続をコンテキストに割り当てる。 * @param propfname DB接続プロパティファイル名. */ public void assignConnection (String propfname) { if (con != null) { getLog().println ("#### ALERT #### DB Connection is already assigned ! This call will cause uncontrolable connection."); } try { con = DBConnection.getConnection (propfname); } catch (Exception e) { throw new com.ngMAT.Common.LowLevelException ("Failed to get connection with properties file : " + propfname + " : " + e.getClass().getName() + " : " + e.getMessage()); } } /** * このコンテキストに割り当てられているDB接続を開放する。 */ public void releaseConnection () { DBConnection.releaseConnection (con); con = null; } /** * このコンテキストに割り当てられているDB接続のトランザクションをコミットする。 */ public void commit() throws java.sql.SQLException { con.commit(); } /** * このコンテキストに割り当てられているDB接続のトランザクションをロールバックする。 */ public void rollback() throws java.sql.SQLException { con.rollback(); } public void debug_print (String s) { System.out.println (s); Log debug_log = ((GenericServletConfig)getConfig()).debug_log; if (debug_log != null) debug_log.println (s); } public void goBack() { String last_url = (String)getSessionValue (GenericConstants.SN.LAST_URL); if (last_url != null) { removeSessionValue (GenericConstants.SN.LAST_URL); super.sendRedirect (last_url); } } public String getRawParameter (String name) { return super.getParameter (name); } public String getParameter (String name) { String s = super.getParameter (name); if (s != null) { s = s.trim(); s = StringConverter.convertDangerZenkakuMarksToPreferedChars (s); s = StringConverter.replaceString (s, "<", "<"); s = StringConverter.replaceString (s, ">", ">"); } return s; } public boolean userHasPowerToAccess() { return true; } public boolean isEmptyParameter (String name) { String s = getParameter (name); return s == null || s.trim().length() == 0; } public static void displayError (HTMLTemplate template, String message) { displayMessage (template, message); } public static void displayError (HTMLTemplate template, Vector messages) { displayMessage (template, messages); } public static void displayMessage (HTMLTemplate template, Vector messages) { if (messages.size() > 0) { StringBuffer buffer = new StringBuffer ((String)messages.firstElement()); for (int i = 1; i < messages.size(); i++) { buffer.append ("
"); buffer.append ((String)messages.elementAt (i)); } displayMessage (template, new String (buffer)); } } public static void displayMessage (HTMLTemplate template, String message) { template.setTagValue ("MESSAGE", message); } }