blob: 4653d389e7be62cc081a66cd671b8ae4791e9018 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.cauldron.bld.obr;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.cauldron.sigil.repository.IBundleRepository;
import org.cauldron.sigil.repository.IRepositoryProvider;
import org.cauldron.sigil.repository.RepositoryException;
public class OBRRepositoryProvider implements IRepositoryProvider {
public IBundleRepository createRepository(String id, Properties preferences) throws RepositoryException {
try {
URL repositoryURL = new URL( preferences.getProperty("url") );
File indexCache = new File( preferences.getProperty("index") );
File localCache = new File( preferences.getProperty("cache") );
// TODO create user configurable updatePeriod
long updatePeriod = TimeUnit.MILLISECONDS.convert(60*60*24*7, TimeUnit.SECONDS);
if ( preferences.getProperty("inmemory") == null ) {
return new NonCachingOBRBundleRepository(id, repositoryURL, indexCache, localCache, updatePeriod);
}
else {
return new CachingOBRBundleRepository(id, repositoryURL, indexCache, localCache, updatePeriod);
}
}
catch (MalformedURLException e) {
throw new RepositoryException("Invalid repository url", e);
}
}
}