import java.util.Properties;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import com.fund858.util.DealingCharacter;
import com.fund858.util.ReadProperties;
/**
* SetupProperty.java
* Description: 从资源文件中获取属性值
* @author li.b
* @version 2.0
* Jun 26, 2008
*/
public class SetupProperty extends TagSupport {
/**
* key : 指定将要获取资源的key; path:资源文件路径;
* filter:是否过滤标签 encod:资源文件的编码
*/
private String key;
private String path;
private boolean filter = false;
private String encod = "";
public int doEndTag() throws JspException {
try {
pageContext.getOut().write(getKey(path, key));
} catch (Exception e) {
e.printStackTrace();
}
return super.doEndTag();
}
/**
* Description:标签处理
* @param path
* @param key
* @return
* @throws Exception
*/
private String getKey(String path,String key) throws Exception{
String result = "";
Properties prop = null;
if(path != null && !path.equals("")){
prop = ReadProperties.getProperties(path);
}else{
String tmp = pageContext.getServletContext()
.getRealPath("WEB-INF/application.properties");
prop = ReadProperties.getProperties(tmp);
}
if(prop != null){
result = ReadProperties.getValue(prop, key,encod);
}
if(result != null && !result.equals("") && filter){
//显示输出特殊符号
result = DealingCharacter.filter(result);
}
return result;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public boolean isFilter() {
return filter;
}
public void setFilter(boolean filter) {
this.filter = filter;
}
public String getEncod() {
return encod;
}
public void setEncod(String encod) {
this.encod = encod;
}
} |