]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.cms/src/org/argeo/cms/util/CmsUtils.java
Disable request for basic auth
[lgpl/argeo-commons.git] / org.argeo.cms / src / org / argeo / cms / util / CmsUtils.java
index d8cd171e2d0441e1bcb0f62352314b3ea6cb95d2..6011345d1dc6ca716b2512b93c5d62fc7d626e5f 100644 (file)
@@ -1,16 +1,21 @@
 package org.argeo.cms.util;
 
+import static org.argeo.cms.internal.kernel.KernelConstants.WEBDAV_PUBLIC;
+import static org.argeo.jcr.ArgeoJcrConstants.ALIAS_NODE;
+
 import java.io.InputStream;
 
 import javax.jcr.Item;
 import javax.jcr.Node;
 import javax.jcr.Property;
 import javax.jcr.RepositoryException;
+import javax.servlet.http.HttpServletRequest;
 
 import org.apache.commons.io.IOUtils;
 import org.argeo.cms.CmsConstants;
 import org.argeo.cms.CmsException;
 import org.argeo.cms.CmsView;
+import org.argeo.eclipse.ui.specific.UiContext;
 import org.argeo.jcr.JcrUtils;
 import org.eclipse.rap.rwt.RWT;
 import org.eclipse.rap.rwt.service.ResourceManager;
@@ -29,15 +34,31 @@ import org.eclipse.swt.widgets.Widget;
 
 /** Static utilities for the CMS framework. */
 public class CmsUtils implements CmsConstants {
-       /** The CMS view related to this display. */
+       /**
+        * The CMS view related to this display, or null if none is available from
+        * this call.
+        */
        public static CmsView getCmsView() {
-               Display display = Display.getCurrent();
-               if (display == null)
-                       throw new CmsException("No display available");
-               CmsView cmsView = (CmsView) display.getData(CmsView.KEY);
-               if (cmsView == null)
-                       throw new CmsException("No CMS view available");
-               return cmsView;
+               return UiContext.getData(CmsView.KEY);
+       }
+
+       public static String getDataUrl(Node node, HttpServletRequest request)
+                       throws RepositoryException {
+               return request.getRequestURL().append(getDataPath(node).substring(1))
+                               .toString();
+       }
+
+       public static String getDataPath(Node node) throws RepositoryException {
+               return new StringBuilder().append(WEBDAV_PUBLIC).append('/')
+                               .append(ALIAS_NODE + "/")
+                               .append(node.getSession().getWorkspace().getName())
+                               .append(node.getPath()).toString();
+       }
+
+       public static String getCanonicalUrl(Node node, HttpServletRequest request)
+                       throws RepositoryException {
+               return request.getRequestURL().append('!').append(node.getPath())
+                               .toString();
        }
 
        /** @deprecated Use rowData16px() instead. GridData should not be reused. */