X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=server%2Fplugins%2Forg.argeo.jcr.ui.explorer%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fjcr%2Fui%2Fexplorer%2Fcommands%2FAddRemoteRepository.java;h=818b6b6fee6ff7e205054d6d475fe5ce718cf416;hb=1d5afdce3e91054f07ddd3c98309c363b4cf1d46;hp=f784bb6985af2d20a8931ee37c6e14189c02e6ed;hpb=30fe2e93369b30c5ebb644413fe181e2940192cc;p=lgpl%2Fargeo-commons.git diff --git a/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/commands/AddRemoteRepository.java b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/commands/AddRemoteRepository.java index f784bb698..818b6b6fe 100644 --- a/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/commands/AddRemoteRepository.java +++ b/server/plugins/org.argeo.jcr.ui.explorer/src/main/java/org/argeo/jcr/ui/explorer/commands/AddRemoteRepository.java @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2007-2012 Mathieu Baudier + * + * 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.jcr.ui.explorer.commands; import java.net.URI; @@ -9,6 +24,7 @@ import javax.jcr.RepositoryFactory; import javax.jcr.Session; import javax.jcr.SimpleCredentials; +import org.argeo.ArgeoException; import org.argeo.eclipse.ui.ErrorFeedback; import org.argeo.jcr.ArgeoJcrConstants; import org.argeo.jcr.ArgeoNames; @@ -53,29 +69,30 @@ public class AddRemoteRepository extends AbstractHandler implements 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 params = new Hashtable(); + 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(); + // uri = dlg.getUri(); } } - if (uri == null) - return null; - - try { - Hashtable params = new Hashtable(); - 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); - } return null; } @@ -92,9 +109,8 @@ public class AddRemoteRepository extends AbstractHandler implements } class RemoteRepositoryLoginDialog extends TitleAreaDialog { - private String uri; private Text name; - private Text uriText; + private Text uri; private Text username; private Text password; @@ -116,7 +132,7 @@ public class AddRemoteRepository extends AbstractHandler implements false)); setMessage("Login to remote repository", IMessageProvider.NONE); name = createLT(composite, "Name", "remoteRepository"); - uriText = createLT(composite, "URI", + uri = createLT(composite, "URI", "http://localhost:7070/org.argeo.jcr.webapp/remoting/node"); username = createLT(composite, "User", ""); password = createLP(composite, "Password"); @@ -138,7 +154,7 @@ public class AddRemoteRepository extends AbstractHandler implements void testConnection() { Session session = null; try { - URI checkedUri = new URI(uriText.getText()); + URI checkedUri = new URI(uri.getText()); String checkedUriStr = checkedUri.toString(); Hashtable params = new Hashtable(); @@ -157,12 +173,11 @@ public class AddRemoteRepository extends AbstractHandler implements username.getText(), pwd); session = repository.login(sc); MessageDialog.openInformation(getParentShell(), "Success", - "Connection to '" + uriText.getText() - + "' successful"); + "Connection to '" + uri.getText() + "' successful"); } } catch (Exception e) { ErrorFeedback.show( - "Connection test failed for " + uriText.getText(), e); + "Connection test failed for " + uri.getText(), e); } finally { JcrUtils.logoutQuietly(session); } @@ -175,19 +190,26 @@ public class AddRemoteRepository extends AbstractHandler implements Node home = JcrUtils.getUserHome(nodeSession); Node remote = home.hasNode(ARGEO_REMOTE) ? home .getNode(ARGEO_REMOTE) : home.addNode(ARGEO_REMOTE); + if (remote.hasNode(name.getText())) + throw new ArgeoException( + "There is already a remote repository named " + + name.getText()); Node remoteRepository = remote.addNode(name.getText(), ArgeoTypes.ARGEO_REMOTE_REPOSITORY); - remoteRepository.setProperty(ARGEO_URI, uriText.getText()); + remoteRepository.setProperty(ARGEO_URI, uri.getText()); remoteRepository.setProperty(ARGEO_USER_ID, username.getText()); Node pwd = remoteRepository.addNode(ARGEO_PASSWORD); keyring.set(pwd.getPath(), password.getText().toCharArray()); nodeSession.save(); + MessageDialog.openInformation( + getParentShell(), + "Repository Added", + "Remote repository '" + username.getText() + "@" + + uri.getText() + "' added"); + super.okPressed(); } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); + ErrorFeedback.show("Cannot add remote repository", e); } - uri = uriText.getText(); - super.okPressed(); } /** Creates label and text. */ @@ -206,9 +228,5 @@ public class AddRemoteRepository extends AbstractHandler implements text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); return text; } - - public String getUri() { - return uri; - } } }