+ // remote repository
+ if (uri != null && !uri.trim().equals("")) {
+ Map<String, String> params = new HashMap<String, String>();
+ params.put(
+ org.apache.jackrabbit.commons.JcrUtils.REPOSITORY_URI,
+ uri);
+ repository = (JackrabbitRepository) new Jcr2davRepositoryFactory()
+ .getRepository(params);
+ if (repository == null)
+ throw new ArgeoException("Remote Davex repository " + uri
+ + " not found");
+ log.info("Initialized Jackrabbit repository " + repository
+ + " from URI " + uri);
+ // do not perform further initialization since we assume that
+ // the
+ // remote repository has been properly configured
+ return repository;
+ }
+
+ // local repository
+ if (inMemory && getHome().exists()) {
+ FileUtils.deleteDirectory(getHome());
+ log.warn("Deleted Jackrabbit home directory " + getHome());
+ }
+
+ RepositoryConfig config;
+ Properties vars = getConfigurationProperties();
+ InputStream in = configuration.getInputStream();
+ try {
+ vars.put(
+ RepositoryConfigurationParser.REPOSITORY_HOME_VARIABLE,
+ getHome().getCanonicalPath());
+ config = RepositoryConfig.create(new InputSource(in), vars);
+ } catch (Exception e) {
+ throw new RuntimeException("Cannot read configuration", e);
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+
+ if (inMemory)
+ repository = new TransientRepository(config);
+ else
+ repository = RepositoryImpl.create(config);
+
+ log.info("Initialized Jackrabbit repository " + repository + " in "
+ + getHome() + " with config " + configuration);
+
+ return repository;