/*
- * Copyright (C) 2007-2012 Mathieu Baudier
+ * 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.
import org.argeo.ArgeoException;
import org.argeo.eclipse.ui.ErrorFeedback;
+import org.argeo.eclipse.ui.utils.CommandUtils;
import org.argeo.jcr.ArgeoJcrConstants;
import org.argeo.jcr.ArgeoNames;
import org.argeo.jcr.ArgeoTypes;
import org.argeo.jcr.JcrUtils;
-import org.argeo.jcr.security.JcrKeyring;
+import org.argeo.jcr.UserJcrUtils;
import org.argeo.jcr.ui.explorer.JcrExplorerConstants;
+import org.argeo.util.security.Keyring;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
-import org.osgi.framework.BundleContext;
/**
* Connect to a remote repository and, if successful publish it as an OSGi
JcrExplorerConstants, ArgeoNames {
private RepositoryFactory repositoryFactory;
- private BundleContext bundleContext;
-
- private JcrKeyring keyring;
+ private Repository nodeRepository;
+ private Keyring keyring;
public Object execute(ExecutionEvent event) throws ExecutionException {
- String uri = null;
- if (event.getParameters().containsKey(PARAM_REPOSITORY_URI)) {
- // FIXME remove this
- uri = event.getParameter(PARAM_REPOSITORY_URI);
- if (uri == null)
- return null;
-
- try {
- Hashtable<String, String> params = new Hashtable<String, String>();
- params.put(ArgeoJcrConstants.JCR_REPOSITORY_URI, uri);
- // by default we use the URI as alias
- params.put(ArgeoJcrConstants.JCR_REPOSITORY_ALIAS, uri);
- Repository repository = repositoryFactory.getRepository(params);
- bundleContext.registerService(Repository.class.getName(),
- repository, params);
- } catch (Exception e) {
- ErrorFeedback.show("Cannot add remote repository " + uri, e);
- }
- } else {
- RemoteRepositoryLoginDialog dlg = new RemoteRepositoryLoginDialog(
- Display.getDefault().getActiveShell());
- if (dlg.open() == Dialog.OK) {
- // uri = dlg.getUri();
- }
+ RemoteRepositoryLoginDialog dlg = new RemoteRepositoryLoginDialog(
+ Display.getDefault().getActiveShell());
+ if (dlg.open() == Dialog.OK) {
+ CommandUtils.callCommand(Refresh.ID);
}
-
return null;
}
this.repositoryFactory = repositoryFactory;
}
- public void setBundleContext(BundleContext bundleContext) {
- this.bundleContext = bundleContext;
+ public void setKeyring(Keyring keyring) {
+ this.keyring = keyring;
}
- public void setKeyring(JcrKeyring keyring) {
- this.keyring = keyring;
+ public void setNodeRepository(Repository nodeRepository) {
+ this.nodeRepository = nodeRepository;
}
class RemoteRepositoryLoginDialog extends TitleAreaDialog {
setMessage("Login to remote repository", IMessageProvider.NONE);
name = createLT(composite, "Name", "remoteRepository");
uri = createLT(composite, "URI",
- "http://localhost:7070/org.argeo.jcr.webapp/remoting/node");
+ "http://localhost:7070/data/jcr/node");
username = createLT(composite, "User", "");
password = createLP(composite, "Password");
Hashtable<String, String> params = new Hashtable<String, String>();
params.put(ArgeoJcrConstants.JCR_REPOSITORY_URI, checkedUriStr);
- // by default we use the URI as alias
- params.put(ArgeoJcrConstants.JCR_REPOSITORY_ALIAS,
- checkedUriStr);
Repository repository = repositoryFactory.getRepository(params);
if (username.getText().trim().equals("")) {// anonymous
session = repository.login();
@Override
protected void okPressed() {
+ Session nodeSession = null;
try {
- Session nodeSession = keyring.getSession();
- Node home = JcrUtils.getUserHome(nodeSession);
-
- // FIXME better deal with non existing home dir
- if (home == null)
- home = JcrUtils.createUserHomeIfNeeded(nodeSession,
- nodeSession.getUserID());
+ nodeSession = nodeRepository.login();
+ Node home = UserJcrUtils.getUserHome(nodeSession);
Node remote = home.hasNode(ARGEO_REMOTE) ? home
.getNode(ARGEO_REMOTE) : home.addNode(ARGEO_REMOTE);
ArgeoTypes.ARGEO_REMOTE_REPOSITORY);
remoteRepository.setProperty(ARGEO_URI, uri.getText());
remoteRepository.setProperty(ARGEO_USER_ID, username.getText());
- Node pwd = remoteRepository.addNode(ARGEO_PASSWORD);
- pwd.getSession().save();
- if (saveInKeyring.getSelection())
- keyring.set(pwd.getPath(), password.getText().toCharArray());
- keyring.getSession().save();
+ nodeSession.save();
+ if (saveInKeyring.getSelection()) {
+ String pwdPath = remoteRepository.getPath() + '/'
+ + ARGEO_PASSWORD;
+ keyring.set(pwdPath, password.getText().toCharArray());
+ }
+ nodeSession.save();
MessageDialog.openInformation(
getParentShell(),
"Repository Added",
super.okPressed();
} catch (Exception e) {
ErrorFeedback.show("Cannot add remote repository", e);
+ } finally {
+ JcrUtils.logoutQuietly(nodeSession);
}
}