【Java开源代码栏目提醒】:网学会员鉴于大家对Java开源代码十分关注,论文会员在此为大家搜集整理了“WebConfig.java”一文,供大家参考学习
package com.cownew.PIS.framework.web.helper;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import org.dom4j.Document;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import com.cownew.ctk.common.ExceptionUtils;
import com.cownew.ctk.common.StringUtils;
import com.cownew.ctk.constant.StringConst;
import com.cownew.ctk.io.ResourceUtils;
public class WebConfig
{
private String serverURL;
private String metaDataPath;
private String entityCacheFile;
private boolean metaCacheEnabled;
private static WebConfig instance;
private WebConfig()
{
super();
}
public static WebConfig getInstance()
{
if (instance == null)
{
instance = new WebConfig();
try
{
instance.initConfig();
} catch (Exception e)
{
ExceptionUtils.toRuntimeException(e);
}
}
return instance;
}
protected void initConfig() throws Exception
{
InputStream beansXFStream = null;
try
{
beansXFStream = getClass().getResourceAsStream(
"/com/cownew/PIS/framework/
web/WebConfig.
xml");
Document doc = new SAXReader().read(new InputStreamReader(
beansXFStream, StringConst.UTF8));
Node serverURLNode = doc.selectSingleNode("//Config/ServerURL");
serverURL = serverURLNode.getText();
metaDataPath = doc.selectSingleNode(
"//Config/MetaData/MetaDataPath").getText();
entityCacheFile = doc.selectSingleNode(
"//Config/MetaData/EntityCacheFile").getText();
String cacheState = doc.selectSingleNode(
"//Config/MetaData/CacheEnabled").getText();
if (StringUtils.isEmpty(cacheState)
|| cacheState.equalsIgnoreCase("false")
|| cacheState.equalsIgnoreCase("no")
|| cacheState.equalsIgnoreCase("off"))
{
metaCacheEnabled = false;
} else
{
metaCacheEnabled = true;
}
} finally
{
ResourceUtils.close(beansXFStream);
}
}
public String getEntityCacheFile()
{
return entityCacheFile;
}
public boolean isMetaCacheEnabled()
{
return metaCacheEnabled;
}
public String getMetaDataPath()
{
return metaDataPath;
}
public URL getServerURL()
{
try
{
return new URL(serverURL);
} catch (MalformedURLException e)
{
throw ExceptionUtils.toRuntimeException(e);
}
}
}