+ protected Repository createRemoteRepository(String uri)
+ throws RepositoryException {
+ Map<String, String> params = new HashMap<String, String>();
+ params.put(JcrUtils.REPOSITORY_URI, uri);
+ Repository repository = new Jcr2davRepositoryFactory()
+ .getRepository(params);
+ if (repository == null)
+ throw new ArgeoException("Remote Davex repository " + uri
+ + " not found");
+ log.info("Initialized remote Jackrabbit repository from uri " + uri);
+ return repository;
+ }
+
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ protected Repository createFileRepository(final String uri, Map parameters)
+ throws RepositoryException {
+ InputStream configurationIn = null;
+ try {
+ Properties vars = new Properties();
+ vars.putAll(parameters);
+ String dirPath = uri.substring("file:".length());
+ File homeDir = new File(dirPath);
+ if (homeDir.exists() && !homeDir.isDirectory())
+ throw new ArgeoException("Repository home " + dirPath
+ + " is not a directory");
+ if (!homeDir.exists())
+ homeDir.mkdirs();
+ configurationIn = fileRepositoryConfiguration.getInputStream();
+ vars.put(RepositoryConfigurationParser.REPOSITORY_HOME_VARIABLE,
+ homeDir.getCanonicalPath());
+ RepositoryConfig repositoryConfig = RepositoryConfig.create(
+ new InputSource(configurationIn), vars);
+
+ // TransientRepository repository = new
+ // TransientRepository(repositoryConfig);
+ final RepositoryImpl repository = RepositoryImpl
+ .create(repositoryConfig);
+ Session session = repository.login();
+ // FIXME make it generic
+ org.argeo.jcr.JcrUtils.addPrivilege(session, "/", "ROLE_ADMIN",
+ "jcr:all");
+ org.argeo.jcr.JcrUtils.logoutQuietly(session);
+ Runtime.getRuntime().addShutdownHook(
+ new Thread("Clean JCR repository " + uri) {
+ public void run() {
+ repository.shutdown();
+ log.info("Destroyed repository " + uri);
+ }
+ });
+ log.info("Initialized file Jackrabbit repository from uri " + uri);
+ return repository;
+ } catch (Exception e) {
+ throw new ArgeoException("Cannot create repository " + uri, e);
+ } finally {
+ IOUtils.closeQuietly(configurationIn);
+ }
+ }
+
+ /**
+ * Called after the repository has been initialised. Does nothing by
+ * default.
+ */
+ @SuppressWarnings("rawtypes")
+ protected void postInitialization(Repository repository, Map parameters) {
+
+ }
+
+ public void setFileRepositoryConfiguration(
+ Resource fileRepositoryConfiguration) {
+ this.fileRepositoryConfiguration = fileRepositoryConfiguration;
+ }
+