public IBundleRepository createRepository(String id, Properties preferences)
throws RepositoryException
{
String urlStr = preferences.getProperty("url");
if (urlStr == null)
throw new RepositoryException("url is not specified.");
try
{
File urlFile = new File(urlStr);
URL repositoryURL = urlFile.exists() ? urlFile.toURI().toURL() : new URL(
urlStr);
URL testURL = urlFile.exists() ? urlFile.toURI().toURL() : new URL(urlStr);
File indexCache = new File(preferences.getProperty(INDEX_CACHE_FILE));
File localCache = new File(preferences.getProperty(CACHE_DIRECTORY));
String auth = preferences.getProperty(AUTH_FILE);
File authFile = auth == null ? null : new File(auth);
Long up = preferences.containsKey(UPDATE_PERIOD) ? Long.parseLong(preferences.getProperty(UPDATE_PERIOD))
: 60 * 60 * 24 * 7;
boolean offline = preferences.containsKey(OFFLINE) ? Boolean.parseBoolean(preferences.getProperty(OFFLINE)) : false;
if (!offline && testURL.openConnection().getLastModified() == 0)
{
String msg = "Failed to read OBR index: ";
if (!indexCache.exists())
throw new RepositoryException(msg + urlStr);
System.err.println("WARNING: " + msg + "using cache: " + urlStr);
}
long updatePeriod = TimeUnit.MILLISECONDS.convert(up, TimeUnit.SECONDS);
if (preferences.getProperty(IN_MEMORY) == null)
{
return new NonCachingOBRBundleRepository(id, repositoryURL, indexCache,
localCache, updatePeriod, authFile, offline);
}
else
{
return new CachingOBRBundleRepository(id, repositoryURL, indexCache,
localCache, updatePeriod, authFile, offline);
}
}
catch (IOException e)
{
throw new RepositoryException(id + ": invalid repository url:" + urlStr, e);
}
}