📄 bbscsutil.java
字号:
package com.laoer.bbscs.comm;
import javax.servlet.http.*;
import org.apache.struts.config.ModuleConfig;
import org.apache.struts.*;
import org.apache.struts.util.*;
import org.apache.commons.lang.*;
import java.net.*;
import java.io.*;
import java.util.*;
import java.util.regex.*;
import org.apache.struts.taglib.TagUtils;
import org.apache.commons.io.*;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
import java.text.*;
import com.laoer.comm.util.*;
import com.laoer.bbscs.bean.UserLevel;
/**
* <p>Title: 天乙社区</p>
*
* <p>Description: BBSCS</p>
*
* <p>Copyright: Copyright (c) 2006</p>
*
* <p>Company: Laoer.com</p>
*
* @author Gong Tianyi
* @version 7.0
*/
public class BBSCSUtil {
private static final Log logger = LogFactory.getLog(BBSCSUtil.class);
public static String getWebRealPath(HttpServletRequest request) {
StringBuffer sb = new StringBuffer();
sb.append("http://");
sb.append(request.getServerName());
if (request.getServerPort() != 80) {
sb.append(":");
sb.append(request.getServerPort());
}
//sb.append(request.getContextPath());
//sb.append("/");
return sb.toString();
}
public static String getActionMappingName(String action) {
String value = action;
int question = action.indexOf("?");
if (question >= 0) {
value = value.substring(0, question);
}
int slash = value.lastIndexOf("/");
int period = value.lastIndexOf(".");
if ( (period >= 0) && (period > slash)) {
value = value.substring(0, period);
}
if (value.startsWith("/")) {
return (value);
}
else {
return ("/" + value);
}
}
public static String getActionMappingNameWithoutPrefix(String action) {
String value = action;
int question = action.indexOf("?");
if (question >= 0) {
value = value.substring(0, question);
}
int slash = value.lastIndexOf("/");
int period = value.lastIndexOf(".");
if ( (period >= 0) && (period > slash)) {
value = value.substring(0, period);
}
return (value);
}
public static String getActionMappingURL(String action) {
StringBuffer value = new StringBuffer();
// Use our servlet mapping, if one is specified
String servletMapping = Constant.SERVLET_MAPPING;
if (servletMapping != null) {
String queryString = null;
int question = action.indexOf("?");
if (question >= 0) {
queryString = action.substring(question);
}
String actionMapping = getActionMappingName(action);
if (servletMapping.startsWith("*.")) {
value.append(actionMapping);
value.append(servletMapping.substring(1));
}
else if (servletMapping.endsWith("/*")) {
value.append(servletMapping.substring(0, servletMapping.length() - 2));
value.append(actionMapping);
}
else if (servletMapping.equals("/")) {
value.append(actionMapping);
}
if (queryString != null) {
value.append(queryString);
}
}
// Otherwise, assume extension mapping is in use and extension is
// already included in the action property
else {
if (!action.startsWith("/")) {
value.append("/");
}
value.append(action);
}
// Return the completed value
return (value.toString());
}
public static String getActionMappingURLWithoutPrefix(String action) {
StringBuffer value = new StringBuffer();
// Use our servlet mapping, if one is specified
String servletMapping = Constant.SERVLET_MAPPING;
if (servletMapping != null) {
String queryString = null;
int question = action.indexOf("?");
if (question >= 0) {
queryString = action.substring(question);
}
String actionMapping = getActionMappingNameWithoutPrefix(action);
if (servletMapping.startsWith("*.")) {
value.append(actionMapping);
value.append(servletMapping.substring(1));
}
else if (servletMapping.endsWith("/*")) {
value.append(servletMapping.substring(0, servletMapping.length() - 2));
value.append(actionMapping);
}
else if (servletMapping.equals("/")) {
value.append(actionMapping);
}
if (queryString != null) {
value.append(queryString);
}
}
// Otherwise, assume extension mapping is in use and extension is
// already included in the action property
//else {
// if (!action.startsWith("/")) {
// value.append("/");
// }
// value.append(action);
//}
// Return the completed value
return (value.toString());
}
public static String getActionMappingURL(String action, HttpServletRequest request) {
StringBuffer value = new StringBuffer(request.getContextPath());
ModuleConfig config = (ModuleConfig) request.getAttribute(Globals.MODULE_KEY);
if (config != null) {
value.append(config.getPrefix());
}
// Use our servlet mapping, if one is specified
String servletMapping = Constant.SERVLET_MAPPING;
if (servletMapping != null) {
String queryString = null;
int question = action.indexOf("?");
if (question >= 0) {
queryString = action.substring(question);
}
String actionMapping = getActionMappingName(action);
if (servletMapping.startsWith("*.")) {
value.append(actionMapping);
value.append(servletMapping.substring(1));
}
else if (servletMapping.endsWith("/*")) {
value.append(servletMapping.substring(0, servletMapping.length() - 2));
value.append(actionMapping);
}
else if (servletMapping.equals("/")) {
value.append(actionMapping);
}
if (queryString != null) {
value.append(queryString);
}
}
// Otherwise, assume extension mapping is in use and extension is
// already included in the action property
else {
if (!action.startsWith("/")) {
value.append("/");
}
value.append(action);
}
// Return the completed value
return (value.toString());
}
public static StringBuffer getActionMappingURLPerfix(HttpServletRequest request) {
StringBuffer value = new StringBuffer(request.getContextPath());
ModuleConfig config = (ModuleConfig) request.getAttribute(Globals.MODULE_KEY);
if (config != null) {
value.append(config.getPrefix());
}
return value;
}
public static String getActionMappingURL(String action, StringBuffer value) {
// Use our servlet mapping, if one is specified
String servletMapping = Constant.SERVLET_MAPPING;
if (servletMapping != null) {
String queryString = null;
int question = action.indexOf("?");
if (question >= 0) {
queryString = action.substring(question);
}
String actionMapping = getActionMappingName(action);
if (servletMapping.startsWith("*.")) {
value.append(actionMapping);
value.append(servletMapping.substring(1));
}
else if (servletMapping.endsWith("/*")) {
value.append(servletMapping.substring(0, servletMapping.length() - 2));
value.append(actionMapping);
}
else if (servletMapping.equals("/")) {
value.append(actionMapping);
}
if (queryString != null) {
value.append(queryString);
}
}
// Otherwise, assume extension mapping is in use and extension is
// already included in the action property
else {
if (!action.startsWith("/")) {
value.append("/");
}
value.append(action);
}
// Return the completed value
return (value.toString());
}
public static URL absoluteActionURL(HttpServletRequest request, String action) throws
MalformedURLException {
return new URL(RequestUtils.serverURL(request) + getActionMappingURL(action, request));
}
public static URL absoluteActionURLHtml(HttpServletRequest request, String url) throws
MalformedURLException {
return new URL(RequestUtils.serverURL(request) + request.getContextPath() + url);
}
public static int getStrLength(String txt, String charset) {
try {
return txt.getBytes(charset).length;
}
catch (UnsupportedEncodingException ex) {
return txt.length();
}
}
public static int getSysCharsetStrLength(String txt) {
try {
return txt.getBytes(Constant.CHARSET).length;
}
catch (UnsupportedEncodingException ex) {
return txt.length();
}
}
public static Vector getDateShowTypeValues(Locale locale) {
Vector v = new Vector();
v.add(new LabelValueBean(Constant.MESSAGE.getMessage(locale, "admin.DateShowType0"), "0"));
v.add(new LabelValueBean(Constant.MESSAGE.getMessage(locale, "admin.DateShowType1"), "1"));
return v;
}
/*
public static Vector getBoardTypeValues(Locale locale) {
Vector v = new Vector();
v.add(new LabelValueBean(Constant.MESSAGE.getMessage(locale, "admin.boardType0"), "0"));
v.add(new LabelValueBean(Constant.MESSAGE.getMessage(locale, "admin.boardType1"), "1"));
v.add(new LabelValueBean(Constant.MESSAGE.getMessage(locale, "admin.boardType2"), "2"));
v.add(new LabelValueBean(Constant.MESSAGE.getMessage(locale, "admin.boardType3"), "3"));
return v;
}*/
public static Vector getBoardTypeValues(Locale locale) {
Vector v = new Vector();
v.add(new LabelValueBean(Constant.MESSAGE.getMessage(locale, "admin.boardType1"), "1"));
v.add(new LabelValueBean(Constant.MESSAGE.getMessage(locale, "admin.boardType3"), "3"));
return v;
}
public static Vector getBoardUseStatValues(Locale locale) {
Vector v = new Vector();
v.add(new LabelValueBean(Constant.MESSAGE.getMessage(locale, "admin.board.useStat0"), "0"));
v.add(new LabelValueBean(Constant.MESSAGE.getMessage(locale, "admin.board.useStat1"), "1"));
return v;
}
public static Vector getBoardsValues(Locale locale) {
Vector v = new Vector();
v.add(new LabelValueBean(Constant.MESSAGE.getMessage(locale, "bbscs.none"), "0"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -