X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2FAbstractCmsEntryPoint.java;h=0a988a63e99d6087ea70490f977984b3aa1fe407;hb=7f9de8a3b7429567129f0f7c58f7a339d41cb060;hp=c101c021f134bc36602a0dc93b1a6da661ac4039;hpb=e6d2d877a7208a13c05a9c9a8b67641972f13870;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms/src/org/argeo/cms/AbstractCmsEntryPoint.java b/org.argeo.cms/src/org/argeo/cms/AbstractCmsEntryPoint.java index c101c021f..0a988a63e 100644 --- a/org.argeo.cms/src/org/argeo/cms/AbstractCmsEntryPoint.java +++ b/org.argeo.cms/src/org/argeo/cms/AbstractCmsEntryPoint.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.Map; import javax.jcr.Node; +import javax.jcr.PathNotFoundException; import javax.jcr.Property; import javax.jcr.Repository; import javax.jcr.RepositoryException; @@ -14,13 +15,13 @@ import javax.security.auth.Subject; import javax.security.auth.login.CredentialNotFoundException; import javax.security.auth.login.LoginContext; import javax.security.auth.login.LoginException; +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.cms.ui.UxContext; import org.argeo.eclipse.ui.specific.UiContext; import org.argeo.jcr.JcrUtils; import org.eclipse.rap.rwt.RWT; @@ -50,6 +51,7 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint // Current state private Session session; private Node node; + private String nodePath;// useful when changing auth private String state; private String page; private Throwable exception; @@ -159,12 +161,12 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint } @Override - public Subject getSubject() { + public synchronized Subject getSubject() { return subject; } @Override - public void logout() { + public synchronized void logout() { if (loginContext == null) throw new CmsException("Login context should not be null"); try { @@ -179,27 +181,23 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint } @Override - public void authChange(LoginContext loginContext) { + public synchronized void authChange(LoginContext loginContext) { if (loginContext == null) throw new CmsException("Login context cannot be null"); this.loginContext = loginContext; - Subject.doAs(subject, new PrivilegedAction() { + Subject.doAs(loginContext.getSubject(), new PrivilegedAction() { @Override public Void run() { try { - String currentPath = null; - if (node != null) - currentPath = node.getPath(); JcrUtils.logoutQuietly(session); - session = repository.login(workspace); - if (currentPath != null) + if (nodePath != null) try { - node = session.getNode(currentPath); - } catch (Exception e) { - logout(); - session = repository.login(workspace); + node = session.getNode(nodePath); + } catch (PathNotFoundException e) { + // logout(); + // session = repository.login(workspace); navigateTo("~"); throw e; } @@ -223,7 +221,7 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint doRefresh(); } - protected void doRefresh() { + protected synchronized void doRefresh() { Subject.doAs(subject, new PrivilegedAction() { @Override public Void run() { @@ -233,23 +231,11 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint }); } - // @Override - // public Object local(Msg msg) { - // String key = msg.getId(); - // int lastDot = key.lastIndexOf('.'); - // String className = key.substring(0, lastDot); - // String fieldName = key.substring(lastDot + 1); - // Locale locale = RWT.getLocale(); - // ResourceBundle rb = ResourceBundle.getBundle(className, locale, - // msg.getClassLoader()); - // return rb.getString(fieldName); - // } - /** Sets the state of the entry point and retrieve the related JCR node. */ protected synchronized String setState(String newState) { String previousState = this.state; - node = null; + Node node = null; page = null; this.state = newState; if (newState.equals("~")) @@ -275,20 +261,12 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint node = getDefaultNode(session); page = state; } - - // Title - String title; - if (node.isNodeType(NodeType.MIX_TITLE) - && node.hasProperty(Property.JCR_TITLE)) - title = node.getProperty(Property.JCR_TITLE).getString() - + " - " + getBaseTitle(); - else - title = getBaseTitle(); - jsExecutor.execute("document.title = \"" + title + "\""); + setNode(node); + String title = publishMetaData(node); if (log.isTraceEnabled()) log.trace("node=" + node + ", state=" + state + " (page=" - + page + ", title=" + title + ")"); + + page + ")"); return title; } catch (Exception e) { @@ -301,10 +279,71 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint } } - protected Node getNode() { + private String publishMetaData(Node node) throws RepositoryException { + // Title + String title; + if (node.isNodeType(NodeType.MIX_TITLE) + && node.hasProperty(Property.JCR_TITLE)) + title = node.getProperty(Property.JCR_TITLE).getString() + " - " + + getBaseTitle(); + else + title = getBaseTitle(); + + HttpServletRequest request = UiContext.getHttpRequest(); + if (request == null) + return null; + // String url = CmsUtils.getCanonicalUrl(node, request); + // String desc = node.hasProperty(JCR_DESCRIPTION) ? node.getProperty( + // JCR_DESCRIPTION).getString() : null; + // String imgUrl = null; + // for (NodeIterator it = node.getNodes(); it.hasNext();) { + // Node child = it.nextNode(); + // if (child.isNodeType(CmsTypes.CMS_IMAGE)) + // imgUrl = CmsUtils.getDataUrl(child, request); + // } + + StringBuilder js = new StringBuilder(); + js.append("document.title = '" + title + "';"); + // js.append("var metas = document.getElementsByTagName('meta');"); + // js.append("for (var i=0; i