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

📄 screenmessagetag.java

📁 j2ee源码
💻 JAVA
字号:
/*
 * Created on 2005/11/7
 */
package com.leeman.common.web.ui.tags;

import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.tagext.TagSupport;

import com.leeman.common.web.ui.ScreenMessage;
import com.leeman.common.web.ui.ScreenMessageHelper;
import com.leeman.wkexs.web.base.BaseConstants;

/**
 * @author Dennis
 */
public class ScreenMessageTag extends TagSupport {
	
	private static final String CLS_FRAME = "screenMessageFrame";
	
	private static final String CLS_INFO = "infoMessage";
	private static final String CLS_SUCCESS = "successMessage";
	private static final String CLS_WARNING = "warningMessage";
	private static final String CLS_ERROR = "errorMessage";
	
	private static final String CLS_BOX_INFO = "messageBoxInfo";
	private static final String CLS_BOX_SUCCESS = "messageBoxSuccess";
	private static final String CLS_BOX_WARNING = "messageBoxWarning";
	private static final String CLS_BOX_ERROR = "messageBoxError";
	
	private static final String IMG_INFO = "base/msg_info.gif";
	private static final String IMG_SUCCESS = "base/msg_success.gif";
	private static final String IMG_WARNING = "base/msg_warning.gif";
	private static final String IMG_ERROR = "base/msg_error.gif";
	
	protected HashMap labelSet;
	private String langId;
	private String bundle;
	private String msgboxWidth = "550";
	
	public void initLabels()
	{
		labelSet = new HashMap();

		//eng
		HashMap label_eng = new HashMap();
		label_eng.put("label.systemMessage", "System Message");

		labelSet.put("eng", label_eng);

		//cht
		HashMap label_cht = new HashMap();
		label_cht.put("label.systemMessage", "系統訊息");

		labelSet.put("cht", label_cht);

		//cht
		HashMap label_chs = new HashMap();
		label_chs.put("label.systemMessage", "系统讯息");

		labelSet.put("chs", label_chs);
	}
	protected String getLoacalizedText(String key)
	{
		HashMap labels = (HashMap)labelSet.get(langId);
		if (labels != null){
			return (String)labels.get(key);
		}
		else{
			return null;
		}
	}
	
	protected String getMessageCssClass(int msgType){
		switch(msgType){
			case ScreenMessage.SUCCESS:
			   return CLS_SUCCESS;
		   case ScreenMessage.WARNING:
			   return CLS_WARNING;
		   case ScreenMessage.ERROR:
			   return CLS_ERROR;
		   default:
			   return CLS_INFO;
		}
	}
	
	protected String getMessageBoxCssClass(int msgType){
		switch(msgType){
			case ScreenMessage.SUCCESS:
			   return CLS_BOX_SUCCESS;
		   case ScreenMessage.WARNING:
			   return CLS_BOX_WARNING;
		   case ScreenMessage.ERROR:
			   return CLS_BOX_ERROR;
		   default:
			   return CLS_BOX_INFO;
		}
	}
	
	protected String getMessageIcon(int msgType){
		switch(msgType){
			case ScreenMessage.SUCCESS:
			   return IMG_SUCCESS;
		   case ScreenMessage.WARNING:
			   return IMG_WARNING;
		   case ScreenMessage.ERROR:
			   return IMG_ERROR;
		   default:
			   return IMG_INFO;
		}
	}
		
