import java.util.List;
import java.util.Map;
+import javax.jcr.Credentials;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.Repository;
private BundleContext bundleContext;
+ /**
+ * Explicitly set admin credentials used in initialization. Useful for
+ * testing, in real applications authentication is rather dealt with
+ * externally
+ */
+ private Credentials adminCredentials = null;
+
/**
* Empty constructor, {@link #init()} should be called after properties have
* been set
if ((cndFiles == null || cndFiles.size() == 0)
&& (namespaces == null || namespaces.size() == 0))
return;
-
+
Session session = null;
try {
- session = login();
+ session = login(adminCredentials);
// register namespaces
if (namespaces.size() > 0) {
NamespaceHelper namespaceHelper = new NamespaceHelper(session);
// load CND files from classpath or as URL
for (String resUrl : cndFiles) {
- boolean classpath;
- // normalize URL
- if (resUrl.startsWith("classpath:")) {
- resUrl = resUrl.substring("classpath:".length());
- classpath = true;
- } else if (resUrl.indexOf(':') < 0) {
- if (!resUrl.startsWith("/")) {
- resUrl = "/" + resUrl;
- log.warn("Classpath should start with '/'");
- }
- // resUrl = "classpath:" + resUrl;
- classpath = true;
- } else {
- classpath = false;
- }
-
URL url;
Bundle dataModelBundle = null;
- if (classpath) {
- if (bundleContext != null) {
- Bundle currentBundle = bundleContext.getBundle();
- url = currentBundle.getResource(resUrl);
- if (url != null) {// found
- dataModelBundle = findDataModelBundle(resUrl);
+
+ {// TODO put this in a separate method
+ boolean classpath;
+ // normalize URL
+ if (bundleContext != null
+ && resUrl.startsWith("classpath:")) {
+ resUrl = resUrl.substring("classpath:".length());
+ classpath = true;
+ } else if (resUrl.indexOf(':') < 0) {
+ if (!resUrl.startsWith("/")) {
+ resUrl = "/" + resUrl;
+ log.warn("Classpath should start with '/'");
}
+ // resUrl = "classpath:" + resUrl;
+ classpath = true;
} else {
- url = getClass().getClassLoader().getResource(resUrl);
- // if (url == null)
- // url = Thread.currentThread()
- // .getContextClassLoader()
- // .getResource(resUrl);
+ classpath = false;
}
- } else {
- url = new URL(resUrl);
- }
+ if (classpath) {
+ if (bundleContext != null) {
+ Bundle currentBundle = bundleContext.getBundle();
+ url = currentBundle.getResource(resUrl);
+ if (url != null) {// found
+ dataModelBundle = findDataModelBundle(resUrl);
+ }
+ } else {
+ resUrl = "classpath:" + resUrl;
+ url = null;
+ // url =
+ // getClass().getClassLoader().getResource(resUrl);
+ // if (url == null)
+ // url = Thread.currentThread()
+ // .getContextClassLoader()
+ // .getResource(resUrl);
+ }
+ } else if (!resUrl.startsWith("classpath:")) {
+ url = new URL(resUrl);
+ } else {
+ url = null;
+ }
+ }
// check existing data model nodes
new NamespaceHelper(session).registerNamespace(
ArgeoNames.ARGEO, ArgeoNames.ARGEO_NAMESPACE);
this.resourceLoader = resourceLoader;
}
+ public void setAdminCredentials(Credentials adminCredentials) {
+ this.adminCredentials = adminCredentials;
+ }
+
}