-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed 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.argeo.cms.internal.kernel;
import java.net.URI;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.jackrabbit.jcr2dav.Jcr2davRepositoryFactory;
-import org.argeo.jcr.ArgeoJcrException;
-import org.argeo.node.NodeConstants;
+import org.argeo.api.NodeConstants;
+import org.argeo.cms.internal.jcr.RepoConf;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
-import org.springframework.core.io.Resource;
/**
* OSGi-aware Jackrabbit repository factory which can retrieve/publish
Collection<ServiceReference<Repository>> srs = bundleContext.getServiceReferences(Repository.class,
"(" + NodeConstants.CN + "=" + alias + ")");
if (srs.size() == 0)
- throw new ArgeoJcrException("No repository with alias " + alias + " found in OSGi registry");
+ throw new IllegalArgumentException("No repository with alias " + alias + " found in OSGi registry");
else if (srs.size() > 1)
- throw new ArgeoJcrException(
+ throw new IllegalArgumentException(
srs.size() + " repositories with alias " + alias + " found in OSGi registry");
return bundleContext.getService(srs.iterator().next());
} catch (InvalidSyntaxException e) {
- throw new ArgeoJcrException("Cannot find repository with alias " + alias, e);
+ throw new IllegalArgumentException("Cannot find repository with alias " + alias, e);
}
}
// check if remote
Repository repository;
String uri = null;
- if (parameters.containsKey(NodeConstants.LABELED_URI))
+ if (parameters.containsKey(RepoConf.labeledUri.name()))
uri = parameters.get(NodeConstants.LABELED_URI).toString();
else if (parameters.containsKey(KernelConstants.JACKRABBIT_REPOSITORY_URI))
uri = parameters.get(KernelConstants.JACKRABBIT_REPOSITORY_URI).toString();
if (uri != null) {
- if (uri.startsWith("http"))// http, https
- repository = createRemoteRepository(uri);
- else if (uri.startsWith("file"))// http, https
+ if (uri.startsWith("http")) {// http, https
+ Object defaultWorkspace = parameters.get(RepoConf.defaultWorkspace.name());
+ repository = createRemoteRepository(uri, defaultWorkspace != null ? defaultWorkspace.toString() : null);
+ } else if (uri.startsWith("file"))// http, https
repository = createFileRepository(uri, parameters);
else if (uri.startsWith("vm")) {
// log.warn("URI " + uri + " should have been managed by generic
// JCR repository factory");
repository = getRepositoryByAlias(getAliasFromURI(uri));
} else
- throw new ArgeoJcrException("Unrecognized URI format " + uri);
+ throw new IllegalArgumentException("Unrecognized URI format " + uri);
}
// with properties " + properties);
repository = getRepositoryByAlias(alias);
} else
- throw new ArgeoJcrException("Not enough information in " + parameters);
+ throw new IllegalArgumentException("Not enough information in " + parameters);
if (repository == null)
- throw new ArgeoJcrException("Repository not found " + parameters);
+ throw new IllegalArgumentException("Repository not found " + parameters);
return repository;
}
- protected Repository createRemoteRepository(String uri) throws RepositoryException {
+ protected Repository createRemoteRepository(String uri, String defaultWorkspace) throws RepositoryException {
Map<String, String> params = new HashMap<String, String>();
params.put(KernelConstants.JACKRABBIT_REPOSITORY_URI, uri);
+ if (defaultWorkspace != null)
+ params.put(KernelConstants.JACKRABBIT_REMOTE_DEFAULT_WORKSPACE, defaultWorkspace);
Repository repository = new Jcr2davRepositoryFactory().getRepository(params);
if (repository == null)
- throw new ArgeoJcrException("Remote Davex repository " + uri + " not found");
+ throw new IllegalArgumentException("Remote Davex repository " + uri + " not found");
log.info("Initialized remote Jackrabbit repository from uri " + uri);
return repository;
}
alias = alias.substring(0, alias.length() - 1);
return alias;
} catch (URISyntaxException e) {
- throw new ArgeoJcrException("Cannot interpret URI " + uri, e);
+ throw new IllegalArgumentException("Cannot interpret URI " + uri, e);
}
}
/**
- * Called after the repository has been initialised. Does nothing by
- * default.
+ * 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;
- }
-
}