Example #1
0
 @Override
 public synchronized boolean updateIfChanged(String identifier)
     throws IOException, RegistryException {
   // identify installed vocabulary by identifier
   Vocabulary installed = get(identifier);
   if (installed != null) {
     // match vocabulary by identifier and issued date
     Vocabulary matched = null;
     for (Vocabulary v : registryManager.getVocabularies()) {
       if (v.getUriString() != null
           && v.getUriString().equalsIgnoreCase(identifier)
           && installed.getIssued() != null
           && v.getIssued() != null
           && installed.getIssued().compareTo(v.getIssued()) == 0) {
         matched = v;
         break;
       }
     }
     // verify the version was updated
     if (matched != null && matched.getUriResolvable() != null) {
       File vocabFile = getVocabFile(matched.getUriResolvable());
       return downloader.downloadIfChanged(matched.getUriResolvable().toURL(), vocabFile);
     }
   }
   return false;
 }
Example #2
0
 /**
  * Download a vocabulary into temporary file and return it.
  *
  * @param url URL of vocabulary to download
  * @return temporary file vocabulary was downloaded to, or null if it failed to be downloaded
  */
 private File download(URL url) throws IOException {
   Preconditions.checkNotNull(url);
   String filename = url.toString().replaceAll("[/:.]+", "_") + ".xml";
   File tmpFile = dataDir.tmpFile(filename);
   StatusLine statusLine = downloader.download(url, tmpFile);
   if (success(statusLine)) {
     log.info("Successfully downloaded vocabulary: " + url.toString());
     return tmpFile;
   } else {
     String msg =
         "Failed to download vocabulary: "
             + url.toString()
             + ". Response="
             + String.valueOf(statusLine.getStatusCode());
     log.error(msg);
     throw new IOException(msg);
   }
 }