这是我自己开发的一个MVC框架
源代码在线查看: message.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;
/**
* Title: 消息封装类
* Description:
* Copyright: Copyright (c) 2004
* Company: DIS
* Create Time: 2004-12-12 1:30:43
* @author darkhe
* @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");
}
}