Beispiel #1
0
 public static boolean loadConfig(String configFilePath) {
   String tmp = System.getProperty("os.name").toLowerCase();
   if (tmp.startsWith("windows")) {
     g.os = g.OS_WINDOWS;
   } else if (tmp.startsWith("linux")) {
     g.os = g.OS_LINUX;
   } else {
     g.os = g.OS_OTHER;
   }
   tmp = System.getProperty("sun.arch.data.model");
   if (tmp.equals("64")) {
     g.arch = g.ARCH_64;
   } else {
     g.arch = g.ARCH_32;
   }
   try {
     if (configFilePath == null) {
       config = new XMLConfiguration(configPath + "config.xml");
     } else {
       config = new XMLConfiguration(configFilePath);
     }
     dbConfig = config.getString("db", "").toLowerCase();
     siteUrl = config.getString("serverInfo.siteUrl");
     siteName = config.getString("serverInfo.siteName");
     uploadTemp = rootPath + config.getString("serverInfo.uploadTemp");
     uploadSizeMax = config.getLong("serverInfo.uploadSizeMax", 0);
     sessionExpiredTime = config.getInt("serverInfo.sessionExpiredTime", 0);
     sessionIdName = config.getString("serverInfo.sessionIdName", "ycsid");
     String _s = g.getConfig().getString("startup");
     if ("".equals(_s)) {
       startup = null;
     } else {
       _s = _s.replaceAll("\\s", "");
       startup = _s.split(";");
     }
     _s = null;
     // 加载全局参数
     List<HierarchicalConfiguration> fields = config.configurationsAt("globalVars.var");
     if (fields != null && fields.size() > 0) {
       vars = new String[fields.size()][2];
       HierarchicalConfiguration sub;
       for (int i = 0; i < fields.size(); i++) {
         sub = fields.get(i);
         vars[i][0] = sub.getString("[@name]");
         vars[i][1] = sub.getString("[@value]");
       }
       sub = null;
     }
     return true;
   } catch (ConfigurationException e) {
     return false;
   }
 }
 @Override
 public void loadFromXML(Reader in) throws IOException {
   try {
     XMLConfiguration xml = ConfigurationUtil.newXMLConfiguration(in);
     defaultDelay = xml.getLong("[@default]", defaultDelay);
     ignoreRobotsCrawlDelay = xml.getBoolean("[@ignoreRobotsCrawlDelay]", ignoreRobotsCrawlDelay);
     scope = xml.getString("[@scope]", SCOPE_CRAWLER);
     List<HierarchicalConfiguration> nodes = xml.configurationsAt("schedule");
     for (HierarchicalConfiguration node : nodes) {
       schedules.add(
           new DelaySchedule(
               node.getString("[@dayOfWeek]", null),
               node.getString("[@dayOfMonth]", null),
               node.getString("[@time]", null),
               node.getLong("", DEFAULT_DELAY)));
     }
   } catch (ConfigurationException e) {
     throw new IOException("Cannot load XML.", e);
   }
 }