Exemplo n.º 1
0
  @SuppressWarnings("unchecked")
  private void initProperty() throws Exception, IOException {
    InputStream in = null;
    if (_prop == null) {
      _prop = new Properties();
      try {
        in = ClassLoader.getSystemResourceAsStream("config.properties");
        _prop.load(in);

        File localFile = new File(".", "config.properties");
        if (localFile.exists()) {
          System.out.println("load local configuration :" + localFile.getAbsolutePath());
          // override
          in.close();
          in = null;
          in = new FileInputStream(localFile);
          _prop.load(in);
          in.close();
          in = null;
        }

        _openonce = Boolean.parseBoolean(_prop.getProperty("openonce", "false"));
        System.out.println("openonce=" + _openonce);
        _lastModified =
            new File(ClassLoader.getSystemResource("config.properties").getFile()).lastModified();
        _client = _prop.getProperty("client");
        _server = _prop.getProperty("server");
        _contextPath = _prop.getProperty("context-path");
        _action = _prop.getProperty("action");
        _delay = _prop.getProperty("delay");
        _browser = _prop.getProperty("browser");
        _timeout = _prop.getProperty("timeout");
        _imgsrc = _prop.getProperty("imgsrc");
        _imgdest = _prop.getProperty("imgdest");
        _comparable = Boolean.parseBoolean(_prop.getProperty("comparable", "false"));
        _granularity = Integer.parseInt(_prop.getProperty("granularity"));
        _leniency = Integer.parseInt(_prop.getProperty("leniency"));
        for (Iterator iter = _prop.entrySet().iterator(); iter.hasNext(); ) {
          final Map.Entry setting = (Map.Entry) iter.next();
          String strKey = (String) setting.getKey();
          if (isBrowserSetting(strKey)) {
            addBrowserNameSetting(strKey, (String) setting.getValue());
            continue;
          }
        }

        String[] allBrowsers = _prop.getProperty(ALL_BROWSERS).split(",");
        for (String browser : allBrowsers) {
          String browserKey = browser.trim();
          // if (_browserNameMap.containsKey(browserKey)) {
          // _allBrowsers.add(browserKey);
          // }

          for (String key : _browserNameMap.keySet()) {
            if (browserKey.toLowerCase().startsWith(key)) {
              _allBrowsers.add(browserKey);
              break;
            }
          }

          String frames = _prop.getProperty(browserKey + "-frame");
          if (frames != null) {
            Integer[] sizes = new Integer[4];
            String[] sz = frames.split(",");
            for (int i = 0; i < sz.length; i++) sizes[i] = Integer.parseInt(sz[i]);
            _frames.put(browserKey, sizes);
            System.out.println(browserKey + "-frame:" + Arrays.asList(sizes));
          }
        }
      } finally {
        if (in != null) {
          in.close();
        }
      }
    }
  }