📄 siteurls2.java
字号:
package com.eline.vod.utils;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import com.blue.web.common.util.AppSettings;
public class SiteUrls2 {
public static final String URL_HOME = "home";
public static final String URL_REGISTER = "register";
public static final String URL_USER_DO = "user.do";
public static final String URL_GROUP = "group";
public static final String URL_MOVIE = "movie";
public static final String URL_WND_MOVIEPLAYER = "window.movie.player";
public static final String URL_PDA_REPWD = "pda.retrievepassword";
public static final String URL_PDA_LOGIN = "pda.login";
private static SiteUrls2 instance = null;
private Map _properties = null;
private SiteUrls2() {
_properties = new HashMap();
}
public static SiteUrls2 getInstance() {
if (instance == null)
instance = new SiteUrls2();
return instance;
}
public void init(String configURL) throws Exception {
Element rootElement = null;
try {
URL url = new URL(configURL);
InputSource xmlInp = new InputSource(url.openStream());
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = docBuilderFactory.newDocumentBuilder();
Document doc = parser.parse(xmlInp);
rootElement = doc.getDocumentElement();
rootElement.normalize();
} catch (IOException e) {
throw new Exception("Failed to open/read configuration file." + e);
} catch (SAXException e) {
throw new Exception("Invalid configuration file's content." + e);
} catch (Exception e) {
throw e;
}
try {
loadValuesFromConfigurationXml(rootElement);
} catch (Exception e) {
throw new Exception("Error for process configuration datas." + e);
}
}
private void loadValuesFromConfigurationXml(Element rootElement) throws Exception {
NodeList nodes = rootElement.getChildNodes();
for (int i = 0; i < nodes.getLength(); i ++) {
Node node = nodes.item(i);
if (node != null && node instanceof Element) {
if ("url".equals(node.getNodeName())) {
processSingleNode(node);
}
}
}
}
private void processSingleNode(Node node) {
NamedNodeMap attrs = node.getAttributes();
String key = null;
String value = null;
for (int i = 0; i < attrs.getLength(); i ++) {
Node attr = attrs.item(i);
if ("name".equals(attr.getNodeName())) {
key = attr.getNodeValue();
} else if ("path".equals(attr.getNodeName())) {
value = attr.getNodeValue();
}
}
if (key != null && key.length() > 0 && value != null && value.length() > 0) {
String rootPath = AppSettings.getInstance().getProperty(AppKeys.APP_ROOT);
System.out.println("url["+key+"]=" + rootPath + value);
_properties.put(key, rootPath + value);
}
}
public synchronized String getProperty(String key) {
return (String)_properties.get(key);
}
public synchronized void setProperty(String key, String value) {
_properties.put(key, value);
}
public String getHomeURL() {
return getProperty(SiteUrls2.URL_HOME);
}
public String getMovieURL() {
return getProperty(SiteUrls2.URL_MOVIE);
}
public String getMovieGroupURL() {
return getProperty(SiteUrls2.URL_GROUP);
}
public String getRegisterURL() {
return getProperty(SiteUrls2.URL_REGISTER);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -