📄 webenv.java
字号:
/******************************************************************************
* 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 Smart Business Solution. The Initial
* Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke
* are Copyright (C) 1999-2005 Jorg Janke.
* All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.util;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.ecs.*;
import org.apache.ecs.xhtml.*;
import org.compiere.*;
import org.compiere.model.*;
/**
* Web Environment and debugging
*
* @author Jorg Janke
* @version $Id: WebEnv.java,v 1.15 2005/11/12 22:59:03 jjanke Exp $
*/
public class WebEnv
{
/** Add HTML Debug Info */
public static boolean DEBUG = true;
/** Logging */
private static CLogger log = CLogger.getCLogger(WebEnv.class);
/**
* Base Directory links <b>http://localhost:8080/compiere</b>
* to the physical <i>%COMPIERE_HOME%/tomcat/webroot/compiere</i> directory
*/
public 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.
/** Removing/modifying the Compiere logo is a violation of the license */
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 - WCmd */
public static final String TARGET_CMD = "WCmd";
/** Frame name for Menu - WMenu */
public static final String TARGET_MENU = "WMenu";
/** Frame name for Apps Window - WWindow */
public static final String TARGET_WINDOW = "WWindow";
/** Frame name for Apps PopUp - WPopUp */
public static final String TARGET_POPUP = "WPopUp";
/** Character Set (iso-8859-1 - utf-8) */
public static final String CHARSET = "UTF-8"; // Default: UNKNOWN
/** Encoding (ISO-8859-1 - UTF-8) */
public static final String ENCODING = "UTF-8";
/** Cookie Name */
public static final String COOKIE_INFO = "CompiereInfo";
/** Timeout - 15 Minutes */
public static final int TIMEOUT = 15*60;
/** Initialization OK? */
private static boolean s_initOK = false;
/** Not Braking Space */
public static String NBSP = " ";
/**
* Init Web Environment.
* 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)
{
log.info(config.getServletName());
return true;
}
Enumeration en = config.getInitParameterNames();
StringBuffer info = new StringBuffer("Servlet Init Parameter: ")
.append(config.getServletName());
while (en.hasMoreElements())
{
String name = en.nextElement().toString();
String value = config.getInitParameter(name);
System.setProperty(name, value);
info.append("\n").append(name).append("=").append(value);
}
boolean retValue = initWeb (config.getServletContext());
// Logging now initiated
log.info(info.toString());
return retValue;
} // initWeb
/**
* Init Web.
* Only call directly for Filters, etc.
* @param context servlet context
* @return false if initialization problems
*/
public static boolean initWeb (ServletContext context)
{
if (s_initOK)
{
log.info(context.getServletContextName());
return true;
}
// Load Environment Variables (serverApps/src/web/WEB-INF/web.xml)
Enumeration en = context.getInitParameterNames();
StringBuffer info = new StringBuffer("Servlet Context Init Parameters: ")
.append(context.getServletContextName());
while (en.hasMoreElements())
{
String name = en.nextElement().toString();
String value = context.getInitParameter(name);
System.setProperty(name, value);
info.append("\n").append(name).append("=").append(value);
}
try
{
s_initOK = Compiere.startup(false);
}
catch (Exception ex)
{
log.log(Level.SEVERE, "startup", ex);
}
if (!s_initOK)
return false;
// Logging now initiated
log.info(info.toString());
//
Properties ctx = new Properties();
MClient client = MClient.get(ctx, 0);
MSystem system = MSystem.get(ctx);
client.sendEMail(client.getRequestEMail(),
"Server started: " + system.getName(),
"ServerInfo: " + context.getServerInfo(), null);
return s_initOK;
} // initWeb
/**************************************************************************
* 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.
* Removing/modifying the Compiere logo is a violation of the license
* <p>
* /compiere/LogoSmall.gif
* @return url to logo
*/
public static String getLogoURL()
{
return getBaseDirectory(LOGO);
} // getLogoPath
/**
* Get Logo Image HTML tag.
* Removing/modifying the Compiere logo or copyright notice is a violation of the license
* @return Image
*/
public static img getLogo()
{
/** Removing/modifying the Compiere logo is a violation of the license */
return new img(getLogoURL()).setAlign(AlignType.RIGHT)
// Changing the copyright notice in any way violates the license
// and you'll be held liable for any damage claims
.setAlt("© Jorg Janke/Compiere");
} // getLogo
/**
* Get Stylesheet Path.
* <p>
* /compiere/standard.css
* @return url of Stylesheet
*/
public static String getStylesheetURL()
{
return getBaseDirectory(STYLE_STD);
} // getStylesheetURL
/**
* Get Cell Content
* @param content optional content
* @return string content or non breaking space
*/
public static String getCellContent (Object content)
{
if (content == null)
return NBSP;
String str = content.toString();
if (str.length() == 0)
return NBSP;
return str;
} // getCellContent
/**
* Get Cell Content
* @param content optional content
* @return string content
*/
public static String getCellContent (int content)
{
return String.valueOf(content);
} // getCellContent
/**************************************************************************
* Dump Servlet Config
* @param config config
*/
public static void dump (ServletConfig config)
{
log.config("ServletConfig " + config.getServletName());
log.config("- Context=" + config.getServletContext());
if (!CLogMgt.isLevelFiner())
return;
boolean first = true;
Enumeration e = config.getInitParameterNames();
while (e.hasMoreElements())
{
if (first)
log.finer("InitParameter:");
first = false;
String key = (String)e.nextElement();
Object value = config.getInitParameter(key);
log.finer("- " + key + " = " + value);
}
} // dump (ServletConfig)
/**
* Dump Session
* @param ctx servlet context
*/
public static void dump (ServletContext ctx)
{
log.config("ServletContext " + ctx.getServletContextName());
log.config("- ServerInfo=" + ctx.getServerInfo());
if (!CLogMgt.isLevelFiner())
return;
boolean first = true;
Enumeration e = ctx.getInitParameterNames();
while (e.hasMoreElements())
{
if (first)
log.finer("InitParameter:");
first = false;
String key = (String)e.nextElement();
Object value = ctx.getInitParameter(key);
log.finer("- " + key + " = " + value);
}
first = true;
e = ctx.getAttributeNames();
while (e.hasMoreElements())
{
if (first)
log.finer("Attributes:");
first = false;
String key = (String)e.nextElement();
Object value = ctx.getAttribute(key);
log.finer("- " + key + " = " + value);
}
} // dump
/**
* Dump Session
* @param session session
*/
public static void dump (HttpSession session)
{
log.config("Session " + session.getId());
log.config("- Created=" + new Timestamp(session.getCreationTime()));
if (!CLogMgt.isLevelFiner())
return;
boolean first = true;
Enumeration e = session.getAttributeNames();
while (e.hasMoreElements())
{
if (first)
log.finer("Attributes:");
first = false;
String key = (String)e.nextElement();
Object value = session.getAttribute(key);
log.finer("- " + key + " = " + value);
}
} // dump (session)
/**
* Dump Request
* @param request request
*/
public static void dump (HttpServletRequest request)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -