12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- package com.pbsage.util;
- import java.io.File;
- import java.net.URL;
- import java.net.URLDecoder;
- import java.util.Iterator;
- import org.apache.log4j.Logger;
- import org.apache.log4j.PropertyConfigurator;
- import org.dom4j.Document;
- import org.dom4j.Element;
- import org.dom4j.io.SAXReader;
- @SuppressWarnings("rawtypes")
- public class Constant {
- public static String data_middle_url;
- public static String metadata_web_url;
- private static Logger logger;
- private static String path = null;
- public static String GetPath() {
- if (path == null) {
- String resource = "/log4j.properties";
- URL resourceUrl = Constant.class.getResource(resource);
- String resourcePath = null;
- if (resourceUrl == null) {
- resourcePath = System.getProperty("user.dir") + resource;
- } else {
- resourcePath = resourceUrl.getPath();
- }
- path = resourcePath.substring(0, resourcePath.length() - resource.length());
- }
- return path;
- }
- static {
- try {
- String filepathLog4j = Constant.GetPath() + "/log4j.properties";
- PropertyConfigurator.configure(URLDecoder.decode(filepathLog4j, "UTF-8"));
- logger = Logger.getLogger(Constant.class);
- } catch (Exception e) {
- e.printStackTrace();
- }
- try {
- {
- File xmlFile = new File(Constant.GetPath() + "/config.xml");
- if (xmlFile.exists()) {
- SAXReader saxReader = new SAXReader();
- Document document = saxReader.read(xmlFile);
- Iterator iter;
- Element element;
- iter = document.selectNodes("/root/data_middle").iterator();
- if (iter.hasNext()) {
- element = (Element) iter.next();
- data_middle_url = element.attribute("url").getValue();
- if (!data_middle_url.endsWith("/")) {
- data_middle_url = data_middle_url + "/";
- }
- }
- iter = document.selectNodes("/root/metadata_web").iterator();
- if (iter.hasNext()) {
- element = (Element) iter.next();
- metadata_web_url = element.attribute("url").getValue();
- if (!metadata_web_url.endsWith("/")) {
- metadata_web_url = metadata_web_url + "/";
- }
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public synchronized static void debug(String message) {
- logger.debug(message);
- }
- public synchronized static void info(String message) {
- logger.info(message);
- }
- public synchronized static void warn(String message) {
- logger.warn(message);
- }
- public synchronized static void error(String message) {
- logger.error(message);
- }
- public synchronized static void fatal(String message) {
- logger.fatal(message);
- }
- }
|