ConfigHelper

原创 2011年01月13日 17:16:00

package com.beetle.framework.web.cache;

/**
 * @author Henry Yu 2005-9-27
 *
 */
import java.io.*;
import java.util.*;

import org.dom4j.*;
import org.dom4j.io.*;

public class ConfigHelper {

  private static Map url_cacheObject = new HashMap();
  private static boolean read_flag = false;
  private static ConfigHelper instance = new ConfigHelper();
  private ConfigHelper() {}

  private static String convertPath(String aStr) {
    return "//".concat(aStr.replace('.', '/'));
  }

  public synchronized void readCachePaths(InputStream xmlIs) {
    url_cacheObject.clear();
    SAXReader reader = new SAXReader();
    try {
      Document doc = reader.read(xmlIs);
      Node node = doc.selectSingleNode(convertPath("mappings.caches"));
      if (node != null) {
        Iterator it = node.selectNodes("cItem").iterator();
        while (it.hasNext()) {
         CacheObject cacheObject = new CacheObject();
          Element e = (Element) it.next();
          cacheObject.setUrl(e.valueOf("@name"));
          cacheObject.setScope(e.valueOf("@scope"));
          cacheObject.setTime(toInt(e.valueOf("@time")));
          url_cacheObject.put(cacheObject.getUrl(), cacheObject);
        }
      }
    }
    catch (Exception de) {
      de.printStackTrace();
    }
  }

  private int toInt(String a) {
    return Integer.parseInt(a);
  }

  public static Map getCachePaths(InputStream xmlIs) {
    if (!read_flag) {
      instance.readCachePaths(xmlIs);
      read_flag = true;
    }
    return url_cacheObject;
  }
}
/*
  public static Map getCacheURLs() {
    if (!read_flag) {
      File f = new File(
          ResourceReader.getAPP_HOME() + "config/WebController.xml");
      if (f.exists()) {
        CacheConfig.getInstance().readCacheURLs(f);
      }
      read_flag = true;
    }
    return url_cacheAttr;
  }
 */

ConfigHelper 配置文件辅助类

using System; using System.Globalization; using System.IO; using System.Security; using System.Secur...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:ConfigHelper
举报原因:
原因补充:

(最多只允许输入30个字)