	public int doEndTag() throws javax.servlet.jsp.JspException{
	  initLabels();
	  try {
	  	  	
		HttpServletRequest request =(HttpServletRequest)pageContext.getRequest();
		HttpSession session= request.getSession();
		
		if (bundle != null && !"".equals(bundle)){
			langId = bundle;
		}
		else{
			langId = (String)session.getAttribute(BaseConstants.SESSION_LANG_ID);
		}
		if (langId == null || "".equals(langId))
		{
			throw new javax.servlet.jsp.JspException("Error processing ScreenMessageTag.doStartTag(): Invalid Language");
		}
		
		StringBuffer shtml = new StringBuffer();
				
		String contextPath = request.getContextPath() + "/";
		String imageDirPath = contextPath + "common/images/";
		
		ArrayList sysMessageList = ScreenMessageHelper.getMessageList(request);
				
		boolean bAllPrompted = true;
		
		if (sysMessageList != null){
			for (int i=0; i < sysMessageList.size(); i++)
			{	
				ScreenMessage msg = (ScreenMessage)sysMessageList.get(i);
				if (msg.isShown()){
					bAllPrompted = false;
					break;
				}
			}
		}
		
		
		if (sysMessageList != null && sysMessageList.size() > 0)
		{
			if (!bAllPrompted)
			{
				
				ScreenMessage msg = (ScreenMessage)sysMessageList.get(0);
								
				shtml.append("<!-- ##### By SysMessageTag() ##### -->");
				shtml.append("\n");
				shtml.append("<table width='100%' border=0 cellpadding=0 cellspacing=0><tr><td width=20 valign='top' style='padding-right:20px;'><img id='SwitchMessageCommandIcon' border=0 onclick='switchMsgBox();'></td><td align=\"center\">");
				shtml.append("<table");
				shtml.append(" width=\"" + msgboxWidth + "\" border=0 id='ScreenMsgArea' class='");
				shtml.append(CLS_FRAME);
				shtml.append("'>");
				shtml.append("<tr>");
				shtml.append("<td colspan='2' class='");
				shtml.append(getMessageBoxCssClass(msg.getMsgType()));
				shtml.append("'>");
				shtml.append(this.getLoacalizedText("label.systemMessage"));
				shtml.append("</td></tr>");
				shtml.append("\n");
			}
						 
			for (int i=0; i < sysMessageList.size(); i++)
			{	
				ScreenMessage msg = (ScreenMessage)sysMessageList.get(i);
				
				if(msg.isPrompted()){
					shtml.append("<script language=javascript>");
					shtml.append("\n");
					shtml.append("promptMsgArray.push('");
					shtml.append(msg.getMsgText());
					shtml.append("');");
					shtml.append("\n");
					shtml.append("</script>");
				}
																	
				if(msg.isShown()){
					shtml.append("<tr>");
					shtml.append("<td class='");
					shtml.append(getMessageCssClass(msg.getMsgType()));
					shtml.append("' width=\"20\"><img src='");
					shtml.append(imageDirPath + getMessageIcon(msg.getMsgType()));
					shtml.append("'></td>");
					shtml.append("\n");
					shtml.append("<td class='");
					shtml.append(getMessageCssClass(msg.getMsgType()));
					shtml.append("'>");
					shtml.append(msg.getMsgText());
					shtml.append("</td></tr>");
				}
			}
			
			if (!bAllPrompted)
			{
				shtml.append("</table>");
				shtml.append("<P><table cellspacing='2' border='0'><tr><td></td></tr></table>");
				shtml.append("</td></tr></table>");
				
				shtml.append("\n");
				shtml.append("<!-- ##### End of SysMessageTag() ##### -->");
			}
		}
		
		pageContext.getOut().println(shtml.toString());
	  } catch (Exception e)
	  {
		throw new javax.servlet.jsp.JspException("Error processing ScreenMessageTag.doEndTag(): " + e.toString());
	  }
	  return EVAL_PAGE;
	}		
	/**
	 * @return
	 */
	public String getBundle() {
		return bundle;
	}

	/**
	 * @return
	 */
	public String getMsgboxWidth() {
		return msgboxWidth;
	}

	/**
	 * @param string
	 */
	public void setBundle(String string) {
		bundle = string;
	}

	/**
	 * @param string
	 */
	public void setMsgboxWidth(String string) {
		msgboxWidth = string;
	}

}

⌨️ 快捷键说明

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