⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wenv.java

📁 Java写的ERP系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
 * The contents of this file are subject to the   Compiere License  Version 1.1
 * ("License"); You may not use this file except in compliance with the License
 * You may obtain a copy of the License at http://www.compiere.org/license.html
 * Software distributed under the License is distributed on an  "AS IS"  basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 * The Original Code is                  Compiere  ERP & CRM  Business Solution
 * The Initial Developer of the Original Code is Jorg Janke  and ComPiere, Inc.
 * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
 * created by ComPiere are Copyright (C) ComPiere, Inc.;   All Rights Reserved.
 * Contributor(s): ______________________________________.
 *****************************************************************************/
package org.compiere.www;

import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.*;
import java.sql.*;
import javax.naming.*;

import org.apache.ecs.*;
import org.apache.ecs.xhtml.*;
import org.apache.log4j.Logger;

import org.compiere.Compiere;
import org.compiere.util.*;

/**
 *  Web Environment and debugging
 *
 *  @author Jorg Janke
 *  @version $Id: WEnv.java,v 1.9 2003/05/04 06:47:28 jjanke Exp $
 */
public class WEnv
{
	/** Add HTML Debug Info                     */
	public static boolean DEBUG                 = true;
	/**	Logging									*/
	private static Logger			s_log = Logger.getLogger("org.compiere.www.WEnv");

	/**
	 *  Base Directory links <b>http://localhost:8080/compiere</b>
	 *  to the physical <i>%COMPIERE_HOME%/tomcat/webroot/compiere</i> directory
	 */
	protected static final String   DIR_BASE    = "/compiere";      //  /compiere
	/** Image Sub-Directory under BASE          */
	private static final String     DIR_IMAGE   = "images";         //  /compiere/images
	/** Stylesheet Name                         */
	private static final String     STYLE_STD   = "standard.css";   //  /compiere/standard.css
	/** Small Logo                              */
	private static final String     LOGO        = "LogoSmall.gif";  //  /compiere/LogoSmall.gif
	/** Store Sub-Directory under BASE          */
	private static final String     DIR_STORE   = "store";          //  /compiere/store

	/**  Frame name for Commands   */
	public static final String      TARGET_CMD  = "WCmd";
	/**  Frame name for Menu       */
	public static final String      TARGET_MENU = "WMenu";
	/**  Frame name for Apps Window */
	public static final String      TARGET_WINDOW = "WWindow";

	/** Character Set (iso-8859-1)              */
	public static final String      CHARACTERSET = "iso-8859-8";     //  Default: UNKNOWN
	/** Cookie Name                             */
	public static final String      COOKIE_INFO = "CompiereInfo";

	/** Timeout - 15 Minutes                    */
	public static final int         TIMEOUT     = 15*60;

	/** Session Attribute - Context             */
	public static final String      SA_CONTEXT  = "SA_Context";
	/** Session Attribute - Window Status              */
	public static final String      SA_WINDOW   = "SA_Window";
	/** Session Attribute - Login Info          */
	public static final String      SA_LOGININFO = "SA_LoginInfo";
	/** Session Locale                          */
	public static final String      SA_LANGUAGE  = "SA_Language";

	/** Initialization OK?                      */
	private static boolean          s_initOK    = false;

	/**
	 *  Init Web Environment.
	 *  <p>
	 *  To be called from every Servlet in the init method
	 *  or any other Web resource to make sure that the
	 *  environment is properly set.
	 *  @param config config
	 *  @return false if initialization problems
	 */
	public static boolean initWeb (ServletConfig config)
	{
		if (s_initOK)
		{
			s_log.info("initWeb " + config.getServletName());
			return true;
		}
		s_log.info("initWeb - Initial Call - " + config.getServletName());

		//  Load Environment Variables
		s_log.info("Web Context Init Parameter for " + config.getServletContext().getServletContextName());
		Enumeration en = config.getServletContext().getInitParameterNames();
		while (en.hasMoreElements())
		{
			String name = en.nextElement().toString();
			String value = (String)config.getServletContext().getInitParameter(name);
			s_log.info(" - " + name + "=" + value);
			System.setProperty(name, value);
		}

		s_log.info("Servlet Init Parameter for " + config.getServletName());
		en = config.getInitParameterNames();
		while (en.hasMoreElements())
		{
			String name = en.nextElement().toString();
			String value = (String)config.getInitParameter(name);
			s_log.info(" - " + name + "=" + value);
			System.setProperty(name, value);
		}

		try
		{
			s_initOK = Compiere.startupServer (new InitialContext());
		}
		catch (Exception ex)
		{
			s_log.error("initWeb", ex);
		}
		if (!s_initOK)
			return false;

		s_log.info("initWeb complete");
		return s_initOK;
	}   //  initWeb


	/**
	 * 	Get AD_Client_ID from Servlet Context or Web Context
	 * 	@param config servlet config
	 * 	@return AD_Client_ID if found or 0
	 */
	public static int getAD_Client_ID (ServletConfig config)
	{
		//	Get Client from Servlet init
		String oo = config.getInitParameter("AD_Client_ID");
		//	Get Client from Web Context
		if (oo == null)
			oo = config.getServletContext().getInitParameter("AD_Client_ID");
		if (oo == null)
		{
			s_log.error("getAD_Client_ID is null");
			return 0;
		}
		int AD_Client_ID = 0;
		try
		{
			AD_Client_ID = Integer.parseInt(oo);
		}
		catch (NumberFormatException ex)
		{
			s_log.error("getAD_Client_ID - " + oo, ex);
		}
		return AD_Client_ID;
	}	//	getAD_Client_ID

	/**
	 * 	Get database user from Servlet Context or Web Context
	 * 	@param servlet servlet config
	 * 	@return db User ID or compiere if not found
	 */
	public static Connection getConnection (HttpServlet servlet)
	{
		//	Get Info from Servlet Context
		String user = servlet.getInitParameter("dbUID");
		String pwd = servlet.getInitParameter("dbPWD");
		//	Get Client Web Context
		if (user == null)
			user = servlet.getServletContext().getInitParameter("dbUID");
		if (pwd == null)
			pwd = servlet.getServletContext().getInitParameter("dbPWD");
		//	Defaults
		if (user == null)
			user = "compiere";
		if (user == null)
			user = "compiere";
/**		//
		try
		{
			Context context = new InitialContext();
			DataSource ds = (DataSource)context.lookup("java:OracleDS");
			log.info ("OracleDS=" + ds.toString());
			Connection con = ds.getConnection(dbUID, dbPWD);
			log.info("Connection AutoCommit=" + con.getAutoCommit());
			//
			BPartnerHome bpHome = (BPartnerHome)context.lookup(BPartnerHome.JNDI_NAME);
			BPartner bp = bpHome.create();
			log.info("BPartner=" + bp.process2());
			bp.remove();
		}
		catch (Exception ex)
		{
			throw new ServletException (ex);
		}
**/
		return null;

	}	//	getDB_UID

	/**
	 * 	Get database user from Servlet Context or Web Context
	 * 	@param config servlet config
	 * 	@return db User ID or compiere if not found
	 */
	public static String getDB_UID (ServletConfig config)
	{
		//	Get DB User from Servlet init
		String user = config.getInitParameter("dbUID");
		//	Get Client from Web Context
		if (user == null)
			user = config.getServletContext().getInitParameter("dbUID");
		if (user == null)
		{
			s_log.error("getDB_UID is null");
			return "compiere";
		}
		return user;
	}	//	getDB_UID

	/**
	 * 	Get database user password from Servlet Context or Web Context
	 * 	@param config servlet config
	 * 	@return db Password or compiere if not found
	 */
	public static String getDB_PWD (ServletConfig config)
	{
		//	Get DB User from Servlet init
		String pwd = config.getInitParameter("dbPWD");
		//	Get Client from Web Context
		if (pwd == null)
			pwd = config.getServletContext().getInitParameter("dbPWD");
		if (pwd == null)
		{
			s_log.error("getDB_PWD is null");
			return "compiere";
		}
		return pwd;
	}	//	getDB_PWD

	/*************************************************************************/

	/**
	 *  Get Base Directory entrry.
	 *  <br>
	 *  /compiere/
	 *  @param entry file entry or path
	 *  @return url to entry in base directory
	 */
	public static String getBaseDirectory (String entry)
	{
		StringBuffer sb = new StringBuffer (DIR_BASE);
		if (!entry.startsWith("/"))
			sb.append("/");
		sb.append(entry);
		return sb.toString();
	}   //  getBaseDirectory

	/**
	 *  Get Image Directory entry.
	 *  <br>
	 *  /compiere/images
	 *  @param entry file entry or path
	 *  @return url to entry in image directory
	 */
	public static String getImageDirectory(String entry)
	{
		StringBuffer sb = new StringBuffer (DIR_BASE);
		sb.append("/").append(DIR_IMAGE);
		if (!entry.startsWith("/"))
			sb.append("/");
		sb.append(entry);
		return sb.toString();
	}   //  getImageDirectory

	/**
	 *  Get Store Directory entry.
	 *  <br>
	 *  /compiere/store
	 *  @param entry file entry or path
	 *  @return url to entry in store directory
	 */
	public static String getStoreDirectory(String entry)
	{
		StringBuffer sb = new StringBuffer (DIR_BASE);
		sb.append("/").append(DIR_STORE);
		if (!entry.startsWith("/"))
			sb.append("/");
		sb.append(entry);
		return sb.toString();
	}   //  getStoreDirectory

	/**
	 *  Get Logo Path.
	 *  <p>
	 *  /compiere/LogoSmall.gif
	 *  @return url to logo
	 */
	public static String getLogoURL()
	{
		return getBaseDirectory(LOGO);
	}   //  getLogoPath

	/**
	 *  Get Logo Image HTML tag
	 *  @return Image
	 */
	public static img getLogo()
	{
		return new img(WEnv.getLogoURL()).setAlign(AlignType.right).setAlt(Compiere.COPYRIGHT);
	}   //  getLogo

	/**
	 *  Get Stylesheet Path.
	 *  <p>
	 *  /compiere/standard.css
	 *  @return url of Stylesheet
	 */
	public static String getStylesheetURL()
	{
		return getBaseDirectory(STYLE_STD);
	}   //  getStylesheetURL

	/*************************************************************************/

	/**
	 * 	Dump Servlet Config
	 * 	@param config config
	 */
	public static void dump (ServletConfig config)
	{
		System.out.println("ServletConfig " + config.getServletName());
		System.out.println(" Context=" + config.getServletContext());
		boolean first = true;
		Enumeration e = config.getInitParameterNames();
		while (e.hasMoreElements())
		{
			if (first)
				System.out.println(" InitParameter:");
			first = false;
			String key = (String)e.nextElement();
			Object value = config.getInitParameter(key);
			System.out.println("  " + key + " = " + value);
		}
	}	//	dump (ServletConfig)

	/**
	 * 	Dump Session
	 * 	@param ctx servlet context
	 */
	public static void dump (ServletContext ctx)
	{
		System.out.println("ServletContext " + ctx.getServletContextName());
		System.out.println(" ServerInfo=" + ctx.getServerInfo());
		boolean first = true;
		Enumeration e = ctx.getInitParameterNames();
		while (e.hasMoreElements())
		{
			if (first)
				System.out.println(" InitParameter:");
			first = false;
			String key = (String)e.nextElement();
			Object value = ctx.getInitParameter(key);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -