X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2Futil%2FCmsUtils.java;h=6011345d1dc6ca716b2512b93c5d62fc7d626e5f;hb=0e53a50b7c0c876d53ab54a714937b3396dc1f90;hp=c1b319fbe99f348e68e3813a102053917ebc3720;hpb=d546fc1b9e19a86eb0e33ac4be824b52239316fc;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms/src/org/argeo/cms/util/CmsUtils.java b/org.argeo.cms/src/org/argeo/cms/util/CmsUtils.java index c1b319fbe..6011345d1 100644 --- a/org.argeo.cms/src/org/argeo/cms/util/CmsUtils.java +++ b/org.argeo.cms/src/org/argeo/cms/util/CmsUtils.java @@ -1,15 +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; @@ -23,10 +29,38 @@ import org.eclipse.swt.layout.RowData; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.Widget; /** Static utilities for the CMS framework. */ public class CmsUtils implements CmsConstants { + /** + * The CMS view related to this display, or null if none is available from + * this call. + */ + public static CmsView getCmsView() { + 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. */ @Deprecated public static RowData ROW_DATA_16px = new RowData(16, 16); @@ -64,14 +98,20 @@ public class CmsUtils implements CmsConstants { return new RowData(16, 16); } + /** Style widget */ public static void style(Widget widget, String style) { widget.setData(CmsConstants.STYLE, style); } + /** Enable markups on widget */ public static void markup(Widget widget) { widget.setData(CmsConstants.MARKUP, true); } + public static void setItemHeight(Table table, int height) { + table.setData(CmsConstants.ITEM_HEIGHT, height); + } + /** @return the path or null if not instrumented */ public static String getDataPath(Widget widget) { // JCR item