Esempio n. 1
0
 protected boolean loadConfigurationFromProvider() throws IOException {
   // TODO use a OSGi service for this.
   Iterable<URL> provider = Environment.getDefault().getConfigurationProvider();
   if (provider == null) {
     return false;
   }
   Iterator<URL> it = provider.iterator();
   ArrayList<URL> props = new ArrayList<>();
   ArrayList<URL> xmls = new ArrayList<>();
   while (it.hasNext()) {
     URL url = it.next();
     String path = url.getPath();
     if (path.endsWith("-config.xml")) {
       xmls.add(url);
     } else if (path.endsWith(".properties")) {
       props.add(url);
     }
   }
   Comparator<URL> comp =
       new Comparator<URL>() {
         @Override
         public int compare(URL o1, URL o2) {
           return o1.getPath().compareTo(o2.getPath());
         }
       };
   Collections.sort(xmls, comp);
   for (URL url : props) {
     loadProperties(url);
   }
   for (URL url : xmls) {
     context.deploy(url);
   }
   return true;
 }
 public void loadProperties(File file) throws IOException {
   InputStream in = new BufferedInputStream(new FileInputStream(file));
   try {
     loadProperties(in);
   } finally {
     in.close();
   }
 }
 public void loadProperties(URL url) throws IOException {
   InputStream in = url.openStream();
   try {
     loadProperties(in);
   } finally {
     if (in != null) {
       in.close();
     }
   }
 }
  protected void loadConfig() throws Exception {
    Environment env = Environment.getDefault();
    if (env != null) {
      log.info("Configuration: host application: " + env.getHostApplicationName());
    } else {
      log.warn("Configuration: no host application");
    }

    File blacklistFile = new File(env.getConfig(), "blacklist");
    if (blacklistFile.isFile()) {
      List<String> lines = FileUtils.readLines(blacklistFile);
      Set<String> blacklist = new HashSet<String>();
      for (String line : lines) {
        line = line.trim();
        if (line.length() > 0) {
          blacklist.add(line);
        }
      }
      manager.setBlacklist(new HashSet<String>(lines));
    }

    String configDir = bundleContext.getProperty(PROP_CONFIG_DIR);
    if (configDir != null && configDir.contains(":/")) { // an url of a
      // config file
      log.debug("Configuration: " + configDir);
      URL url = new URL(configDir);
      log.debug("Configuration:   loading properties url: " + configDir);
      loadProperties(url);
      return;
    }

    if (env == null) {
      return;
    }

    // TODO: in JBoss there is a deployer that will deploy nuxeo
    // configuration files ..
    boolean isNotJBoss4 = !isJBoss4(env);

    File dir = env.getConfig();
    // File dir = new File(configDir);
    String[] names = dir.list();
    if (names != null) {
      Arrays.sort(
          names,
          new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
              return o1.compareToIgnoreCase(o2);
            }
          });
      for (String name : names) {
        if (name.endsWith("-config.xml") || name.endsWith("-bundle.xml")) {
          // TODO
          // because of some dep bugs (regarding the deployment of
          // demo-ds.xml)
          // we cannot let the runtime deploy config dir at
          // beginning...
          // until fixing this we deploy config dir from
          // NuxeoDeployer
          if (isNotJBoss4) {
            File file = new File(dir, name);
            log.debug("Configuration: deploy config component: " + name);
            context.deploy(file.toURI().toURL());
          }
        } else if (name.endsWith(".config")
            || name.endsWith(".ini")
            || name.endsWith(".properties")) {
          File file = new File(dir, name);
          log.debug("Configuration: loading properties: " + name);
          loadProperties(file);
        } else {
          log.debug("Configuration: ignoring: " + name);
        }
      }
    } else if (dir.isFile()) { // a file - load it
      log.debug("Configuration: loading properties: " + dir);
      loadProperties(dir);
    } else {
      log.debug("Configuration: no configuration file found");
    }

    loadDefaultConfig();
  }