Include workspace in the browser's state interpretation.
[gpl/argeo-suite.git] / org.argeo.suite.e4.rap / src / org / argeo / suite / e4 / rap / ArgeoSuiteLoginLifecycle.java
index 32623110eae8006d672cfc07e5988758057a594a..aab4eefe63cd93a3571b0919847e0fc4e2ce78da 100644 (file)
@@ -36,31 +36,51 @@ public class ArgeoSuiteLoginLifecycle extends CmsLoginLifecycle {
 
        private void loadState() {
                String state = getState();
-               if (state != null && state.startsWith("/")) {
-                       Session session = null;
-                       try {
+               // for the time being we systematically open a session, in order to make sure
+               // that home is initialised
+               Session session = null;
+               try {
+                       if (state != null && state.startsWith("/")) {
+                               String path = state.substring(1);
+                               String workspace;
+                               if (path.equals("")) {
+                                       workspace = null;
+                                       path = "/";
+                               } else {
+                                       int index = path.indexOf('/');
+                                       if (index == 0) {
+                                               log.error("Cannot interpret // " + state);
+                                               getBrowserNavigation().pushState("~", null);
+                                               return;
+                                       } else if (index > 0) {
+                                               workspace = path.substring(0, index);
+                                               path = path.substring(index);
+                                       } else {// index<0, assuming root node
+                                               workspace = path;
+                                               path = "/";
+                                       }
+                               }
                                Subject subject = getSubject();
                                session = Subject.doAs(subject, new PrivilegedExceptionAction<Session>() {
 
                                        @Override
                                        public Session run() throws PrivilegedActionException {
                                                try {
-                                                       return repository.login();
+                                                       return repository.login(workspace);
                                                } catch (RepositoryException e) {
                                                        throw new PrivilegedActionException(e);
                                                }
                                        }
 
                                });
-                               if (state.startsWith("/")) {
-                                       Node node = session.getNode(state);
-                                       systemWorkbenchService.openEntityEditor(node);
-                               }
-                       } catch (RepositoryException | PrivilegedActionException e) {
-                               log.error("Cannot load state " + state, e);
-                       } finally {
-                               JcrUtils.logoutQuietly(session);
+                               Node node = session.getNode(path);
+                               systemWorkbenchService.openEntityEditor(node);
                        }
+               } catch (RepositoryException | PrivilegedActionException e) {
+                       log.error("Cannot load state " + state, e);
+                       getBrowserNavigation().pushState("~", null);
+               } finally {
+                       JcrUtils.logoutQuietly(session);
                }
        }
 }