示例#1
0
 /**
  * remove Registry url to url list and update the file
  *
  * @param info
  */
 public void removeRegistryUrl(RegistryURLInfo info) {
   if (urlList.contains(info)) {
     urlList.remove(info);
     saveUrlsToFile();
     removeRegistryPropertyFile(info.getUrl().getHost() + "." + info.getUrl().getPort());
   }
 }
示例#2
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;
 }
示例#3
0
  public void modifyRegistryUrl(String registryUrl, String username, String oldUser) {

    Iterator<RegistryURLInfo> iterator = urlList.iterator();
    while (iterator.hasNext()) {
      RegistryURLInfo reginfo = iterator.next();
      if (registryUrl.equals(reginfo.getUrl().toString())
          && (oldUser == null || oldUser.equals(reginfo.getUsername()))) {
        reginfo.setUsername(username);
      }
    }
    saveUrlsToFile();
  }
示例#4
0
 /** save newly added registry url to the url file */
 private void saveUrlsToFile() {
   if (urlListFile.exists()) {
     urlListFile.delete();
   }
   if (!urlListFile.getParentFile().exists()) {
     urlListFile.getParentFile().mkdirs();
   }
   Writer output = null;
   try {
     output = new BufferedWriter(new FileWriter(urlListFile));
     for (RegistryURLInfo registryURLInfo : urlList) {
       try {
         output.write(
             registryURLInfo.getUrl().toString()
                 + " "
                 + Boolean.toString(registryURLInfo.isEnabled())
                 + " "
                 + registryURLInfo.getUsername()
                 + " "
                 + registryURLInfo.getPath()
                 + "\n");
       } catch (IOException e) {
         log.error(e);
       }
     }
   } catch (IOException e) {
     log.error(e);
   } finally {
     if (output != null)
       try {
         output.close();
       } catch (IOException e) {
         log.error(e);
       }
   }
 }
示例#5
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();
      }
    }
  }