Esempio n. 1
0
 /**
  * add Registry url to url list and save it to the file
  *
  * @param registryUrl
  * @param username
  * @param path
  * @return
  */
 public RegistryURLInfo addRegistryUrl(URL registryUrl, String username, String path) {
   createRegistryPropertyFile(registryUrl.getHost() + "." + registryUrl.getPort());
   RegistryURLInfo info = new RegistryURLInfo();
   info.setUrl(registryUrl);
   info.setPath(path);
   info.setUsername(username);
   if (!urlList.contains(info)) {
     urlList.add(info);
     saveUrlsToFile();
   }
   return info;
 }
Esempio n. 2
0
  /** read added regisrty urls from the temperary file which contains urls of added registries */
  private void readUrlsFromFile() {
    urlList.clear();
    synchronized (urlList) {
      if (!urlListFile.exists()) {
        return;
      }
      StringBuilder contents = new StringBuilder();

      try {
        BufferedReader input = new BufferedReader(new FileReader(urlListFile));
        try {
          String line = null; // not declared within while loop
          while ((line = input.readLine()) != null) {
            int i = line.indexOf(" ");
            if (i > 0) {
              String url = line.substring(0, i).trim();
              String state_uname_path = line.substring(i).trim();
              i = state_uname_path.indexOf(" ");
              if (i > 0) {
                String state = state_uname_path.substring(0, i).trim();
                String uname_path = state_uname_path.substring(i).trim();
                i = uname_path.indexOf(" ");
                if (i > 0) {
                  String uname = uname_path.substring(0, i).trim();
                  String path = uname_path.substring(i).trim();
                  RegistryURLInfo registryURLInfo = new RegistryURLInfo();
                  registryURLInfo.setPersist(false);
                  registryURLInfo.setUrl(new URL(url));
                  registryURLInfo.setPath(path);
                  registryURLInfo.setUsername(uname);
                  registryURLInfo.setEnabled(state.equalsIgnoreCase("true"));
                  urlList.add(registryURLInfo);
                  registryURLInfo.setPersist(true);
                }
              }
            }
            contents.append(line);
            contents.append(System.getProperty("line.separator"));
          }
        } finally {
          input.close();
        }
      } catch (IOException ex) {
        ex.printStackTrace();
      }
    }
  }