import javax.jcr.RepositoryException;
-import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.jackrabbit.core.RepositoryContext;
public class RepositoryBuilder {
private final static Log log = LogFactory.getLog(RepositoryBuilder.class);
- public RepositoryContext createRepositoryContext(Dictionary<String, ?> properties) throws RepositoryException {
+ public RepositoryContext createRepositoryContext(Dictionary<String, ?> properties)
+ throws RepositoryException, IOException {
RepositoryConfig repositoryConfig = createRepositoryConfig(properties);
RepositoryContext repositoryContext = createJackrabbitRepository(repositoryConfig);
RepositoryImpl repository = repositoryContext.getRepository();
return repositoryContext;
}
- RepositoryConfig createRepositoryConfig(Dictionary<String, ?> properties) throws RepositoryException {
+ RepositoryConfig createRepositoryConfig(Dictionary<String, ?> properties) throws RepositoryException, IOException {
JackrabbitType type = JackrabbitType.valueOf(prop(properties, RepoConf.type).toString());
ClassLoader cl = getClass().getClassLoader();
- InputStream in = null;
- try {
- final String base = "/org/argeo/cms/internal/jcr";
- in = cl.getResourceAsStream(base + "/repository-" + type.name() + ".xml");
-
+ final String base = "/org/argeo/cms/internal/jcr";
+ try (InputStream in = cl.getResourceAsStream(base + "/repository-" + type.name() + ".xml")) {
if (in == null)
throw new ArgeoJcrException("Repository configuration not found");
InputSource config = new InputSource(in);
Properties jackrabbitVars = getConfigurationProperties(type, properties);
RepositoryConfig repositoryConfig = RepositoryConfig.create(config, jackrabbitVars);
return repositoryConfig;
- } finally {
- IOUtils.closeQuietly(in);
}
}
}
} else {
try {
- homePath = Paths.get(new URI(homeUri)).toAbsolutePath();
+ URI uri = new URI(homeUri);
+ String host = uri.getHost();
+ if (host == null || host.trim().equals("")) {
+ homePath = Paths.get(uri).toAbsolutePath();
+ } else {
+ // TODO remote at this stage?
+ throw new IllegalArgumentException("Cannot manage repository path for host " + host);
+ }
} catch (URISyntaxException e) {
throw new CmsException("Invalid repository home URI", e);
}
RepositoryContext repositoryContext = RepositoryContext.create(repositoryConfig);
double duration = ((double) (System.currentTimeMillis() - begin)) / 1000;
- if (log.isTraceEnabled())
- log.trace(
+ if (log.isDebugEnabled())
+ log.debug(
"Created Jackrabbit repository in " + duration + " s, home: " + repositoryConfig.getHomeDir());
return repositoryContext;