From 3a0d866fbeea3f78c293212f4b4fbaeba7dfe2bd Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Fri, 9 Sep 2016 10:40:41 +0000 Subject: [PATCH] Refactor monitor and exceptions git-svn-id: https://svn.argeo.org/commons/trunk@9108 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../org/argeo/cms/AbstractCmsEntryPoint.java | 5 +- .../src/org/argeo/cms/CmsException.java | 4 +- .../argeo/cms/auth/UserAdminLoginModule.java | 4 +- .../org/argeo/cms/forms/FormPageViewer.java | 9 +- .../src/org/argeo/cms/forms/FormUtils.java | 4 +- .../internal/auth/ConsoleCallbackHandler.java | 4 +- .../argeo/cms/internal/auth/LocaleChoice.java | 4 +- .../internal/backup/AbstractAtomicBackup.java | 10 +- .../backup/BackupFileSystemManager.java | 4 +- .../cms/internal/backup/OpenLdapBackup.java | 4 +- .../cms/internal/backup/OsCallBackup.java | 11 +- .../internal/backup/SimpleBackupPurge.java | 4 +- .../cms/internal/backup/SystemBackup.java | 163 +++++++--------- .../cms/internal/kernel/HomeRepository.java | 7 +- .../argeo/cms/internal/kernel/NodeLogger.java | 10 +- .../argeo/cms/internal/kernel/PkiUtils.java | 8 +- .../kernel/RepositoryServiceFactory.java | 6 +- .../src/org/argeo/cms/maintenance/Browse.java | 13 +- .../org/argeo/cms/util/LoginEntryPoint.java | 3 +- .../argeo/cms/util/SystemNotifications.java | 4 +- .../cms/util/useradmin/UserAdminUtils.java | 10 +- .../cms/util/useradmin/UserAdminWrapper.java | 4 +- .../core/AbstractSystemExecution.java | 6 +- .../security/core/SimpleRoleRegistration.java | 6 +- .../eclipse/spring/SpringCommandHandler.java | 4 +- .../spring/SpringExtensionFactory.java | 10 +- .../eclipse/ui/workbench/CommandUtils.java | 4 +- .../ui/workbench/commands/AddPrivileges.java | 4 +- .../commands/AddRemoteRepository.java | 4 +- .../ui/workbench/commands/DeleteNodes.java | 4 +- .../ui/workbench/commands/DumpNode.java | 6 +- .../commands/NodeConfigurableDump.java | 8 +- .../ui/workbench/commands/OpenEditor.java | 4 +- .../workbench/commands/RemovePrivileges.java | 8 +- .../ui/workbench/commands/RenameNode.java | 4 +- .../FullVersioningTreeContentProvider.java | 8 +- .../jcr/GenericNodeDoubleClickListener.java | 6 +- .../internal/jcr/JcrBrowserUtils.java | 4 +- .../internal/jcr/NodeContentProvider.java | 4 +- .../internal/jcr/NodeLabelProvider.java | 4 +- .../jcr/PropertiesContentProvider.java | 4 +- .../internal/jcr/PropertyLabelProvider.java | 6 +- .../jcr/SingleNodeAsTreeContentProvider.java | 8 +- .../internal/jcr/VersionLabelProvider.java | 4 +- .../jcr/model/RemoteRepositoryElem.java | 4 +- .../internal/jcr/model/RepositoriesElem.java | 4 +- .../internal/jcr/model/RepositoryElem.java | 8 +- .../internal/jcr/model/SingleJcrNodeElem.java | 6 +- .../internal/jcr/model/WorkspaceElem.java | 11 +- .../jcr/parts/AbstractJcrQueryEditor.java | 8 +- .../jcr/parts/AddPrivilegeWizard.java | 6 +- .../internal/jcr/parts/ChildNodesPage.java | 6 +- .../jcr/parts/GenericNodeEditorInput.java | 4 +- .../internal/jcr/parts/GenericNodePage.java | 12 +- .../jcr/parts/GenericPropertyPage.java | 18 +- .../jcr/parts/ImportFileSystemWizard.java | 6 +- .../jcr/parts/NodePrivilegesPage.java | 12 +- .../jcr/parts/NodeVersionHistoryPage.java | 14 +- .../workbench/internal/users/UsersUtils.java | 8 +- .../ui/workbench/jcr/DefaultNodeEditor.java | 8 +- .../ui/workbench/jcr/JcrBrowserView.java | 12 +- .../ui/workbench/jcr/JcrPreferenceStore.java | 12 +- .../ui/workbench/users/PickUpUserDialog.java | 4 +- .../eclipse/ui/workbench/users/UserLP.java | 5 +- org.argeo.eclipse.ui/bnd.bnd | 1 + .../argeo/eclipse/ui/EclipseArgeoMonitor.java | 39 +--- .../argeo/eclipse/ui/EclipseJcrMonitor.java | 59 ++++++ .../argeo/eclipse/ui/EclipseUiException.java | 15 ++ .../ui/dialogs/NonModalErrorFeedback.java | 4 +- .../ui/jcr/AbstractNodeContentProvider.java | 8 +- .../eclipse/ui/jcr/AsyncUiEventListener.java | 6 +- .../ui/jcr/DefaultNodeLabelProvider.java | 8 +- .../org/argeo/eclipse/ui/jcr/JcrUiUtils.java | 6 +- .../eclipse/ui/jcr/NodeElementComparer.java | 6 +- .../argeo/eclipse/ui/jcr/NodesWrapper.java | 4 +- .../ui/jcr/SimpleNodeContentProvider.java | 4 +- .../ui/jcr/lists/NodeViewerComparator.java | 6 +- .../ui/jcr/lists/RowViewerComparator.java | 4 +- .../jcr/lists/SimpleJcrNodeLabelProvider.java | 6 +- .../jcr/lists/SimpleJcrRowLabelProvider.java | 4 +- .../eclipse/ui/jcr/utils/JcrFileProvider.java | 12 +- .../ui/jcr/utils/JcrItemsComparator.java | 4 +- .../ui/jcr/utils/NodeViewerComparer.java | 4 +- .../jcr/utils/SingleSessionFileProvider.java | 14 +- .../argeo/eclipse/ui/parts/JcrUsersTable.java | 10 +- .../eclipse/ui/parts/LdifUsersTable.java | 6 +- org.argeo.security.core/bnd.bnd | 5 - .../argeo/osgi/useradmin/LdifParserTest.java | 9 +- .../osgi/useradmin/LdifUserAdminTest.java | 9 +- .../transaction/simple/SimpleTransaction.java | 164 ---------------- .../simple/SimpleTransactionManager.java | 173 ----------------- .../osgi/transaction/simple/UuidXid.java | 132 ------------- .../org/argeo/osgi/useradmin/DigestUtils.java | 20 ++ .../argeo/osgi/useradmin/LdapUserAdmin.java | 3 +- .../org/argeo/osgi/useradmin/LdifUser.java | 55 ++---- .../argeo/osgi/useradmin/LdifUserAdmin.java | 3 +- .../src/org/argeo/util/naming/LdifParser.java | 18 +- .../src/org/argeo/util/naming/LdifWriter.java | 4 +- .../ui/admin/internal/PartStateChanged.java | 4 +- .../ui/admin/internal/UiAdminUtils.java | 4 +- .../ui/admin/internal/UserAdminWrapper.java | 4 +- .../ui/admin/internal/commands/NewGroup.java | 4 +- .../ui/admin/internal/commands/NewUser.java | 6 +- .../commands/UserTransactionHandler.java | 12 +- .../internal/parts/DefaultUserMainPage.java | 8 +- .../ui/admin/internal/parts/GroupsView.java | 4 +- .../internal/parts/UserBatchUpdateWizard.java | 16 +- .../ui/admin/internal/parts/UserEditor.java | 4 +- .../ui/admin/internal/parts/UserMainPage.java | 4 +- .../ui/admin/internal/parts/UsersView.java | 4 +- .../providers/UserAdminAbstractLP.java | 4 +- .../UserTableDefaultDClickListener.java | 4 +- .../providers/UserTransactionProvider.java | 4 +- .../security/ui/rap/AnonymousEntryPoint.java | 4 +- .../security/ui/rap/SecureEntryPoint.java | 8 +- .../argeo/security/ui/SecurityUiPlugin.java | 11 +- .../ui/commands/OpenChangePasswordDialog.java | 12 +- .../argeo/jackrabbit/JackrabbitContainer.java | 22 +-- .../JackrabbitDataModelMigration.java | 6 +- .../JackrabbitRepositoryFactory.java | 9 +- .../argeo/jackrabbit/JackrabbitWrapper.java | 15 +- .../src/org/argeo/jcr/ArgeoJcrUtils.java | 6 +- .../src/org/argeo/jcr/DefaultJcrListener.java | 5 +- .../argeo/jcr/DefaultRepositoryFactory.java | 4 +- .../src/org/argeo/jcr/JcrMonitor.java | 89 +++++++++ .../org/argeo/jcr/JcrRepositoryWrapper.java | 6 +- .../src/org/argeo/jcr/JcrResourceAdapter.java | 21 +- .../src/org/argeo/jcr/JcrUtils.java | 98 +++++----- .../src/org/argeo/jcr/PropertyDiff.java | 12 +- .../jcr/ThreadBoundJcrSessionFactory.java | 9 +- .../src/org/argeo/jcr/UserJcrUtils.java | 6 +- .../org/argeo/jcr/proxy/AbstractUrlProxy.java | 10 +- .../argeo/jcr/proxy/ResourceProxyServlet.java | 4 +- .../argeo/jcr/security/JcrAuthorizations.java | 10 +- .../org/argeo/jcr/security/JcrKeyring.java | 24 +-- .../jcr/tabular/JcrTabularRowIterator.java | 4 +- .../argeo/jcr/tabular/JcrTabularWriter.java | 6 +- .../argeo/jcr/unit/AbstractJcrTestCase.java | 34 +--- .../security/PasswordBasedEncryptionTest.java | 2 +- .../src/org/argeo/ArgeoException.java | 28 +-- .../src/org/argeo/ArgeoMonitor.java | 3 + org.argeo.util/src/org/argeo/StreamUtils.java | 183 ------------------ .../src/org/argeo/util/CsvParser.java | 10 +- .../argeo/util/CsvParserWithLinesAsMap.java | 4 +- .../src/org/argeo/util/CsvWriter.java | 8 +- .../src/org/argeo/util/LangUtils.java | 21 ++ .../src/org/argeo/util/Throughput.java | 10 +- .../org/argeo/util/internal/StreamUtils.java | 96 +++++++++ .../argeo/util/internal/UtilsException.java | 32 +++ .../argeo/util/security/AbstractKeyring.java | 16 +- .../argeo/util/security/ChecksumFactory.java | 6 +- .../org/argeo/util/security/DigestUtils.java | 45 +++-- .../security/PasswordBasedEncryption.java | 16 +- .../argeo/util/security/SimplePrincipal.java | 4 +- 154 files changed, 991 insertions(+), 1422 deletions(-) create mode 100644 org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/EclipseJcrMonitor.java create mode 100644 org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/EclipseUiException.java delete mode 100644 org.argeo.security.core/src/org/argeo/osgi/transaction/simple/SimpleTransaction.java delete mode 100644 org.argeo.security.core/src/org/argeo/osgi/transaction/simple/SimpleTransactionManager.java delete mode 100644 org.argeo.security.core/src/org/argeo/osgi/transaction/simple/UuidXid.java create mode 100644 org.argeo.security.core/src/org/argeo/osgi/useradmin/DigestUtils.java create mode 100644 org.argeo.server.jcr/src/org/argeo/jcr/JcrMonitor.java delete mode 100644 org.argeo.util/src/org/argeo/StreamUtils.java create mode 100644 org.argeo.util/src/org/argeo/util/internal/StreamUtils.java create mode 100644 org.argeo.util/src/org/argeo/util/internal/UtilsException.java diff --git a/org.argeo.cms/src/org/argeo/cms/AbstractCmsEntryPoint.java b/org.argeo.cms/src/org/argeo/cms/AbstractCmsEntryPoint.java index 311a8ff7c..743a142a4 100644 --- a/org.argeo.cms/src/org/argeo/cms/AbstractCmsEntryPoint.java +++ b/org.argeo.cms/src/org/argeo/cms/AbstractCmsEntryPoint.java @@ -19,7 +19,6 @@ import javax.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; import org.argeo.cms.auth.AuthConstants; import org.argeo.cms.auth.HttpRequestCallbackHandler; import org.argeo.eclipse.ui.specific.UiContext; @@ -77,10 +76,10 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint implement loginContext = new LoginContext(AuthConstants.LOGIN_CONTEXT_ANONYMOUS, subject); loginContext.login(); } catch (LoginException e1) { - throw new ArgeoException("Cannot log as anonymous", e); + throw new CmsException("Cannot log as anonymous", e); } } catch (LoginException e) { - throw new ArgeoException("Cannot initialize subject", e); + throw new CmsException("Cannot initialize subject", e); } authChange(loginContext); diff --git a/org.argeo.cms/src/org/argeo/cms/CmsException.java b/org.argeo.cms/src/org/argeo/cms/CmsException.java index 285741d7b..fb11c8977 100644 --- a/org.argeo.cms/src/org/argeo/cms/CmsException.java +++ b/org.argeo.cms/src/org/argeo/cms/CmsException.java @@ -1,9 +1,7 @@ package org.argeo.cms; -import org.argeo.ArgeoException; - /** CMS specific exceptions. */ -public class CmsException extends ArgeoException { +public class CmsException extends RuntimeException { private static final long serialVersionUID = -5341764743356771313L; public CmsException(String message) { diff --git a/org.argeo.cms/src/org/argeo/cms/auth/UserAdminLoginModule.java b/org.argeo.cms/src/org/argeo/cms/auth/UserAdminLoginModule.java index 492ab0fba..d4c41022f 100644 --- a/org.argeo.cms/src/org/argeo/cms/auth/UserAdminLoginModule.java +++ b/org.argeo.cms/src/org/argeo/cms/auth/UserAdminLoginModule.java @@ -16,7 +16,7 @@ import javax.security.auth.login.FailedLoginException; import javax.security.auth.login.LoginException; import javax.security.auth.spi.LoginModule; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.argeo.eclipse.ui.specific.UiContext; import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; @@ -50,7 +50,7 @@ public class UserAdminLoginModule implements LoginModule, AuthConstants { if (options.containsKey("anonymous")) isAnonymous = Boolean.parseBoolean(options.get("anonymous").toString()); } catch (Exception e) { - throw new ArgeoException("Cannot initialize login module", e); + throw new CmsException("Cannot initialize login module", e); } } diff --git a/org.argeo.cms/src/org/argeo/cms/forms/FormPageViewer.java b/org.argeo.cms/src/org/argeo/cms/forms/FormPageViewer.java index 65110619b..b4d24bf95 100644 --- a/org.argeo.cms/src/org/argeo/cms/forms/FormPageViewer.java +++ b/org.argeo.cms/src/org/argeo/cms/forms/FormPageViewer.java @@ -16,7 +16,6 @@ import javax.jcr.ValueFormatException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; import org.argeo.cms.CmsEditable; import org.argeo.cms.CmsException; import org.argeo.cms.CmsImageManager; @@ -476,13 +475,13 @@ public class FormPageViewer extends AbstractPageViewer { section.layout(); section.getParent().layout(); } catch (RepositoryException re) { - throw new ArgeoException("unable to refresh " + throw new CmsException("unable to refresh " + "image section for " + context); } } }); } catch (RepositoryException re) { - throw new ArgeoException("unable to upload image " + name + throw new CmsException("unable to upload image " + name + " at " + context); } } @@ -554,7 +553,7 @@ public class FormPageViewer extends AbstractPageViewer { refresh(parSection); layout(parSection); } catch (RepositoryException re) { - throw new ArgeoException("Unable to delete " + throw new CmsException("Unable to delete " + sessionNode, re); } @@ -604,7 +603,7 @@ public class FormPageViewer extends AbstractPageViewer { edit(emsp, 0); cancelEdit(); } catch (RepositoryException e1) { - throw new ArgeoException( + throw new CmsException( "Unable to remove value " + obj, e1); } layout(emsp); diff --git a/org.argeo.cms/src/org/argeo/cms/forms/FormUtils.java b/org.argeo.cms/src/org/argeo/cms/forms/FormUtils.java index cf9984b86..f8d08b08d 100644 --- a/org.argeo.cms/src/org/argeo/cms/forms/FormUtils.java +++ b/org.argeo.cms/src/org/argeo/cms/forms/FormUtils.java @@ -11,7 +11,7 @@ import javax.jcr.RepositoryException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.argeo.cms.CmsView; import org.argeo.cms.util.CmsUtils; import org.argeo.eclipse.ui.EclipseUiUtils; @@ -62,7 +62,7 @@ public class FormUtils { try { cmsView.navigateTo(node.getPath()); } catch (RepositoryException e) { - throw new ArgeoException("Unable to get path for node " + throw new CmsException("Unable to get path for node " + node + " before calling navigateTo(path)", e); } } diff --git a/org.argeo.cms/src/org/argeo/cms/internal/auth/ConsoleCallbackHandler.java b/org.argeo.cms/src/org/argeo/cms/internal/auth/ConsoleCallbackHandler.java index 4edcb6341..44bc33159 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/auth/ConsoleCallbackHandler.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/auth/ConsoleCallbackHandler.java @@ -13,7 +13,7 @@ import javax.security.auth.callback.PasswordCallback; import javax.security.auth.callback.TextOutputCallback; import javax.security.auth.callback.UnsupportedCallbackException; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; /** Callback handler to be used with a command line UI. */ public class ConsoleCallbackHandler implements CallbackHandler { @@ -23,7 +23,7 @@ public class ConsoleCallbackHandler implements CallbackHandler { UnsupportedCallbackException { Console console = System.console(); if (console == null) - throw new ArgeoException("No console available"); + throw new CmsException("No console available"); PrintWriter writer = console.writer(); for (int i = 0; i < callbacks.length; i++) { diff --git a/org.argeo.cms/src/org/argeo/cms/internal/auth/LocaleChoice.java b/org.argeo.cms/src/org/argeo/cms/internal/auth/LocaleChoice.java index 9ec9f7a0b..a23348fac 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/auth/LocaleChoice.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/auth/LocaleChoice.java @@ -22,7 +22,7 @@ import java.util.Locale; import javax.security.auth.callback.LanguageCallback; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; /** Choose in a list of locales. TODO: replace with {@link LanguageCallback} */ public class LocaleChoice { @@ -45,7 +45,7 @@ public class LocaleChoice { defaultIndex = i; if (defaultIndex == null) - throw new ArgeoException("Default locale " + defaultLocale + " is not in available locales " + locales); + throw new CmsException("Default locale " + defaultLocale + " is not in available locales " + locales); this.defaultIndex = defaultIndex; this.selectedIndex = defaultIndex; diff --git a/org.argeo.cms/src/org/argeo/cms/internal/backup/AbstractAtomicBackup.java b/org.argeo.cms/src/org/argeo/cms/internal/backup/AbstractAtomicBackup.java index 88fbb5a1c..d8824ba4e 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/backup/AbstractAtomicBackup.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/backup/AbstractAtomicBackup.java @@ -19,7 +19,7 @@ import org.apache.commons.vfs2.FileObject; import org.apache.commons.vfs2.FileSystemManager; import org.apache.commons.vfs2.FileSystemOptions; import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; /** * Simplify atomic backups implementation, especially by managing VFS. @@ -39,7 +39,7 @@ public abstract class AbstractAtomicBackup implements AtomicBackup { public void init() { if (name == null) - throw new ArgeoException("Atomic backup name must be set"); + throw new CmsException("Atomic backup name must be set"); } public void destroy() { @@ -51,7 +51,7 @@ public abstract class AbstractAtomicBackup implements AtomicBackup { String backupsBase, BackupContext backupContext, FileSystemOptions opts) { if (name == null) - throw new ArgeoException("Atomic backup name must be set"); + throw new CmsException("Atomic backup name must be set"); FileObject targetFo = null; try { @@ -70,14 +70,14 @@ public abstract class AbstractAtomicBackup implements AtomicBackup { + '/' + backupContext.getRelativeFolder() + '/' + name + ".gz" + "!" + name, opts); else - throw new ArgeoException("Unsupported compression " + throw new CmsException("Unsupported compression " + compression); writeBackup(targetFo); return targetFo.toString(); } catch (Exception e) { - throw new ArgeoException("Cannot backup " + name + " to " + throw new CmsException("Cannot backup " + name + " to " + targetFo, e); } finally { BackupUtils.closeFOQuietly(targetFo); diff --git a/org.argeo.cms/src/org/argeo/cms/internal/backup/BackupFileSystemManager.java b/org.argeo.cms/src/org/argeo/cms/internal/backup/BackupFileSystemManager.java index 2883e05ed..05c7d61a3 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/backup/BackupFileSystemManager.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/backup/BackupFileSystemManager.java @@ -24,7 +24,7 @@ import org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider; import org.apache.commons.vfs2.provider.ram.RamFileProvider; import org.apache.commons.vfs2.provider.sftp.SftpFileProvider; import org.apache.commons.vfs2.provider.url.UrlFileProvider; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; /** * Programatically configured VFS file system manager which can be declared as a @@ -46,7 +46,7 @@ public class BackupFileSystemManager extends DefaultFileSystemManager { addProvider("ram", new RamFileProvider()); setDefaultProvider(new UrlFileProvider()); } catch (FileSystemException e) { - throw new ArgeoException("Cannot configure backup file provider", e); + throw new CmsException("Cannot configure backup file provider", e); } } } diff --git a/org.argeo.cms/src/org/argeo/cms/internal/backup/OpenLdapBackup.java b/org.argeo.cms/src/org/argeo/cms/internal/backup/OpenLdapBackup.java index 278e36276..96c2f3a77 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/backup/OpenLdapBackup.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/backup/OpenLdapBackup.java @@ -16,7 +16,7 @@ package org.argeo.cms.internal.backup; import org.apache.commons.vfs2.FileObject; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; /** Backups an OpenLDAP server using slapcat */ public class OpenLdapBackup extends OsCallBackup { @@ -36,7 +36,7 @@ public class OpenLdapBackup extends OsCallBackup { @Override public void writeBackup(FileObject targetFo) { if (baseDn == null) - throw new ArgeoException("Base DN must be set"); + throw new CmsException("Base DN must be set"); if (getCommand() == null) setCommand(slapcatLocation diff --git a/org.argeo.cms/src/org/argeo/cms/internal/backup/OsCallBackup.java b/org.argeo.cms/src/org/argeo/cms/internal/backup/OsCallBackup.java index e588a0b2e..ad8ffe861 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/backup/OsCallBackup.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/backup/OsCallBackup.java @@ -30,7 +30,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.vfs2.FileContent; import org.apache.commons.vfs2.FileObject; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; /** * Runs an OS command and save its standard output as a file. Typically used for @@ -81,20 +81,17 @@ public class OsCallBackup extends AbstractAtomicBackup { // stdout FileContent targetContent = targetFo.getContent(); // stderr - ExecuteStreamHandler streamHandler = new PumpStreamHandler( - targetContent.getOutputStream(), errBos); + ExecuteStreamHandler streamHandler = new PumpStreamHandler(targetContent.getOutputStream(), errBos); executor.setStreamHandler(streamHandler); executor.execute(commandLine, environment); } catch (ExecuteException e) { byte[] err = errBos.toByteArray(); String errStr = new String(err); - throw new ArgeoException("Process " + commandLine + " failed (" - + e.getExitValue() + "): " + errStr, e); + throw new CmsException("Process " + commandLine + " failed (" + e.getExitValue() + "): " + errStr, e); } catch (Exception e) { byte[] err = errBos.toByteArray(); String errStr = new String(err); - throw new ArgeoException("Process " + commandLine + " failed: " - + errStr, e); + throw new CmsException("Process " + commandLine + " failed: " + errStr, e); } finally { IOUtils.closeQuietly(errBos); } diff --git a/org.argeo.cms/src/org/argeo/cms/internal/backup/SimpleBackupPurge.java b/org.argeo.cms/src/org/argeo/cms/internal/backup/SimpleBackupPurge.java index 64d749bee..64863759f 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/backup/SimpleBackupPurge.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/backup/SimpleBackupPurge.java @@ -26,7 +26,7 @@ import org.apache.commons.vfs2.FileObject; import org.apache.commons.vfs2.FileSystemManager; import org.apache.commons.vfs2.FileSystemOptions; import org.apache.commons.vfs2.Selectors; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.joda.time.DateTime; import org.joda.time.Period; @@ -82,7 +82,7 @@ public class SimpleBackupPurge implements BackupPurge { log.debug("Deleted backup " + backupFo); } } catch (Exception e) { - throw new ArgeoException("Could not purge previous backups", e); + throw new CmsException("Could not purge previous backups", e); } } diff --git a/org.argeo.cms/src/org/argeo/cms/internal/backup/SystemBackup.java b/org.argeo.cms/src/org/argeo/cms/internal/backup/SystemBackup.java index 5036cc481..36d3e0b2d 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/backup/SystemBackup.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/backup/SystemBackup.java @@ -29,7 +29,8 @@ import org.apache.commons.vfs2.FileSystemOptions; import org.apache.commons.vfs2.Selectors; import org.apache.commons.vfs2.UserAuthenticator; import org.apache.commons.vfs2.impl.DefaultFileSystemConfigBuilder; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; +import org.argeo.util.LangUtils; /** * Combines multiple backups and transfer them to a remote location. Purges @@ -52,25 +53,22 @@ public class SystemBackup implements Runnable { @Override public void run() { if (atomicBackups.size() == 0) - throw new ArgeoException("No atomic backup listed"); + throw new CmsException("No atomic backup listed"); List failures = new ArrayList(); - SimpleBackupContext backupContext = new SimpleBackupContext( - fileSystemManager, backupsBase, systemName); + SimpleBackupContext backupContext = new SimpleBackupContext(fileSystemManager, backupsBase, systemName); // purge older backups FileSystemOptions opts = new FileSystemOptions(); try { - DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator( - opts, userAuthenticator); + DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, userAuthenticator); } catch (FileSystemException e) { - throw new ArgeoException("Cannot create authentication", e); + throw new CmsException("Cannot create authentication", e); } try { - backupPurge.purge(fileSystemManager, backupsBase, systemName, - backupContext.getDateFormat(), opts); + backupPurge.purge(fileSystemManager, backupsBase, systemName, backupContext.getDateFormat(), opts); } catch (Exception e) { failures.add("Purge " + backupsBase + " failed: " + e.getMessage()); log.error("Purge of " + backupsBase + " failed", e); @@ -79,19 +77,16 @@ public class SystemBackup implements Runnable { // perform backup for (AtomicBackup atomickBackup : atomicBackups) { try { - String target = atomickBackup.backup(fileSystemManager, - backupsBase, backupContext, opts); + String target = atomickBackup.backup(fileSystemManager, backupsBase, backupContext, opts); if (log.isDebugEnabled()) log.debug("Performed backup " + target); } catch (Exception e) { - String msg = "Atomic backup " + atomickBackup.getName() - + " failed: " + ArgeoException.chainCausesMessages(e); + String msg = "Atomic backup " + atomickBackup.getName() + " failed: " + + LangUtils.chainCausesMessages(e); failures.add(msg); log.error(msg); if (log.isTraceEnabled()) - log.trace( - "Stacktrace of atomic backup " - + atomickBackup.getName() + " failure.", e); + log.trace("Stacktrace of atomic backup " + atomickBackup.getName() + " failure.", e); } } @@ -104,33 +99,25 @@ public class SystemBackup implements Runnable { // authentication FileSystemOptions remoteOpts = new FileSystemOptions(); try { - DefaultFileSystemConfigBuilder.getInstance() - .setUserAuthenticator(remoteOpts, auth); - backupPurge.purge(fileSystemManager, remoteBase, systemName, - backupContext.getDateFormat(), remoteOpts); + DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(remoteOpts, auth); + backupPurge.purge(fileSystemManager, remoteBase, systemName, backupContext.getDateFormat(), remoteOpts); } catch (Exception e) { - failures.add("Purge " + remoteBase + " failed: " - + e.getMessage()); + failures.add("Purge " + remoteBase + " failed: " + e.getMessage()); log.error("Cannot purge " + remoteBase, e); } try { - localBaseFo = fileSystemManager.resolveFile(backupsBase + '/' - + backupContext.getRelativeFolder(), opts); - remoteBaseFo = fileSystemManager.resolveFile(remoteBase + '/' - + backupContext.getRelativeFolder(), remoteOpts); + localBaseFo = fileSystemManager.resolveFile(backupsBase + '/' + backupContext.getRelativeFolder(), + opts); + remoteBaseFo = fileSystemManager.resolveFile(remoteBase + '/' + backupContext.getRelativeFolder(), + remoteOpts); remoteBaseFo.copyFrom(localBaseFo, Selectors.SELECT_ALL); if (log.isDebugEnabled()) - log.debug("Copied backup to " + remoteBaseFo + " from " - + localBaseFo); + log.debug("Copied backup to " + remoteBaseFo + " from " + localBaseFo); // } } catch (Exception e) { - failures.add("Dispatch to " + remoteBase + " failed: " - + e.getMessage()); - log.error( - "Cannot dispatch backups from " - + backupContext.getRelativeFolder() + " to " - + remoteBase, e); + failures.add("Dispatch to " + remoteBase + " failed: " + e.getMessage()); + log.error("Cannot dispatch backups from " + backupContext.getRelativeFolder() + " to " + remoteBase, e); } BackupUtils.closeFOQuietly(localBaseFo); BackupUtils.closeFOQuietly(remoteBaseFo); @@ -140,14 +127,11 @@ public class SystemBackup implements Runnable { if (failures.size() > 0) { StringBuffer buf = new StringBuffer(); for (String failure : failures) { - buf.append('\n').append(failureCount).append(" - ") - .append(failure); + buf.append('\n').append(failureCount).append(" - ").append(failure); failureCount++; } - throw new ArgeoException(failureCount - + " error(s) when running the backup," - + " check the logs and the backups as soon as possible." - + buf); + throw new CmsException(failureCount + " error(s) when running the backup," + + " check the logs and the backups as soon as possible." + buf); } } @@ -179,53 +163,54 @@ public class SystemBackup implements Runnable { this.remoteBases = remoteBases; } -// public static void main(String args[]) { -// while (true) { -// try { -// StandardFileSystemManager fsm = new StandardFileSystemManager(); -// fsm.init(); -// -// SystemBackup systemBackup = new SystemBackup(); -// systemBackup.setSystemName("mySystem"); -// systemBackup -// .setBackupsBase("/home/mbaudier/dev/src/commons/server/runtime/org.argeo.server.core/target"); -// systemBackup.setFileSystemManager(fsm); -// -// List atomicBackups = new ArrayList(); -// -// MySqlBackup mySqlBackup = new MySqlBackup("root", "", "test"); -// atomicBackups.add(mySqlBackup); -// PostgreSqlBackup postgreSqlBackup = new PostgreSqlBackup( -// "argeo", "argeo", "gis_template"); -// atomicBackups.add(postgreSqlBackup); -// SvnBackup svnBackup = new SvnBackup( -// "/home/mbaudier/tmp/testsvnrepo"); -// atomicBackups.add(svnBackup); -// -// systemBackup.setAtomicBackups(atomicBackups); -// -// Map remoteBases = new HashMap(); -// StaticUserAuthenticator userAuthenticator = new StaticUserAuthenticator( -// null, "demo", "demo"); -// remoteBases.put("sftp://localhost/home/mbaudier/test", -// userAuthenticator); -// systemBackup.setRemoteBases(remoteBases); -// -// systemBackup.run(); -// -// fsm.close(); -// } catch (FileSystemException e) { -// // TODO Auto-generated catch block -// e.printStackTrace(); -// System.exit(1); -// } -// -// // wait -// try { -// Thread.sleep(120 * 1000); -// } catch (InterruptedException e) { -// e.printStackTrace(); -// } -// } -// } + // public static void main(String args[]) { + // while (true) { + // try { + // StandardFileSystemManager fsm = new StandardFileSystemManager(); + // fsm.init(); + // + // SystemBackup systemBackup = new SystemBackup(); + // systemBackup.setSystemName("mySystem"); + // systemBackup + // .setBackupsBase("/home/mbaudier/dev/src/commons/server/runtime/org.argeo.server.core/target"); + // systemBackup.setFileSystemManager(fsm); + // + // List atomicBackups = new ArrayList(); + // + // MySqlBackup mySqlBackup = new MySqlBackup("root", "", "test"); + // atomicBackups.add(mySqlBackup); + // PostgreSqlBackup postgreSqlBackup = new PostgreSqlBackup( + // "argeo", "argeo", "gis_template"); + // atomicBackups.add(postgreSqlBackup); + // SvnBackup svnBackup = new SvnBackup( + // "/home/mbaudier/tmp/testsvnrepo"); + // atomicBackups.add(svnBackup); + // + // systemBackup.setAtomicBackups(atomicBackups); + // + // Map remoteBases = new HashMap(); + // StaticUserAuthenticator userAuthenticator = new StaticUserAuthenticator( + // null, "demo", "demo"); + // remoteBases.put("sftp://localhost/home/mbaudier/test", + // userAuthenticator); + // systemBackup.setRemoteBases(remoteBases); + // + // systemBackup.run(); + // + // fsm.close(); + // } catch (FileSystemException e) { + // // TODO Auto-generated catch block + // e.printStackTrace(); + // System.exit(1); + // } + // + // // wait + // try { + // Thread.sleep(120 * 1000); + // } catch (InterruptedException e) { + // e.printStackTrace(); + // } + // } + // } } diff --git a/org.argeo.cms/src/org/argeo/cms/internal/kernel/HomeRepository.java b/org.argeo.cms/src/org/argeo/cms/internal/kernel/HomeRepository.java index c0cf3e025..6900be3ad 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/kernel/HomeRepository.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/kernel/HomeRepository.java @@ -15,7 +15,6 @@ import javax.security.auth.Subject; import javax.security.auth.login.LoginContext; import org.apache.jackrabbit.core.security.SecurityConstants; -import org.argeo.ArgeoException; import org.argeo.cms.CmsException; import org.argeo.cms.auth.AuthConstants; import org.argeo.jcr.ArgeoJcrConstants; @@ -179,7 +178,7 @@ class HomeRepository extends JcrRepositoryWrapper implements KernelConstants, Ar return userProfile; } catch (RepositoryException e) { JcrUtils.discardQuietly(session); - throw new ArgeoException("Cannot sync node security model for " + username, e); + throw new CmsException("Cannot sync node security model for " + username, e); } } @@ -189,7 +188,7 @@ class HomeRepository extends JcrRepositoryWrapper implements KernelConstants, Ar try { dn = new LdapName(username); } catch (InvalidNameException e) { - throw new ArgeoException("Invalid name " + username, e); + throw new CmsException("Invalid name " + username, e); } String userId = dn.getRdn(dn.size() - 1).getValue().toString(); int atIndex = userId.indexOf('@'); @@ -199,7 +198,7 @@ class HomeRepository extends JcrRepositoryWrapper implements KernelConstants, Ar return base + '/' + JcrUtils.firstCharsToPath(domain, 2) + '/' + domain + '/' + JcrUtils.firstCharsToPath(name, 2) + '/' + name; } else if (atIndex == 0 || atIndex == (userId.length() - 1)) { - throw new ArgeoException("Unsupported username " + userId); + throw new CmsException("Unsupported username " + userId); } else { return base + '/' + JcrUtils.firstCharsToPath(userId, 2) + '/' + userId; } diff --git a/org.argeo.cms/src/org/argeo/cms/internal/kernel/NodeLogger.java b/org.argeo.cms/src/org/argeo/cms/internal/kernel/NodeLogger.java index 4f58e7525..5fa0d07cd 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/kernel/NodeLogger.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/kernel/NodeLogger.java @@ -37,7 +37,7 @@ import org.apache.log4j.LogManager; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.spi.LoggingEvent; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.argeo.cms.auth.CurrentUser; import org.argeo.node.ArgeoLogListener; import org.argeo.node.ArgeoLogger; @@ -109,7 +109,7 @@ class NodeLogger implements ArgeoLogger, LogListener { logDispatcherThread = new LogDispatcherThread(); logDispatcherThread.start(); } catch (Exception e) { - throw new ArgeoException("Cannot initialize log4j"); + throw new CmsException("Cannot initialize log4j"); } } @@ -204,7 +204,7 @@ class NodeLogger implements ArgeoLogger, LogListener { public synchronized void register(ArgeoLogListener listener, Integer numberOfPreviousEvents) { String username = CurrentUser.getUsername(); if (username == null) - throw new ArgeoException("Only authenticated users can register a log listener"); + throw new CmsException("Only authenticated users can register a log listener"); if (!userListeners.containsKey(username)) { List lst = Collections.synchronizedList(new ArrayList()); @@ -233,9 +233,9 @@ class NodeLogger implements ArgeoLogger, LogListener { if (username == null)// FIXME return; if (!userListeners.containsKey(username)) - throw new ArgeoException("No user listeners " + listener + " registered for user " + username); + throw new CmsException("No user listeners " + listener + " registered for user " + username); if (!userListeners.get(username).contains(listener)) - throw new ArgeoException("No user listeners " + listener + " registered for user " + username); + throw new CmsException("No user listeners " + listener + " registered for user " + username); userListeners.get(username).remove(listener); if (userListeners.get(username).isEmpty()) userListeners.remove(username); diff --git a/org.argeo.cms/src/org/argeo/cms/internal/kernel/PkiUtils.java b/org.argeo.cms/src/org/argeo/cms/internal/kernel/PkiUtils.java index 67f8f01c6..050b7d4d7 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/kernel/PkiUtils.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/kernel/PkiUtils.java @@ -15,7 +15,7 @@ import java.util.Date; import javax.security.auth.x500.X500Principal; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.bouncycastle.cert.X509v3CertificateBuilder; import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter; import org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder; @@ -55,7 +55,7 @@ class PkiUtils { keyStore.setKeyEntry(x500Principal.getName(), pair.getPrivate(), keyPassword, new Certificate[] { cert }); return cert; } catch (Exception e) { - throw new ArgeoException("Cannot generate self-signed certificate", e); + throw new CmsException("Cannot generate self-signed certificate", e); } } @@ -71,7 +71,7 @@ class PkiUtils { } return store; } catch (Exception e) { - throw new ArgeoException("Cannot load keystore " + keyStoreFile, e); + throw new CmsException("Cannot load keystore " + keyStoreFile, e); } } @@ -81,7 +81,7 @@ class PkiUtils { keyStore.store(fis, keyStorePassword); } } catch (Exception e) { - throw new ArgeoException("Cannot save keystore " + keyStoreFile, e); + throw new CmsException("Cannot save keystore " + keyStoreFile, e); } } diff --git a/org.argeo.cms/src/org/argeo/cms/internal/kernel/RepositoryServiceFactory.java b/org.argeo.cms/src/org/argeo/cms/internal/kernel/RepositoryServiceFactory.java index 7e8b1c07e..1355f852c 100644 --- a/org.argeo.cms/src/org/argeo/cms/internal/kernel/RepositoryServiceFactory.java +++ b/org.argeo.cms/src/org/argeo/cms/internal/kernel/RepositoryServiceFactory.java @@ -7,7 +7,7 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.jackrabbit.core.RepositoryContext; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.argeo.jcr.ArgeoJcrConstants; import org.argeo.node.NodeConstants; import org.argeo.util.LangUtils; @@ -32,7 +32,7 @@ class RepositoryServiceFactory implements ManagedServiceFactory { @Override public void updated(String pid, Dictionary properties) throws ConfigurationException { if (repositories.containsKey(pid)) - throw new ArgeoException("Already a repository registered for " + pid); + throw new CmsException("Already a repository registered for " + pid); if (properties == null) return; @@ -57,7 +57,7 @@ class RepositoryServiceFactory implements ManagedServiceFactory { } bc.registerService(RepositoryContext.class, repositoryContext, props); } catch (Exception e) { - throw new ArgeoException("Cannot create Jackrabbit repository " + pid, e); + throw new CmsException("Cannot create Jackrabbit repository " + pid, e); } } diff --git a/org.argeo.cms/src/org/argeo/cms/maintenance/Browse.java b/org.argeo.cms/src/org/argeo/cms/maintenance/Browse.java index 98792575b..7dafd72c4 100644 --- a/org.argeo.cms/src/org/argeo/cms/maintenance/Browse.java +++ b/org.argeo.cms/src/org/argeo/cms/maintenance/Browse.java @@ -16,7 +16,6 @@ import javax.jcr.PropertyType; import javax.jcr.RepositoryException; import javax.jcr.Value; -import org.argeo.ArgeoException; import org.argeo.cms.CmsException; import org.argeo.cms.CmsTypes; import org.argeo.cms.CmsUiProvider; @@ -217,7 +216,7 @@ public class Browse implements CmsUiProvider { e.doit = false; } } catch (RepositoryException e1) { - throw new ArgeoException( + throw new CmsException( "Unexpected error in key management for " + currEdited + "with filter " + filterTxt.getText(), e1); @@ -236,7 +235,7 @@ public class Browse implements CmsUiProvider { refreshFilters(node); refreshBrowser(node); } catch (RepositoryException re) { - throw new ArgeoException("Unable to update browser for " + node, re); + throw new CmsException("Unable to update browser for " + node, re); } } @@ -336,7 +335,7 @@ public class Browse implements CmsUiProvider { try { return node.getPath(); } catch (RepositoryException e) { - throw new ArgeoException("Unable to get path for node " + node, e); + throw new CmsException("Unable to get path for node " + node, e); } } @@ -458,7 +457,7 @@ public class Browse implements CmsUiProvider { NodeIterator nit = context.getNodes(filter); refreshFilteredList(nit); } catch (RepositoryException e) { - throw new ArgeoException("Unable to filter " + getNode() + throw new CmsException("Unable to filter " + getNode() + " children with filter " + filter, e); } @@ -557,7 +556,7 @@ public class Browse implements CmsUiProvider { } } } catch (RepositoryException ie) { - throw new ArgeoException("Error while managing arrow " + throw new CmsException("Error while managing arrow " + "events in the browser for " + selected, ie); } } @@ -606,7 +605,7 @@ public class Browse implements CmsUiProvider { try { return curr.getName(); } catch (RepositoryException e) { - throw new ArgeoException("Unable to get name for" + throw new CmsException("Unable to get name for" + curr); } } diff --git a/org.argeo.cms/src/org/argeo/cms/util/LoginEntryPoint.java b/org.argeo.cms/src/org/argeo/cms/util/LoginEntryPoint.java index a05165f5b..2ccb3ca06 100644 --- a/org.argeo.cms/src/org/argeo/cms/util/LoginEntryPoint.java +++ b/org.argeo.cms/src/org/argeo/cms/util/LoginEntryPoint.java @@ -8,7 +8,6 @@ import javax.security.auth.login.LoginContext; import javax.security.auth.login.LoginException; import javax.servlet.http.HttpServletRequest; -import org.argeo.ArgeoException; import org.argeo.cms.CmsException; import org.argeo.cms.CmsImageManager; import org.argeo.cms.CmsView; @@ -58,7 +57,7 @@ public class LoginEntryPoint implements EntryPoint, CmsView { // } } } catch (LoginException e) { - throw new ArgeoException("Cannot log in", e); + throw new CmsException("Cannot log in", e); } if (CurrentUser.getUsername() == null) diff --git a/org.argeo.cms/src/org/argeo/cms/util/SystemNotifications.java b/org.argeo.cms/src/org/argeo/cms/util/SystemNotifications.java index 9d0c63845..54e8eb544 100644 --- a/org.argeo.cms/src/org/argeo/cms/util/SystemNotifications.java +++ b/org.argeo.cms/src/org/argeo/cms/util/SystemNotifications.java @@ -8,7 +8,7 @@ import java.text.SimpleDateFormat; import java.util.Date; import org.apache.commons.io.IOUtils; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.argeo.cms.CmsStyles; import org.eclipse.rap.rwt.RWT; import org.eclipse.swt.SWT; @@ -59,7 +59,7 @@ public class SystemNotifications extends Shell implements CmsStyles, Label lbl = new Label(pane, SWT.NONE); lbl.setText(exception.getLocalizedMessage() - + (exception instanceof ArgeoException ? "" : "(" + + (exception instanceof CmsException ? "" : "(" + exception.getClass().getName() + ")") + "\n"); lbl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); lbl.addMouseListener(this); diff --git a/org.argeo.cms/src/org/argeo/cms/util/useradmin/UserAdminUtils.java b/org.argeo.cms/src/org/argeo/cms/util/useradmin/UserAdminUtils.java index 5c197c1ae..9ccc3057f 100644 --- a/org.argeo.cms/src/org/argeo/cms/util/useradmin/UserAdminUtils.java +++ b/org.argeo.cms/src/org/argeo/cms/util/useradmin/UserAdminUtils.java @@ -10,7 +10,7 @@ import javax.naming.ldap.Rdn; import javax.security.auth.Subject; import javax.security.auth.x500.X500Principal; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.argeo.cms.CmsView; import org.argeo.cms.auth.AuthConstants; import org.argeo.cms.auth.CurrentUser; @@ -106,7 +106,7 @@ public class UserAdminUtils { else return false; } catch (InvalidNameException e) { - throw new ArgeoException("User " + user + " has an unvalid dn: " + throw new CmsException("User " + user + " has an unvalid dn: " + userName, e); } } @@ -166,7 +166,7 @@ public class UserAdminUtils { || last.getType().toLowerCase().equals(LdifName.cn.name())) return (String) last.getValue(); else - throw new ArgeoException("Cannot retrieve user uid, " + throw new CmsException("Cannot retrieve user uid, " + "non valid dn: " + dn); } @@ -226,7 +226,7 @@ public class UserAdminUtils { } return dname; } catch (InvalidNameException e) { - throw new ArgeoException("Unable to get domain name for " + dn, e); + throw new CmsException("Unable to get domain name for " + dn, e); } } @@ -236,7 +236,7 @@ public class UserAdminUtils { try { return new LdapName(dn); } catch (InvalidNameException e) { - throw new ArgeoException("Cannot parse LDAP name " + dn, e); + throw new CmsException("Cannot parse LDAP name " + dn, e); } } } \ No newline at end of file diff --git a/org.argeo.cms/src/org/argeo/cms/util/useradmin/UserAdminWrapper.java b/org.argeo.cms/src/org/argeo/cms/util/useradmin/UserAdminWrapper.java index 911b92ea8..aa764d57c 100644 --- a/org.argeo.cms/src/org/argeo/cms/util/useradmin/UserAdminWrapper.java +++ b/org.argeo.cms/src/org/argeo/cms/util/useradmin/UserAdminWrapper.java @@ -9,7 +9,7 @@ import java.util.Map; import javax.transaction.Status; import javax.transaction.UserTransaction; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.argeo.cms.auth.AuthConstants; import org.argeo.osgi.useradmin.UserAdminConf; import org.osgi.framework.ServiceReference; @@ -48,7 +48,7 @@ public abstract class UserAdminWrapper { } return userTransaction; } catch (Exception e) { - throw new ArgeoException("Unable to begin transaction", e); + throw new CmsException("Unable to begin transaction", e); } } diff --git a/org.argeo.cms/src/org/argeo/security/core/AbstractSystemExecution.java b/org.argeo.cms/src/org/argeo/security/core/AbstractSystemExecution.java index c4beeed52..9c3e5cd83 100644 --- a/org.argeo.cms/src/org/argeo/security/core/AbstractSystemExecution.java +++ b/org.argeo.cms/src/org/argeo/security/core/AbstractSystemExecution.java @@ -21,7 +21,7 @@ import javax.security.auth.login.LoginException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; /** Provides base method for executing code with system authorization. */ public abstract class AbstractSystemExecution { @@ -41,7 +41,7 @@ public abstract class AbstractSystemExecution { LoginContext lc = new LoginContext(loginModule, subject); lc.login(); } catch (LoginException e) { - throw new ArgeoException("Cannot login as system", e); + throw new CmsException("Cannot login as system", e); } finally { Thread.currentThread().setContextClassLoader(origClassLoader); } @@ -56,7 +56,7 @@ public abstract class AbstractSystemExecution { LoginContext lc = new LoginContext(loginModule, subject); lc.logout(); } catch (LoginException e) { - throw new ArgeoException("Cannot logout as system", e); + throw new CmsException("Cannot logout as system", e); } finally { Thread.currentThread().setContextClassLoader(origClassLoader); } diff --git a/org.argeo.cms/src/org/argeo/security/core/SimpleRoleRegistration.java b/org.argeo.cms/src/org/argeo/security/core/SimpleRoleRegistration.java index 4d107dabb..58f6686ac 100644 --- a/org.argeo.cms/src/org/argeo/security/core/SimpleRoleRegistration.java +++ b/org.argeo.cms/src/org/argeo/security/core/SimpleRoleRegistration.java @@ -10,7 +10,7 @@ import javax.transaction.UserTransaction; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.osgi.service.useradmin.Role; import org.osgi.service.useradmin.UserAdmin; @@ -44,7 +44,7 @@ public class SimpleRoleRegistration implements Runnable { } catch (Exception e1) { log.error("Cannot rollback", e1); } - throw new ArgeoException("Cannot add roles", e); + throw new CmsException("Cannot add roles", e); } } @@ -66,7 +66,7 @@ public class SimpleRoleRegistration implements Runnable { try { return new LdapName("cn=" + name + ",ou=roles,ou=node"); } catch (InvalidNameException e) { - throw new ArgeoException("Badly formatted role name " + name, e); + throw new CmsException("Badly formatted role name " + name, e); } } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/spring/SpringCommandHandler.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/spring/SpringCommandHandler.java index 4c7a152df..1bbf9cbed 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/spring/SpringCommandHandler.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/spring/SpringCommandHandler.java @@ -17,7 +17,7 @@ package org.argeo.eclipse.spring; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.commands.IHandler; @@ -47,7 +47,7 @@ public class SpringCommandHandler implements IHandler { ApplicationContext applicationContext = ApplicationContextTracker .getApplicationContext(bundleSymbolicName); if (applicationContext == null) - throw new ArgeoException("No application context found for " + throw new EclipseUiException("No application context found for " + bundleSymbolicName); // retrieve the command via its id diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/spring/SpringExtensionFactory.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/spring/SpringExtensionFactory.java index 7a0486fd2..6a5626625 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/spring/SpringExtensionFactory.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/spring/SpringExtensionFactory.java @@ -15,7 +15,7 @@ */ package org.argeo.eclipse.spring; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExecutableExtension; @@ -55,7 +55,7 @@ public class SpringExtensionFactory implements IExecutableExtensionFactory, public Object create() throws CoreException { if (bean == null) - throw new ArgeoException("No underlying bean for extension"); + throw new EclipseUiException("No underlying bean for extension"); return bean; } @@ -65,13 +65,13 @@ public class SpringExtensionFactory implements IExecutableExtensionFactory, ApplicationContext applicationContext = ApplicationContextTracker .getApplicationContext(bundleSymbolicName); if (applicationContext == null) - throw new ArgeoException( + throw new EclipseUiException( "Cannot find application context for bundle " + bundleSymbolicName); String beanName = getBeanName(data, config); if (beanName == null) - throw new ArgeoException("Cannot find bean name for extension " + throw new EclipseUiException("Cannot find bean name for extension " + config); if (!applicationContext.containsBean(beanName)) { @@ -80,7 +80,7 @@ public class SpringExtensionFactory implements IExecutableExtensionFactory, } if (!applicationContext.containsBean(beanName)) - throw new ArgeoException("No bean with name '" + beanName + "'"); + throw new EclipseUiException("No bean with name '" + beanName + "'"); this.bean = applicationContext.getBean(beanName); if (this.bean instanceof IExecutableExtension) { diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/CommandUtils.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/CommandUtils.java index 3670efbe5..36f12936d 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/CommandUtils.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/CommandUtils.java @@ -19,7 +19,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Map; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.eclipse.core.commands.Command; import org.eclipse.core.commands.Parameterization; import org.eclipse.core.commands.ParameterizedCommand; @@ -173,7 +173,7 @@ public class CommandUtils { // execute the command handlerService.executeCommand(pc, null); } catch (Exception e) { - throw new ArgeoException("Unexpected error while" + throw new EclipseUiException("Unexpected error while" + " calling the command " + commandID, e); } } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/AddPrivileges.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/AddPrivileges.java index cc7d94ee6..8ad021f72 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/AddPrivileges.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/AddPrivileges.java @@ -18,7 +18,7 @@ package org.argeo.eclipse.ui.workbench.commands; import javax.jcr.Node; import javax.jcr.RepositoryException; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.TreeParent; import org.argeo.eclipse.ui.dialogs.ErrorFeedback; import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin; @@ -69,7 +69,7 @@ public class AddPrivileges extends AbstractHandler { dialog.open(); return null; } catch (RepositoryException re) { - throw new ArgeoException("Unable to retrieve " + throw new EclipseUiException("Unable to retrieve " + "path or JCR session to add privilege on " + jcrParentNode, re); } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/AddRemoteRepository.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/AddRemoteRepository.java index 2ee8f8963..ba86eb71c 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/AddRemoteRepository.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/AddRemoteRepository.java @@ -24,7 +24,7 @@ import javax.jcr.RepositoryFactory; import javax.jcr.Session; import javax.jcr.SimpleCredentials; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.dialogs.ErrorFeedback; import org.argeo.eclipse.ui.workbench.CommandUtils; import org.argeo.eclipse.ui.workbench.WorkbenchConstants; @@ -175,7 +175,7 @@ public class AddRemoteRepository extends AbstractHandler implements Node remote = home.hasNode(ARGEO_REMOTE) ? home .getNode(ARGEO_REMOTE) : home.addNode(ARGEO_REMOTE); if (remote.hasNode(name.getText())) - throw new ArgeoException( + throw new EclipseUiException( "There is already a remote repository named " + name.getText()); Node remoteRepository = remote.addNode(name.getText(), diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/DeleteNodes.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/DeleteNodes.java index d8c0f0cef..76530484a 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/DeleteNodes.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/DeleteNodes.java @@ -20,7 +20,7 @@ import java.util.Iterator; import javax.jcr.Node; import javax.jcr.RepositoryException; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.TreeParent; import org.argeo.eclipse.ui.dialogs.ErrorFeedback; import org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem; @@ -112,7 +112,7 @@ public class DeleteNodes extends AbstractHandler { else return A.getNode().getDepth() <= B.getNode().getDepth() ? A : B; } catch (RepositoryException re) { - throw new ArgeoException("Cannot find ancestor", re); + throw new EclipseUiException("Cannot find ancestor", re); } } } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/DumpNode.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/DumpNode.java index 2823988c9..f62a5c07e 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/DumpNode.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/DumpNode.java @@ -29,7 +29,7 @@ import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.Session; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.workbench.CommandUtils; import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin; import org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem; @@ -89,10 +89,10 @@ public class DumpNode extends AbstractHandler { + JcrUtils.replaceInvalidChars(node.getName()) + "-" + dateVal + ".xml"); } catch (RepositoryException e) { - throw new ArgeoException( + throw new EclipseUiException( "Unable to perform SystemExport on " + node, e); } catch (IOException e) { - throw new ArgeoException("Unable to SystemExport " + node, + throw new EclipseUiException("Unable to SystemExport " + node, e); } } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/NodeConfigurableDump.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/NodeConfigurableDump.java index cd6c0dc98..81f5a60fe 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/NodeConfigurableDump.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/NodeConfigurableDump.java @@ -31,7 +31,7 @@ import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.RepositoryException; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.EclipseUiUtils; import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin; import org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem; @@ -122,10 +122,10 @@ public class NodeConfigurableDump extends AbstractHandler { fos.close(); } } catch (RepositoryException e) { - throw new ArgeoException( + throw new EclipseUiException( "Unable to perform SystemExport on " + node, e); } catch (IOException e) { - throw new ArgeoException("Unable to SystemExport " + throw new EclipseUiException("Unable to SystemExport " + node, e); } } @@ -187,7 +187,7 @@ public class NodeConfigurableDump extends AbstractHandler { page = new BasicPage("Main page"); addPage(page); } catch (Exception e) { - throw new ArgeoException("Cannot add page to wizard", e); + throw new EclipseUiException("Cannot add page to wizard", e); } } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/OpenEditor.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/OpenEditor.java index bf2f824e8..57ae9f28d 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/OpenEditor.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/OpenEditor.java @@ -17,7 +17,7 @@ package org.argeo.eclipse.ui.workbench.commands; import javax.jcr.Node; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin; import org.argeo.eclipse.ui.workbench.internal.jcr.parts.JcrQueryEditorInput; import org.argeo.eclipse.ui.workbench.internal.jcr.parts.NodeEditorInput; @@ -52,7 +52,7 @@ public class OpenEditor extends AbstractHandler { activePage.openEditor(editorInput, editorId); } } catch (PartInitException e) { - throw new ArgeoException("Cannot open editor of ID " + editorId, e); + throw new EclipseUiException("Cannot open editor of ID " + editorId, e); } return null; } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/RemovePrivileges.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/RemovePrivileges.java index c11413d9f..f706a6453 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/RemovePrivileges.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/RemovePrivileges.java @@ -25,7 +25,7 @@ import javax.jcr.security.AccessControlList; import javax.jcr.security.AccessControlManager; import javax.jcr.security.Privilege; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.EclipseUiUtils; import org.argeo.eclipse.ui.TreeParent; import org.argeo.eclipse.ui.dialogs.ErrorFeedback; @@ -86,7 +86,7 @@ public class RemovePrivileges extends AbstractHandler { dialog.open(); return null; } catch (RepositoryException re) { - throw new ArgeoException("Unable to retrieve " + throw new EclipseUiException("Unable to retrieve " + "path or JCR session to add privilege on " + jcrNode, re); } @@ -145,7 +145,7 @@ public class RemovePrivileges extends AbstractHandler { IMessageProvider.INFORMATION); } } catch (RepositoryException e) { - throw new ArgeoException( + throw new EclipseUiException( "Unable to list privileges on " + path, e); } body.layout(true, true); @@ -176,7 +176,7 @@ public class RemovePrivileges extends AbstractHandler { session.save(); refreshContent(); } catch (RepositoryException re) { - throw new ArgeoException("Unable to " + throw new EclipseUiException("Unable to " + "remove privilege for " + currPrincipalName + " on " + path, re); } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/RenameNode.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/RenameNode.java index 1d246078b..b9d2c287d 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/RenameNode.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/RenameNode.java @@ -21,7 +21,7 @@ import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.Session; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.dialogs.SingleValue; import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin; import org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem; @@ -77,7 +77,7 @@ public class RenameNode extends AbstractHandler { if (iwp.getActivePart() instanceof JcrBrowserView) ((JcrBrowserView) iwp.getActivePart()).refresh(sjn); } catch (RepositoryException e) { - throw new ArgeoException("Unable to rename " + node + throw new EclipseUiException("Unable to rename " + node + " to " + newName, e); } } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/FullVersioningTreeContentProvider.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/FullVersioningTreeContentProvider.java index b4132ed85..7e4e2918a 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/FullVersioningTreeContentProvider.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/FullVersioningTreeContentProvider.java @@ -26,7 +26,7 @@ import javax.jcr.version.VersionHistory; import javax.jcr.version.VersionIterator; import javax.jcr.version.VersionManager; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; @@ -57,7 +57,7 @@ public class FullVersioningTreeContentProvider implements ITreeContentProvider { } return result.toArray(); } catch (RepositoryException re) { - throw new ArgeoException( + throw new EclipseUiException( "Unexpected error while getting version elements", re); } } @@ -70,7 +70,7 @@ public class FullVersioningTreeContentProvider implements ITreeContentProvider { return tmp.toArray(); } } catch (RepositoryException re) { - throw new ArgeoException("Unexpected error while getting child " + throw new EclipseUiException("Unexpected error while getting child " + "node for version element", re); } return null; @@ -100,7 +100,7 @@ public class FullVersioningTreeContentProvider implements ITreeContentProvider { else return false; } catch (RepositoryException e) { - throw new ArgeoException("Cannot check children of " + element, e); + throw new EclipseUiException("Cannot check children of " + element, e); } } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/GenericNodeDoubleClickListener.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/GenericNodeDoubleClickListener.java index 469713ae0..7d898fd8e 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/GenericNodeDoubleClickListener.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/GenericNodeDoubleClickListener.java @@ -19,7 +19,7 @@ import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.nodetype.NodeType; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin; import org.argeo.eclipse.ui.workbench.internal.jcr.model.RepositoryElem; import org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem; @@ -103,10 +103,10 @@ public class GenericNodeDoubleClickListener implements IDoubleClickListener { .getActiveWorkbenchWindow().getActivePage() .openEditor(gnei, DefaultNodeEditor.ID); } catch (RepositoryException re) { - throw new ArgeoException( + throw new EclipseUiException( "Repository error while getting node info", re); } catch (PartInitException pie) { - throw new ArgeoException( + throw new EclipseUiException( "Unexepected exception while opening node editor", pie); } } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/JcrBrowserUtils.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/JcrBrowserUtils.java index 4261d9f40..9e3e31878 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/JcrBrowserUtils.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/JcrBrowserUtils.java @@ -18,7 +18,7 @@ package org.argeo.eclipse.ui.workbench.internal.jcr; import javax.jcr.Node; import javax.jcr.RepositoryException; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.TreeParent; import org.argeo.eclipse.ui.workbench.internal.jcr.model.RepositoriesElem; import org.argeo.eclipse.ui.workbench.internal.jcr.model.RepositoryElem; @@ -69,7 +69,7 @@ public class JcrBrowserUtils { element.getChildren(); } } catch (RepositoryException re) { - throw new ArgeoException( + throw new EclipseUiException( "Unexpected error while synchronising the UI with the JCR repository", re); } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/NodeContentProvider.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/NodeContentProvider.java index e9bb70678..652da3fd8 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/NodeContentProvider.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/NodeContentProvider.java @@ -27,11 +27,11 @@ import javax.jcr.Session; import javax.jcr.nodetype.NodeType; import org.argeo.eclipse.ui.TreeParent; +import org.argeo.eclipse.ui.workbench.internal.jcr.model.RepositoriesElem; +import org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem; import org.argeo.jcr.ArgeoJcrConstants; import org.argeo.jcr.RepositoryRegister; import org.argeo.jcr.UserJcrUtils; -import org.argeo.eclipse.ui.workbench.internal.jcr.model.RepositoriesElem; -import org.argeo.eclipse.ui.workbench.internal.jcr.model.SingleJcrNodeElem; import org.argeo.util.security.Keyring; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/NodeLabelProvider.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/NodeLabelProvider.java index 0686c2342..2ed6232a6 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/NodeLabelProvider.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/NodeLabelProvider.java @@ -21,7 +21,7 @@ import javax.jcr.nodetype.NodeType; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.workbench.internal.jcr.model.RemoteRepositoryElem; import org.argeo.eclipse.ui.workbench.internal.jcr.model.RepositoriesElem; import org.argeo.eclipse.ui.workbench.internal.jcr.model.RepositoryElem; @@ -48,7 +48,7 @@ public class NodeLabelProvider extends ColumnLabelProvider { } else return super.getText(element); } catch (RepositoryException e) { - throw new ArgeoException( + throw new EclipseUiException( "Unexpected JCR error while getting node name."); } } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/PropertiesContentProvider.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/PropertiesContentProvider.java index 58571eba8..d0b0e394c 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/PropertiesContentProvider.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/PropertiesContentProvider.java @@ -23,7 +23,7 @@ import javax.jcr.Property; import javax.jcr.PropertyIterator; import javax.jcr.RepositoryException; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.jcr.utils.JcrItemsComparator; import org.eclipse.jface.viewers.IStructuredContentProvider; import org.eclipse.jface.viewers.Viewer; @@ -49,7 +49,7 @@ public class PropertiesContentProvider implements IStructuredContentProvider { } return new Object[] {}; } catch (RepositoryException e) { - throw new ArgeoException("Cannot get element for " + inputElement, + throw new EclipseUiException("Cannot get element for " + inputElement, e); } } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/PropertyLabelProvider.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/PropertyLabelProvider.java index 1964b7b74..34e91f4ca 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/PropertyLabelProvider.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/PropertyLabelProvider.java @@ -23,7 +23,7 @@ import javax.jcr.PropertyType; import javax.jcr.RepositoryException; import javax.jcr.Value; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.workbench.WorkbenchConstants; import org.argeo.jcr.JcrUtils; import org.eclipse.jface.viewers.ColumnLabelProvider; @@ -87,7 +87,7 @@ public class PropertyLabelProvider extends ColumnLabelProvider implements } } catch (RepositoryException re) { - throw new ArgeoException( + throw new EclipseUiException( "Unexepected error while getting property values", re); } return null; @@ -106,7 +106,7 @@ public class PropertyLabelProvider extends ColumnLabelProvider implements strValue = value.getString(); return strValue; } catch (RepositoryException e) { - throw new ArgeoException("unexpected error while formatting value", + throw new EclipseUiException("unexpected error while formatting value", e); } } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/SingleNodeAsTreeContentProvider.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/SingleNodeAsTreeContentProvider.java index 1dcd28720..7050b7b89 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/SingleNodeAsTreeContentProvider.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/SingleNodeAsTreeContentProvider.java @@ -23,7 +23,7 @@ import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.RepositoryException; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.jcr.utils.JcrItemsComparator; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; @@ -52,7 +52,7 @@ public class SingleNodeAsTreeContentProvider implements ITreeContentProvider { return result.toArray(); } catch (RepositoryException re) { - throw new ArgeoException( + throw new EclipseUiException( "Unexpected error while getting child nodes for children editor page ", re); } @@ -78,7 +78,7 @@ public class SingleNodeAsTreeContentProvider implements ITreeContentProvider { try { return ((Node) element).hasNodes(); } catch (RepositoryException e) { - throw new ArgeoException("Cannot check children of " + element, e); + throw new EclipseUiException("Cannot check children of " + element, e); } } @@ -100,7 +100,7 @@ public class SingleNodeAsTreeContentProvider implements ITreeContentProvider { Arrays.sort(arr, itemComparator); return arr; } catch (RepositoryException e) { - throw new ArgeoException("Cannot list children of " + parentNode, e); + throw new EclipseUiException("Cannot list children of " + parentNode, e); } } } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/VersionLabelProvider.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/VersionLabelProvider.java index f7e110ae8..e6672f2ce 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/VersionLabelProvider.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/VersionLabelProvider.java @@ -19,7 +19,7 @@ import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.version.Version; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.eclipse.jface.viewers.ColumnLabelProvider; /** @@ -40,7 +40,7 @@ public class VersionLabelProvider extends ColumnLabelProvider { return ((Node) element).getName(); } } catch (RepositoryException re) { - throw new ArgeoException( + throw new EclipseUiException( "Unexpected error while getting element name", re); } return super.getText(element); diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/model/RemoteRepositoryElem.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/model/RemoteRepositoryElem.java index f243a2dd0..ec8db4aab 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/model/RemoteRepositoryElem.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/model/RemoteRepositoryElem.java @@ -24,7 +24,7 @@ import javax.jcr.RepositoryFactory; import javax.jcr.Session; import javax.jcr.SimpleCredentials; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.TreeParent; import org.argeo.jcr.ArgeoJcrUtils; import org.argeo.jcr.ArgeoNames; @@ -87,7 +87,7 @@ public class RemoteRepositoryElem extends RepositoryElem { remoteNode.remove(); remoteNode.getSession().save(); } catch (RepositoryException e) { - throw new ArgeoException("Cannot remove " + remoteNodePath, e); + throw new EclipseUiException("Cannot remove " + remoteNodePath, e); } } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/model/RepositoriesElem.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/model/RepositoriesElem.java index 073754487..ceab362bc 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/model/RepositoriesElem.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/model/RepositoriesElem.java @@ -24,7 +24,7 @@ import javax.jcr.RepositoryException; import javax.jcr.RepositoryFactory; import javax.jcr.Session; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.TreeParent; import org.argeo.eclipse.ui.dialogs.ErrorFeedback; import org.argeo.jcr.ArgeoNames; @@ -88,7 +88,7 @@ public class RepositoriesElem extends TreeParent implements ArgeoNames { try { addRemoteRepositories(keyring); } catch (RepositoryException e) { - throw new ArgeoException("Cannot browse remote repositories", e); + throw new EclipseUiException("Cannot browse remote repositories", e); } } return super.getChildren(); diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/model/RepositoryElem.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/model/RepositoryElem.java index 5adf6f546..f3b73b042 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/model/RepositoryElem.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/model/RepositoryElem.java @@ -19,7 +19,7 @@ import javax.jcr.Repository; import javax.jcr.RepositoryException; import javax.jcr.Session; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.TreeParent; /** @@ -53,7 +53,7 @@ public class RepositoryElem extends TreeParent { addChild(new WorkspaceElem(this, wkpName)); } } catch (RepositoryException e) { - throw new ArgeoException("Cannot connect to repository " + alias, e); + throw new EclipseUiException("Cannot connect to repository " + alias, e); } } @@ -71,7 +71,7 @@ public class RepositoryElem extends TreeParent { try { return defaultSession.getWorkspace().getAccessibleWorkspaceNames(); } catch (RepositoryException e) { - throw new ArgeoException("Cannot retrieve workspace names", e); + throw new EclipseUiException("Cannot retrieve workspace names", e); } } @@ -81,7 +81,7 @@ public class RepositoryElem extends TreeParent { try { defaultSession.getWorkspace().createWorkspace(workspaceName); } catch (RepositoryException e) { - throw new ArgeoException("Cannot create workspace", e); + throw new EclipseUiException("Cannot create workspace", e); } } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/model/SingleJcrNodeElem.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/model/SingleJcrNodeElem.java index dfc0b3d29..b69a4803a 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/model/SingleJcrNodeElem.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/model/SingleJcrNodeElem.java @@ -20,7 +20,7 @@ import javax.jcr.NodeIterator; import javax.jcr.RepositoryException; import javax.jcr.Workspace; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.TreeParent; /** @@ -84,7 +84,7 @@ public class SingleJcrNodeElem extends TreeParent { } return super.getChildren(); } catch (RepositoryException re) { - throw new ArgeoException( + throw new EclipseUiException( "Unexcpected error while initializing children SingleJcrNode", re); } @@ -99,7 +99,7 @@ public class SingleJcrNodeElem extends TreeParent { else return false; } catch (RepositoryException re) { - throw new ArgeoException( + throw new EclipseUiException( "Unexpected error while checking children node existence", re); } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/model/WorkspaceElem.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/model/WorkspaceElem.java index c20fb98d7..e0e9a3e22 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/model/WorkspaceElem.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/model/WorkspaceElem.java @@ -20,8 +20,9 @@ import javax.jcr.NodeIterator; import javax.jcr.RepositoryException; import javax.jcr.Session; // import javax.jcr.Workspace; +import javax.jcr.Workspace; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.TreeParent; import org.argeo.jcr.JcrUtils; @@ -54,7 +55,7 @@ public class WorkspaceElem extends TreeParent { else return null; } catch (RepositoryException e) { - throw new ArgeoException("Cannot get root node of workspace " + throw new EclipseUiException("Cannot get root node of workspace " + getName(), e); } } @@ -63,7 +64,7 @@ public class WorkspaceElem extends TreeParent { try { session = ((RepositoryElem) getParent()).repositoryLogin(getName()); } catch (RepositoryException e) { - throw new ArgeoException("Cannot connect to repository " + throw new EclipseUiException("Cannot connect to repository " + getName(), e); } } @@ -96,7 +97,7 @@ public class WorkspaceElem extends TreeParent { else return false; } catch (RepositoryException re) { - throw new ArgeoException( + throw new EclipseUiException( "Unexpected error while checking children node existence", re); } @@ -122,7 +123,7 @@ public class WorkspaceElem extends TreeParent { } return super.getChildren(); } catch (RepositoryException e) { - throw new ArgeoException( + throw new EclipseUiException( "Cannot initialize WorkspaceNode UI object." + getName(), e); } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/AbstractJcrQueryEditor.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/AbstractJcrQueryEditor.java index 81914e37b..0633454ce 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/AbstractJcrQueryEditor.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/AbstractJcrQueryEditor.java @@ -26,7 +26,7 @@ import javax.jcr.query.RowIterator; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.GenericTableComparator; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -146,7 +146,7 @@ public abstract class AbstractJcrQueryEditor extends EditorPart { } viewer.setInput(rows); } catch (RepositoryException e) { - throw new ArgeoException("Cannot read query result", e); + throw new EclipseUiException("Cannot read query result", e); } } catch (RepositoryException e) { @@ -209,7 +209,7 @@ public abstract class AbstractJcrQueryEditor extends EditorPart { try { return row.getValue(columnName).getString(); } catch (RepositoryException e) { - throw new ArgeoException("Cannot display row " + row, e); + throw new EclipseUiException("Cannot display row " + row, e); } } @@ -274,7 +274,7 @@ public abstract class AbstractJcrQueryEditor extends EditorPart { // } return rows.toArray(); } catch (RepositoryException e) { - throw new ArgeoException("Cannot read query result", e); + throw new EclipseUiException("Cannot read query result", e); } } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/AddPrivilegeWizard.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/AddPrivilegeWizard.java index caca94366..1837ee7b7 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/AddPrivilegeWizard.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/AddPrivilegeWizard.java @@ -23,7 +23,7 @@ import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.security.Privilege; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.EclipseUiUtils; import org.argeo.eclipse.ui.workbench.internal.users.UsersUtils; import org.argeo.eclipse.ui.workbench.users.PickUpUserDialog; @@ -103,7 +103,7 @@ public class AddPrivilegeWizard extends Wizard { page = new DefinePrivilegePage(userAdmin, targetPath); addPage(page); } catch (Exception e) { - throw new ArgeoException("Cannot add page to wizard ", e); + throw new EclipseUiException("Cannot add page to wizard ", e); } } @@ -115,7 +115,7 @@ public class AddPrivilegeWizard extends Wizard { JcrUtils.addPrivilege(currentSession, targetPath, chosenUser.getName(), jcrPrivilege); } catch (RepositoryException re) { - throw new ArgeoException("Cannot set " + jcrPrivilege + " for " + throw new EclipseUiException("Cannot set " + jcrPrivilege + " for " + chosenUser.getName() + " on " + targetPath, re); } return true; diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/ChildNodesPage.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/ChildNodesPage.java index 8a7d49665..90ae7b5e9 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/ChildNodesPage.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/ChildNodesPage.java @@ -17,7 +17,7 @@ package org.argeo.eclipse.ui.workbench.internal.jcr.parts; import javax.jcr.Node; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.EclipseUiUtils; import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin; import org.argeo.eclipse.ui.workbench.internal.jcr.NodeLabelProvider; @@ -74,7 +74,7 @@ public class ChildNodesPage extends FormPage { nodesViewer.setInput(currentNode); } } catch (Exception e) { - throw new ArgeoException( + throw new EclipseUiException( "Unexpected error while creating child node page", e); } } @@ -108,7 +108,7 @@ public class ChildNodesPage extends FormPage { .getActiveWorkbenchWindow().getActivePage() .openEditor(gnei, DefaultNodeEditor.ID); } catch (PartInitException pie) { - throw new ArgeoException( + throw new EclipseUiException( "Unexepected exception while opening node editor", pie); } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/GenericNodeEditorInput.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/GenericNodeEditorInput.java index 6e12cb81f..e54ad6333 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/GenericNodeEditorInput.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/GenericNodeEditorInput.java @@ -18,7 +18,7 @@ package org.argeo.eclipse.ui.workbench.internal.jcr.parts; import javax.jcr.Node; import javax.jcr.RepositoryException; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IPersistableElement; @@ -43,7 +43,7 @@ public class GenericNodeEditorInput implements IEditorInput { uid = currentNode.getIdentifier(); path = currentNode.getPath(); } catch (RepositoryException re) { - throw new ArgeoException( + throw new EclipseUiException( "unexpected error while getting node key values at creation time", re); } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/GenericNodePage.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/GenericNodePage.java index cc7352b6f..13bc676fa 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/GenericNodePage.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/GenericNodePage.java @@ -28,7 +28,7 @@ import javax.jcr.PropertyIterator; import javax.jcr.PropertyType; import javax.jcr.RepositoryException; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.workbench.WorkbenchConstants; import org.argeo.jcr.JcrUtils; import org.eclipse.swt.SWT; @@ -111,7 +111,7 @@ public class GenericNodePage extends FormPage implements WorkbenchConstants { currentNode.getSession().save(); } } catch (RepositoryException re) { - throw new ArgeoException( + throw new EclipseUiException( "Unexpected error while saving properties", re); } } @@ -124,7 +124,7 @@ public class GenericNodePage extends FormPage implements WorkbenchConstants { getManagedForm().addPart(part); } catch (RepositoryException re) { - throw new ArgeoException( + throw new EclipseUiException( "Error during creation of network details section", re); } @@ -142,7 +142,7 @@ public class GenericNodePage extends FormPage implements WorkbenchConstants { } else addModifyableValueWidget(parent, part, prop); } catch (RepositoryException re) { - throw new ArgeoException("Cannot get property " + prop, re); + throw new EclipseUiException("Cannot get property " + prop, re); } } @@ -162,7 +162,7 @@ public class GenericNodePage extends FormPage implements WorkbenchConstants { return strValue; } catch (RepositoryException re) { - throw new ArgeoException( + throw new EclipseUiException( "Unexpected error while formatting read only property value", re); } @@ -188,7 +188,7 @@ public class GenericNodePage extends FormPage implements WorkbenchConstants { } return null; } catch (RepositoryException re) { - throw new ArgeoException( + throw new EclipseUiException( "Unexpected error while formatting read only property value", re); } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/GenericPropertyPage.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/GenericPropertyPage.java index 8d43ad40c..17afa7d14 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/GenericPropertyPage.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/GenericPropertyPage.java @@ -24,7 +24,7 @@ import javax.jcr.PropertyIterator; import javax.jcr.RepositoryException; import javax.jcr.Value; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.workbench.WorkbenchConstants; import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin; import org.argeo.eclipse.ui.workbench.internal.jcr.PropertyLabelProvider; @@ -138,7 +138,7 @@ public class GenericPropertyPage extends FormPage implements WorkbenchConstants // super.commit(onSave); // } // } catch (RepositoryException re) { - // throw new ArgeoException( + // throw new EclipseUiException( // "Unexpected error while saving properties", re); // } // } @@ -151,7 +151,7 @@ public class GenericPropertyPage extends FormPage implements WorkbenchConstants // // getManagedForm().addPart(part); // } catch (RepositoryException re) { - // throw new ArgeoException( + // throw new EclipseUiException( // "Error during creation of network details section", re); // } // @@ -169,7 +169,7 @@ public class GenericPropertyPage extends FormPage implements WorkbenchConstants // } else // addModifyableValueWidget(parent, part, prop); // } catch (RepositoryException re) { - // throw new ArgeoException("Cannot get property " + prop, re); + // throw new EclipseUiException("Cannot get property " + prop, re); // } // } // @@ -189,7 +189,7 @@ public class GenericPropertyPage extends FormPage implements WorkbenchConstants // // return strValue; // } catch (RepositoryException re) { - // throw new ArgeoException( + // throw new EclipseUiException( // "Unexpected error while formatting read only property value", // re); // } @@ -214,7 +214,7 @@ public class GenericPropertyPage extends FormPage implements WorkbenchConstants // } // return null; // } catch (RepositoryException re) { - // throw new ArgeoException( + // throw new EclipseUiException( // "Unexpected error while formatting read only property value", // re); // } @@ -258,7 +258,7 @@ public class GenericPropertyPage extends FormPage implements WorkbenchConstants props = propList.toArray(); } } catch (RepositoryException e) { - throw new ArgeoException( + throw new EclipseUiException( "Unexpected exception while listing node properties", e); } return props; @@ -287,7 +287,7 @@ public class GenericPropertyPage extends FormPage implements WorkbenchConstants return values; } } catch (RepositoryException e) { - throw new ArgeoException( + throw new EclipseUiException( "Unexpected error getting multiple values property.", e); } @@ -302,7 +302,7 @@ public class GenericPropertyPage extends FormPage implements WorkbenchConstants return true; } } catch (RepositoryException e) { - throw new ArgeoException( + throw new EclipseUiException( "Unexpected exception while checking if property is multiple", e); } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/ImportFileSystemWizard.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/ImportFileSystemWizard.java index 1ccec0fb6..5ac403cce 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/ImportFileSystemWizard.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/ImportFileSystemWizard.java @@ -28,7 +28,7 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.dialogs.ErrorFeedback; import org.argeo.eclipse.ui.specific.UploadFileWizardPage; import org.eclipse.core.runtime.IProgressMonitor; @@ -117,7 +117,7 @@ public class ImportFileSystemWizard extends Wizard { if (e instanceof RuntimeException) throw (RuntimeException) e; else - throw new ArgeoException("Cannot import " + throw new EclipseUiException("Cannot import " + objectPath, e); } } @@ -225,7 +225,7 @@ public class ImportFileSystemWizard extends Wizard { } } } catch (Exception e) { - throw new ArgeoException("Cannot import " + dir + " to " + folder, + throw new EclipseUiException("Cannot import " + dir + " to " + folder, e); } } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/NodePrivilegesPage.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/NodePrivilegesPage.java index 760a21319..1732fa439 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/NodePrivilegesPage.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/NodePrivilegesPage.java @@ -23,7 +23,7 @@ import javax.jcr.NodeIterator; import javax.jcr.RepositoryException; import javax.jcr.Value; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin; import org.eclipse.jface.viewers.ColumnLabelProvider; import org.eclipse.jface.viewers.IStructuredContentProvider; @@ -89,7 +89,7 @@ public class NodePrivilegesPage extends FormPage { return node.getProperty("rep:principalName") .getString(); } catch (RepositoryException e) { - throw new ArgeoException("Unable to retrieve " + throw new EclipseUiException("Unable to retrieve " + "principal name on " + node, e); } return ""; @@ -126,7 +126,7 @@ public class NodePrivilegesPage extends FormPage { } } catch (RepositoryException e) { - throw new ArgeoException("Unable to retrieve " + throw new EclipseUiException("Unable to retrieve " + "privileges on " + node, e); } return ""; @@ -150,7 +150,7 @@ public class NodePrivilegesPage extends FormPage { try { return node.getParent().getParent().getPath(); } catch (RepositoryException e) { - throw new ArgeoException("Unable get path for " + node, e); + throw new EclipseUiException("Unable get path for " + node, e); } } @@ -232,7 +232,7 @@ public class NodePrivilegesPage extends FormPage { return privs.toArray(); } catch (Exception e) { - throw new ArgeoException("Cannot retrieve authorization for " + throw new EclipseUiException("Cannot retrieve authorization for " + context, e); } } @@ -244,7 +244,7 @@ public class NodePrivilegesPage extends FormPage { String cname = context.getSession().getClass().getName(); return cname.startsWith("org.apache.jackrabbit"); } catch (RepositoryException e) { - throw new ArgeoException("Cannot check JCR implementation used on " + throw new EclipseUiException("Cannot check JCR implementation used on " + context, e); } } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/NodeVersionHistoryPage.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/NodeVersionHistoryPage.java index e760ad82e..f91e3987c 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/NodeVersionHistoryPage.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/jcr/parts/NodeVersionHistoryPage.java @@ -33,15 +33,15 @@ import javax.jcr.version.VersionHistory; import javax.jcr.version.VersionIterator; import javax.jcr.version.VersionManager; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.workbench.WorkbenchConstants; import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin; -import org.argeo.jcr.JcrUtils; -import org.argeo.jcr.PropertyDiff; -import org.argeo.jcr.VersionDiff; import org.argeo.eclipse.ui.workbench.internal.jcr.FullVersioningTreeContentProvider; import org.argeo.eclipse.ui.workbench.internal.jcr.GenericNodeDoubleClickListener; import org.argeo.eclipse.ui.workbench.internal.jcr.VersionLabelProvider; +import org.argeo.jcr.JcrUtils; +import org.argeo.jcr.PropertyDiff; +import org.argeo.jcr.VersionDiff; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.swt.SWT; @@ -105,7 +105,7 @@ public class NodeVersionHistoryPage extends FormPage implements createTreeSection(form.getBody()); } } catch (RepositoryException e) { - throw new ArgeoException( + throw new EclipseUiException( "Unexpected error while checking if node is versionable", e); } } @@ -253,7 +253,7 @@ public class NodeVersionHistoryPage extends FormPage implements } styledText.setText(main.toString()); } catch (RepositoryException e) { - throw new ArgeoException("Cannot generate history for node", e); + throw new EclipseUiException("Cannot generate history for node", e); } } @@ -307,7 +307,7 @@ public class NodeVersionHistoryPage extends FormPage implements } return res; } catch (RepositoryException e) { - throw new ArgeoException("Cannot generate history for node "); + throw new EclipseUiException("Cannot generate history for node "); } } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/users/UsersUtils.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/users/UsersUtils.java index 8ad28fc25..397ecdebd 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/users/UsersUtils.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/internal/users/UsersUtils.java @@ -9,7 +9,7 @@ import javax.naming.ldap.Rdn; import javax.security.auth.Subject; import javax.security.auth.x500.X500Principal; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.osgi.useradmin.LdifName; import org.osgi.service.useradmin.Role; import org.osgi.service.useradmin.User; @@ -29,7 +29,7 @@ public class UsersUtils { else return false; } catch (InvalidNameException e) { - throw new ArgeoException("User " + user + " has an unvalid dn: " + throw new EclipseUiException("User " + user + " has an unvalid dn: " + userName, e); } } @@ -42,7 +42,7 @@ public class UsersUtils { try { dn = new LdapName(name); } catch (InvalidNameException e) { - throw new ArgeoException("Invalid user dn " + name, e); + throw new EclipseUiException("Invalid user dn " + name, e); } return dn; } @@ -74,7 +74,7 @@ public class UsersUtils { } return dname; } catch (InvalidNameException e) { - throw new ArgeoException("Unable to get domain name for " + dn, e); + throw new EclipseUiException("Unable to get domain name for " + dn, e); } } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/DefaultNodeEditor.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/DefaultNodeEditor.java index 89c812d17..e103bf61f 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/DefaultNodeEditor.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/DefaultNodeEditor.java @@ -24,7 +24,7 @@ import javax.jcr.nodetype.NodeType; import javax.jcr.security.AccessControlManager; import javax.jcr.security.Privilege; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin; import org.argeo.eclipse.ui.workbench.internal.jcr.parts.ChildNodesPage; import org.argeo.eclipse.ui.workbench.internal.jcr.parts.GenericNodeEditorInput; @@ -109,10 +109,10 @@ public class DefaultNodeEditor extends FormEditor { } } catch (RepositoryException e) { - throw new ArgeoException("Cannot get node info for " + currentNode, + throw new EclipseUiException("Cannot get node info for " + currentNode, e); } catch (PartInitException e) { - throw new ArgeoException("Cannot add page " + "on node editor for " + throw new EclipseUiException("Cannot add page " + "on node editor for " + currentNode, e); } } @@ -129,7 +129,7 @@ public class DefaultNodeEditor extends FormEditor { commitPages(true); firePropertyChange(PROP_DIRTY); } catch (Exception e) { - throw new ArgeoException("Error while saving node", e); + throw new EclipseUiException("Error while saving node", e); } } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/JcrBrowserView.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/JcrBrowserView.java index 3474f6ba1..b98553559 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/JcrBrowserView.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/JcrBrowserView.java @@ -28,7 +28,7 @@ import javax.jcr.observation.Event; import javax.jcr.observation.EventListener; import javax.jcr.observation.ObservationManager; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.TreeParent; import org.argeo.eclipse.ui.jcr.AsyncUiEventListener; import org.argeo.eclipse.ui.jcr.utils.NodeViewerComparer; @@ -99,7 +99,7 @@ public class JcrBrowserView extends ViewPart { try { this.userSession = this.nodeRepository.login(); } catch (RepositoryException e) { - throw new ArgeoException("Cannot open user session", e); + throw new EclipseUiException("Cannot open user session", e); } nodeContentProvider = new NodeContentProvider(userSession, keyring, @@ -184,7 +184,7 @@ public class JcrBrowserView extends ViewPart { Event.PROPERTY_ADDED | Event.PROPERTY_CHANGED, "/", true, null, null, false); } catch (RepositoryException e) { - throw new ArgeoException("Cannot register listeners", e); + throw new EclipseUiException("Cannot register listeners", e); } tmpNodeViewer @@ -210,7 +210,7 @@ public class JcrBrowserView extends ViewPart { try { return ((Property) element).getName(); } catch (RepositoryException e) { - throw new ArgeoException( + throw new EclipseUiException( "Unexpected exception in label provider", e); } } @@ -239,7 +239,7 @@ public class JcrBrowserView extends ViewPart { } else return property.getValue().getString(); } catch (RepositoryException e) { - throw new ArgeoException( + throw new EclipseUiException( "Unexpected exception in label provider", e); } } @@ -255,7 +255,7 @@ public class JcrBrowserView extends ViewPart { return PropertyType.nameFromValue(((Property) element) .getType()); } catch (RepositoryException e) { - throw new ArgeoException( + throw new EclipseUiException( "Unexpected exception in label provider", e); } } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/JcrPreferenceStore.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/JcrPreferenceStore.java index b317e12bc..27349f95d 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/JcrPreferenceStore.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/JcrPreferenceStore.java @@ -28,7 +28,7 @@ import javax.jcr.Session; import javax.jcr.version.VersionManager; import org.apache.commons.io.IOUtils; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.jcr.ArgeoNames; import org.argeo.jcr.ArgeoTypes; import org.argeo.jcr.JcrUtils; @@ -57,7 +57,7 @@ public class JcrPreferenceStore extends PreferenceStore implements ArgeoNames { session.save(); Node userHome = UserJcrUtils.getUserHome(session); if (userHome == null) - throw new ArgeoException("No user home for " + throw new EclipseUiException("No user home for " + session.getUserID()); Node preferences; if (!userHome.hasNode(ARGEO_PREFERENCES)) { @@ -83,7 +83,7 @@ public class JcrPreferenceStore extends PreferenceStore implements ArgeoNames { } catch (RepositoryException e) { e.printStackTrace(); JcrUtils.discardQuietly(session); - throw new ArgeoException("Cannot retrieve preferences", e); + throw new EclipseUiException("Cannot retrieve preferences", e); } } @@ -107,7 +107,7 @@ public class JcrPreferenceStore extends PreferenceStore implements ArgeoNames { load(in); } catch (Exception e) { e.printStackTrace(); - throw new ArgeoException("Cannot load preferences", e); + throw new EclipseUiException("Cannot load preferences", e); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); @@ -139,7 +139,7 @@ public class JcrPreferenceStore extends PreferenceStore implements ArgeoNames { vm.checkin(pluginPreferences.getPath()); } catch (Exception e) { JcrUtils.discardUnderlyingSessionQuietly(pluginPreferences); - throw new ArgeoException("Cannot save preferences", e); + throw new EclipseUiException("Cannot save preferences", e); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); @@ -150,7 +150,7 @@ public class JcrPreferenceStore extends PreferenceStore implements ArgeoNames { try { load(); } catch (IOException e) { - throw new ArgeoException("Cannot initialize preference store", e); + throw new EclipseUiException("Cannot initialize preference store", e); } } diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/users/PickUpUserDialog.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/users/PickUpUserDialog.java index d10053079..b74af70bc 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/users/PickUpUserDialog.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/users/PickUpUserDialog.java @@ -18,8 +18,8 @@ package org.argeo.eclipse.ui.workbench.users; import java.util.ArrayList; import java.util.List; -import org.argeo.ArgeoException; import org.argeo.eclipse.ui.ColumnDefinition; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.EclipseUiUtils; import org.argeo.eclipse.ui.parts.LdifUsersTable; import org.argeo.eclipse.ui.workbench.internal.users.UsersUtils; @@ -240,7 +240,7 @@ public class PickUpUserDialog extends TrayDialog { } roles = userAdmin.getRoles(builder.toString()); } catch (InvalidSyntaxException e) { - throw new ArgeoException("Unable to get roles with filter: " + throw new EclipseUiException("Unable to get roles with filter: " + filter, e); } List users = new ArrayList(); diff --git a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/users/UserLP.java b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/users/UserLP.java index 450702373..0340f8dfe 100644 --- a/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/users/UserLP.java +++ b/org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/users/UserLP.java @@ -3,10 +3,9 @@ package org.argeo.eclipse.ui.workbench.users; import javax.naming.InvalidNameException; import javax.naming.ldap.LdapName; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.workbench.internal.users.UsersImages; import org.argeo.eclipse.ui.workbench.internal.users.UsersUtils; -import org.argeo.osgi.useradmin.LdifName; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.viewers.ColumnLabelProvider; import org.eclipse.swt.SWT; @@ -49,7 +48,7 @@ class UserLP extends ColumnLabelProvider { return bold; } } catch (InvalidNameException e) { - throw new ArgeoException("cannot parse dn for " + element, e); + throw new EclipseUiException("cannot parse dn for " + element, e); } // Disabled as Italic diff --git a/org.argeo.eclipse.ui/bnd.bnd b/org.argeo.eclipse.ui/bnd.bnd index b836fc0e9..65e408ddf 100644 --- a/org.argeo.eclipse.ui/bnd.bnd +++ b/org.argeo.eclipse.ui/bnd.bnd @@ -2,4 +2,5 @@ Import-Package: javax.jcr.nodetype,\ org.eclipse.swt,\ org.eclipse.jface.window,\ org.eclipse.core.commands.common,\ + org.argeo,\ * diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/EclipseArgeoMonitor.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/EclipseArgeoMonitor.java index 7c0b39884..46c19b564 100644 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/EclipseArgeoMonitor.java +++ b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/EclipseArgeoMonitor.java @@ -15,45 +15,14 @@ */ package org.argeo.eclipse.ui; -import org.argeo.ArgeoMonitor; import org.eclipse.core.runtime.IProgressMonitor; /** - * Wraps an Eclipse {@link IProgressMonitor} so that it can be passed to - * framework agnostic Argeo routines. + * @deprecated use {@link EclipseJcrMonitor} instead */ -public class EclipseArgeoMonitor implements ArgeoMonitor { - private final IProgressMonitor progressMonitor; - +@Deprecated +public class EclipseArgeoMonitor extends EclipseJcrMonitor { public EclipseArgeoMonitor(IProgressMonitor progressMonitor) { - this.progressMonitor = progressMonitor; - } - - public void beginTask(String name, int totalWork) { - progressMonitor.beginTask(name, totalWork); - } - - public void done() { - progressMonitor.done(); - } - - public boolean isCanceled() { - return progressMonitor.isCanceled(); - } - - public void setCanceled(boolean value) { - progressMonitor.setCanceled(value); - } - - public void setTaskName(String name) { - progressMonitor.setTaskName(name); - } - - public void subTask(String name) { - progressMonitor.subTask(name); - } - - public void worked(int work) { - progressMonitor.worked(work); + super(progressMonitor); } } diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/EclipseJcrMonitor.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/EclipseJcrMonitor.java new file mode 100644 index 000000000..d9cdd83c7 --- /dev/null +++ b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/EclipseJcrMonitor.java @@ -0,0 +1,59 @@ +/* + * 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.eclipse.ui; + +import org.argeo.jcr.JcrMonitor; +import org.eclipse.core.runtime.IProgressMonitor; + +/** + * Wraps an Eclipse {@link IProgressMonitor} so that it can be passed to + * framework agnostic Argeo routines. + */ +public class EclipseJcrMonitor implements JcrMonitor { + private final IProgressMonitor progressMonitor; + + public EclipseJcrMonitor(IProgressMonitor progressMonitor) { + this.progressMonitor = progressMonitor; + } + + public void beginTask(String name, int totalWork) { + progressMonitor.beginTask(name, totalWork); + } + + public void done() { + progressMonitor.done(); + } + + public boolean isCanceled() { + return progressMonitor.isCanceled(); + } + + public void setCanceled(boolean value) { + progressMonitor.setCanceled(value); + } + + public void setTaskName(String name) { + progressMonitor.setTaskName(name); + } + + public void subTask(String name) { + progressMonitor.subTask(name); + } + + public void worked(int work) { + progressMonitor.worked(work); + } +} diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/EclipseUiException.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/EclipseUiException.java new file mode 100644 index 000000000..37a36e859 --- /dev/null +++ b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/EclipseUiException.java @@ -0,0 +1,15 @@ +package org.argeo.eclipse.ui; + +/** CMS specific exceptions. */ +public class EclipseUiException extends RuntimeException { + private static final long serialVersionUID = -5341764743356771313L; + + public EclipseUiException(String message) { + super(message); + } + + public EclipseUiException(String message, Throwable e) { + super(message, e); + } + +} diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/dialogs/NonModalErrorFeedback.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/dialogs/NonModalErrorFeedback.java index 69d69f90c..513a24838 100644 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/dialogs/NonModalErrorFeedback.java +++ b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/dialogs/NonModalErrorFeedback.java @@ -20,7 +20,7 @@ import java.io.StringWriter; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ShellAdapter; import org.eclipse.swt.events.ShellEvent; @@ -81,7 +81,7 @@ class NonModalErrorFeedback { public void open() { if (shell != null) - throw new ArgeoException("There is already a shell"); + throw new EclipseUiException("There is already a shell"); shell = new Shell(getDisplay(), SWT.NO_TRIM | SWT.BORDER | SWT.ON_TOP); shell.setLayout(new GridLayout()); // shell.setText("Error"); diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/AbstractNodeContentProvider.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/AbstractNodeContentProvider.java index 997b466ed..8d80660a4 100644 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/AbstractNodeContentProvider.java +++ b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/AbstractNodeContentProvider.java @@ -25,8 +25,8 @@ import javax.jcr.Session; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; import org.argeo.eclipse.ui.AbstractTreeContentProvider; +import org.argeo.eclipse.ui.EclipseUiException; /** Canonical implementation of tree content provider manipulating JCR nodes. */ public abstract class AbstractNodeContentProvider extends @@ -59,14 +59,14 @@ public abstract class AbstractNodeContentProvider extends Node node = (Node) element; children = getChildren(node); } catch (RepositoryException e) { - throw new ArgeoException("Cannot get children of " + element, e); + throw new EclipseUiException("Cannot get children of " + element, e); } } else if (element instanceof WrappedNode) { WrappedNode wrappedNode = (WrappedNode) element; try { children = getChildren(wrappedNode.getNode()); } catch (RepositoryException e) { - throw new ArgeoException("Cannot get children of " + throw new EclipseUiException("Cannot get children of " + wrappedNode, e); } } else if (element instanceof NodesWrapper) { @@ -142,7 +142,7 @@ public abstract class AbstractNodeContentProvider extends } } catch (RepositoryException e) { - throw new ArgeoException("Cannot check whether " + element + throw new EclipseUiException("Cannot check whether " + element + " has children", e); } return super.hasChildren(element); diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/AsyncUiEventListener.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/AsyncUiEventListener.java index 100ceb444..5d5a06f58 100644 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/AsyncUiEventListener.java +++ b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/AsyncUiEventListener.java @@ -25,7 +25,7 @@ import javax.jcr.observation.EventListener; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.eclipse.swt.widgets.Display; /** {@link EventListener} which simplifies running actions within the UI thread. */ @@ -70,7 +70,7 @@ public abstract class AsyncUiEventListener implements EventListener { if (!willProcessInUiThread(events)) return; } catch (RepositoryException e) { - throw new ArgeoException("Cannot test skip events " + events, e); + throw new EclipseUiException("Cannot test skip events " + events, e); } // Job job = new Job("JCR Events") { @@ -85,7 +85,7 @@ public abstract class AsyncUiEventListener implements EventListener { try { onEventInUiThread(events); } catch (RepositoryException e) { - throw new ArgeoException("Cannot process events " + throw new EclipseUiException("Cannot process events " + events, e); } } diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/DefaultNodeLabelProvider.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/DefaultNodeLabelProvider.java index 4699597b3..e8157b2fb 100644 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/DefaultNodeLabelProvider.java +++ b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/DefaultNodeLabelProvider.java @@ -20,7 +20,7 @@ import javax.jcr.Property; import javax.jcr.RepositoryException; import javax.jcr.nodetype.NodeType; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.eclipse.jface.viewers.ColumnLabelProvider; import org.eclipse.swt.graphics.Image; @@ -42,7 +42,7 @@ public class DefaultNodeLabelProvider extends ColumnLabelProvider { } return super.getText(element); } catch (RepositoryException e) { - throw new ArgeoException("Cannot get text for of " + element, e); + throw new EclipseUiException("Cannot get text for of " + element, e); } } @@ -65,7 +65,7 @@ public class DefaultNodeLabelProvider extends ColumnLabelProvider { return getImage(((NodesWrapper) element).getNode()); } } catch (RepositoryException e) { - throw new ArgeoException("Cannot retrieve image for " + element, e); + throw new EclipseUiException("Cannot retrieve image for " + element, e); } return super.getImage(element); } @@ -86,7 +86,7 @@ public class DefaultNodeLabelProvider extends ColumnLabelProvider { return getToolTipText(((NodesWrapper) element).getNode()); } } catch (RepositoryException e) { - throw new ArgeoException("Cannot get tooltip for " + element, e); + throw new EclipseUiException("Cannot get tooltip for " + element, e); } return super.getToolTipText(element); } diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/JcrUiUtils.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/JcrUiUtils.java index dd571ae6e..420154b83 100644 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/JcrUiUtils.java +++ b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/JcrUiUtils.java @@ -6,7 +6,7 @@ import javax.jcr.Node; import javax.jcr.PropertyType; import javax.jcr.RepositoryException; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.jcr.lists.NodeViewerComparator; import org.argeo.eclipse.ui.jcr.lists.RowViewerComparator; import org.eclipse.jface.viewers.TableViewer; @@ -82,10 +82,10 @@ public class JcrUiUtils { } default: - throw new ArgeoException("Unimplemented property save"); + throw new EclipseUiException("Unimplemented property save"); } } catch (RepositoryException re) { - throw new ArgeoException("Unexpected error while setting property", + throw new EclipseUiException("Unexpected error while setting property", re); } } diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/NodeElementComparer.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/NodeElementComparer.java index f284b9c13..9afb92d65 100644 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/NodeElementComparer.java +++ b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/NodeElementComparer.java @@ -18,7 +18,7 @@ package org.argeo.eclipse.ui.jcr; import javax.jcr.Node; import javax.jcr.RepositoryException; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.eclipse.jface.viewers.IElementComparer; /** Element comparer for JCR node, to be used in JFace viewers. */ @@ -34,7 +34,7 @@ public class NodeElementComparer implements IElementComparer { return a.equals(b); } } catch (RepositoryException e) { - throw new ArgeoException("Cannot compare nodes", e); + throw new EclipseUiException("Cannot compare nodes", e); } } @@ -44,7 +44,7 @@ public class NodeElementComparer implements IElementComparer { return ((Node) element).getIdentifier().hashCode(); return element.hashCode(); } catch (RepositoryException e) { - throw new ArgeoException("Cannot get hash code", e); + throw new EclipseUiException("Cannot get hash code", e); } } diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/NodesWrapper.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/NodesWrapper.java index dcd3b42f6..d899b00ce 100644 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/NodesWrapper.java +++ b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/NodesWrapper.java @@ -22,7 +22,7 @@ import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.RepositoryException; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; /** * Element of tree which is based on a node, but whose children are not @@ -51,7 +51,7 @@ public class NodesWrapper { try { return getWrappedNodes().toArray(); } catch (RepositoryException e) { - throw new ArgeoException("Cannot get wrapped children", e); + throw new EclipseUiException("Cannot get wrapped children", e); } } diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/SimpleNodeContentProvider.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/SimpleNodeContentProvider.java index 89883073d..43848f671 100644 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/SimpleNodeContentProvider.java +++ b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/SimpleNodeContentProvider.java @@ -23,7 +23,7 @@ import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.Session; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.jcr.JcrUtils; /** Simple JCR node content provider taking a list of String as base path. */ @@ -58,7 +58,7 @@ public class SimpleNodeContentProvider extends AbstractNodeContentProvider { baseNodes.add(getSession().getNode(basePath)); return baseNodes.toArray(); } catch (RepositoryException e) { - throw new ArgeoException("Cannot get base nodes for " + basePaths, + throw new EclipseUiException("Cannot get base nodes for " + basePaths, e); } } diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/lists/NodeViewerComparator.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/lists/NodeViewerComparator.java index 1fa46f099..948c340a7 100644 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/lists/NodeViewerComparator.java +++ b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/lists/NodeViewerComparator.java @@ -9,7 +9,7 @@ import javax.jcr.RepositoryException; import javax.jcr.Value; import javax.jcr.ValueFormatException; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerComparator; @@ -129,7 +129,7 @@ public class NodeViewerComparator extends ViewerComparator { rc = d1.compareTo(d2); break; default: - throw new ArgeoException( + throw new EclipseUiException( "Unimplemented comparaison for PropertyType " + propertyType); } @@ -139,7 +139,7 @@ public class NodeViewerComparator extends ViewerComparator { } } catch (RepositoryException re) { - throw new ArgeoException("Unexpected error " + throw new EclipseUiException("Unexpected error " + "while comparing nodes", re); } return rc; diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/lists/RowViewerComparator.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/lists/RowViewerComparator.java index 45b5f68b3..ffd065599 100644 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/lists/RowViewerComparator.java +++ b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/lists/RowViewerComparator.java @@ -4,7 +4,7 @@ import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.query.Row; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.eclipse.jface.viewers.Viewer; /** @@ -33,7 +33,7 @@ public class RowViewerComparator extends NodeViewerComparator { Node n2 = ((Row) e2).getNode(selectorName); return super.compare(viewer, n1, n2); } catch (RepositoryException re) { - throw new ArgeoException("Unexpected error " + throw new EclipseUiException("Unexpected error " + "while comparing nodes", re); } } diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/lists/SimpleJcrNodeLabelProvider.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/lists/SimpleJcrNodeLabelProvider.java index 76611dbe5..acdd844fa 100644 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/lists/SimpleJcrNodeLabelProvider.java +++ b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/lists/SimpleJcrNodeLabelProvider.java @@ -10,7 +10,7 @@ import javax.jcr.PropertyType; import javax.jcr.RepositoryException; import javax.jcr.Value; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.eclipse.jface.viewers.ColumnLabelProvider; /** Base implementation of a label provider for controls that display JCR Nodes */ @@ -76,7 +76,7 @@ public class SimpleJcrNodeLabelProvider extends ColumnLabelProvider { } else return ""; } catch (RepositoryException re) { - throw new ArgeoException("Unable to get text from row", re); + throw new EclipseUiException("Unable to get text from row", re); } } @@ -98,7 +98,7 @@ public class SimpleJcrNodeLabelProvider extends ColumnLabelProvider { case PropertyType.NAME: return value.getString(); default: - throw new ArgeoException("Unimplemented label provider " + throw new EclipseUiException("Unimplemented label provider " + "for property type " + value.getType() + " while getting property " + propertyName + " - value: " + value.getString()); diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/lists/SimpleJcrRowLabelProvider.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/lists/SimpleJcrRowLabelProvider.java index bb55f187d..6d19e1c39 100644 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/lists/SimpleJcrRowLabelProvider.java +++ b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/lists/SimpleJcrRowLabelProvider.java @@ -4,7 +4,7 @@ import javax.jcr.Node; import javax.jcr.RepositoryException; import javax.jcr.query.Row; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; /** * Base implementation of a label provider for widgets that display JCR Rows. @@ -40,7 +40,7 @@ public class SimpleJcrRowLabelProvider extends SimpleJcrNodeLabelProvider { Node currNode = currRow.getNode(selectorName); return super.getText(currNode); } catch (RepositoryException re) { - throw new ArgeoException("Unable to get Node " + selectorName + throw new EclipseUiException("Unable to get Node " + selectorName + " from row " + element, re); } } diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/utils/JcrFileProvider.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/utils/JcrFileProvider.java index 3ca745dc4..6967af461 100644 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/utils/JcrFileProvider.java +++ b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/utils/JcrFileProvider.java @@ -23,7 +23,7 @@ import javax.jcr.RepositoryException; import javax.jcr.nodetype.NodeType; import org.apache.commons.io.IOUtils; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.FileProvider; /** @@ -92,7 +92,7 @@ public class JcrFileProvider implements FileProvider { ba = IOUtils.toByteArray(fis); } catch (Exception e) { - throw new ArgeoException("Stream error while opening file", e); + throw new EclipseUiException("Stream error while opening file", e); } finally { IOUtils.closeQuietly(fis); } @@ -108,7 +108,7 @@ public class JcrFileProvider implements FileProvider { .getBinary().getStream(); return fis; } catch (RepositoryException re) { - throw new ArgeoException("Cannot get stream from file node for Id " + throw new EclipseUiException("Cannot get stream from file node for Id " + fileId, re); } } @@ -147,7 +147,7 @@ public class JcrFileProvider implements FileProvider { // Sanity checks if (result == null) - throw new ArgeoException("File node not found for ID" + fileId); + throw new EclipseUiException("File node not found for ID" + fileId); Node child = null; @@ -164,7 +164,7 @@ public class JcrFileProvider implements FileProvider { } if (!isValid) - throw new ArgeoException( + throw new EclipseUiException( "ERROR: In the current implemented model, '" + NodeType.NT_FILE + "' file node must have a child node named jcr:content " @@ -173,7 +173,7 @@ public class JcrFileProvider implements FileProvider { return child; } catch (RepositoryException re) { - throw new ArgeoException("Erreur while getting file node of ID " + throw new EclipseUiException("Erreur while getting file node of ID " + fileId, re); } } diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/utils/JcrItemsComparator.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/utils/JcrItemsComparator.java index 2d36bf28a..5f17f4163 100644 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/utils/JcrItemsComparator.java +++ b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/utils/JcrItemsComparator.java @@ -20,7 +20,7 @@ import java.util.Comparator; import javax.jcr.Item; import javax.jcr.RepositoryException; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; /** Compares two JCR items (node or properties) based on their names. */ public class JcrItemsComparator implements Comparator { @@ -29,7 +29,7 @@ public class JcrItemsComparator implements Comparator { // TODO: put folder before files return o1.getName().compareTo(o2.getName()); } catch (RepositoryException e) { - throw new ArgeoException("Cannot compare " + o1 + " and " + o2, e); + throw new EclipseUiException("Cannot compare " + o1 + " and " + o2, e); } } diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/utils/NodeViewerComparer.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/utils/NodeViewerComparer.java index 5a94ee76a..db8ca0866 100644 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/utils/NodeViewerComparer.java +++ b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/utils/NodeViewerComparer.java @@ -18,7 +18,7 @@ package org.argeo.eclipse.ui.jcr.utils; import javax.jcr.Node; import javax.jcr.RepositoryException; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.eclipse.jface.viewers.IElementComparer; /** Compare JCR nodes based on their JCR identifiers, for use in JFace viewers. */ @@ -37,7 +37,7 @@ public class NodeViewerComparer implements IElementComparer { String idB = ((Node) elementB).getIdentifier(); result = idA == null ? idB == null : idA.equals(idB); } catch (RepositoryException re) { - throw new ArgeoException("cannot compare nodes", re); + throw new EclipseUiException("cannot compare nodes", re); } return result; diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/utils/SingleSessionFileProvider.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/utils/SingleSessionFileProvider.java index 57bdf246e..caa43481e 100644 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/utils/SingleSessionFileProvider.java +++ b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/jcr/utils/SingleSessionFileProvider.java @@ -24,7 +24,7 @@ import javax.jcr.Session; import javax.jcr.nodetype.NodeType; import org.apache.commons.io.IOUtils; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.FileProvider; /** @@ -58,7 +58,7 @@ public class SingleSessionFileProvider implements FileProvider { ba = IOUtils.toByteArray(fis); } catch (Exception e) { - throw new ArgeoException("Stream error while opening file", e); + throw new EclipseUiException("Stream error while opening file", e); } finally { IOUtils.closeQuietly(fis); } @@ -74,7 +74,7 @@ public class SingleSessionFileProvider implements FileProvider { .getBinary().getStream(); return fis; } catch (RepositoryException re) { - throw new ArgeoException("Cannot get stream from file node for Id " + throw new EclipseUiException("Cannot get stream from file node for Id " + fileId, re); } } @@ -93,23 +93,23 @@ public class SingleSessionFileProvider implements FileProvider { // Sanity checks if (result == null) - throw new ArgeoException("File node not found for ID" + fileId); + throw new EclipseUiException("File node not found for ID" + fileId); // Ensure that the node have the correct type. if (!result.isNodeType(NodeType.NT_FILE)) - throw new ArgeoException( + throw new EclipseUiException( "Cannot open file children Node that are not of " + NodeType.NT_RESOURCE + " type."); Node child = result.getNodes().nextNode(); if (child == null || !child.isNodeType(NodeType.NT_RESOURCE)) - throw new ArgeoException( + throw new EclipseUiException( "ERROR: IN the current implemented model, " + NodeType.NT_FILE + " file node must have one and only one child of the nt:ressource, where actual data is stored"); return child; } catch (RepositoryException re) { - throw new ArgeoException("Erreur while getting file node of ID " + throw new EclipseUiException("Erreur while getting file node of ID " + fileId, re); } } diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/parts/JcrUsersTable.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/parts/JcrUsersTable.java index 5c02b6ec3..0b8b3b262 100644 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/parts/JcrUsersTable.java +++ b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/parts/JcrUsersTable.java @@ -18,7 +18,7 @@ import javax.jcr.query.qom.QueryObjectModelFactory; import javax.jcr.query.qom.Selector; import javax.jcr.query.qom.StaticOperand; -import org.argeo.ArgeoException; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.EclipseUiUtils; import org.argeo.eclipse.ui.jcr.JcrUiUtils; import org.argeo.eclipse.ui.jcr.lists.JcrColumnDefinition; @@ -137,7 +137,7 @@ public class JcrUsersTable extends Composite implements ArgeoNames { } return result; } else - throw new ArgeoException("Unvalid request: no selection column " + throw new EclipseUiException("Unvalid request: no selection column " + "has been created for the current table"); } @@ -247,7 +247,7 @@ public class JcrUsersTable extends Composite implements ArgeoNames { else return null; } catch (RepositoryException e) { - throw new ArgeoException("Cannot get font for " + username, e); + throw new EclipseUiException("Cannot get font for " + username, e); } } } @@ -273,7 +273,7 @@ public class JcrUsersTable extends Composite implements ArgeoNames { return userProfile.hasProperty(name) ? userProfile .getProperty(name).getString() : ""; } catch (RepositoryException e) { - throw new ArgeoException("Cannot get property " + name, e); + throw new EclipseUiException("Cannot get property " + name, e); } } @@ -319,7 +319,7 @@ public class JcrUsersTable extends Composite implements ArgeoNames { hasFilter ? filterTxt.getText() : null)); usersViewer.setInput(nodes.toArray()); } catch (RepositoryException e) { - throw new ArgeoException("Unable to list users", e); + throw new EclipseUiException("Unable to list users", e); } } diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/parts/LdifUsersTable.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/parts/LdifUsersTable.java index 5597e9e7c..91e01d07a 100644 --- a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/parts/LdifUsersTable.java +++ b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/parts/LdifUsersTable.java @@ -3,8 +3,8 @@ package org.argeo.eclipse.ui.parts; import java.util.ArrayList; import java.util.List; -import org.argeo.ArgeoException; import org.argeo.eclipse.ui.ColumnDefinition; +import org.argeo.eclipse.ui.EclipseUiException; import org.argeo.eclipse.ui.EclipseUiUtils; import org.argeo.eclipse.ui.utils.ViewerUtils; import org.eclipse.jface.layout.TableColumnLayout; @@ -143,7 +143,7 @@ public abstract class LdifUsersTable extends Composite { } return result; } else - throw new ArgeoException("Unvalid request: no selection column " + throw new EclipseUiException("Unvalid request: no selection column " + "has been created for the current table"); } @@ -174,7 +174,7 @@ public abstract class LdifUsersTable extends Composite { // for (Role role : roles) // users.add((User) role); // } catch (InvalidSyntaxException e) { - // throw new ArgeoException("Unable to get roles with filter: " + // throw new EclipseUiException("Unable to get roles with filter: " // + filter, e); // } // return users; diff --git a/org.argeo.security.core/bnd.bnd b/org.argeo.security.core/bnd.bnd index 7c2da3ae3..e69de29bb 100644 --- a/org.argeo.security.core/bnd.bnd +++ b/org.argeo.security.core/bnd.bnd @@ -1,5 +0,0 @@ -Import-Package:org.bouncycastle.*;resolution:=optional,\ -bitronix.tm.*;resolution:=optional,\ -org.apache.commons.codec,\ -org.apache.commons.codec.digest,\ -* diff --git a/org.argeo.security.core/ext/test/org/argeo/osgi/useradmin/LdifParserTest.java b/org.argeo.security.core/ext/test/org/argeo/osgi/useradmin/LdifParserTest.java index aabc9a0e7..fecf5dd5a 100644 --- a/org.argeo.security.core/ext/test/org/argeo/osgi/useradmin/LdifParserTest.java +++ b/org.argeo.security.core/ext/test/org/argeo/osgi/useradmin/LdifParserTest.java @@ -1,6 +1,7 @@ package org.argeo.osgi.useradmin; import java.util.ArrayList; +import java.util.Base64; import java.util.List; import java.util.SortedMap; @@ -9,12 +10,10 @@ import javax.naming.directory.Attribute; import javax.naming.directory.Attributes; import javax.naming.ldap.LdapName; -import junit.framework.TestCase; - -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.codec.digest.DigestUtils; import org.argeo.util.naming.LdifParser; +import junit.framework.TestCase; + public class LdifParserTest extends TestCase implements BasicTestConstants { public void testBasicLdif() throws Exception { LdifParser ldifParser = new LdifParser(); @@ -30,7 +29,7 @@ public class LdifParserTest extends TestCase implements BasicTestConstants { assertEquals("{SHA}ieSV55Qc+eQOaYDRSha/AjzNTJE=", new String(rawPwEntry)); byte[] hashedPassword = DigestUtils.sha1("demo".getBytes()); - assertEquals("{SHA}" + Base64.encodeBase64String(hashedPassword), + assertEquals("{SHA}" + Base64.getEncoder().encodeToString(hashedPassword), new String(rawPwEntry)); LdapName adminDn = new LdapName(ADMIN_GROUP_DN); diff --git a/org.argeo.security.core/ext/test/org/argeo/osgi/useradmin/LdifUserAdminTest.java b/org.argeo.security.core/ext/test/org/argeo/osgi/useradmin/LdifUserAdminTest.java index e76769d71..a8a7d226a 100644 --- a/org.argeo.security.core/ext/test/org/argeo/osgi/useradmin/LdifUserAdminTest.java +++ b/org.argeo.security.core/ext/test/org/argeo/osgi/useradmin/LdifUserAdminTest.java @@ -8,6 +8,7 @@ import java.net.URI; import java.nio.file.Files; import java.nio.file.Path; import java.util.Arrays; +import java.util.Base64; import java.util.Dictionary; import java.util.Hashtable; import java.util.List; @@ -15,9 +16,6 @@ import java.util.UUID; import javax.transaction.TransactionManager; -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.codec.digest.DigestUtils; -import org.apache.commons.io.IOUtils; import org.osgi.service.useradmin.Authorization; import org.osgi.service.useradmin.Group; import org.osgi.service.useradmin.Role; @@ -95,7 +93,8 @@ public class LdifUserAdminTest extends TestCase implements BasicTestConstants { assertEquals("root@localhost", rootUser.getProperties().get("mail")); // credentials - byte[] hashedPassword = ("{SHA}" + Base64.encodeBase64String(DigestUtils.sha1("demo".getBytes()))).getBytes(); + byte[] hashedPassword = ("{SHA}" + Base64.getEncoder().encodeToString(DigestUtils.sha1("demo".getBytes()))) + .getBytes(); assertTrue(rootUser.hasCredential(LdifName.userPassword.name(), hashedPassword)); assertTrue(demoUser.hasCredential(LdifName.userPassword.name(), hashedPassword)); @@ -116,7 +115,7 @@ public class LdifUserAdminTest extends TestCase implements BasicTestConstants { ByteArrayOutputStream out = new ByteArrayOutputStream(); ((LdifUserAdmin) userAdmin).save(out); byte[] arr = out.toByteArray(); - IOUtils.closeQuietly(out); + out.close(); userAdmin.destroy(); // String written = new String(arr); // System.out.print(written); diff --git a/org.argeo.security.core/src/org/argeo/osgi/transaction/simple/SimpleTransaction.java b/org.argeo.security.core/src/org/argeo/osgi/transaction/simple/SimpleTransaction.java deleted file mode 100644 index 0e4a58851..000000000 --- a/org.argeo.security.core/src/org/argeo/osgi/transaction/simple/SimpleTransaction.java +++ /dev/null @@ -1,164 +0,0 @@ -package org.argeo.osgi.transaction.simple; - -import java.util.ArrayList; -import java.util.List; - -import javax.transaction.HeuristicMixedException; -import javax.transaction.HeuristicRollbackException; -import javax.transaction.RollbackException; -import javax.transaction.Status; -import javax.transaction.Synchronization; -import javax.transaction.SystemException; -import javax.transaction.Transaction; -import javax.transaction.xa.XAException; -import javax.transaction.xa.XAResource; -import javax.transaction.xa.Xid; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -class SimpleTransaction implements Transaction, Status { - private final static Log log = LogFactory.getLog(SimpleTransaction.class); - - private final Xid xid; - private int status = Status.STATUS_ACTIVE; - private final List xaResources = new ArrayList(); - - private final SimpleTransactionManager transactionManager; - - public SimpleTransaction(SimpleTransactionManager transactionManager) { - this.xid = new UuidXid(); - this.transactionManager = transactionManager; - } - - @Override - public synchronized void commit() throws RollbackException, - HeuristicMixedException, HeuristicRollbackException, - SecurityException, IllegalStateException, SystemException { - status = STATUS_PREPARING; - for (XAResource xaRes : xaResources) { - if (status == STATUS_MARKED_ROLLBACK) - break; - try { - xaRes.prepare(xid); - } catch (XAException e) { - status = STATUS_MARKED_ROLLBACK; - log.error("Cannot prepare " + xaRes + " for " + xid, e); - } - } - if (status == STATUS_MARKED_ROLLBACK) { - rollback(); - throw new RollbackException(); - } - status = STATUS_PREPARED; - - status = STATUS_COMMITTING; - for (XAResource xaRes : xaResources) { - if (status == STATUS_MARKED_ROLLBACK) - break; - try { - xaRes.commit(xid, false); - } catch (XAException e) { - status = STATUS_MARKED_ROLLBACK; - log.error("Cannot prepare " + xaRes + " for " + xid, e); - } - } - if (status == STATUS_MARKED_ROLLBACK) { - rollback(); - throw new RollbackException(); - } - - // complete - status = STATUS_COMMITTED; - if (log.isDebugEnabled()) - log.debug("COMMITTED " + xid); - clearResources(XAResource.TMSUCCESS); - transactionManager.unregister(xid); - } - - @Override - public synchronized void rollback() throws IllegalStateException, - SystemException { - status = STATUS_ROLLING_BACK; - for (XAResource xaRes : xaResources) { - try { - xaRes.rollback(xid); - } catch (XAException e) { - log.error("Cannot rollback " + xaRes + " for " + xid, e); - } - } - - // complete - status = STATUS_ROLLEDBACK; - if (log.isDebugEnabled()) - log.debug("ROLLEDBACK " + xid); - clearResources(XAResource.TMFAIL); - transactionManager.unregister(xid); - } - - @Override - public synchronized boolean enlistResource(XAResource xaRes) - throws RollbackException, IllegalStateException, SystemException { - if (xaResources.add(xaRes)) { - try { - xaRes.start(getXid(), XAResource.TMNOFLAGS); - return true; - } catch (XAException e) { - log.error("Cannot enlist " + xaRes, e); - return false; - } - } else - return false; - } - - @Override - public synchronized boolean delistResource(XAResource xaRes, int flag) - throws IllegalStateException, SystemException { - if (xaResources.remove(xaRes)) { - try { - xaRes.end(getXid(), flag); - } catch (XAException e) { - log.error("Cannot delist " + xaRes, e); - return false; - } - return true; - } else - return false; - } - - protected void clearResources(int flag) { - for (XAResource xaRes : xaResources) - try { - xaRes.end(getXid(), flag); - } catch (XAException e) { - log.error("Cannot end " + xaRes, e); - } - xaResources.clear(); - } - - @Override - public synchronized int getStatus() throws SystemException { - return status; - } - - @Override - public void registerSynchronization(Synchronization sync) - throws RollbackException, IllegalStateException, SystemException { - throw new UnsupportedOperationException(); - } - - @Override - public void setRollbackOnly() throws IllegalStateException, SystemException { - status = STATUS_MARKED_ROLLBACK; - } - - @Override - public int hashCode() { - return xid.hashCode(); - } - - Xid getXid() { - return xid; - } - -} diff --git a/org.argeo.security.core/src/org/argeo/osgi/transaction/simple/SimpleTransactionManager.java b/org.argeo.security.core/src/org/argeo/osgi/transaction/simple/SimpleTransactionManager.java deleted file mode 100644 index 696f0c099..000000000 --- a/org.argeo.security.core/src/org/argeo/osgi/transaction/simple/SimpleTransactionManager.java +++ /dev/null @@ -1,173 +0,0 @@ -package org.argeo.osgi.transaction.simple; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import javax.transaction.HeuristicMixedException; -import javax.transaction.HeuristicRollbackException; -import javax.transaction.InvalidTransactionException; -import javax.transaction.NotSupportedException; -import javax.transaction.RollbackException; -import javax.transaction.Status; -import javax.transaction.Synchronization; -import javax.transaction.SystemException; -import javax.transaction.Transaction; -import javax.transaction.TransactionManager; -import javax.transaction.TransactionSynchronizationRegistry; -import javax.transaction.UserTransaction; -import javax.transaction.xa.Xid; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -public class SimpleTransactionManager implements TransactionManager, UserTransaction { - private final static Log log = LogFactory.getLog(SimpleTransactionManager.class); - - private ThreadLocal current = new ThreadLocal(); - - private Map knownTransactions = Collections - .synchronizedMap(new HashMap()); - private SyncRegistry syncRegistry = new SyncRegistry(); - - @Override - public void begin() throws NotSupportedException, SystemException { - if (getCurrent() != null) - throw new NotSupportedException("Nested transactions are not supported"); - SimpleTransaction transaction = new SimpleTransaction(this); - knownTransactions.put(transaction.getXid(), transaction); - current.set(transaction); - if (log.isDebugEnabled()) - log.debug("STARTED " + transaction.getXid()); - } - - @Override - public void commit() throws RollbackException, HeuristicMixedException, HeuristicRollbackException, - SecurityException, IllegalStateException, SystemException { - if (getCurrent() == null) - throw new IllegalStateException("No transaction registered with the current thread."); - getCurrent().commit(); - } - - @Override - public int getStatus() throws SystemException { - if (getCurrent() == null) - return Status.STATUS_NO_TRANSACTION; - return getTransaction().getStatus(); - } - - @Override - public Transaction getTransaction() throws SystemException { - return getCurrent(); - } - - protected SimpleTransaction getCurrent() throws SystemException { - SimpleTransaction transaction = current.get(); - if (transaction == null) - return null; - int status = transaction.getStatus(); - if (Status.STATUS_COMMITTED == status || Status.STATUS_ROLLEDBACK == status) { - current.remove(); - return null; - } - return transaction; - } - - void unregister(Xid xid) { - knownTransactions.remove(xid); - } - - @Override - public void resume(Transaction tobj) throws InvalidTransactionException, IllegalStateException, SystemException { - if (getCurrent() != null) - throw new IllegalStateException("Transaction " + current.get() + " already registered"); - current.set((SimpleTransaction) tobj); - } - - @Override - public void rollback() throws IllegalStateException, SecurityException, SystemException { - if (getCurrent() == null) - throw new IllegalStateException("No transaction registered with the current thread."); - getCurrent().rollback(); - } - - @Override - public void setRollbackOnly() throws IllegalStateException, SystemException { - if (getCurrent() == null) - throw new IllegalStateException("No transaction registered with the current thread."); - getCurrent().setRollbackOnly(); - } - - @Override - public void setTransactionTimeout(int seconds) throws SystemException { - throw new UnsupportedOperationException(); - } - - @Override - public Transaction suspend() throws SystemException { - Transaction transaction = getCurrent(); - current.remove(); - return transaction; - } - - public TransactionSynchronizationRegistry getTsr() { - return syncRegistry; - } - - private class SyncRegistry implements TransactionSynchronizationRegistry { - @Override - public Object getTransactionKey() { - try { - SimpleTransaction transaction = getCurrent(); - if (transaction == null) - return null; - return getCurrent().getXid(); - } catch (SystemException e) { - throw new RuntimeException("Cannot get transaction key", e); - } - } - - @Override - public void putResource(Object key, Object value) { - throw new UnsupportedOperationException(); - } - - @Override - public Object getResource(Object key) { - throw new UnsupportedOperationException(); - } - - @Override - public void registerInterposedSynchronization(Synchronization sync) { - throw new UnsupportedOperationException(); - } - - @Override - public int getTransactionStatus() { - try { - return getStatus(); - } catch (SystemException e) { - throw new RuntimeException("Cannot get status", e); - } - } - - @Override - public boolean getRollbackOnly() { - try { - return getStatus() == Status.STATUS_MARKED_ROLLBACK; - } catch (SystemException e) { - throw new RuntimeException("Cannot get status", e); - } - } - - @Override - public void setRollbackOnly() { - try { - getCurrent().setRollbackOnly(); - } catch (Exception e) { - throw new RuntimeException("Cannot set rollback only", e); - } - } - - } -} diff --git a/org.argeo.security.core/src/org/argeo/osgi/transaction/simple/UuidXid.java b/org.argeo.security.core/src/org/argeo/osgi/transaction/simple/UuidXid.java deleted file mode 100644 index cf355551f..000000000 --- a/org.argeo.security.core/src/org/argeo/osgi/transaction/simple/UuidXid.java +++ /dev/null @@ -1,132 +0,0 @@ -package org.argeo.osgi.transaction.simple; - -import java.io.Serializable; -import java.nio.ByteBuffer; -import java.util.Arrays; -import java.util.UUID; - -import javax.transaction.xa.Xid; - -/** - * Implementation of {@link Xid} based on {@link UUID}, using max significant - * bits as global transaction id, and least significant bits as branch - * qualifier. - */ -public class UuidXid implements Xid, Serializable { - private static final long serialVersionUID = -5380531989917886819L; - public final static int FORMAT = (int) serialVersionUID; - - private final static int BYTES_PER_LONG = Long.SIZE / Byte.SIZE; - - private final int format; - private final byte[] globalTransactionId; - private final byte[] branchQualifier; - private final String uuid; - private final int hashCode; - - public UuidXid() { - this(UUID.randomUUID()); - } - - public UuidXid(UUID uuid) { - this.format = FORMAT; - this.globalTransactionId = uuidToBytes(uuid.getMostSignificantBits()); - this.branchQualifier = uuidToBytes(uuid.getLeastSignificantBits()); - this.uuid = uuid.toString(); - this.hashCode = uuid.hashCode(); - } - - public UuidXid(Xid xid) { - this(xid.getFormatId(), xid.getGlobalTransactionId(), xid - .getBranchQualifier()); - } - - private UuidXid(int format, byte[] globalTransactionId, - byte[] branchQualifier) { - this.format = format; - this.globalTransactionId = globalTransactionId; - this.branchQualifier = branchQualifier; - this.uuid = bytesToUUID(globalTransactionId, branchQualifier) - .toString(); - this.hashCode = uuid.hashCode(); - } - - @Override - public int getFormatId() { - return format; - } - - @Override - public byte[] getGlobalTransactionId() { - return Arrays.copyOf(globalTransactionId, globalTransactionId.length); - } - - @Override - public byte[] getBranchQualifier() { - return Arrays.copyOf(branchQualifier, branchQualifier.length); - } - - @Override - public int hashCode() { - return hashCode; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj instanceof UuidXid) { - UuidXid that = (UuidXid) obj; - return Arrays.equals(globalTransactionId, that.globalTransactionId) - && Arrays.equals(branchQualifier, that.branchQualifier); - } - if (obj instanceof Xid) { - Xid that = (Xid) obj; - return Arrays.equals(globalTransactionId, - that.getGlobalTransactionId()) - && Arrays - .equals(branchQualifier, that.getBranchQualifier()); - } - return uuid.equals(obj.toString()); - } - - @Override - protected Object clone() throws CloneNotSupportedException { - return new UuidXid(format, globalTransactionId, branchQualifier); - } - - @Override - public String toString() { - return uuid; - } - - public UUID asUuid() { - return bytesToUUID(globalTransactionId, branchQualifier); - } - - public static byte[] uuidToBytes(long bits) { - ByteBuffer buffer = ByteBuffer.allocate(BYTES_PER_LONG); - buffer.putLong(0, bits); - return buffer.array(); - } - - public static UUID bytesToUUID(byte[] most, byte[] least) { - if (most.length < BYTES_PER_LONG) - most = Arrays.copyOf(most, BYTES_PER_LONG); - if (least.length < BYTES_PER_LONG) - least = Arrays.copyOf(least, BYTES_PER_LONG); - ByteBuffer buffer = ByteBuffer.allocate(2 * BYTES_PER_LONG); - buffer.put(most, 0, BYTES_PER_LONG); - buffer.put(least, 0, BYTES_PER_LONG); - buffer.flip(); - return new UUID(buffer.getLong(), buffer.getLong()); - } - - // public static void main(String[] args) { - // UUID uuid = UUID.randomUUID(); - // System.out.println(uuid); - // uuid = bytesToUUID(uuidToBytes(uuid.getMostSignificantBits()), - // uuidToBytes(uuid.getLeastSignificantBits())); - // System.out.println(uuid); - // } -} diff --git a/org.argeo.security.core/src/org/argeo/osgi/useradmin/DigestUtils.java b/org.argeo.security.core/src/org/argeo/osgi/useradmin/DigestUtils.java new file mode 100644 index 000000000..d8f8ce9d5 --- /dev/null +++ b/org.argeo.security.core/src/org/argeo/osgi/useradmin/DigestUtils.java @@ -0,0 +1,20 @@ +package org.argeo.osgi.useradmin; + +import java.security.MessageDigest; + +class DigestUtils { + static byte[] sha1(byte[] bytes) { + try { + MessageDigest digest = MessageDigest.getInstance("SHA1"); + digest.update(bytes); + byte[] checksum = digest.digest(); + return checksum; + } catch (Exception e) { + throw new UserDirectoryException("Cannot SHA1 digest", e); + } + } + + private DigestUtils() { + } + +} diff --git a/org.argeo.security.core/src/org/argeo/osgi/useradmin/LdapUserAdmin.java b/org.argeo.security.core/src/org/argeo/osgi/useradmin/LdapUserAdmin.java index b1360c65c..7a617dfd6 100644 --- a/org.argeo.security.core/src/org/argeo/osgi/useradmin/LdapUserAdmin.java +++ b/org.argeo.security.core/src/org/argeo/osgi/useradmin/LdapUserAdmin.java @@ -24,7 +24,6 @@ import javax.transaction.TransactionManager; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; import org.osgi.framework.Filter; /** @@ -162,7 +161,7 @@ public class LdapUserAdmin extends AbstractUserDirectory { } return directGroups; } catch (Exception e) { - throw new ArgeoException("Cannot populate direct members of " + dn, e); + throw new UserDirectoryException("Cannot populate direct members of " + dn, e); } } diff --git a/org.argeo.security.core/src/org/argeo/osgi/useradmin/LdifUser.java b/org.argeo.security.core/src/org/argeo/osgi/useradmin/LdifUser.java index d5ddba50c..866c48c6b 100644 --- a/org.argeo.security.core/src/org/argeo/osgi/useradmin/LdifUser.java +++ b/org.argeo.security.core/src/org/argeo/osgi/useradmin/LdifUser.java @@ -6,6 +6,7 @@ import java.nio.CharBuffer; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Arrays; +import java.util.Base64; import java.util.Collections; import java.util.Dictionary; import java.util.Enumeration; @@ -21,9 +22,6 @@ import javax.naming.directory.Attributes; import javax.naming.directory.BasicAttribute; import javax.naming.ldap.LdapName; -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.codec.digest.DigestUtils; - /** Directory user implementation */ class LdifUser implements DirectoryUser { private final AbstractUserDirectory userAdmin; @@ -40,8 +38,7 @@ class LdifUser implements DirectoryUser { this(userAdmin, dn, attributes, false); } - private LdifUser(AbstractUserDirectory userAdmin, LdapName dn, - Attributes attributes, boolean frozen) { + private LdifUser(AbstractUserDirectory userAdmin, LdapName dn, Attributes attributes, boolean frozen) { this.userAdmin = userAdmin; this.dn = dn; this.publishedAttributes = attributes; @@ -93,8 +90,7 @@ class LdifUser implements DirectoryUser { /** Hash and clear the password */ private byte[] hash(char[] password) { - byte[] hashedPassword = ("{SHA}" + Base64 - .encodeBase64String(DigestUtils.sha1(toBytes(password)))) + byte[] hashedPassword = ("{SHA}" + Base64.getEncoder().encodeToString(DigestUtils.sha1(toBytes(password)))) .getBytes(); Arrays.fill(password, '\u0000'); return hashedPassword; @@ -103,8 +99,7 @@ class LdifUser implements DirectoryUser { private byte[] toBytes(char[] chars) { CharBuffer charBuffer = CharBuffer.wrap(chars); ByteBuffer byteBuffer = Charset.forName("UTF-8").encode(charBuffer); - byte[] bytes = Arrays.copyOfRange(byteBuffer.array(), - byteBuffer.position(), byteBuffer.limit()); + byte[] bytes = Arrays.copyOfRange(byteBuffer.array(), byteBuffer.position(), byteBuffer.limit()); Arrays.fill(charBuffer.array(), '\u0000'); // clear sensitive data Arrays.fill(byteBuffer.array(), (byte) 0); // clear sensitive data return bytes; @@ -114,12 +109,10 @@ class LdifUser implements DirectoryUser { if (obj instanceof char[]) return (char[]) obj; if (!(obj instanceof byte[])) - throw new IllegalArgumentException(obj.getClass() - + " is not a byte array"); + throw new IllegalArgumentException(obj.getClass() + " is not a byte array"); ByteBuffer fromBuffer = ByteBuffer.wrap((byte[]) obj); CharBuffer toBuffer = Charset.forName("UTF-8").decode(fromBuffer); - char[] res = Arrays.copyOfRange(toBuffer.array(), toBuffer.position(), - toBuffer.limit()); + char[] res = Arrays.copyOfRange(toBuffer.array(), toBuffer.position(), toBuffer.limit()); Arrays.fill(fromBuffer.array(), (byte) 0); // clear sensitive data Arrays.fill((byte[]) obj, (byte) 0); // clear sensitive data Arrays.fill(toBuffer.array(), '\u0000'); // clear sensitive data @@ -211,8 +204,7 @@ class LdifUser implements DirectoryUser { effectiveKeys.add(id); } } catch (NamingException e) { - throw new UserDirectoryException( - "Cannot initialise attribute dictionary", e); + throw new UserDirectoryException("Cannot initialise attribute dictionary", e); } } @@ -277,14 +269,12 @@ class LdifUser implements DirectoryUser { if (objectClasses.contains(userAdmin.getUserObjectClass())) return userAdmin.getUserObjectClass(); - else if (objectClasses - .contains(userAdmin.getGroupObjectClass())) + else if (objectClasses.contains(userAdmin.getGroupObjectClass())) return userAdmin.getGroupObjectClass(); else return value; } catch (NamingException e) { - throw new UserDirectoryException( - "Cannot get value for attribute " + key, e); + throw new UserDirectoryException("Cannot get value for attribute " + key, e); } } @@ -302,38 +292,31 @@ class LdifUser implements DirectoryUser { startEditing(); if (!(value instanceof String || value instanceof byte[])) - throw new IllegalArgumentException( - "Value must be String or byte[]"); + throw new IllegalArgumentException("Value must be String or byte[]"); if (includeFilter && !attrFilter.contains(key)) - throw new IllegalArgumentException("Key " + key - + " not included"); + throw new IllegalArgumentException("Key " + key + " not included"); else if (!includeFilter && attrFilter.contains(key)) throw new IllegalArgumentException("Key " + key + " excluded"); try { - Attribute attribute = getModifiedAttributes().get( - key.toString()); + Attribute attribute = getModifiedAttributes().get(key.toString()); attribute = new BasicAttribute(key.toString()); - if (value instanceof String - && !isAsciiPrintable(((String) value))) + if (value instanceof String && !isAsciiPrintable(((String) value))) try { attribute.add(((String) value).getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { - throw new UserDirectoryException("Cannot encode " - + value, e); + throw new UserDirectoryException("Cannot encode " + value, e); } else attribute.add(value); - Attribute previousAttribute = getModifiedAttributes().put( - attribute); + Attribute previousAttribute = getModifiedAttributes().put(attribute); if (previousAttribute != null) return previousAttribute.get(); else return null; } catch (NamingException e) { - throw new UserDirectoryException( - "Cannot get value for attribute " + key, e); + throw new UserDirectoryException("Cannot get value for attribute " + key, e); } } @@ -344,8 +327,7 @@ class LdifUser implements DirectoryUser { startEditing(); if (includeFilter && !attrFilter.contains(key)) - throw new IllegalArgumentException("Key " + key - + " not included"); + throw new IllegalArgumentException("Key " + key + " not included"); else if (!includeFilter && attrFilter.contains(key)) throw new IllegalArgumentException("Key " + key + " excluded"); @@ -356,8 +338,7 @@ class LdifUser implements DirectoryUser { else return null; } catch (NamingException e) { - throw new UserDirectoryException("Cannot remove attribute " - + key, e); + throw new UserDirectoryException("Cannot remove attribute " + key, e); } } } diff --git a/org.argeo.security.core/src/org/argeo/osgi/useradmin/LdifUserAdmin.java b/org.argeo.security.core/src/org/argeo/osgi/useradmin/LdifUserAdmin.java index e83186f22..521ae8bb6 100644 --- a/org.argeo.security.core/src/org/argeo/osgi/useradmin/LdifUserAdmin.java +++ b/org.argeo.security.core/src/org/argeo/osgi/useradmin/LdifUserAdmin.java @@ -22,7 +22,6 @@ import javax.naming.directory.Attributes; import javax.naming.ldap.LdapName; import javax.transaction.TransactionManager; -import org.apache.commons.io.IOUtils; import org.argeo.util.naming.LdifParser; import org.argeo.util.naming.LdifWriter; import org.osgi.framework.Filter; @@ -89,7 +88,7 @@ public class LdifUserAdmin extends AbstractUserDirectory { for (LdapName name : users.keySet()) ldifWriter.writeEntry(name, users.get(name).getAttributes()); } finally { - IOUtils.closeQuietly(out); + out.close(); } } diff --git a/org.argeo.security.core/src/org/argeo/util/naming/LdifParser.java b/org.argeo.security.core/src/org/argeo/util/naming/LdifParser.java index c2cd77186..ec73e8acc 100644 --- a/org.argeo.security.core/src/org/argeo/util/naming/LdifParser.java +++ b/org.argeo.security.core/src/org/argeo/util/naming/LdifParser.java @@ -2,8 +2,12 @@ package org.argeo.util.naming; import static org.argeo.osgi.useradmin.LdifName.dn; +import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Base64; import java.util.List; import java.util.SortedMap; import java.util.TreeMap; @@ -17,8 +21,6 @@ import javax.naming.directory.BasicAttributes; import javax.naming.ldap.LdapName; import javax.naming.ldap.Rdn; -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.osgi.useradmin.UserDirectoryException; @@ -50,7 +52,13 @@ public class LdifParser { public SortedMap read(InputStream in) throws IOException { SortedMap res = new TreeMap(); try { - List lines = IOUtils.readLines(in); + List lines = new ArrayList<>(); + try (BufferedReader br = new BufferedReader(new InputStreamReader(in))) { + String line; + while ((line = br.readLine()) != null) { + lines.add(line); + } + } if (lines.size() == 0) return res; // add an empty new line since the last line is not checked @@ -90,7 +98,7 @@ public class LdifParser { String attributeId = attrId.toString(); String cleanValueStr = currentEntry.toString().trim(); - Object attributeValue = isBase64 ? Base64.decodeBase64(cleanValueStr) : cleanValueStr; + Object attributeValue = isBase64 ? Base64.getDecoder().decode(cleanValueStr) : cleanValueStr; // manage DN attributes if (attributeId.equals(dn.name()) || isLastLine) { @@ -130,7 +138,7 @@ public class LdifParser { currentEntry.append(line); } } finally { - IOUtils.closeQuietly(in); + in.close(); } return res; } diff --git a/org.argeo.security.core/src/org/argeo/util/naming/LdifWriter.java b/org.argeo.security.core/src/org/argeo/util/naming/LdifWriter.java index 56f322476..37d90b4e4 100644 --- a/org.argeo.security.core/src/org/argeo/util/naming/LdifWriter.java +++ b/org.argeo.security.core/src/org/argeo/util/naming/LdifWriter.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; +import java.util.Base64; import java.util.Map; import javax.naming.NamingEnumeration; @@ -15,7 +16,6 @@ import javax.naming.directory.Attributes; import javax.naming.ldap.LdapName; import javax.naming.ldap.Rdn; -import org.apache.commons.codec.binary.Base64; import org.argeo.osgi.useradmin.UserDirectoryException; /** Basic LDIF writer */ @@ -67,7 +67,7 @@ public class LdifWriter { for (NamingEnumeration attrValues = attribute.getAll(); attrValues.hasMore();) { Object value = attrValues.next(); if (value instanceof byte[]) { - String encoded = Base64.encodeBase64String((byte[]) value); + String encoded = Base64.getEncoder().encodeToString((byte[]) value); writer.append(attribute.getID()).append("::").append(encoded).append('\n'); } else { writer.append(attribute.getID()).append(':').append(value.toString()).append('\n'); diff --git a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/PartStateChanged.java b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/PartStateChanged.java index 1a5f375d0..aacf6ef63 100644 --- a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/PartStateChanged.java +++ b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/PartStateChanged.java @@ -1,6 +1,6 @@ package org.argeo.security.ui.admin.internal; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IPartListener; import org.eclipse.ui.IStartup; @@ -23,7 +23,7 @@ public class PartStateChanged implements IPartListener, IStartup { if (iwp != null) iwp.addPartListener(new PartStateChanged()); } catch (Exception e) { - throw new ArgeoException( + throw new CmsException( "Error while registering the PartStateChangedListener", e); } diff --git a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/UiAdminUtils.java b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/UiAdminUtils.java index 14762632e..871877a0e 100644 --- a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/UiAdminUtils.java +++ b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/UiAdminUtils.java @@ -2,7 +2,7 @@ package org.argeo.security.ui.admin.internal; import javax.transaction.UserTransaction; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.argeo.security.ui.admin.internal.providers.UserTransactionProvider; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; @@ -26,7 +26,7 @@ public class UiAdminUtils { .getSourceProvider(UserTransactionProvider.TRANSACTION_STATE); esp.fireTransactionStateChange(); } catch (Exception e) { - throw new ArgeoException("Unable to begin transaction", e); + throw new CmsException("Unable to begin transaction", e); } } } \ No newline at end of file diff --git a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/UserAdminWrapper.java b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/UserAdminWrapper.java index 43ce58da9..8306e1552 100644 --- a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/UserAdminWrapper.java +++ b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/UserAdminWrapper.java @@ -6,7 +6,7 @@ import java.util.List; import javax.transaction.Status; import javax.transaction.UserTransaction; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.osgi.service.useradmin.UserAdminEvent; import org.osgi.service.useradmin.UserAdminListener; @@ -31,7 +31,7 @@ public class UserAdminWrapper extends } return userTransaction; } catch (Exception e) { - throw new ArgeoException("Unable to begin transaction", e); + throw new CmsException("Unable to begin transaction", e); } } diff --git a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/commands/NewGroup.java b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/commands/NewGroup.java index b83412d10..f075fbc31 100644 --- a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/commands/NewGroup.java +++ b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/commands/NewGroup.java @@ -18,7 +18,7 @@ package org.argeo.security.ui.admin.internal.commands; import java.util.Dictionary; import java.util.Map; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.argeo.eclipse.ui.EclipseUiUtils; import org.argeo.eclipse.ui.dialogs.ErrorFeedback; import org.argeo.jcr.ArgeoNames; @@ -215,7 +215,7 @@ public class NewGroup extends AbstractHandler { private void initialiseDnCmb(Combo combo) { Map dns = userAdminWrapper.getKnownBaseDns(true); if (dns.isEmpty()) - throw new ArgeoException( + throw new CmsException( "No writable base dn found. Cannot create group"); combo.setItems(dns.keySet().toArray(new String[0])); if (dns.size() == 1) diff --git a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/commands/NewUser.java b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/commands/NewUser.java index e408b1bee..1a85253ad 100644 --- a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/commands/NewUser.java +++ b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/commands/NewUser.java @@ -23,7 +23,7 @@ import javax.naming.InvalidNameException; import javax.naming.ldap.LdapName; import javax.naming.ldap.Rdn; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.argeo.cms.util.useradmin.UserAdminUtils; import org.argeo.eclipse.ui.EclipseUiUtils; import org.argeo.eclipse.ui.dialogs.ErrorFeedback; @@ -289,7 +289,7 @@ public class NewUser extends AbstractHandler { private void initialiseDnCmb(Combo combo) { Map dns = userAdminWrapper.getKnownBaseDns(true); if (dns.isEmpty()) - throw new ArgeoException( + throw new CmsException( "No writable base dn found. Cannot create user"); combo.setItems(dns.keySet().toArray(new String[0])); if (dns.size() == 1) @@ -306,7 +306,7 @@ public class NewUser extends AbstractHandler { return username + "@" + (String) rdns.get(1).getValue() + '.' + (String) rdns.get(0).getValue(); } catch (InvalidNameException e) { - throw new ArgeoException("Unable to generate mail for " + throw new CmsException("Unable to generate mail for " + username + " with base dn " + baseDn, e); } } diff --git a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/commands/UserTransactionHandler.java b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/commands/UserTransactionHandler.java index 1e881694d..c2925792c 100644 --- a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/commands/UserTransactionHandler.java +++ b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/commands/UserTransactionHandler.java @@ -18,7 +18,7 @@ package org.argeo.security.ui.admin.internal.commands; import javax.transaction.Status; import javax.transaction.UserTransaction; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.argeo.security.ui.admin.SecurityAdminPlugin; import org.argeo.security.ui.admin.internal.UiAdminUtils; import org.argeo.security.ui.admin.internal.UserAdminWrapper; @@ -49,17 +49,17 @@ public class UserTransactionHandler extends AbstractHandler { try { if (TRANSACTION_BEGIN.equals(commandId)) { if (userTransaction.getStatus() != Status.STATUS_NO_TRANSACTION) - throw new ArgeoException("A transaction already exists"); + throw new CmsException("A transaction already exists"); else userTransaction.begin(); } else if (TRANSACTION_COMMIT.equals(commandId)) { if (userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION) - throw new ArgeoException("No transaction."); + throw new CmsException("No transaction."); else userTransaction.commit(); } else if (TRANSACTION_ROLLBACK.equals(commandId)) { if (userTransaction.getStatus() == Status.STATUS_NO_TRANSACTION) - throw new ArgeoException("No transaction to rollback."); + throw new CmsException("No transaction to rollback."); else { userTransaction.rollback(); userAdminWrapper.notifyListeners(new UserAdminEvent(null, @@ -77,10 +77,10 @@ public class UserTransactionHandler extends AbstractHandler { } }); - } catch (ArgeoException e) { + } catch (CmsException e) { throw e; } catch (Exception e) { - throw new ArgeoException("Unable to call " + commandId + " on " + throw new CmsException("Unable to call " + commandId + " on " + userTransaction, e); } return null; diff --git a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/parts/DefaultUserMainPage.java b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/parts/DefaultUserMainPage.java index 306a872e7..6529efe30 100644 --- a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/parts/DefaultUserMainPage.java +++ b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/parts/DefaultUserMainPage.java @@ -23,7 +23,7 @@ import javax.jcr.RepositoryException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.argeo.jcr.ArgeoNames; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; @@ -66,7 +66,7 @@ public class DefaultUserMainPage extends FormPage implements ArgeoNames { createGeneralPart(form.getBody()); createPassworPart(form.getBody()); } catch (RepositoryException e) { - throw new ArgeoException("Cannot create form content", e); + throw new CmsException("Cannot create form content", e); } } @@ -118,7 +118,7 @@ public class DefaultUserMainPage extends FormPage implements ArgeoNames { if (log.isTraceEnabled()) log.trace("General part committed"); } catch (RepositoryException e) { - throw new ArgeoException("Cannot commit", e); + throw new CmsException("Cannot commit", e); } } }; @@ -174,7 +174,7 @@ public class DefaultUserMainPage extends FormPage implements ArgeoNames { } else { password1.setText(""); password2.setText(""); - throw new ArgeoException("Passwords are not equals"); + throw new CmsException("Passwords are not equals"); } } } diff --git a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/parts/GroupsView.java b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/parts/GroupsView.java index 6b193f444..82f4e1bdd 100644 --- a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/parts/GroupsView.java +++ b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/parts/GroupsView.java @@ -20,7 +20,7 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.argeo.cms.auth.AuthConstants; import org.argeo.cms.util.useradmin.UserAdminUtils; import org.argeo.eclipse.ui.ColumnDefinition; @@ -216,7 +216,7 @@ public class GroupsView extends ViewPart implements ArgeoNames { roles = userAdminWrapper.getUserAdmin().getRoles( builder.toString()); } catch (InvalidSyntaxException e) { - throw new ArgeoException("Unable to get roles with filter: " + throw new CmsException("Unable to get roles with filter: " + filter, e); } List users = new ArrayList(); diff --git a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/parts/UserBatchUpdateWizard.java b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/parts/UserBatchUpdateWizard.java index d2dbadd08..80c817ebe 100644 --- a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/parts/UserBatchUpdateWizard.java +++ b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/parts/UserBatchUpdateWizard.java @@ -10,7 +10,7 @@ import javax.transaction.UserTransaction; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.argeo.cms.auth.AuthConstants; import org.argeo.cms.util.useradmin.UserAdminUtils; import org.argeo.eclipse.ui.ColumnDefinition; @@ -98,7 +98,7 @@ public class UserBatchUpdateWizard extends Wizard { + "are you sure you want to proceed ?")) return false; } catch (SystemException e) { - throw new ArgeoException("Cannot get user transaction state " + throw new CmsException("Cannot get user transaction state " + "before user batch update", e); } @@ -111,7 +111,7 @@ public class UserBatchUpdateWizard extends Wizard { if (CMD_UPDATE_PASSWORD.equals(chooseCommandPage.getCommand())) { char[] newValue = chooseCommandPage.getPwdValue(); if (newValue == null) - throw new ArgeoException( + throw new CmsException( "Password cannot be null or an empty string"); ResetPassword job = new ResetPassword(userAdminWrapper, userListPage.getSelectedUsers(), newValue); @@ -150,7 +150,7 @@ public class UserBatchUpdateWizard extends Wizard { userTransaction.commit(); UiAdminUtils.notifyTransactionStateChange(userTransaction); } catch (Exception e) { - throw new ArgeoException( + throw new CmsException( "Cannot perform batch update on users", e); } finally { UserTransaction ut = userAdminWrapper.getUserTransaction(); @@ -183,9 +183,9 @@ public class UserBatchUpdateWizard extends Wizard { // log.info("Add/Remove to group actions are not yet implemented"); // // TODO implement this // // try { - // // throw new ArgeoException("Not yet implemented"); + // // throw new CmsException("Not yet implemented"); // // } catch (RepositoryException re) { - // // throw new ArgeoException( + // // throw new CmsException( // // "Unable to update boolean value for node " + node, re); // // } // } @@ -223,7 +223,7 @@ public class UserBatchUpdateWizard extends Wizard { // } // userAdminWrapper.getUserTransaction().commit(); // } catch (Exception e) { - // throw new ArgeoException( + // throw new CmsException( // "Cannot perform batch update on users", e); // } finally { // UserTransaction ut = userAdminWrapper.getUserTransaction(); @@ -495,7 +495,7 @@ public class UserBatchUpdateWizard extends Wizard { roles = userAdminWrapper.getUserAdmin().getRoles( builder.toString()); } catch (InvalidSyntaxException e) { - throw new ArgeoException( + throw new CmsException( "Unable to get roles with filter: " + filter, e); } List users = new ArrayList(); diff --git a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/parts/UserEditor.java b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/parts/UserEditor.java index 715d34310..0fae9f49a 100644 --- a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/parts/UserEditor.java +++ b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/parts/UserEditor.java @@ -18,7 +18,7 @@ package org.argeo.security.ui.admin.internal.parts; import java.util.ArrayList; import java.util.List; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.argeo.cms.util.useradmin.UserAdminUtils; import org.argeo.osgi.useradmin.LdifName; import org.argeo.security.ui.admin.SecurityAdminPlugin; @@ -113,7 +113,7 @@ public class UserEditor extends FormEditor { else addPage(new UserMainPage(this, userAdminWrapper)); } catch (Exception e) { - throw new ArgeoException("Cannot add pages", e); + throw new CmsException("Cannot add pages", e); } } diff --git a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/parts/UserMainPage.java b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/parts/UserMainPage.java index 833ae32a7..9bd2d2de1 100644 --- a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/parts/UserMainPage.java +++ b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/parts/UserMainPage.java @@ -19,7 +19,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.argeo.cms.auth.AuthConstants; import org.argeo.cms.util.useradmin.UserAdminUtils; import org.argeo.eclipse.ui.ColumnDefinition; @@ -236,7 +236,7 @@ public class UserMainPage extends FormPage implements ArgeoNames { } else { password1.setText(""); password2.setText(""); - throw new ArgeoException("Passwords are not equals"); + throw new CmsException("Passwords are not equals"); } } } diff --git a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/parts/UsersView.java b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/parts/UsersView.java index edafa2851..a397432a8 100644 --- a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/parts/UsersView.java +++ b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/parts/UsersView.java @@ -18,7 +18,7 @@ package org.argeo.security.ui.admin.internal.parts; import java.util.ArrayList; import java.util.List; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.argeo.cms.auth.AuthConstants; import org.argeo.cms.util.useradmin.UserAdminUtils; import org.argeo.eclipse.ui.ColumnDefinition; @@ -159,7 +159,7 @@ public class UsersView extends ViewPart implements ArgeoNames { roles = userAdminWrapper.getUserAdmin().getRoles( builder.toString()); } catch (InvalidSyntaxException e) { - throw new ArgeoException("Unable to get roles with filter: " + throw new CmsException("Unable to get roles with filter: " + filter, e); } List users = new ArrayList(); diff --git a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/providers/UserAdminAbstractLP.java b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/providers/UserAdminAbstractLP.java index 39bac0a2a..2b0a13db7 100644 --- a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/providers/UserAdminAbstractLP.java +++ b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/providers/UserAdminAbstractLP.java @@ -3,7 +3,7 @@ package org.argeo.security.ui.admin.internal.providers; import javax.naming.InvalidNameException; import javax.naming.ldap.LdapName; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.argeo.cms.util.useradmin.UserAdminUtils; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.jface.viewers.ColumnLabelProvider; @@ -37,7 +37,7 @@ public abstract class UserAdminAbstractLP extends ColumnLabelProvider { return bold; } } catch (InvalidNameException e) { - throw new ArgeoException("cannot parse dn for " + element, e); + throw new CmsException("cannot parse dn for " + element, e); } // Disabled as Italic diff --git a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/providers/UserTableDefaultDClickListener.java b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/providers/UserTableDefaultDClickListener.java index fa45edd86..8f4a35a18 100644 --- a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/providers/UserTableDefaultDClickListener.java +++ b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/providers/UserTableDefaultDClickListener.java @@ -1,6 +1,6 @@ package org.argeo.security.ui.admin.internal.providers; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin; import org.argeo.security.ui.admin.internal.parts.UserEditor; import org.argeo.security.ui.admin.internal.parts.UserEditorInput; @@ -37,7 +37,7 @@ public class UserTableDefaultDClickListener implements IDoubleClickListener { else iwp.openEditor(uei, UserEditor.USER_EDITOR_ID); } catch (PartInitException pie) { - throw new ArgeoException("Unable to open UserEditor for " + user, + throw new CmsException("Unable to open UserEditor for " + user, pie); } } diff --git a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/providers/UserTransactionProvider.java b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/providers/UserTransactionProvider.java index cf1dd5dac..c5b9026c7 100644 --- a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/providers/UserTransactionProvider.java +++ b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/providers/UserTransactionProvider.java @@ -8,7 +8,7 @@ import javax.transaction.UserTransaction; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.argeo.security.ui.admin.SecurityAdminPlugin; import org.eclipse.swt.SWTException; import org.eclipse.ui.AbstractSourceProvider; @@ -53,7 +53,7 @@ public class UserTransactionProvider extends AbstractSourceProvider { transactionState = STATUS_ACTIVE; return transactionState; } catch (Exception e) { - throw new ArgeoException("Unable to begin transaction", e); + throw new CmsException("Unable to begin transaction", e); } } diff --git a/org.argeo.security.ui.rap/src/org/argeo/security/ui/rap/AnonymousEntryPoint.java b/org.argeo.security.ui.rap/src/org/argeo/security/ui/rap/AnonymousEntryPoint.java index 7c1702d8d..04b6f0a9d 100644 --- a/org.argeo.security.ui.rap/src/org/argeo/security/ui/rap/AnonymousEntryPoint.java +++ b/org.argeo.security.ui.rap/src/org/argeo/security/ui/rap/AnonymousEntryPoint.java @@ -23,7 +23,7 @@ import javax.security.auth.login.LoginException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.argeo.cms.auth.AuthConstants; import org.eclipse.rap.rwt.RWT; import org.eclipse.rap.rwt.application.EntryPoint; @@ -60,7 +60,7 @@ public class AnonymousEntryPoint implements EntryPoint { subject); loginContext.login(); } catch (LoginException e1) { - throw new ArgeoException("Cannot initialize login context", e1); + throw new CmsException("Cannot initialize login context", e1); } // identify after successful login diff --git a/org.argeo.security.ui.rap/src/org/argeo/security/ui/rap/SecureEntryPoint.java b/org.argeo.security.ui.rap/src/org/argeo/security/ui/rap/SecureEntryPoint.java index 7463f8b53..a681527f7 100644 --- a/org.argeo.security.ui.rap/src/org/argeo/security/ui/rap/SecureEntryPoint.java +++ b/org.argeo.security.ui.rap/src/org/argeo/security/ui/rap/SecureEntryPoint.java @@ -30,7 +30,7 @@ import javax.servlet.http.HttpSession; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.argeo.cms.auth.AuthConstants; import org.argeo.cms.auth.ThreadDeathLoginException; import org.argeo.cms.widgets.auth.DefaultLoginDialog; @@ -96,14 +96,14 @@ public class SecureEntryPoint implements EntryPoint { AuthConstants.LOGIN_CONTEXT_USER, subject, callbackHandler); } catch (LoginException e1) { - throw new ArgeoException("Cannot initialize login context", e1); + throw new CmsException("Cannot initialize login context", e1); } tryLogin: while (subject.getPrincipals(X500Principal.class).size() == 0) { try { loginContext.login(); if (subject.getPrincipals(X500Principal.class).size() == 0) - throw new ArgeoException("Login succeeded but no auth");// fatal + throw new CmsException("Login succeeded but no auth");// fatal // add thread locale to RWT session // if (log.isTraceEnabled()) @@ -189,7 +189,7 @@ public class SecureEntryPoint implements EntryPoint { display.dispose(); return -1; } else { - throw new ArgeoException( + throw new CmsException( "Unexpected exception during authentication", e); } diff --git a/org.argeo.security.ui/src/org/argeo/security/ui/SecurityUiPlugin.java b/org.argeo.security.ui/src/org/argeo/security/ui/SecurityUiPlugin.java index e5987938b..935b54386 100644 --- a/org.argeo.security.ui/src/org/argeo/security/ui/SecurityUiPlugin.java +++ b/org.argeo.security.ui/src/org/argeo/security/ui/SecurityUiPlugin.java @@ -21,7 +21,7 @@ import javax.security.auth.callback.Callback; import javax.security.auth.callback.CallbackHandler; import javax.security.auth.callback.UnsupportedCallbackException; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.argeo.cms.widgets.auth.DefaultLoginDialog; import org.eclipse.swt.widgets.Display; import org.osgi.framework.BundleActivator; @@ -50,13 +50,6 @@ public class SecurityUiPlugin implements BundleActivator { private ServiceRegistration defaultCallbackHandlerReg; public void start(BundleContext context) throws Exception { - if (bundleContext != null) - if (!bundleContext.equals(bundleContext)) - throw new ArgeoException( - "Bundle context already set with a different value"); - else - return; - bundleContext = context; defaultCallbackHandler = new DefaultCallbackHandler(); @@ -88,7 +81,7 @@ public class SecurityUiPlugin implements BundleActivator { try { dialog.handle(callbacks); } catch (IOException e) { - throw new ArgeoException("Cannot open dialog", e); + throw new CmsException("Cannot open dialog", e); } } }); diff --git a/org.argeo.security.ui/src/org/argeo/security/ui/commands/OpenChangePasswordDialog.java b/org.argeo.security.ui/src/org/argeo/security/ui/commands/OpenChangePasswordDialog.java index 5f2a9cadd..817354f70 100644 --- a/org.argeo.security.ui/src/org/argeo/security/ui/commands/OpenChangePasswordDialog.java +++ b/org.argeo.security.ui/src/org/argeo/security/ui/commands/OpenChangePasswordDialog.java @@ -32,7 +32,7 @@ import javax.transaction.UserTransaction; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; +import org.argeo.cms.CmsException; import org.argeo.eclipse.ui.dialogs.ErrorFeedback; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; @@ -79,13 +79,13 @@ public class OpenChangePasswordDialog extends AbstractHandler { try { dn = new LdapName(name); } catch (InvalidNameException e) { - throw new ArgeoException("Invalid user dn " + name, e); + throw new CmsException("Invalid user dn " + name, e); } User user = (User) userAdmin.getRole(dn.toString()); if (!user.hasCredential(null, oldPassword)) - throw new ArgeoException("Invalid password"); + throw new CmsException("Invalid password"); if (newPassword.equals("")) - throw new ArgeoException("New password empty"); + throw new CmsException("New password empty"); try { userTransaction.begin(); user.getCredentials().put(null, newPassword); @@ -99,7 +99,7 @@ public class OpenChangePasswordDialog extends AbstractHandler { if (e instanceof RuntimeException) throw (RuntimeException) e; else - throw new ArgeoException("Cannot change password", e); + throw new CmsException("Cannot change password", e); } } @@ -144,7 +144,7 @@ public class OpenChangePasswordDialog extends AbstractHandler { protected void okPressed() { try { if (!newPassword1.getText().equals(newPassword2.getText())) - throw new ArgeoException("New passwords are different"); + throw new CmsException("New passwords are different"); changePassword(oldPassword.getTextChars(), newPassword1.getTextChars()); close(); diff --git a/org.argeo.server.jcr/src/org/argeo/jackrabbit/JackrabbitContainer.java b/org.argeo.server.jcr/src/org/argeo/jackrabbit/JackrabbitContainer.java index 547db9b0d..c5ca7952c 100644 --- a/org.argeo.server.jcr/src/org/argeo/jackrabbit/JackrabbitContainer.java +++ b/org.argeo.server.jcr/src/org/argeo/jackrabbit/JackrabbitContainer.java @@ -38,7 +38,7 @@ import org.apache.jackrabbit.api.JackrabbitRepository; import org.apache.jackrabbit.core.RepositoryImpl; import org.apache.jackrabbit.core.config.RepositoryConfig; import org.apache.jackrabbit.core.config.RepositoryConfigurationParser; -import org.argeo.ArgeoException; +import org.argeo.jcr.ArgeoJcrException; import org.argeo.jcr.ArgeoNames; import org.argeo.jcr.JcrUtils; import org.springframework.core.io.Resource; @@ -80,7 +80,7 @@ public class JackrabbitContainer extends JackrabbitWrapper { // long begin = System.currentTimeMillis(); if (getRepository() != null) - throw new ArgeoException("Cannot be used to wrap another repository"); + throw new ArgeoJcrException("Cannot be used to wrap another repository"); Repository repository = createJackrabbitRepository(); super.setRepository(repository); @@ -132,7 +132,7 @@ public class JackrabbitContainer extends JackrabbitWrapper { return repository; } catch (Exception e) { - throw new ArgeoException("Cannot create Jackrabbit repository " + getHomeDirectory(), e); + throw new ArgeoJcrException("Cannot create Jackrabbit repository " + getHomeDirectory(), e); } finally { IOUtils.closeQuietly(configurationIn); } @@ -153,7 +153,7 @@ public class JackrabbitContainer extends JackrabbitWrapper { return homeDirectory.getCanonicalFile(); } catch (IOException e) { - throw new ArgeoException("Cannot get canonical file for " + homeDirectory, e); + throw new ArgeoJcrException("Cannot get canonical file for " + homeDirectory, e); } } @@ -175,10 +175,10 @@ public class JackrabbitContainer extends JackrabbitWrapper { restartAndClearCaches = true; } } - } catch (ArgeoException e) { + } catch (ArgeoJcrException e) { throw e; } catch (Exception e) { - throw new ArgeoException("Cannot migrate", e); + throw new ArgeoJcrException("Cannot migrate", e); } finally { JcrUtils.logoutQuietly(session); } @@ -197,7 +197,7 @@ public class JackrabbitContainer extends JackrabbitWrapper { try { session = login(); } catch (RepositoryException e) { - throw new ArgeoException("Cannot login to migrated repository", e); + throw new ArgeoJcrException("Cannot login to migrated repository", e); } for (JackrabbitDataModelMigration dataModelMigration : new TreeSet( @@ -250,7 +250,7 @@ public class JackrabbitContainer extends JackrabbitWrapper { try { return configuration != null ? configuration.getInputStream() : null; } catch (IOException e) { - throw new ArgeoException("Cannot read Jackrabbit configuration " + configuration, e); + throw new ArgeoJcrException("Cannot read Jackrabbit configuration " + configuration, e); } } @@ -264,7 +264,7 @@ public class JackrabbitContainer extends JackrabbitWrapper { try { return variables != null ? variables.getInputStream() : null; } catch (IOException e) { - throw new ArgeoException("Cannot read Jackrabbit variables " + variables, e); + throw new ArgeoJcrException("Cannot read Jackrabbit variables " + variables, e); } } @@ -305,7 +305,7 @@ public class JackrabbitContainer extends JackrabbitWrapper { } } catch (IOException e) { - throw new ArgeoException("Cannot read configuration properties", e); + throw new ArgeoJcrException("Cannot read configuration properties", e); } finally { IOUtils.closeQuietly(propsIn); } @@ -325,7 +325,7 @@ public class JackrabbitContainer extends JackrabbitWrapper { } public void setRepository(Repository repository) { - throw new ArgeoException("Cannot be used to wrap another repository"); + throw new ArgeoJcrException("Cannot be used to wrap another repository"); } public void setDataModelMigrations(Set dataModelMigrations) { diff --git a/org.argeo.server.jcr/src/org/argeo/jackrabbit/JackrabbitDataModelMigration.java b/org.argeo.server.jcr/src/org/argeo/jackrabbit/JackrabbitDataModelMigration.java index 56fffcbea..53f0e4457 100644 --- a/org.argeo.server.jcr/src/org/argeo/jackrabbit/JackrabbitDataModelMigration.java +++ b/org.argeo.server.jcr/src/org/argeo/jackrabbit/JackrabbitDataModelMigration.java @@ -26,7 +26,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.jackrabbit.commons.cnd.CndImporter; import org.apache.jackrabbit.core.config.RepositoryConfig; -import org.argeo.ArgeoException; +import org.argeo.jcr.ArgeoJcrException; import org.argeo.jcr.ArgeoNames; import org.argeo.jcr.JcrCallback; import org.argeo.jcr.JcrUtils; @@ -91,7 +91,7 @@ public class JackrabbitDataModelMigration implements return true; } catch (Exception e) { JcrUtils.discardQuietly(session); - throw new ArgeoException("Migration of data model " + throw new ArgeoJcrException("Migration of data model " + dataModelNodePath + " to " + targetVersion + " failed.", e); } finally { @@ -114,7 +114,7 @@ public class JackrabbitDataModelMigration implements if (log.isDebugEnabled()) log.debug("Cleared " + customeNodeTypesPath); } catch (Exception e) { - throw new ArgeoException("Cannot clear caches", e); + throw new ArgeoJcrException("Cannot clear caches", e); } // File customNodeTypes = new File(home.getPath() diff --git a/org.argeo.server.jcr/src/org/argeo/jackrabbit/JackrabbitRepositoryFactory.java b/org.argeo.server.jcr/src/org/argeo/jackrabbit/JackrabbitRepositoryFactory.java index 3502abd59..e4134883c 100644 --- a/org.argeo.server.jcr/src/org/argeo/jackrabbit/JackrabbitRepositoryFactory.java +++ b/org.argeo.server.jcr/src/org/argeo/jackrabbit/JackrabbitRepositoryFactory.java @@ -36,7 +36,6 @@ import org.apache.jackrabbit.core.RepositoryImpl; import org.apache.jackrabbit.core.config.RepositoryConfig; import org.apache.jackrabbit.core.config.RepositoryConfigurationParser; import org.apache.jackrabbit.jcr2dav.Jcr2davRepositoryFactory; -import org.argeo.ArgeoException; import org.argeo.jcr.ArgeoJcrConstants; import org.argeo.jcr.ArgeoJcrException; import org.springframework.core.io.ClassPathResource; @@ -106,7 +105,7 @@ public class JackrabbitRepositoryFactory implements RepositoryFactory, ArgeoJcrC params.put(JcrUtils.REPOSITORY_URI, uri); Repository repository = new Jcr2davRepositoryFactory().getRepository(params); if (repository == null) - throw new ArgeoException("Remote Davex repository " + uri + " not found"); + throw new ArgeoJcrException("Remote Davex repository " + uri + " not found"); log.info("Initialized remote Jackrabbit repository from uri " + uri); return repository; } @@ -120,7 +119,7 @@ public class JackrabbitRepositoryFactory implements RepositoryFactory, ArgeoJcrC 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"); + throw new ArgeoJcrException("Repository home " + dirPath + " is not a directory"); if (!homeDir.exists()) homeDir.mkdirs(); configurationIn = fileRepositoryConfiguration.getInputStream(); @@ -143,7 +142,7 @@ public class JackrabbitRepositoryFactory implements RepositoryFactory, ArgeoJcrC log.info("Initialized file Jackrabbit repository from uri " + uri); return repository; } catch (Exception e) { - throw new ArgeoException("Cannot create repository " + uri, e); + throw new ArgeoJcrException("Cannot create repository " + uri, e); } finally { IOUtils.closeQuietly(configurationIn); } @@ -159,7 +158,7 @@ public class JackrabbitRepositoryFactory implements RepositoryFactory, ArgeoJcrC alias = alias.substring(0, alias.length() - 1); return alias; } catch (URISyntaxException e) { - throw new ArgeoException("Cannot interpret URI " + uri, e); + throw new ArgeoJcrException("Cannot interpret URI " + uri, e); } } diff --git a/org.argeo.server.jcr/src/org/argeo/jackrabbit/JackrabbitWrapper.java b/org.argeo.server.jcr/src/org/argeo/jackrabbit/JackrabbitWrapper.java index 89a39496d..268ecdb28 100644 --- a/org.argeo.server.jcr/src/org/argeo/jackrabbit/JackrabbitWrapper.java +++ b/org.argeo.server.jcr/src/org/argeo/jackrabbit/JackrabbitWrapper.java @@ -30,6 +30,7 @@ import javax.jcr.LoginException; import javax.jcr.NoSuchWorkspaceException; import javax.jcr.Node; import javax.jcr.NodeIterator; +import javax.jcr.Repository; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.nodetype.NodeType; @@ -41,8 +42,8 @@ import org.apache.commons.logging.LogFactory; import org.apache.jackrabbit.api.JackrabbitRepository; import org.apache.jackrabbit.commons.NamespaceHelper; import org.apache.jackrabbit.commons.cnd.CndImporter; -import org.argeo.ArgeoException; import org.argeo.jcr.ArgeoJcrConstants; +import org.argeo.jcr.ArgeoJcrException; import org.argeo.jcr.ArgeoNames; import org.argeo.jcr.ArgeoTypes; import org.argeo.jcr.JcrRepositoryWrapper; @@ -132,7 +133,7 @@ public class JackrabbitWrapper extends JcrRepositoryWrapper implements } } catch (Exception e) { JcrUtils.discardQuietly(session); - throw new ArgeoException("Cannot import node type definitions " + throw new ArgeoJcrException("Cannot import node type definitions " + cndFiles, e); } finally { JcrUtils.logoutQuietly(session); @@ -245,7 +246,7 @@ public class JackrabbitWrapper extends JcrRepositoryWrapper implements + (bundle != null ? ", version " + bundle.getVersion() + ", bundle " + bundle.getSymbolicName() : "")); } catch (Exception e) { - throw new ArgeoException("Cannot process data model " + resUrl, e); + throw new ArgeoJcrException("Cannot process data model " + resUrl, e); } finally { IOUtils.closeQuietly(reader); } @@ -289,13 +290,13 @@ public class JackrabbitWrapper extends JcrRepositoryWrapper implements in = res.getInputStream(); url = res.getURL(); } else { - throw new ArgeoException("No " + resUrl + " in the classpath," + throw new ArgeoJcrException("No " + resUrl + " in the classpath," + " make sure the containing" + " package is visible."); } return IOUtils.toByteArray(in); } catch (Exception e) { - throw new ArgeoException("Cannot read CND from " + resUrl, e); + throw new ArgeoJcrException("Cannot read CND from " + resUrl, e); } finally { IOUtils.closeQuietly(in); } @@ -340,7 +341,7 @@ public class JackrabbitWrapper extends JcrRepositoryWrapper implements ExportedPackage[] exportedPackages = packageAdmin .getExportedPackages(pkg); if (exportedPackages == null) - throw new ArgeoException("No exported package found for " + pkg); + throw new ArgeoJcrException("No exported package found for " + pkg); for (ExportedPackage ep : exportedPackages) { for (Bundle b : ep.getImportingBundles()) { if (b.getBundleId() == bundleContext.getBundle().getBundleId()) { @@ -356,7 +357,7 @@ public class JackrabbitWrapper extends JcrRepositoryWrapper implements } else { // assume this is in the same bundle exportingBundle = bundleContext.getBundle(); - // throw new ArgeoException("No OSGi exporting package found for " + // throw new ArgeoJcrException("No OSGi exporting package found for " // + resUrl); } return exportingBundle; diff --git a/org.argeo.server.jcr/src/org/argeo/jcr/ArgeoJcrUtils.java b/org.argeo.server.jcr/src/org/argeo/jcr/ArgeoJcrUtils.java index dccb06cf4..9a0fd1971 100644 --- a/org.argeo.server.jcr/src/org/argeo/jcr/ArgeoJcrUtils.java +++ b/org.argeo.server.jcr/src/org/argeo/jcr/ArgeoJcrUtils.java @@ -22,8 +22,6 @@ import javax.jcr.Repository; import javax.jcr.RepositoryException; import javax.jcr.RepositoryFactory; -import org.argeo.ArgeoException; - /** Utilities related to Argeo model in JCR */ public class ArgeoJcrUtils implements ArgeoJcrConstants { /** @@ -38,7 +36,7 @@ public class ArgeoJcrUtils implements ArgeoJcrConstants { parameters.put(JCR_REPOSITORY_ALIAS, alias); return repositoryFactory.getRepository(parameters); } catch (RepositoryException e) { - throw new ArgeoException( + throw new ArgeoJcrException( "Unexpected exception when trying to retrieve repository with alias " + alias, e); } @@ -68,7 +66,7 @@ public class ArgeoJcrUtils implements ArgeoJcrConstants { parameters.put(JCR_REPOSITORY_ALIAS, alias); return repositoryFactory.getRepository(parameters); } catch (RepositoryException e) { - throw new ArgeoException( + throw new ArgeoJcrException( "Unexpected exception when trying to retrieve repository with uri " + uri, e); } diff --git a/org.argeo.server.jcr/src/org/argeo/jcr/DefaultJcrListener.java b/org.argeo.server.jcr/src/org/argeo/jcr/DefaultJcrListener.java index 253b3055d..5ef8edd56 100644 --- a/org.argeo.server.jcr/src/org/argeo/jcr/DefaultJcrListener.java +++ b/org.argeo.server.jcr/src/org/argeo/jcr/DefaultJcrListener.java @@ -24,7 +24,6 @@ import javax.jcr.observation.ObservationManager; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; /** To be overridden */ public class DefaultJcrListener implements EventListener { @@ -39,7 +38,7 @@ public class DefaultJcrListener implements EventListener { if (log.isDebugEnabled()) log.debug("Registered JCR event listener on " + path); } catch (Exception e) { - throw new ArgeoException("Cannot register event listener", e); + throw new ArgeoJcrException("Cannot register event listener", e); } } @@ -50,7 +49,7 @@ public class DefaultJcrListener implements EventListener { if (log.isDebugEnabled()) log.debug("Unregistered JCR event listener on " + path); } catch (Exception e) { - throw new ArgeoException("Cannot unregister event listener", e); + throw new ArgeoJcrException("Cannot unregister event listener", e); } } diff --git a/org.argeo.server.jcr/src/org/argeo/jcr/DefaultRepositoryFactory.java b/org.argeo.server.jcr/src/org/argeo/jcr/DefaultRepositoryFactory.java index c60f023dd..ccfc2698e 100644 --- a/org.argeo.server.jcr/src/org/argeo/jcr/DefaultRepositoryFactory.java +++ b/org.argeo.server.jcr/src/org/argeo/jcr/DefaultRepositoryFactory.java @@ -24,8 +24,6 @@ import javax.jcr.Repository; import javax.jcr.RepositoryException; import javax.jcr.RepositoryFactory; -import org.argeo.ArgeoException; - /** * Simple implementation of {@link RepositoryFactory}, supporting OSGi aliases. */ @@ -54,7 +52,7 @@ public class DefaultRepositoryFactory extends DefaultRepositoryRegister alias = alias.substring(0, alias.length() - 1); return alias; } catch (URISyntaxException e) { - throw new ArgeoException("Cannot interpret URI " + uri, e); + throw new ArgeoJcrException("Cannot interpret URI " + uri, e); } } diff --git a/org.argeo.server.jcr/src/org/argeo/jcr/JcrMonitor.java b/org.argeo.server.jcr/src/org/argeo/jcr/JcrMonitor.java new file mode 100644 index 000000000..f04be9aa5 --- /dev/null +++ b/org.argeo.server.jcr/src/org/argeo/jcr/JcrMonitor.java @@ -0,0 +1,89 @@ +package org.argeo.jcr; + +import org.argeo.ArgeoMonitor; + +/** + * Simple monitor abstraction. Inspired by Eclipse IProgressMOnitor, but without + * dependency to it. + */ +@SuppressWarnings("deprecation") +public interface JcrMonitor extends ArgeoMonitor { + /** + * Constant indicating an unknown amount of work. + */ + public final static int UNKNOWN = -1; + + /** + * Notifies that the main task is beginning. This must only be called once + * on a given progress monitor instance. + * + * @param name + * the name (or description) of the main task + * @param totalWork + * the total number of work units into which the main task is + * been subdivided. If the value is UNKNOWN the + * implementation is free to indicate progress in a way which + * doesn't require the total number of work units in advance. + */ + public void beginTask(String name, int totalWork); + + /** + * Notifies that the work is done; that is, either the main task is + * completed or the user canceled it. This method may be called more than + * once (implementations should be prepared to handle this case). + */ + public void done(); + + /** + * Returns whether cancelation of current operation has been requested. + * Long-running operations should poll to see if cancelation has been + * requested. + * + * @return true if cancellation has been requested, and + * false otherwise + * @see #setCanceled(boolean) + */ + public boolean isCanceled(); + + /** + * Sets the cancel state to the given value. + * + * @param value + * true indicates that cancelation has been + * requested (but not necessarily acknowledged); + * false clears this flag + * @see #isCanceled() + */ + public void setCanceled(boolean value); + + /** + * Sets the task name to the given value. This method is used to restore the + * task label after a nested operation was executed. Normally there is no + * need for clients to call this method. + * + * @param name + * the name (or description) of the main task + * @see #beginTask(java.lang.String, int) + */ + public void setTaskName(String name); + + /** + * Notifies that a subtask of the main task is beginning. Subtasks are + * optional; the main task might not have subtasks. + * + * @param name + * the name (or description) of the subtask + */ + public void subTask(String name); + + /** + * Notifies that a given number of work unit of the main task has been + * completed. Note that this amount represents an installment, as opposed to + * a cumulative amount of work done to date. + * + * @param work + * a non-negative number of work units just completed + */ + public void worked(int work); + +} diff --git a/org.argeo.server.jcr/src/org/argeo/jcr/JcrRepositoryWrapper.java b/org.argeo.server.jcr/src/org/argeo/jcr/JcrRepositoryWrapper.java index f993c2f58..6c23acaac 100644 --- a/org.argeo.server.jcr/src/org/argeo/jcr/JcrRepositoryWrapper.java +++ b/org.argeo.server.jcr/src/org/argeo/jcr/JcrRepositoryWrapper.java @@ -23,8 +23,6 @@ import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.Value; -import org.argeo.ArgeoException; - /** * Wrapper around a JCR repository which allows to simplify configuration and * intercept some actions. It exposes itself as a {@link Repository}. @@ -103,7 +101,7 @@ public abstract class JcrRepositoryWrapper implements Repository { /** Wraps access to the repository, making sure it is available. */ protected synchronized Repository getRepository() { // if (repository == null) { -// throw new ArgeoException("No repository initialized." +// throw new ArgeoJcrException("No repository initialized." // + " Was the init() method called?" // + " The destroy() method should also" // + " be called on shutdown."); @@ -118,7 +116,7 @@ public abstract class JcrRepositoryWrapper implements Repository { protected Session createWorkspaceAndLogsIn(Credentials credentials, String workspaceName) throws RepositoryException { if (workspaceName == null) - throw new ArgeoException("No workspace specified."); + throw new ArgeoJcrException("No workspace specified."); Session session = getRepository().login(credentials); session.getWorkspace().createWorkspace(workspaceName); session.logout(); diff --git a/org.argeo.server.jcr/src/org/argeo/jcr/JcrResourceAdapter.java b/org.argeo.server.jcr/src/org/argeo/jcr/JcrResourceAdapter.java index 0b1a98cf0..1ccce4f76 100644 --- a/org.argeo.server.jcr/src/org/argeo/jcr/JcrResourceAdapter.java +++ b/org.argeo.server.jcr/src/org/argeo/jcr/JcrResourceAdapter.java @@ -32,7 +32,6 @@ import javax.jcr.version.VersionIterator; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; /** * Bridge Spring resources and JCR folder / files semantics (nt:folder / @@ -63,7 +62,7 @@ public class JcrResourceAdapter { public void create(String path, InputStream in, String mimeType) { try { if (session().itemExists(path)) { - throw new ArgeoException("Node " + path + " already exists."); + throw new ArgeoJcrException("Node " + path + " already exists."); } int index = path.lastIndexOf('/'); @@ -72,7 +71,7 @@ public class JcrResourceAdapter { parentPath = "/"; String fileName = path.substring(index + 1); if (!session().itemExists(parentPath)) - throw new ArgeoException("Parent folder of node " + path + throw new ArgeoJcrException("Parent folder of node " + path + " does not exist: " + parentPath); Node folderNode = (Node) session().getItem(parentPath); @@ -103,7 +102,7 @@ public class JcrResourceAdapter { if (log.isDebugEnabled()) log.debug("Created " + path); } catch (Exception e) { - throw new ArgeoException("Cannot create node for " + path, e); + throw new ArgeoJcrException("Cannot create node for " + path, e); } } @@ -141,13 +140,13 @@ public class JcrResourceAdapter { if (log.isDebugEnabled()) log.debug("Updated " + path); } catch (Exception e) { - throw new ArgeoException("Cannot update node " + path, e); + throw new ArgeoJcrException("Cannot update node " + path, e); } } public List listVersions(String path) { if (!versioning) - throw new ArgeoException("Versioning is not activated"); + throw new ArgeoJcrException("Versioning is not activated"); try { List versions = new ArrayList(); @@ -164,7 +163,7 @@ public class JcrResourceAdapter { } return versions; } catch (Exception e) { - throw new ArgeoException("Cannot list version of node " + path, e); + throw new ArgeoJcrException("Cannot list version of node " + path, e); } } @@ -175,13 +174,13 @@ public class JcrResourceAdapter { Property property = node.getProperty(Property.JCR_DATA); return property.getBinary().getStream(); } catch (Exception e) { - throw new ArgeoException("Cannot retrieve " + path, e); + throw new ArgeoJcrException("Cannot retrieve " + path, e); } } public synchronized InputStream retrieve(String path, Integer revision) { if (!versioning) - throw new ArgeoException("Versioning is not activated"); + throw new ArgeoJcrException("Versioning is not activated"); try { Node fileNode = (Node) session().getItem(path); @@ -201,11 +200,11 @@ public class JcrResourceAdapter { count++; } } catch (Exception e) { - throw new ArgeoException("Cannot retrieve version " + revision + throw new ArgeoJcrException("Cannot retrieve version " + revision + " of " + path, e); } - throw new ArgeoException("Version " + revision + throw new ArgeoJcrException("Version " + revision + " does not exist for node " + path); } diff --git a/org.argeo.server.jcr/src/org/argeo/jcr/JcrUtils.java b/org.argeo.server.jcr/src/org/argeo/jcr/JcrUtils.java index c42f84ece..98a2da8f3 100644 --- a/org.argeo.server.jcr/src/org/argeo/jcr/JcrUtils.java +++ b/org.argeo.server.jcr/src/org/argeo/jcr/JcrUtils.java @@ -63,7 +63,6 @@ import javax.jcr.security.Privilege; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; import org.argeo.ArgeoMonitor; import org.argeo.util.security.DigestUtils; import org.argeo.util.security.SimplePrincipal; @@ -92,7 +91,7 @@ public class JcrUtils implements ArgeoJcrConstants { * Queries one single node. * * @return one single node or null if none was found - * @throws ArgeoException + * @throws ArgeoJcrException * if more than one node was found */ public static Node querySingleNode(Query query) { @@ -101,7 +100,7 @@ public class JcrUtils implements ArgeoJcrConstants { QueryResult queryResult = query.execute(); nodeIterator = queryResult.getNodes(); } catch (RepositoryException e) { - throw new ArgeoException("Cannot execute query " + query, e); + throw new ArgeoJcrException("Cannot execute query " + query, e); } Node node; if (nodeIterator.hasNext()) @@ -110,7 +109,7 @@ public class JcrUtils implements ArgeoJcrConstants { return null; if (nodeIterator.hasNext()) - throw new ArgeoException("Query returned more than one node."); + throw new ArgeoJcrException("Query returned more than one node."); return node; } @@ -119,7 +118,7 @@ public class JcrUtils implements ArgeoJcrConstants { if (path.equals("/")) return ""; if (path.charAt(0) != '/') - throw new ArgeoException("Path " + path + " must start with a '/'"); + throw new ArgeoJcrException("Path " + path + " must start with a '/'"); String pathT = path; if (pathT.charAt(pathT.length() - 1) == '/') pathT = pathT.substring(0, pathT.length() - 2); @@ -131,9 +130,9 @@ public class JcrUtils implements ArgeoJcrConstants { /** Retrieves the parent path of the provided path */ public static String parentPath(String path) { if (path.equals("/")) - throw new ArgeoException("Root path '/' has no parent path"); + throw new ArgeoJcrException("Root path '/' has no parent path"); if (path.charAt(0) != '/') - throw new ArgeoException("Path " + path + " must start with a '/'"); + throw new ArgeoJcrException("Path " + path + " must start with a '/'"); String pathT = path; if (pathT.charAt(pathT.length() - 1) == '/') pathT = pathT.substring(0, pathT.length() - 2); @@ -162,7 +161,7 @@ public class JcrUtils implements ArgeoJcrConstants { path.append(u.getPath()); return path.toString(); } catch (MalformedURLException e) { - throw new ArgeoException("Cannot generate URL path for " + url, e); + throw new ArgeoJcrException("Cannot generate URL path for " + url, e); } } @@ -175,7 +174,7 @@ public class JcrUtils implements ArgeoJcrConstants { node.setProperty(Property.JCR_PORT, Integer.toString(u.getPort())); node.setProperty(Property.JCR_PATH, normalizePath(u.getPath())); } catch (Exception e) { - throw new ArgeoException("Cannot set URL " + url + throw new ArgeoJcrException("Cannot set URL " + url + " as nt:address properties", e); } } @@ -190,7 +189,7 @@ public class JcrUtils implements ArgeoJcrConstants { .getProperty(Property.JCR_PATH).getString()); return u.toString(); } catch (Exception e) { - throw new ArgeoException( + throw new ArgeoJcrException( "Cannot get URL from nt:address properties of " + node, e); } } @@ -288,7 +287,7 @@ public class JcrUtils implements ArgeoJcrConstants { calendar.setTime(date); return calendar; } catch (ParseException e) { - throw new ArgeoException("Cannot parse " + value + throw new ArgeoJcrException("Cannot parse " + value + " with date format " + dateFormat, e); } @@ -297,7 +296,7 @@ public class JcrUtils implements ArgeoJcrConstants { /** The last element of a path. */ public static String lastPathElement(String path) { if (path.charAt(path.length() - 1) == '/') - throw new ArgeoException("Path " + path + " cannot end with '/'"); + throw new ArgeoJcrException("Path " + path + " cannot end with '/'"); int index = path.lastIndexOf('/'); if (index < 0) return path; @@ -312,7 +311,7 @@ public class JcrUtils implements ArgeoJcrConstants { try { return node.getName(); } catch (RepositoryException e) { - throw new ArgeoException("Cannot get name from " + node, e); + throw new ArgeoJcrException("Cannot get name from " + node, e); } } @@ -324,7 +323,7 @@ public class JcrUtils implements ArgeoJcrConstants { try { return node.getProperty(propertyName).getString(); } catch (RepositoryException e) { - throw new ArgeoException("Cannot get name from " + node, e); + throw new ArgeoJcrException("Cannot get name from " + node, e); } } @@ -371,7 +370,7 @@ public class JcrUtils implements ArgeoJcrConstants { return null; return node.getProperty(propertyName).getString(); } catch (RepositoryException e) { - throw new ArgeoException("Cannot get property " + propertyName + throw new ArgeoJcrException("Cannot get property " + propertyName + " of " + node, e); } } @@ -381,7 +380,7 @@ public class JcrUtils implements ArgeoJcrConstants { try { return node.getProperty(propertyName).getBoolean(); } catch (RepositoryException e) { - throw new ArgeoException("Cannot get property " + propertyName + throw new ArgeoJcrException("Cannot get property " + propertyName + " of " + node, e); } } @@ -391,7 +390,7 @@ public class JcrUtils implements ArgeoJcrConstants { try { return getBinaryAsBytes(node.getProperty(propertyName)); } catch (RepositoryException e) { - throw new ArgeoException("Cannot get property " + propertyName + throw new ArgeoJcrException("Cannot get property " + propertyName + " of " + node, e); } } @@ -457,7 +456,7 @@ public class JcrUtils implements ArgeoJcrConstants { } return currParent; } catch (RepositoryException e) { - throw new ArgeoException("Cannot mkdirs relative path " + throw new ArgeoJcrException("Cannot mkdirs relative path " + relativePath + " from " + parentNode, e); } } @@ -470,14 +469,14 @@ public class JcrUtils implements ArgeoJcrConstants { String type) { try { if (session.hasPendingChanges()) - throw new ArgeoException( + throw new ArgeoJcrException( "Session has pending changes, save them first."); Node node = mkdirs(session, path, type); session.save(); return node; } catch (RepositoryException e) { discardQuietly(session); - throw new ArgeoException("Cannot safely make directories", e); + throw new ArgeoJcrException("Cannot safely make directories", e); } } @@ -501,7 +500,7 @@ public class JcrUtils implements ArgeoJcrConstants { // check type if (type != null && !node.isNodeType(type) && !node.getPath().equals("/")) - throw new ArgeoException("Node " + node + throw new ArgeoJcrException("Node " + node + " exists but is of type " + node.getPrimaryNodeType().getName() + " not of type " + type); @@ -534,7 +533,7 @@ public class JcrUtils implements ArgeoJcrConstants { return currentNode; } catch (RepositoryException e) { discardQuietly(session); - throw new ArgeoException("Cannot mkdirs " + path, e); + throw new ArgeoJcrException("Cannot mkdirs " + path, e); } finally { } } @@ -582,7 +581,7 @@ public class JcrUtils implements ArgeoJcrConstants { registerNamespaceSafely(session.getWorkspace() .getNamespaceRegistry(), prefix, uri); } catch (RepositoryException e) { - throw new ArgeoException("Cannot find namespace registry", e); + throw new ArgeoJcrException("Cannot find namespace registry", e); } } @@ -598,7 +597,7 @@ public class JcrUtils implements ArgeoJcrConstants { if (pref.equals(prefix)) { String registeredUri = nr.getURI(pref); if (!registeredUri.equals(uri)) - throw new ArgeoException("Prefix " + pref + throw new ArgeoJcrException("Prefix " + pref + " already registered for URI " + registeredUri + " which is different from provided URI " @@ -608,7 +607,7 @@ public class JcrUtils implements ArgeoJcrConstants { } nr.registerNamespace(prefix, uri); } catch (RepositoryException e) { - throw new ArgeoException("Cannot register namespace " + uri + throw new ArgeoJcrException("Cannot register namespace " + uri + " under prefix " + prefix, e); } } @@ -706,7 +705,7 @@ public class JcrUtils implements ArgeoJcrConstants { } return buf.toString(); } catch (RepositoryException e) { - throw new ArgeoException("Cannot write summary of " + acl, e); + throw new ArgeoJcrException("Cannot write summary of " + acl, e); } } @@ -773,7 +772,7 @@ public class JcrUtils implements ArgeoJcrConstants { copy(fromChild, toChild); } } catch (RepositoryException e) { - throw new ArgeoException("Cannot copy " + fromNode + " to " + throw new ArgeoJcrException("Cannot copy " + fromNode + " to " + toNode, e); } } @@ -804,7 +803,7 @@ public class JcrUtils implements ArgeoJcrConstants { } return true; } catch (RepositoryException e) { - throw new ArgeoException("Cannot check all properties equals of " + throw new ArgeoJcrException("Cannot check all properties equals of " + reference + " and " + observed, e); } } @@ -871,7 +870,7 @@ public class JcrUtils implements ArgeoJcrConstants { } } } catch (RepositoryException e) { - throw new ArgeoException("Cannot diff " + reference + " and " + throw new ArgeoJcrException("Cannot diff " + reference + " and " + observed, e); } } @@ -920,7 +919,7 @@ public class JcrUtils implements ArgeoJcrConstants { } } } catch (RepositoryException e) { - throw new ArgeoException("Cannot diff " + reference + " and " + throw new ArgeoJcrException("Cannot diff " + reference + " and " + observed, e); } return diffs; @@ -1008,7 +1007,7 @@ public class JcrUtils implements ArgeoJcrConstants { IOUtils.copy(in, out); return out.toByteArray(); } catch (Exception e) { - throw new ArgeoException("Cannot read binary " + property + throw new ArgeoJcrException("Cannot read binary " + property + " as bytes", e); } finally { IOUtils.closeQuietly(out); @@ -1026,7 +1025,7 @@ public class JcrUtils implements ArgeoJcrConstants { binary = node.getSession().getValueFactory().createBinary(in); node.setProperty(property, binary); } catch (Exception e) { - throw new ArgeoException("Cannot read binary " + property + throw new ArgeoJcrException("Cannot read binary " + property + " as bytes", e); } finally { IOUtils.closeQuietly(in); @@ -1040,7 +1039,7 @@ public class JcrUtils implements ArgeoJcrConstants { */ public static String firstCharsToPath(String str, Integer nbrOfChars) { if (str.length() < nbrOfChars) - throw new ArgeoException("String " + str + throw new ArgeoJcrException("String " + str + " length must be greater or equal than " + nbrOfChars); StringBuffer path = new StringBuffer(""); StringBuffer curr = new StringBuffer(""); @@ -1135,7 +1134,7 @@ public class JcrUtils implements ArgeoJcrConstants { nodeType == null ? null : new String[] { nodeType }, true); } catch (RepositoryException e) { - throw new ArgeoException("Cannot add JCR listener " + listener + throw new ArgeoJcrException("Cannot add JCR listener " + listener + " to session " + session, e); } } @@ -1202,7 +1201,7 @@ public class JcrUtils implements ArgeoJcrConstants { node.setProperty(Property.JCR_LAST_MODIFIED_BY, node.getSession() .getUserID()); } catch (RepositoryException e) { - throw new ArgeoException("Cannot update last modified on " + node, + throw new ArgeoJcrException("Cannot update last modified on " + node, e); } } @@ -1218,7 +1217,7 @@ public class JcrUtils implements ArgeoJcrConstants { public static void updateLastModifiedAndParents(Node node, String untilPath) { try { if (untilPath != null && !node.getPath().startsWith(untilPath)) - throw new ArgeoException(node + " is not under " + untilPath); + throw new ArgeoJcrException(node + " is not under " + untilPath); updateLastModified(node); if (untilPath == null) { if (!node.getPath().equals("/")) @@ -1228,7 +1227,7 @@ public class JcrUtils implements ArgeoJcrConstants { updateLastModifiedAndParents(node.getParent(), untilPath); } } catch (RepositoryException e) { - throw new ArgeoException("Cannot update lastModified from " + node + throw new ArgeoJcrException("Cannot update lastModified from " + node + " until " + untilPath, e); } } @@ -1253,7 +1252,7 @@ public class JcrUtils implements ArgeoJcrConstants { if (prop.getDefinition().isMultiple()) sbuf.append("*"); } catch (RepositoryException re) { - throw new ArgeoException( + throw new ArgeoJcrException( "unexpected error while getting property definition as String", re); } @@ -1287,7 +1286,7 @@ public class JcrUtils implements ArgeoJcrConstants { curNodeSize += getNodeApproxSize(ni.nextNode()); return curNodeSize; } catch (RepositoryException re) { - throw new ArgeoException( + throw new ArgeoJcrException( "Unexpected error while recursively determining node size.", re); } @@ -1380,7 +1379,7 @@ public class JcrUtils implements ArgeoJcrConstants { if (acl != null) return acl; else - throw new ArgeoException("ACL not found at " + path); + throw new ArgeoJcrException("ACL not found at " + path); } /** Clear authorizations for a user at this path */ @@ -1418,6 +1417,7 @@ public class JcrUtils implements ArgeoJcrConstants { * files * @return how many files were copied */ + @SuppressWarnings("deprecation") public static Long copyFiles(Node fromNode, Node toNode, Boolean recursive, ArgeoMonitor monitor) { long count = 0l; @@ -1428,7 +1428,7 @@ public class JcrUtils implements ArgeoJcrConstants { NodeIterator fromChildren = fromNode.getNodes(); while (fromChildren.hasNext()) { if (monitor != null && monitor.isCanceled()) - throw new ArgeoException( + throw new ArgeoJcrException( "Copy cancelled before it was completed"); Node fromChild = fromChildren.nextNode(); @@ -1457,7 +1457,7 @@ public class JcrUtils implements ArgeoJcrConstants { if (toNode.hasNode(fileName)) { toChildFolder = toNode.getNode(fileName); if (!toChildFolder.isNodeType(NodeType.NT_FOLDER)) - throw new ArgeoException(toChildFolder + throw new ArgeoJcrException(toChildFolder + " is not of type nt:folder"); } else { toChildFolder = toNode.addNode(fileName, @@ -1473,7 +1473,7 @@ public class JcrUtils implements ArgeoJcrConstants { } return count; } catch (RepositoryException e) { - throw new ArgeoException("Cannot copy files between " + fromNode + throw new ArgeoJcrException("Cannot copy files between " + fromNode + " and " + toNode); } finally { // in case there was an exception @@ -1497,7 +1497,7 @@ public class JcrUtils implements ArgeoJcrConstants { localCount = localCount + 1; } } catch (RepositoryException e) { - throw new ArgeoException("Cannot count all children of " + node); + throw new ArgeoJcrException("Cannot count all children of " + node); } return localCount; } @@ -1514,7 +1514,7 @@ public class JcrUtils implements ArgeoJcrConstants { in = new FileInputStream(file); return copyStreamAsFile(folderNode, file.getName(), in); } catch (IOException e) { - throw new ArgeoException("Cannot copy file " + file + " under " + throw new ArgeoJcrException("Cannot copy file " + file + " under " + folderNode, e); } finally { IOUtils.closeQuietly(in); @@ -1529,7 +1529,7 @@ public class JcrUtils implements ArgeoJcrConstants { in = new ByteArrayInputStream(bytes); return copyStreamAsFile(folderNode, fileName, in); } catch (Exception e) { - throw new ArgeoException("Cannot copy file " + fileName + " under " + throw new ArgeoJcrException("Cannot copy file " + fileName + " under " + folderNode, e); } finally { IOUtils.closeQuietly(in); @@ -1551,7 +1551,7 @@ public class JcrUtils implements ArgeoJcrConstants { if (folderNode.hasNode(fileName)) { fileNode = folderNode.getNode(fileName); if (!fileNode.isNodeType(NodeType.NT_FILE)) - throw new ArgeoException(fileNode + throw new ArgeoJcrException(fileNode + " is not of type nt:file"); // we assume that the content node is already there contentNode = fileNode.getNode(Node.JCR_CONTENT); @@ -1565,7 +1565,7 @@ public class JcrUtils implements ArgeoJcrConstants { contentNode.setProperty(Property.JCR_DATA, binary); return fileNode; } catch (Exception e) { - throw new ArgeoException("Cannot create file node " + fileName + throw new ArgeoJcrException("Cannot create file node " + fileName + " under " + folderNode, e); } finally { closeQuietly(binary); @@ -1582,7 +1582,7 @@ public class JcrUtils implements ArgeoJcrConstants { in = data.getStream(); return DigestUtils.digest(algorithm, in); } catch (RepositoryException e) { - throw new ArgeoException("Cannot checksum file " + fileNode, e); + throw new ArgeoJcrException("Cannot checksum file " + fileNode, e); } finally { IOUtils.closeQuietly(in); closeQuietly(data); diff --git a/org.argeo.server.jcr/src/org/argeo/jcr/PropertyDiff.java b/org.argeo.server.jcr/src/org/argeo/jcr/PropertyDiff.java index bdd316f31..a0ff4712a 100644 --- a/org.argeo.server.jcr/src/org/argeo/jcr/PropertyDiff.java +++ b/org.argeo.server.jcr/src/org/argeo/jcr/PropertyDiff.java @@ -17,8 +17,6 @@ package org.argeo.jcr; import javax.jcr.Value; -import org.argeo.ArgeoException; - /** The result of the comparison of two JCR properties. */ public class PropertyDiff { public final static Integer MODIFIED = 0; @@ -36,22 +34,22 @@ public class PropertyDiff { if (type == MODIFIED) { if (referenceValue == null || newValue == null) - throw new ArgeoException( + throw new ArgeoJcrException( "Reference and new values must be specified."); } else if (type == ADDED) { if (referenceValue != null || newValue == null) - throw new ArgeoException( + throw new ArgeoJcrException( "New value and only it must be specified."); } else if (type == REMOVED) { if (referenceValue == null || newValue != null) - throw new ArgeoException( + throw new ArgeoJcrException( "Reference value and only it must be specified."); } else { - throw new ArgeoException("Unkown diff type " + type); + throw new ArgeoJcrException("Unkown diff type " + type); } if (relPath == null) - throw new ArgeoException("Relative path must be specified"); + throw new ArgeoJcrException("Relative path must be specified"); this.type = type; this.relPath = relPath; diff --git a/org.argeo.server.jcr/src/org/argeo/jcr/ThreadBoundJcrSessionFactory.java b/org.argeo.server.jcr/src/org/argeo/jcr/ThreadBoundJcrSessionFactory.java index 56caab0a3..9662e221b 100644 --- a/org.argeo.server.jcr/src/org/argeo/jcr/ThreadBoundJcrSessionFactory.java +++ b/org.argeo.server.jcr/src/org/argeo/jcr/ThreadBoundJcrSessionFactory.java @@ -34,7 +34,6 @@ import javax.jcr.SimpleCredentials; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; /** Proxy JCR sessions and attach them to calling threads. */ @Deprecated @@ -74,7 +73,7 @@ public abstract class ThreadBoundJcrSessionFactory { /** Logs in to the repository using various strategies. */ protected synchronized Session login() { if (!isActive()) - throw new ArgeoException("Thread bound session factory inactive"); + throw new ArgeoJcrException("Thread bound session factory inactive"); // discard session previously attached to this thread Thread thread = Thread.currentThread(); @@ -96,7 +95,7 @@ public abstract class ThreadBoundJcrSessionFactory { // invalid credentials, go to the next step } catch (RepositoryException e1) { // other kind of exception, fail - throw new ArgeoException("Cannot log in to repository", e1); + throw new ArgeoJcrException("Cannot log in to repository", e1); } // log using default username / password (useful for testing purposes) @@ -106,7 +105,7 @@ public abstract class ThreadBoundJcrSessionFactory { defaultPassword.toCharArray()); newSession = repository().login(sc, workspace); } catch (RepositoryException e) { - throw new ArgeoException("Cannot log in to repository", e); + throw new ArgeoJcrException("Cannot log in to repository", e); } session.set(newSession); @@ -214,7 +213,7 @@ public abstract class ThreadBoundJcrSessionFactory { if (it.hasNext()) return it.next(); } - throw new ArgeoException("No repository injected"); + throw new ArgeoJcrException("No repository injected"); } // /** Useful for declarative registration of OSGi services (blueprint) */ diff --git a/org.argeo.server.jcr/src/org/argeo/jcr/UserJcrUtils.java b/org.argeo.server.jcr/src/org/argeo/jcr/UserJcrUtils.java index 7caccf6a8..95269475e 100644 --- a/org.argeo.server.jcr/src/org/argeo/jcr/UserJcrUtils.java +++ b/org.argeo.server.jcr/src/org/argeo/jcr/UserJcrUtils.java @@ -25,8 +25,6 @@ import javax.jcr.query.qom.QueryObjectModelFactory; import javax.jcr.query.qom.Selector; import javax.jcr.query.qom.StaticOperand; -import org.argeo.ArgeoException; - /** * Utilities related to the user home and properties based on Argeo JCR model. * Do not use anymore. Does not fit with current security model @@ -65,7 +63,7 @@ public class UserJcrUtils { Query query = qomf.createQuery(userHomeSel, constraint, null, null); return JcrUtils.querySingleNode(query); } catch (RepositoryException e) { - throw new ArgeoException("Cannot find home for user " + username, e); + throw new ArgeoJcrException("Cannot find home for user " + username, e); } } @@ -84,7 +82,7 @@ public class UserJcrUtils { Query query = qomf.createQuery(userHomeSel, constraint, null, null); return JcrUtils.querySingleNode(query); } catch (RepositoryException e) { - throw new ArgeoException( + throw new ArgeoJcrException( "Cannot find profile for user " + username, e); } } diff --git a/org.argeo.server.jcr/src/org/argeo/jcr/proxy/AbstractUrlProxy.java b/org.argeo.server.jcr/src/org/argeo/jcr/proxy/AbstractUrlProxy.java index 8a66f3102..30369ce7d 100644 --- a/org.argeo.server.jcr/src/org/argeo/jcr/proxy/AbstractUrlProxy.java +++ b/org.argeo.server.jcr/src/org/argeo/jcr/proxy/AbstractUrlProxy.java @@ -30,7 +30,7 @@ import javax.jcr.nodetype.NodeType; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; +import org.argeo.jcr.ArgeoJcrException; import org.argeo.jcr.JcrUtils; /** Base class for URL based proxys. */ @@ -52,7 +52,7 @@ public abstract class AbstractUrlProxy implements ResourceProxy { jcrAdminSession.save(); } catch (Exception e) { JcrUtils.discardQuietly(jcrAdminSession); - throw new ArgeoException("Cannot initialize Maven proxy", e); + throw new ArgeoJcrException("Cannot initialize Maven proxy", e); } } @@ -92,7 +92,7 @@ public abstract class AbstractUrlProxy implements ResourceProxy { nodeClient = clientSession.getNode(path); return nodeClient; } catch (RepositoryException e) { - throw new ArgeoException("Cannot proxy " + path, e); + throw new ArgeoJcrException("Cannot proxy " + path, e); } finally { if (nodeClient == null) JcrUtils.logoutQuietly(clientSession); @@ -108,7 +108,7 @@ public abstract class AbstractUrlProxy implements ResourceProxy { return node; } catch (RepositoryException e) { JcrUtils.discardQuietly(jcrAdminSession); - throw new ArgeoException("Cannot retrieve and save " + path, e); + throw new ArgeoJcrException("Cannot retrieve and save " + path, e); } finally { notifyAll(); } @@ -119,7 +119,7 @@ public abstract class AbstractUrlProxy implements ResourceProxy { String path) throws RepositoryException { Node node = null; if (session.itemExists(path)) { - // throw new ArgeoException("Node " + path + " already exists"); + // throw new ArgeoJcrException("Node " + path + " already exists"); } InputStream in = null; try { diff --git a/org.argeo.server.jcr/src/org/argeo/jcr/proxy/ResourceProxyServlet.java b/org.argeo.server.jcr/src/org/argeo/jcr/proxy/ResourceProxyServlet.java index 61854131b..e92e2a402 100644 --- a/org.argeo.server.jcr/src/org/argeo/jcr/proxy/ResourceProxyServlet.java +++ b/org.argeo.server.jcr/src/org/argeo/jcr/proxy/ResourceProxyServlet.java @@ -32,7 +32,7 @@ import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; +import org.argeo.jcr.ArgeoJcrException; import org.argeo.jcr.JcrUtils; /** Wraps a proxy via HTTP */ @@ -126,7 +126,7 @@ public class ResourceProxyServlet extends HttpServlet { in = binary.getStream(); IOUtils.copy(in, response.getOutputStream()); } catch (Exception e) { - throw new ArgeoException("Cannot download " + node, e); + throw new ArgeoJcrException("Cannot download " + node, e); } finally { IOUtils.closeQuietly(in); JcrUtils.closeQuietly(binary); diff --git a/org.argeo.server.jcr/src/org/argeo/jcr/security/JcrAuthorizations.java b/org.argeo.server.jcr/src/org/argeo/jcr/security/JcrAuthorizations.java index 491f8a6fe..9ad249252 100644 --- a/org.argeo.server.jcr/src/org/argeo/jcr/security/JcrAuthorizations.java +++ b/org.argeo.server.jcr/src/org/argeo/jcr/security/JcrAuthorizations.java @@ -27,7 +27,7 @@ import javax.jcr.Session; import javax.jcr.security.AccessControlManager; import javax.jcr.security.Privilege; -import org.argeo.ArgeoException; +import org.argeo.jcr.ArgeoJcrException; import org.argeo.jcr.JcrUtils; import org.argeo.util.security.SimplePrincipal; @@ -70,7 +70,7 @@ public class JcrAuthorizations implements Runnable { } } catch (Exception e) { JcrUtils.discardQuietly(session); - throw new ArgeoException( + throw new ArgeoJcrException( "Cannot set authorizations " + principalPrivileges + " on workspace " + currentWorkspace, e); } finally { @@ -85,7 +85,7 @@ public class JcrAuthorizations implements Runnable { initAuthorizations(session); } catch (Exception e) { JcrUtils.discardQuietly(session); - throw new ArgeoException("Cannot set authorizations " + throw new ArgeoJcrException("Cannot set authorizations " + principalPrivileges + " on repository " + repository, e); } finally { JcrUtils.logoutQuietly(session); @@ -106,7 +106,7 @@ public class JcrAuthorizations implements Runnable { String path = null; int slashIndex = privileges.indexOf('/'); if (slashIndex == 0) { - throw new ArgeoException("Privilege " + privileges + throw new ArgeoJcrException("Privilege " + privileges + " badly formatted it starts with /"); } else if (slashIndex > 0) { path = privileges.substring(slashIndex); @@ -192,7 +192,7 @@ public class JcrAuthorizations implements Runnable { // + session.getWorkspace().getName() + "'"); // } // } else { - // throw new ArgeoException("Don't know how to apply privileges " + // throw new ArgeoJcrException("Don't know how to apply privileges " // + privs + " to " + principal + " on " + path // + " from workspace '" + session.getWorkspace().getName() // + "'"); diff --git a/org.argeo.server.jcr/src/org/argeo/jcr/security/JcrKeyring.java b/org.argeo.server.jcr/src/org/argeo/jcr/security/JcrKeyring.java index 77e969509..b43c5d6c6 100644 --- a/org.argeo.server.jcr/src/org/argeo/jcr/security/JcrKeyring.java +++ b/org.argeo.server.jcr/src/org/argeo/jcr/security/JcrKeyring.java @@ -32,7 +32,7 @@ import javax.jcr.RepositoryException; import javax.jcr.Session; import org.apache.commons.io.IOUtils; -import org.argeo.ArgeoException; +import org.argeo.jcr.ArgeoJcrException; import org.argeo.jcr.ArgeoNames; import org.argeo.jcr.ArgeoTypes; import org.argeo.jcr.JcrUtils; @@ -83,7 +83,7 @@ public class JcrKeyring extends AbstractKeyring implements ArgeoNames { Node userHome = UserJcrUtils.getUserHome(session); return userHome.hasNode(ARGEO_KEYRING); } catch (RepositoryException e) { - throw new ArgeoException("Cannot check whether keyring is setup", e); + throw new ArgeoJcrException("Cannot check whether keyring is setup", e); } } @@ -94,7 +94,7 @@ public class JcrKeyring extends AbstractKeyring implements ArgeoNames { try { Node userHome = UserJcrUtils.getUserHome(session); if (userHome.hasNode(ARGEO_KEYRING)) - throw new ArgeoException("Keyring already setup"); + throw new ArgeoJcrException("Keyring already setup"); Node keyring = userHome.addNode(ARGEO_KEYRING); keyring.addMixin(ArgeoTypes.ARGEO_PBE_SPEC); @@ -123,6 +123,8 @@ public class JcrKeyring extends AbstractKeyring implements ArgeoNames { secreteKeyEncryption); keyring.setProperty(ARGEO_CIPHER, cipherName); + //keyring.getSession().save(); + // encrypted password hash // IOUtils.closeQuietly(in); // JcrUtils.closeQuietly(binary); @@ -133,7 +135,7 @@ public class JcrKeyring extends AbstractKeyring implements ArgeoNames { notYetSavedKeyring.set(keyring); } catch (Exception e) { - throw new ArgeoException("Cannot setup keyring", e); + throw new ArgeoJcrException("Cannot setup keyring", e); } finally { JcrUtils.closeQuietly(binary); IOUtils.closeQuietly(in); @@ -151,7 +153,7 @@ public class JcrKeyring extends AbstractKeyring implements ArgeoNames { else if (notYetSavedKeyring.get() != null) keyring = notYetSavedKeyring.get(); else - throw new ArgeoException("Keyring not setup"); + throw new ArgeoJcrException("Keyring not setup"); pbeCallback.set(keyring.getProperty(ARGEO_SECRET_KEY_FACTORY) .getString(), JcrUtils.getBinaryAsBytes(keyring @@ -164,7 +166,7 @@ public class JcrKeyring extends AbstractKeyring implements ArgeoNames { if (notYetSavedKeyring.get() != null) notYetSavedKeyring.remove(); } catch (RepositoryException e) { - throw new ArgeoException("Cannot handle key spec callback", e); + throw new ArgeoJcrException("Cannot handle key spec callback", e); } } @@ -182,7 +184,7 @@ public class JcrKeyring extends AbstractKeyring implements ArgeoNames { if (!session.nodeExists(path)) { String parentPath = JcrUtils.parentPath(path); if (!session.nodeExists(parentPath)) - throw new ArgeoException("No parent node of " + path); + throw new ArgeoJcrException("No parent node of " + path); Node parentNode = session.getNode(parentPath); node = parentNode.addNode(JcrUtils.nodeNameFromPath(path)); } else { @@ -200,7 +202,7 @@ public class JcrKeyring extends AbstractKeyring implements ArgeoNames { node.setProperty(Property.JCR_DATA, binary); session.save(); } catch (Exception e) { - throw new ArgeoException("Cannot encrypt", e); + throw new ArgeoJcrException("Cannot encrypt", e); } finally { IOUtils.closeQuietly(unencrypted); IOUtils.closeQuietly(in); @@ -239,7 +241,7 @@ public class JcrKeyring extends AbstractKeyring implements ArgeoNames { return new CipherInputStream(encrypted, cipher); } } catch (Exception e) { - throw new ArgeoException("Cannot decrypt", e); + throw new ArgeoJcrException("Cannot decrypt", e); } finally { IOUtils.closeQuietly(encrypted); IOUtils.closeQuietly(reader); @@ -251,14 +253,14 @@ public class JcrKeyring extends AbstractKeyring implements ArgeoNames { try { Node userHome = UserJcrUtils.getUserHome(session); if (!userHome.hasNode(ARGEO_KEYRING)) - throw new ArgeoException("Keyring not setup"); + throw new ArgeoJcrException("Keyring not setup"); Node keyring = userHome.getNode(ARGEO_KEYRING); Cipher cipher = Cipher.getInstance(keyring .getProperty(ARGEO_CIPHER).getString(), getSecurityProvider()); return cipher; } catch (Exception e) { - throw new ArgeoException("Cannot get cipher", e); + throw new ArgeoJcrException("Cannot get cipher", e); } } diff --git a/org.argeo.server.jcr/src/org/argeo/jcr/tabular/JcrTabularRowIterator.java b/org.argeo.server.jcr/src/org/argeo/jcr/tabular/JcrTabularRowIterator.java index ca0635c95..d4ffbf8c2 100644 --- a/org.argeo.server.jcr/src/org/argeo/jcr/tabular/JcrTabularRowIterator.java +++ b/org.argeo.server.jcr/src/org/argeo/jcr/tabular/JcrTabularRowIterator.java @@ -28,7 +28,7 @@ import javax.jcr.PropertyType; import javax.jcr.RepositoryException; import org.apache.commons.io.IOUtils; -import org.argeo.ArgeoException; +import org.argeo.jcr.ArgeoJcrException; import org.argeo.jcr.ArgeoTypes; import org.argeo.util.CsvParser; import org.argeo.util.tabular.ArrayTabularRow; @@ -101,7 +101,7 @@ public class JcrTabularRowIterator implements TabularRowIterator { thread.start(); } } catch (RepositoryException e) { - throw new ArgeoException("Cannot read table " + tableNode, e); + throw new ArgeoJcrException("Cannot read table " + tableNode, e); } } diff --git a/org.argeo.server.jcr/src/org/argeo/jcr/tabular/JcrTabularWriter.java b/org.argeo.server.jcr/src/org/argeo/jcr/tabular/JcrTabularWriter.java index 718ff2374..c3fd97cbd 100644 --- a/org.argeo.server.jcr/src/org/argeo/jcr/tabular/JcrTabularWriter.java +++ b/org.argeo.server.jcr/src/org/argeo/jcr/tabular/JcrTabularWriter.java @@ -27,7 +27,7 @@ import javax.jcr.PropertyType; import javax.jcr.RepositoryException; import org.apache.commons.io.IOUtils; -import org.argeo.ArgeoException; +import org.argeo.jcr.ArgeoJcrException; import org.argeo.jcr.ArgeoTypes; import org.argeo.jcr.JcrUtils; import org.argeo.util.CsvWriter; @@ -70,7 +70,7 @@ public class JcrTabularWriter implements TabularWriter { csvWriter = new CsvWriter(out); } } catch (RepositoryException e) { - throw new ArgeoException("Cannot create table node " + tableNode, e); + throw new ArgeoJcrException("Cannot create table node " + tableNode, e); } } @@ -88,7 +88,7 @@ public class JcrTabularWriter implements TabularWriter { .createBinary(in); contentNode.setProperty(Property.JCR_DATA, binary); } catch (RepositoryException e) { - throw new ArgeoException("Cannot store data in " + contentNode, e); + throw new ArgeoJcrException("Cannot store data in " + contentNode, e); } finally { IOUtils.closeQuietly(in); JcrUtils.closeQuietly(binary); diff --git a/org.argeo.server.jcr/src/org/argeo/jcr/unit/AbstractJcrTestCase.java b/org.argeo.server.jcr/src/org/argeo/jcr/unit/AbstractJcrTestCase.java index db8d70d39..1269a3ee5 100644 --- a/org.argeo.server.jcr/src/org/argeo/jcr/unit/AbstractJcrTestCase.java +++ b/org.argeo.server.jcr/src/org/argeo/jcr/unit/AbstractJcrTestCase.java @@ -26,12 +26,12 @@ import javax.security.auth.Subject; import javax.security.auth.login.LoginContext; import javax.security.auth.login.LoginException; -import junit.framework.TestCase; - import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.ArgeoException; +import org.argeo.jcr.ArgeoJcrException; + +import junit.framework.TestCase; public abstract class AbstractJcrTestCase extends TestCase { private final static Log log = LogFactory.getLog(AbstractJcrTestCase.class); @@ -75,7 +75,7 @@ public abstract class AbstractJcrTestCase extends TestCase { lc = new LoginContext(getLoginContext()); lc.login(); } catch (LoginException e) { - throw new ArgeoException("JAAS login failed", e); + throw new ArgeoJcrException("JAAS login failed", e); } session = Subject.doAs(lc.getSubject(), new PrivilegedAction() { @@ -107,7 +107,7 @@ public abstract class AbstractJcrTestCase extends TestCase { return getRepository().login( new SimpleCredentials("demo", "demo".toCharArray())); } catch (Exception e) { - throw new ArgeoException("Cannot login to repository", e); + throw new ArgeoJcrException("Cannot login to repository", e); } } @@ -123,30 +123,6 @@ public abstract class AbstractJcrTestCase extends TestCase { this.repository = repository; } - // public void logout() { - // if (session != null && session.isLive()) - // JcrUtils.logoutQuietly(session); - // } - // - // protected static TestSuite defaultTestSuite(Class - // clss) { - // String testSuiteClassName = - // "org.argeo.jackrabbit.unit.JackrabbitTestSuite"; - // try { - // Class testSuiteClass = AbstractJcrTestCase.class - // .getClassLoader().loadClass(testSuiteClassName); - // if (clss == null) { - // return (TestSuite) testSuiteClass.newInstance(); - // } else { - // return (TestSuite) testSuiteClass.getConstructor(Class.class) - // .newInstance(clss); - // } - // } catch (Exception e) { - // throw new ArgeoException("Cannot find default test suite " - // + testSuiteClassName, e); - // } - // } - protected File getHomeDir() { File homeDir = new File(System.getProperty("java.io.tmpdir"), AbstractJcrTestCase.class.getSimpleName() + "-" diff --git a/org.argeo.util/ext/test/org/argeo/util/security/PasswordBasedEncryptionTest.java b/org.argeo.util/ext/test/org/argeo/util/security/PasswordBasedEncryptionTest.java index 42630cfee..0895c6bbe 100644 --- a/org.argeo.util/ext/test/org/argeo/util/security/PasswordBasedEncryptionTest.java +++ b/org.argeo.util/ext/test/org/argeo/util/security/PasswordBasedEncryptionTest.java @@ -34,7 +34,7 @@ import junit.framework.TestCase; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.argeo.StreamUtils; +import org.argeo.util.internal.StreamUtils; import org.argeo.util.security.PasswordBasedEncryption; public class PasswordBasedEncryptionTest extends TestCase { diff --git a/org.argeo.util/src/org/argeo/ArgeoException.java b/org.argeo.util/src/org/argeo/ArgeoException.java index 9cf918667..4fa296afa 100644 --- a/org.argeo.util/src/org/argeo/ArgeoException.java +++ b/org.argeo.util/src/org/argeo/ArgeoException.java @@ -15,7 +15,16 @@ */ package org.argeo; -/** Argeo Commons specific exception. */ +import javax.naming.OperationNotSupportedException; + +/** + * Argeo Commons specific exception. + * + * @deprecated Use project specific exceptions or standard ones like + * {@link OperationNotSupportedException}, + * {@link IllegalArgumentException}, etc. + */ +@Deprecated public class ArgeoException extends RuntimeException { private static final long serialVersionUID = 1L; @@ -29,21 +38,4 @@ public class ArgeoException extends RuntimeException { super(message, e); } - /** - * Chain the messages of all causes (one per line, starts with a line - * return) without all the stack - */ - public static String chainCausesMessages(Throwable t) { - StringBuffer buf = new StringBuffer(); - chainCauseMessage(buf, t); - return buf.toString(); - } - - /** Recursive chaining of messages */ - private static void chainCauseMessage(StringBuffer buf, Throwable t) { - buf.append('\n').append(' ').append(t.getClass().getCanonicalName()) - .append(": ").append(t.getMessage()); - if (t.getCause() != null) - chainCauseMessage(buf, t.getCause()); - } } diff --git a/org.argeo.util/src/org/argeo/ArgeoMonitor.java b/org.argeo.util/src/org/argeo/ArgeoMonitor.java index 9ef23cc8b..307581ea7 100644 --- a/org.argeo.util/src/org/argeo/ArgeoMonitor.java +++ b/org.argeo.util/src/org/argeo/ArgeoMonitor.java @@ -18,7 +18,10 @@ package org.argeo; /** * Simple monitor abstraction. Inspired by Eclipse IProgressMOnitor, but without * dependency to it. + * + * @deprecated use org.argeo.jcr.JcrMonitor instead */ +@Deprecated public interface ArgeoMonitor { /** * Constant indicating an unknown amount of work. diff --git a/org.argeo.util/src/org/argeo/StreamUtils.java b/org.argeo.util/src/org/argeo/StreamUtils.java deleted file mode 100644 index 39caaddda..000000000 --- a/org.argeo.util/src/org/argeo/StreamUtils.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * 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; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.Reader; -import java.io.Writer; - -/** Utilities to be used when APache COmmons IO is not available. */ -public class StreamUtils { - private static final int DEFAULT_BUFFER_SIZE = 1024 * 4; - - /* - * APACHE COMMONS IO (inspired) - */ - - /** @return the number of bytes */ - public static Long copy(InputStream in, OutputStream out) - throws IOException { - Long count = 0l; - byte[] buf = new byte[DEFAULT_BUFFER_SIZE]; - while (true) { - int length = in.read(buf); - if (length < 0) - break; - out.write(buf, 0, length); - count = count + length; - } - return count; - } - - /** @return the number of chars */ - public static Long copy(Reader in, Writer out) throws IOException { - Long count = 0l; - char[] buf = new char[DEFAULT_BUFFER_SIZE]; - while (true) { - int length = in.read(buf); - if (length < 0) - break; - out.write(buf, 0, length); - count = count + length; - } - return count; - } - - public static void closeQuietly(InputStream in) { - if (in != null) - try { - in.close(); - } catch (Exception e) { - // - } - } - - public static void closeQuietly(OutputStream out) { - if (out != null) - try { - out.close(); - } catch (Exception e) { - // - } - } - - public static void closeQuietly(Reader in) { - if (in != null) - try { - in.close(); - } catch (Exception e) { - // - } - } - - public static void closeQuietly(Writer out) { - if (out != null) - try { - out.close(); - } catch (Exception e) { - // - } - } - - /* - * APACHE COMMONS CODEC (forked) - */ - /** - * Used to build output as Hex - */ - private static final char[] DIGITS_LOWER = { '0', '1', '2', '3', '4', '5', - '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' }; - - /** - * Used to build output as Hex - */ - private static final char[] DIGITS_UPPER = { '0', '1', '2', '3', '4', '5', - '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; - - /** - * Converts an array of bytes into a String representing the hexadecimal - * values of each byte in order. The returned String will be double the - * length of the passed array, as it takes two characters to represent any - * given byte. - * - * @param data - * a byte[] to convert to Hex characters - * @return A String containing hexadecimal characters - * @since 1.4 - */ - public static String encodeHexString(byte[] data) { - return new String(encodeHex(data)); - } - - /** - * Converts an array of bytes into an array of characters representing the - * hexadecimal values of each byte in order. The returned array will be - * double the length of the passed array, as it takes two characters to - * represent any given byte. - * - * @param data - * a byte[] to convert to Hex characters - * @return A char[] containing hexadecimal characters - */ - public static char[] encodeHex(byte[] data) { - return encodeHex(data, true); - } - - /** - * Converts an array of bytes into an array of characters representing the - * hexadecimal values of each byte in order. The returned array will be - * double the length of the passed array, as it takes two characters to - * represent any given byte. - * - * @param data - * a byte[] to convert to Hex characters - * @param toLowerCase - * true converts to lowercase, false to - * uppercase - * @return A char[] containing hexadecimal characters - * @since 1.4 - */ - public static char[] encodeHex(byte[] data, boolean toLowerCase) { - return encodeHex(data, toLowerCase ? DIGITS_LOWER : DIGITS_UPPER); - } - - /** - * Converts an array of bytes into an array of characters representing the - * hexadecimal values of each byte in order. The returned array will be - * double the length of the passed array, as it takes two characters to - * represent any given byte. - * - * @param data - * a byte[] to convert to Hex characters - * @param toDigits - * the output alphabet - * @return A char[] containing hexadecimal characters - * @since 1.4 - */ - protected static char[] encodeHex(byte[] data, char[] toDigits) { - int l = data.length; - char[] out = new char[l << 1]; - // two characters form the hex value. - for (int i = 0, j = 0; i < l; i++) { - out[j++] = toDigits[(0xF0 & data[i]) >>> 4]; - out[j++] = toDigits[0x0F & data[i]]; - } - return out; - } - -} diff --git a/org.argeo.util/src/org/argeo/util/CsvParser.java b/org.argeo.util/src/org/argeo/util/CsvParser.java index 7680b3267..569f08c73 100644 --- a/org.argeo.util/src/org/argeo/util/CsvParser.java +++ b/org.argeo.util/src/org/argeo/util/CsvParser.java @@ -23,8 +23,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.argeo.ArgeoException; -import org.argeo.StreamUtils; +import org.argeo.util.internal.StreamUtils; +import org.argeo.util.internal.UtilsException; /** * Parses a CSV file interpreting the first line as a header. The @@ -114,7 +114,7 @@ public abstract class CsvParser { if (tokenSize == 1 && line.trim().equals("")) continue lines;// empty line if (headerSize != tokenSize) { - throw new ArgeoException("Token size " + tokenSize + throw new UtilsException("Token size " + tokenSize + " is different from header size " + headerSize + " at line " + lineCount + ", line: " + line + ", header: " + header @@ -123,10 +123,10 @@ public abstract class CsvParser { } processLine(lineCount, header, tokens); } - } catch (ArgeoException e) { + } catch (UtilsException e) { throw e; } catch (IOException e) { - throw new ArgeoException("Cannot parse CSV file (line: " + throw new UtilsException("Cannot parse CSV file (line: " + lineCount + ")", e); } finally { StreamUtils.closeQuietly(reader); diff --git a/org.argeo.util/src/org/argeo/util/CsvParserWithLinesAsMap.java b/org.argeo.util/src/org/argeo/util/CsvParserWithLinesAsMap.java index e7baabbf0..fe1750a23 100644 --- a/org.argeo.util/src/org/argeo/util/CsvParserWithLinesAsMap.java +++ b/org.argeo.util/src/org/argeo/util/CsvParserWithLinesAsMap.java @@ -19,7 +19,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.argeo.ArgeoException; +import org.argeo.util.internal.UtilsException; /** * CSV parser allowing to process lines as maps whose keys are the header @@ -42,7 +42,7 @@ public abstract class CsvParserWithLinesAsMap extends CsvParser { protected final void processLine(Integer lineNumber, List header, List tokens) { if (header == null) - throw new ArgeoException("Only CSV with header is supported"); + throw new UtilsException("Only CSV with header is supported"); Map line = new HashMap(); for (int i = 0; i < header.size(); i++) { String key = header.get(i); diff --git a/org.argeo.util/src/org/argeo/util/CsvWriter.java b/org.argeo.util/src/org/argeo/util/CsvWriter.java index d90f47412..1ebe1022d 100644 --- a/org.argeo.util/src/org/argeo/util/CsvWriter.java +++ b/org.argeo.util/src/org/argeo/util/CsvWriter.java @@ -23,7 +23,7 @@ import java.io.Writer; import java.util.Iterator; import java.util.List; -import org.argeo.ArgeoException; +import org.argeo.util.internal.UtilsException; /** Write in CSV format. */ public class CsvWriter { @@ -52,7 +52,7 @@ public class CsvWriter { try { this.out = new OutputStreamWriter(out, encoding); } catch (UnsupportedEncodingException e) { - throw new ArgeoException("Cannot initialize CSV writer", e); + throw new UtilsException("Cannot initialize CSV writer", e); } } @@ -72,7 +72,7 @@ public class CsvWriter { out.write('\n'); out.flush(); } catch (IOException e) { - throw new ArgeoException("Could not write " + tokens, e); + throw new UtilsException("Could not write " + tokens, e); } } @@ -96,7 +96,7 @@ public class CsvWriter { out.write('\n'); out.flush(); } catch (IOException e) { - throw new ArgeoException("Could not write " + tokens, e); + throw new UtilsException("Could not write " + tokens, e); } } diff --git a/org.argeo.util/src/org/argeo/util/LangUtils.java b/org.argeo.util/src/org/argeo/util/LangUtils.java index 3c0baed1c..8810d6463 100644 --- a/org.argeo.util/src/org/argeo/util/LangUtils.java +++ b/org.argeo.util/src/org/argeo/util/LangUtils.java @@ -136,6 +136,27 @@ public class LangUtils { res.put(key.toString(), toLoad.get(key)); return res; } + + /* + * EXCEPTIONS + */ + /** + * Chain the messages of all causes (one per line, starts with a line + * return) without all the stack + */ + public static String chainCausesMessages(Throwable t) { + StringBuffer buf = new StringBuffer(); + chainCauseMessage(buf, t); + return buf.toString(); + } + + /** Recursive chaining of messages */ + private static void chainCauseMessage(StringBuffer buf, Throwable t) { + buf.append('\n').append(' ').append(t.getClass().getCanonicalName()) + .append(": ").append(t.getMessage()); + if (t.getCause() != null) + chainCauseMessage(buf, t.getCause()); + } /** Singleton constructor. */ private LangUtils() { diff --git a/org.argeo.util/src/org/argeo/util/Throughput.java b/org.argeo.util/src/org/argeo/util/Throughput.java index d081189e2..fb928002e 100644 --- a/org.argeo.util/src/org/argeo/util/Throughput.java +++ b/org.argeo.util/src/org/argeo/util/Throughput.java @@ -19,7 +19,7 @@ import java.text.NumberFormat; import java.text.ParseException; import java.util.Locale; -import org.argeo.ArgeoException; +import org.argeo.util.internal.UtilsException; public class Throughput { private final static NumberFormat usNumberFormat = NumberFormat @@ -47,7 +47,7 @@ public class Throughput { else if (unit.equals(Unit.d)) value = ((double) count * 24d * 60d * 60d * 1000d) / periodMs; else - throw new ArgeoException("Unsupported unit " + unit); + throw new UtilsException("Unsupported unit " + unit); this.unit = unit; } @@ -58,14 +58,14 @@ public class Throughput { public Throughput(String def) { int index = def.indexOf('/'); if (def.length() < 3 || index <= 0 || index != def.length() - 2) - throw new ArgeoException(def + " no a proper throughput definition" + throw new UtilsException(def + " no a proper throughput definition" + " (should be /, e.g. 3.54/s or 1500/h"); String valueStr = def.substring(0, index); String unitStr = def.substring(index + 1); try { this.value = usNumberFormat.parse(valueStr).doubleValue(); } catch (ParseException e) { - throw new ArgeoException("Cannot parse " + valueStr + throw new UtilsException("Cannot parse " + valueStr + " as a number.", e); } this.unit = Unit.valueOf(unitStr); @@ -81,7 +81,7 @@ public class Throughput { else if (unit.equals(Unit.d)) return Math.round((24d * 60d * 60d * 1000d) / value); else - throw new ArgeoException("Unsupported unit " + unit); + throw new UtilsException("Unsupported unit " + unit); } @Override diff --git a/org.argeo.util/src/org/argeo/util/internal/StreamUtils.java b/org.argeo.util/src/org/argeo/util/internal/StreamUtils.java new file mode 100644 index 000000000..cf6fc0c0e --- /dev/null +++ b/org.argeo.util/src/org/argeo/util/internal/StreamUtils.java @@ -0,0 +1,96 @@ +/* + * 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.util.internal; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.Reader; +import java.io.Writer; + +/** Utilities to be used when APache COmmons IO is not available. */ +public class StreamUtils { + private static final int DEFAULT_BUFFER_SIZE = 1024 * 4; + + /* + * APACHE COMMONS IO (inspired) + */ + + /** @return the number of bytes */ + public static Long copy(InputStream in, OutputStream out) + throws IOException { + Long count = 0l; + byte[] buf = new byte[DEFAULT_BUFFER_SIZE]; + while (true) { + int length = in.read(buf); + if (length < 0) + break; + out.write(buf, 0, length); + count = count + length; + } + return count; + } + + /** @return the number of chars */ + public static Long copy(Reader in, Writer out) throws IOException { + Long count = 0l; + char[] buf = new char[DEFAULT_BUFFER_SIZE]; + while (true) { + int length = in.read(buf); + if (length < 0) + break; + out.write(buf, 0, length); + count = count + length; + } + return count; + } + + public static void closeQuietly(InputStream in) { + if (in != null) + try { + in.close(); + } catch (Exception e) { + // + } + } + + public static void closeQuietly(OutputStream out) { + if (out != null) + try { + out.close(); + } catch (Exception e) { + // + } + } + + public static void closeQuietly(Reader in) { + if (in != null) + try { + in.close(); + } catch (Exception e) { + // + } + } + + public static void closeQuietly(Writer out) { + if (out != null) + try { + out.close(); + } catch (Exception e) { + // + } + } +} diff --git a/org.argeo.util/src/org/argeo/util/internal/UtilsException.java b/org.argeo.util/src/org/argeo/util/internal/UtilsException.java new file mode 100644 index 000000000..d93851cdb --- /dev/null +++ b/org.argeo.util/src/org/argeo/util/internal/UtilsException.java @@ -0,0 +1,32 @@ +/* + * 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.util.internal; + +/** Utils specific exception. */ +public class UtilsException extends RuntimeException { + private static final long serialVersionUID = 1L; + + /** Creates an exception with a message. */ + public UtilsException(String message) { + super(message); + } + + /** Creates an exception with a message and a root cause. */ + public UtilsException(String message, Throwable e) { + super(message, e); + } + +} diff --git a/org.argeo.util/src/org/argeo/util/security/AbstractKeyring.java b/org.argeo.util/src/org/argeo/util/security/AbstractKeyring.java index 28763f82b..68ae1a20e 100644 --- a/org.argeo.util/src/org/argeo/util/security/AbstractKeyring.java +++ b/org.argeo.util/src/org/argeo/util/security/AbstractKeyring.java @@ -41,8 +41,8 @@ import javax.security.auth.callback.UnsupportedCallbackException; import javax.security.auth.login.LoginContext; import javax.security.auth.login.LoginException; -import org.argeo.ArgeoException; -import org.argeo.StreamUtils; +import org.argeo.util.internal.UtilsException; +import org.argeo.util.internal.StreamUtils; /** username / password based keyring. TODO internationalize */ public abstract class AbstractKeyring implements Keyring, CryptoKeyring { @@ -95,13 +95,13 @@ public abstract class AbstractKeyring implements Keyring, CryptoKeyring { .iterator(); return iterator.next(); } catch (LoginException e) { - throw new ArgeoException("Keyring login failed", e); + throw new UtilsException("Keyring login failed", e); } } else { SecretKey secretKey = iterator.next(); if (iterator.hasNext()) - throw new ArgeoException( + throw new UtilsException( "More than one secret key in private credentials"); return secretKey; } @@ -125,7 +125,7 @@ public abstract class AbstractKeyring implements Keyring, CryptoKeyring { StreamUtils.copy(reader, writer); return writer.toCharArray(); } catch (IOException e) { - throw new ArgeoException("Cannot decrypt to char array", e); + throw new UtilsException("Cannot decrypt to char array", e); } finally { StreamUtils.closeQuietly(reader); StreamUtils.closeQuietly(in); @@ -144,7 +144,7 @@ public abstract class AbstractKeyring implements Keyring, CryptoKeyring { in = new ByteArrayInputStream(out.toByteArray()); set(path, in); } catch (IOException e) { - throw new ArgeoException("Cannot encrypt to char array", e); + throw new UtilsException("Cannot encrypt to char array", e); } finally { StreamUtils.closeQuietly(writer); StreamUtils.closeQuietly(out); @@ -191,7 +191,7 @@ public abstract class AbstractKeyring implements Keyring, CryptoKeyring { } return btPass; } catch (Exception e) { - throw new ArgeoException("Cannot hash", e); + throw new UtilsException("Cannot hash", e); } finally { StreamUtils.closeQuietly(out); StreamUtils.closeQuietly(writer); @@ -211,7 +211,7 @@ public abstract class AbstractKeyring implements Keyring, CryptoKeyring { char[] password = passwordCb.getPassword(); return password; } catch (Exception e) { - throw new ArgeoException("Cannot ask for a password", e); + throw new UtilsException("Cannot ask for a password", e); } } diff --git a/org.argeo.util/src/org/argeo/util/security/ChecksumFactory.java b/org.argeo.util/src/org/argeo/util/security/ChecksumFactory.java index 76592c853..b57db2c98 100644 --- a/org.argeo.util/src/org/argeo/util/security/ChecksumFactory.java +++ b/org.argeo.util/src/org/argeo/util/security/ChecksumFactory.java @@ -15,7 +15,7 @@ import java.nio.file.attribute.BasicFileAttributes; import java.security.MessageDigest; import java.util.zip.Checksum; -import org.argeo.ArgeoException; +import org.argeo.util.internal.UtilsException; /** Allows to fine tune how files are read. */ public class ChecksumFactory { @@ -91,7 +91,7 @@ public class ChecksumFactory { } } } catch (Exception e) { - throw new ArgeoException("Cannot digest " + path, e); + throw new UtilsException("Cannot digest " + path, e); } } @@ -124,7 +124,7 @@ public class ChecksumFactory { } return crc.getValue(); } catch (Exception e) { - throw new ArgeoException("Cannot checksum " + path, e); + throw new UtilsException("Cannot checksum " + path, e); } finally { long duration = System.currentTimeMillis() - begin; System.out.println(duration / 1000 + "s"); diff --git a/org.argeo.util/src/org/argeo/util/security/DigestUtils.java b/org.argeo.util/src/org/argeo/util/security/DigestUtils.java index b6aae6fd4..6d46c288f 100644 --- a/org.argeo.util/src/org/argeo/util/security/DigestUtils.java +++ b/org.argeo.util/src/org/argeo/util/security/DigestUtils.java @@ -24,8 +24,8 @@ import java.nio.channels.FileChannel; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import org.argeo.ArgeoException; -import org.argeo.StreamUtils; +import org.argeo.util.internal.UtilsException; +import org.argeo.util.internal.StreamUtils; /** Utilities around cryptographic digests */ public class DigestUtils { @@ -38,11 +38,10 @@ public class DigestUtils { MessageDigest digest = MessageDigest.getInstance(algorithm); digest.update(bytes); byte[] checksum = digest.digest(); - String res = StreamUtils.encodeHexString(checksum); + String res = encodeHexString(checksum); return res; } catch (Exception e) { - throw new ArgeoException("Cannot digest with algorithm " - + algorithm, e); + throw new UtilsException("Cannot digest with algorithm " + algorithm, e); } } @@ -60,11 +59,10 @@ public class DigestUtils { } byte[] checksum = digest.digest(); - String res = StreamUtils.encodeHexString(checksum); + String res = encodeHexString(checksum); return res; } catch (Exception e) { - throw new ArgeoException("Cannot digest with algorithm " - + algorithm, e); + throw new UtilsException("Cannot digest with algorithm " + algorithm, e); } finally { StreamUtils.closeQuietly(in); } @@ -82,8 +80,7 @@ public class DigestUtils { ByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz); return digest(algorithm, bb); } catch (IOException e) { - throw new ArgeoException("Cannot digest " + file - + " with algorithm " + algorithm, e); + throw new UtilsException("Cannot digest " + file + " with algorithm " + algorithm, e); } finally { StreamUtils.closeQuietly(fis); if (fc.isOpen()) @@ -101,15 +98,13 @@ public class DigestUtils { MessageDigest digest = MessageDigest.getInstance(algorithm); digest.update(bb); byte[] checksum = digest.digest(); - String res = StreamUtils.encodeHexString(checksum); + String res = encodeHexString(checksum); long end = System.currentTimeMillis(); if (debug) - System.out.println((end - begin) + " ms / " - + ((end - begin) / 1000) + " s"); + System.out.println((end - begin) + " ms / " + ((end - begin) / 1000) + " s"); return res; } catch (NoSuchAlgorithmException e) { - throw new ArgeoException("Cannot digest with algorithm " - + algorithm, e); + throw new UtilsException("Cannot digest with algorithm " + algorithm, e); } } @@ -118,8 +113,7 @@ public class DigestUtils { if (args.length > 0) file = new File(args[0]); else { - System.err.println("Usage: []" - + " (see http://java.sun.com/j2se/1.5.0/" + System.err.println("Usage: []" + " (see http://java.sun.com/j2se/1.5.0/" + "docs/guide/security/CryptoSpec.html#AppA)"); return; } @@ -139,4 +133,21 @@ public class DigestUtils { } } + final private static char[] hexArray = "0123456789ABCDEF".toCharArray(); + + /** + * From + * http://stackoverflow.com/questions/9655181/how-to-convert-a-byte-array-to + * -a-hex-string-in-java + */ + private static String encodeHexString(byte[] bytes) { + char[] hexChars = new char[bytes.length * 2]; + for (int j = 0; j < bytes.length; j++) { + int v = bytes[j] & 0xFF; + hexChars[j * 2] = hexArray[v >>> 4]; + hexChars[j * 2 + 1] = hexArray[v & 0x0F]; + } + return new String(hexChars); + } + } diff --git a/org.argeo.util/src/org/argeo/util/security/PasswordBasedEncryption.java b/org.argeo.util/src/org/argeo/util/security/PasswordBasedEncryption.java index d7866a810..fcc5f8319 100644 --- a/org.argeo.util/src/org/argeo/util/security/PasswordBasedEncryption.java +++ b/org.argeo.util/src/org/argeo/util/security/PasswordBasedEncryption.java @@ -33,8 +33,8 @@ import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.PBEKeySpec; import javax.crypto.spec.SecretKeySpec; -import org.argeo.ArgeoException; -import org.argeo.StreamUtils; +import org.argeo.util.internal.UtilsException; +import org.argeo.util.internal.StreamUtils; /** Simple password based encryption / decryption */ public class PasswordBasedEncryption { @@ -92,11 +92,11 @@ public class PasswordBasedEncryption { try { initKeyAndCiphers(password, passwordSalt, initializationVector); } catch (Exception e1) { - throw new ArgeoException( + throw new UtilsException( "Cannot get secret key (with restricted length)", e1); } } catch (Exception e) { - throw new ArgeoException("Cannot get secret key", e); + throw new UtilsException("Cannot get secret key", e); } } @@ -139,7 +139,7 @@ public class PasswordBasedEncryption { } catch (IOException e) { throw e; } catch (Exception e) { - throw new ArgeoException("Cannot encrypt", e); + throw new UtilsException("Cannot encrypt", e); } finally { StreamUtils.closeQuietly(decryptedIn); } @@ -154,7 +154,7 @@ public class PasswordBasedEncryption { } catch (IOException e) { throw e; } catch (Exception e) { - throw new ArgeoException("Cannot decrypt", e); + throw new UtilsException("Cannot decrypt", e); } finally { StreamUtils.closeQuietly(encryptedIn); } @@ -169,7 +169,7 @@ public class PasswordBasedEncryption { encrypt(in, out); return out.toByteArray(); } catch (Exception e) { - throw new ArgeoException("Cannot encrypt", e); + throw new UtilsException("Cannot encrypt", e); } finally { StreamUtils.closeQuietly(out); } @@ -183,7 +183,7 @@ public class PasswordBasedEncryption { decrypt(in, out); return new String(out.toByteArray(), DEFAULT_CHARSET); } catch (Exception e) { - throw new ArgeoException("Cannot decrypt", e); + throw new UtilsException("Cannot decrypt", e); } finally { StreamUtils.closeQuietly(out); } diff --git a/org.argeo.util/src/org/argeo/util/security/SimplePrincipal.java b/org.argeo.util/src/org/argeo/util/security/SimplePrincipal.java index 03c573e25..29b8626e1 100644 --- a/org.argeo.util/src/org/argeo/util/security/SimplePrincipal.java +++ b/org.argeo.util/src/org/argeo/util/security/SimplePrincipal.java @@ -17,7 +17,7 @@ package org.argeo.util.security; import java.security.Principal; -import org.argeo.ArgeoException; +import org.argeo.util.internal.UtilsException; /** Canonical implementation of a {@link Principal} */ public class SimplePrincipal implements Principal { @@ -25,7 +25,7 @@ public class SimplePrincipal implements Principal { public SimplePrincipal(String name) { if (name == null) - throw new ArgeoException("Principal name cannot be null"); + throw new UtilsException("Principal name cannot be null"); this.name = name; } -- 2.30.2