Fix behaviour when CMS JCR context is not available.
authorMathieu Baudier <mbaudier@argeo.org>
Fri, 30 Sep 2016 09:57:44 +0000 (09:57 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Fri, 30 Sep 2016 09:57:44 +0000 (09:57 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@9228 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

org.argeo.cms.ui/src/org/argeo/cms/forms/EditableMultiStringProperty.java
org.argeo.cms.ui/src/org/argeo/cms/maintenance/DeploymentEntryPoint.java
org.argeo.cms.ui/src/org/argeo/cms/ui/AbstractCmsEntryPoint.java
org.argeo.cms.ui/src/org/argeo/cms/util/SimpleApp.java
org.argeo.cms.ui/src/org/argeo/cms/util/SimpleErgonomics.java

index fdaa0365ca61a56c4ba55f00117356a28173c34b..e02bdeb930823ce41b77c3e454d6c1c0092e17b5 100644 (file)
@@ -31,7 +31,7 @@ public class EditableMultiStringProperty extends StyledControl implements
        private String propertyName;
        private String message;
        // TODO implement the ability to provide a list of legal values
-       private String[] possibleValues;
+//     private String[] possibleValues;
        private boolean canEdit;
        private SelectionListener removeValueSL;
        private List<String> values;
@@ -52,7 +52,7 @@ public class EditableMultiStringProperty extends StyledControl implements
 
                this.propertyName = propertyName;
                this.values = values;
-               this.possibleValues = possibleValues;
+//             this.possibleValues = possibleValues;
                this.message = addValueMsg;
                this.canEdit = removeValueSelectionListener != null;
                this.removeValueSL = removeValueSelectionListener;
index 1769c6372b1bd1ec875924f6628787dae44a2c27..8dda4c476b662ba0c3cb4efcb81c89595a4d1d93 100644 (file)
@@ -3,8 +3,6 @@ package org.argeo.cms.maintenance;
 import java.util.GregorianCalendar;
 import java.util.TimeZone;
 
-import org.argeo.cms.auth.AuthConstants;
-import org.argeo.cms.auth.CurrentUser;
 import org.argeo.cms.util.CmsUtils;
 import org.argeo.node.NodeConstants;
 import org.argeo.node.NodeDeployment;
index 4729c5b75d200dc07d3f87536f54af956821eee8..a5fa5ef6517c42ae61d0415ad6811c497abab8e1 100644 (file)
@@ -38,6 +38,8 @@ import org.eclipse.swt.widgets.Shell;
 
 /** Manages history and navigation */
 public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint implements CmsView {
+       private static final long serialVersionUID = 906558779562569784L;
+
        private final Log log = LogFactory.getLog(AbstractCmsEntryPoint.class);
 
        private final Subject subject;
@@ -191,10 +193,7 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint implement
                                                try {
                                                        node = session.getNode(nodePath);
                                                } catch (PathNotFoundException e) {
-                                                       // logout();
-                                                       // session = repository.login(workspace);
                                                        navigateTo("~");
-                                                       // throw e;
                                                }
 
                                        // refresh UI
@@ -239,10 +238,7 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint implement
                try {
                        int firstSlash = state.indexOf('/');
                        if (firstSlash == 0) {
-                               if (session.nodeExists(state))
-                                       node = session.getNode(state);
-                               else
-                                       throw new CmsException("Data " + state + " does not exist");
+                               node = session.getNode(state);
                                page = "";
                        } else if (firstSlash > 0) {
                                String prefix = state.substring(0, firstSlash);
@@ -265,6 +261,8 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint implement
                        return title;
                } catch (Exception e) {
                        log.error("Cannot set state '" + state + "'", e);
+                       if (state.equals("") || newState.equals("~") || newState.equals(previousState))
+                               return "Unrecoverable exception : " + e.getClass().getSimpleName();
                        if (previousState.equals(""))
                                previousState = "~";
                        navigateTo(previousState);
index a0dc732624051108ebf391a91a1c1d8b8de0cbc9..51aafcb23794d3295b2b846c82ba50e980d1389d 100644 (file)
@@ -70,10 +70,8 @@ public class SimpleApp implements CmsConstants, ApplicationConfiguration {
 
        public void configure(Application application) {
                try {
-                       StyleSheetResourceLoader styleSheetRL = new StyleSheetResourceLoader(
-                                       bundleContext);
-                       BundleResourceLoader bundleRL = new BundleResourceLoader(
-                                       bundleContext);
+                       StyleSheetResourceLoader styleSheetRL = new StyleSheetResourceLoader(bundleContext);
+                       BundleResourceLoader bundleRL = new BundleResourceLoader(bundleContext);
 
                        application.setOperationMode(OperationMode.SWT_COMPATIBILITY);
                        // application.setOperationMode(OperationMode.JEE_COMPATIBILITY);
@@ -81,8 +79,7 @@ public class SimpleApp implements CmsConstants, ApplicationConfiguration {
                        application.setExceptionHandler(new CmsExceptionHandler());
 
                        // loading animated gif
-                       application.addResource(LOADING_IMAGE,
-                                       createResourceLoader(LOADING_IMAGE));
+                       application.addResource(LOADING_IMAGE, createResourceLoader(LOADING_IMAGE));
                        // empty image
                        application.addResource(NO_IMAGE, createResourceLoader(NO_IMAGE));
 
@@ -98,16 +95,15 @@ public class SimpleApp implements CmsConstants, ApplicationConfiguration {
 
                        // entry points
                        for (String page : pages.keySet()) {
-                               Map<String, String> properties = defaultBranding != null ? new HashMap<String, String>(
-                                               defaultBranding) : new HashMap<String, String>();
+                               Map<String, String> properties = defaultBranding != null ? new HashMap<String, String>(defaultBranding)
+                                               : new HashMap<String, String>();
                                if (branding.containsKey(page)) {
                                        properties.putAll(branding.get(page));
                                }
                                // favicon
                                if (properties.containsKey(WebClient.FAVICON)) {
                                        String faviconRelPath = properties.get(WebClient.FAVICON);
-                                       application.addResource(faviconRelPath,
-                                                       new BundleResourceLoader(bundleContext));
+                                       application.addResource(faviconRelPath, new BundleResourceLoader(bundleContext));
                                        if (log.isTraceEnabled())
                                                log.trace("Favicon " + faviconRelPath);
 
@@ -116,10 +112,7 @@ public class SimpleApp implements CmsConstants, ApplicationConfiguration {
                                // page title
                                if (!properties.containsKey(WebClient.PAGE_TITLE)) {
                                        if (page.length() > 0)
-                                               properties.put(
-                                                               WebClient.PAGE_TITLE,
-                                                               Character.toUpperCase(page.charAt(0))
-                                                                               + page.substring(1));
+                                               properties.put(WebClient.PAGE_TITLE, Character.toUpperCase(page.charAt(0)) + page.substring(1));
                                }
 
                                // default body HTML
@@ -129,9 +122,8 @@ public class SimpleApp implements CmsConstants, ApplicationConfiguration {
                                //
                                // ADD ENTRY POINT
                                //
-                               application.addEntryPoint("/" + page, new CmsEntryPointFactory(
-                                               pages.get(page), repository, workspace, properties),
-                                               properties);
+                               application.addEntryPoint("/" + page,
+                                               new CmsEntryPointFactory(pages.get(page), repository, workspace, properties), properties);
                                log.info("Page /" + page);
                        }
 
@@ -149,8 +141,7 @@ public class SimpleApp implements CmsConstants, ApplicationConfiguration {
                        }
                } catch (RuntimeException e) {
                        // Easier access to initialisation errors
-                       log.error("Unexpected exception when configuring RWT application.",
-                                       e);
+                       log.error("Unexpected exception when configuring RWT application.", e);
                        throw e;
                }
        }
@@ -164,19 +155,16 @@ public class SimpleApp implements CmsConstants, ApplicationConfiguration {
                                vm.checkout("/");
                        JcrUtils.mkdirs(session, jcrBasePath);
                        for (String principal : rwPrincipals)
-                               JcrUtils.addPrivilege(session, jcrBasePath, principal,
-                                               Privilege.JCR_WRITE);
+                               JcrUtils.addPrivilege(session, jcrBasePath, principal, Privilege.JCR_WRITE);
                        for (String principal : roPrincipals)
-                               JcrUtils.addPrivilege(session, jcrBasePath, principal,
-                                               Privilege.JCR_READ);
+                               JcrUtils.addPrivilege(session, jcrBasePath, principal, Privilege.JCR_READ);
 
                        for (String pageName : pages.keySet()) {
                                try {
                                        initPage(session, pages.get(pageName));
                                        session.save();
                                } catch (Exception e) {
-                                       throw new CmsException(
-                                                       "Cannot initialize page " + pageName, e);
+                                       throw new CmsException("Cannot initialize page " + pageName, e);
                                }
                        }
 
@@ -188,8 +176,7 @@ public class SimpleApp implements CmsConstants, ApplicationConfiguration {
                register();
        }
 
-       protected void initPage(Session adminSession, CmsUiProvider page)
-                       throws RepositoryException {
+       protected void initPage(Session adminSession, CmsUiProvider page) throws RepositoryException {
                if (page instanceof LifeCycleUiProvider)
                        ((LifeCycleUiProvider) page).init(adminSession);
        }
@@ -210,8 +197,7 @@ public class SimpleApp implements CmsConstants, ApplicationConfiguration {
                Hashtable<String, String> props = new Hashtable<String, String>();
                if (contextName != null)
                        props.put("contextName", contextName);
-               appReg = bundleContext.registerService(ApplicationConfiguration.class,
-                               this, props);
+               appReg = bundleContext.registerService(ApplicationConfiguration.class, this, props);
                if (log.isDebugEnabled())
                        log.debug("Registered " + (contextName == null ? "/" : contextName));
        }
@@ -219,8 +205,7 @@ public class SimpleApp implements CmsConstants, ApplicationConfiguration {
        protected void unregister() {
                appReg.unregister();
                if (log.isDebugEnabled())
-                       log.debug("Unregistered "
-                                       + (contextName == null ? "/" : contextName));
+                       log.debug("Unregistered " + (contextName == null ? "/" : contextName));
        }
 
        public void setRepository(Repository repository) {
@@ -291,8 +276,8 @@ public class SimpleApp implements CmsConstants, ApplicationConfiguration {
                private final String workspace;
                private final Map<String, String> properties;
 
-               public CmsEntryPointFactory(CmsUiProvider page, Repository repository,
-                               String workspace, Map<String, String> properties) {
+               public CmsEntryPointFactory(CmsUiProvider page, Repository repository, String workspace,
+                               Map<String, String> properties) {
                        this.page = page;
                        this.repository = repository;
                        this.workspace = workspace;
@@ -301,8 +286,8 @@ public class SimpleApp implements CmsConstants, ApplicationConfiguration {
 
                @Override
                public EntryPoint create() {
-                       SimpleErgonomics entryPoint = new SimpleErgonomics(repository,
-                                       workspace, jcrBasePath, page, properties) {
+                       SimpleErgonomics entryPoint = new SimpleErgonomics(repository, workspace, jcrBasePath, page, properties) {
+                               private static final long serialVersionUID = -637940404865527290L;
 
                                @Override
                                protected void createAdminArea(Composite parent) {
@@ -316,13 +301,8 @@ public class SimpleApp implements CmsConstants, ApplicationConfiguration {
                                                @Override
                                                public void widgetSelected(SelectionEvent e) {
                                                        long timeBeforeReload = 1000;
-                                                       RWT.getClient()
-                                                                       .getService(JavaScriptExecutor.class)
-                                                                       .execute(
-                                                                                       "setTimeout(function() { "
-                                                                                                       + "location.reload();"
-                                                                                                       + "}," + timeBeforeReload
-                                                                                                       + ");");
+                                                       RWT.getClient().getService(JavaScriptExecutor.class).execute(
+                                                                       "setTimeout(function() { " + "location.reload();" + "}," + timeBeforeReload + ");");
                                                        reloadApp();
                                                }
                                        });
@@ -348,10 +328,8 @@ public class SimpleApp implements CmsConstants, ApplicationConfiguration {
 
        private static ResourceLoader createResourceLoader(final String resourceName) {
                return new ResourceLoader() {
-                       public InputStream getResourceAsStream(String resourceName)
-                                       throws IOException {
-                               return getClass().getClassLoader().getResourceAsStream(
-                                               resourceName);
+                       public InputStream getResourceAsStream(String resourceName) throws IOException {
+                               return getClass().getClassLoader().getResourceAsStream(resourceName);
                        }
                };
        }
@@ -371,6 +349,5 @@ public class SimpleApp implements CmsConstants, ApplicationConfiguration {
        private static String DEFAULT_LOADING_BODY = "<div"
                        + " style=\"position: absolute; left: 50%; top: 50%; margin: -32px -32px; width: 64px; height:64px\">"
                        + "<img src=\"./rwt-resources/" + LOADING_IMAGE
-                       + "\" width=\"32\" height=\"32\" style=\"margin: 16px 16px\"/>"
-                       + "</div>";
+                       + "\" width=\"32\" height=\"32\" style=\"margin: 16px 16px\"/>" + "</div>";
 }
index 620bc5302ae65f5224cacece398f840b394bf74b..a16587a2268d7c864bdcabc2287fba4329496722 100644 (file)
@@ -2,6 +2,7 @@ package org.argeo.cms.util;
 
 import java.util.Map;
 
+import javax.jcr.Node;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 
@@ -23,6 +24,8 @@ import org.eclipse.swt.widgets.Control;
 
 /** Simple header/body ergonomics. */
 public class SimpleErgonomics extends AbstractCmsEntryPoint {
+       private static final long serialVersionUID = 8743413921359548523L;
+
        private final static Log log = LogFactory.getLog(SimpleErgonomics.class);
 
        private boolean uiInitialized = false;
@@ -36,8 +39,7 @@ public class SimpleErgonomics extends AbstractCmsEntryPoint {
        private CmsImageManager imageManager = new ImageManagerImpl();
        private UxContext uxContext = null;
 
-       public SimpleErgonomics(Repository repository, String workspace,
-                       String defaultPath, CmsUiProvider uiProvider,
+       public SimpleErgonomics(Repository repository, String workspace, String defaultPath, CmsUiProvider uiProvider,
                        Map<String, String> factoryProperties) {
                super(repository, workspace, defaultPath, factoryProperties);
                this.uiProvider = uiProvider;
@@ -94,8 +96,7 @@ public class SimpleErgonomics extends AbstractCmsEntryPoint {
                // Exception
                Throwable exception = getException();
                if (exception != null) {
-                       SystemNotifications systemNotifications = new SystemNotifications(
-                                       bodyArea);
+                       SystemNotifications systemNotifications = new SystemNotifications(bodyArea);
                        systemNotifications.notifyException(exception);
                        resetException();
                        return;
@@ -108,7 +109,10 @@ public class SimpleErgonomics extends AbstractCmsEntryPoint {
                bodyArea.setLayout(CmsUtils.noSpaceGridLayout());
 
                try {
-                       uiProvider.createUi(bodyArea, getNode());
+                       Node node = getNode();
+                       if (node == null)
+                               throw new CmsException("Context cannot be null");
+                       uiProvider.createUi(bodyArea, node);
                } catch (RepositoryException e) {
                        throw new CmsException("Cannot refresh body", e);
                }