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

📄 message.java

📁 这是我自己开发的一个MVC框架
💻 JAVA
字号:
package dark.web.frame;

import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;

import dark.util.string.StringUtils;

import org.apache.commons.configuration.PropertiesConfiguration;

/**
 * <p>Title:            消息封装类</p>
 * <p>Description:      </p>
 * <p>Copyright:        Copyright (c) 2004</p>
 * <p>Company:          DIS</p>
 * <p>Create Time:      2004-12-12 1:30:43</p>
 * @author             <a href="mailto:dark_he@hotmail.com">darkhe</a>
 * @version            1.0
 */
public class Message
{
	/**
	 * 消息读取器
	 */
	private static PropertiesConfiguration configuration =
		new PropertiesConfiguration();

	/**
	 * 消息存放地
	 */
	private HashMap map = new HashMap();

	public Message()
	{
	}

	/**	 
	 * @param is
	 */
	public Message(InputStream is) throws IOException
	{		
		configuration.load(is);
	}

	/**
	 * @param name
	 * @return
	 */
	public String getMessage(String name)
	{
		String msg = (String) map.get(name);
		if (msg != null)
		{
			if (getCoding().equalsIgnoreCase("gb2312"))
			{
				try
				{
					return StringUtils.toGb(msg);
				}
				catch (UnsupportedEncodingException e)
				{
					return msg;
				}
			}
			else if (getCoding().equalsIgnoreCase("iso8859"))
			{
				try
				{
					return StringUtils.toIso(msg);
				}
				catch (UnsupportedEncodingException e)
				{
					return msg;
				}
			}
			else
			{
				return msg;
			}

		}
		else
		{
			return "";
		}
	}

	/**
	 * @param name
	 * @param value
	 * @return
	 */
	public void setMessage(String name, String value)
	{
		map.put(name, value);
	}

	/**
	 * 从消息文件中读取消息并存入Message对象
	 * @param name
	 */
	public void readMessage(String name)
	{
		String msg = "";
		if (!configuration.isEmpty())
		{
			msg = configuration.getString(name);
		}

		setMessage(name, msg);
	}

	/**
	 * 
	 */
	public void clear()
	{
		map.clear();
	}

	/**
	 * @return
	 */
	public boolean isEmpty()
	{
		return map.isEmpty();
	}

	/**
	 * @return
	 */
	public int size()
	{
		return map.size();
	}

	/**
	 * @return
	 * @see java.lang.Object#toString()
	 */
	public String toString()
	{
		return map.toString();
	}

	public String getCoding()
	{
		return configuration.getString("message.coding");
	}
}

⌨️ 快捷键说明

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