diff --git a/config/alfresco/messages/webclient.properties b/config/alfresco/messages/webclient.properties index 36445df11e..76224db2a5 100644 --- a/config/alfresco/messages/webclient.properties +++ b/config/alfresco/messages/webclient.properties @@ -824,6 +824,8 @@ avm_node_deleted=Deleted submit=Submit submit_success=Successfully submitted item: {0} submitall_success=Successfully submitted sandbox for user: {0} +folder_preview=Preview Folder +file_preview=Preview File # Website actions and dialog messages title_import_content=Import Content into Website diff --git a/config/alfresco/web-client-config-wcm-actions.xml b/config/alfresco/web-client-config-wcm-actions.xml index 9962534054..4ac0af3df5 100644 --- a/config/alfresco/web-client-config-wcm-actions.xml +++ b/config/alfresco/web-client-config-wcm-actions.xml @@ -45,17 +45,35 @@ + + + folder_preview + /images/icons/preview_website.gif + #{actionContext.previewUrl} + new + + + + + file_preview + /images/icons/preview_website.gif + #{actionContext.previewUrl} + new + + false + false + @@ -64,6 +82,7 @@ false + @@ -71,6 +90,7 @@ false + diff --git a/source/java/org/alfresco/web/bean/wcm/AVMBrowseBean.java b/source/java/org/alfresco/web/bean/wcm/AVMBrowseBean.java index ecd71855a4..a661518c75 100644 --- a/source/java/org/alfresco/web/bean/wcm/AVMBrowseBean.java +++ b/source/java/org/alfresco/web/bean/wcm/AVMBrowseBean.java @@ -29,7 +29,6 @@ import javax.faces.context.FacesContext; import javax.faces.event.ActionEvent; import javax.transaction.UserTransaction; -import org.alfresco.config.ConfigService; import org.alfresco.model.ContentModel; import org.alfresco.repo.avm.AVMNodeConverter; import org.alfresco.service.cmr.action.Action; @@ -52,7 +51,6 @@ import org.alfresco.web.bean.NavigationBean; import org.alfresco.web.bean.repository.Node; import org.alfresco.web.bean.repository.Repository; import org.alfresco.web.config.ClientConfigElement; -import org.alfresco.web.config.ViewsConfigElement; import org.alfresco.web.ui.common.Utils; import org.alfresco.web.ui.common.component.IBreadcrumbHandler; import org.alfresco.web.ui.common.component.UIActionLink; @@ -517,6 +515,9 @@ public class AVMBrowseBean implements IContextListener tx = Repository.getUserTransaction(context, true); tx.begin(); + String dns = AVMConstants.lookupStoreDNS(getSandbox()); + int rootPathIndex = AVMConstants.buildAVMStoreRootPath(getSandbox()).length() + 1; + Map nodes = this.avmService.getDirectoryListing(-1, getCurrentPath()); this.files = new ArrayList(nodes.size()); this.folders = new ArrayList(nodes.size()); @@ -526,6 +527,7 @@ public class AVMBrowseBean implements IContextListener // build the client representation of the AVM node AVMNode node = new AVMNode(avmRef); + String path = avmRef.getPath(); // properties specific to folders or files if (avmRef.isDirectory()) @@ -537,9 +539,15 @@ public class AVMBrowseBean implements IContextListener { node.getProperties().put("fileType16", Utils.getFileTypeImage(name, true)); node.getProperties().put("url", DownloadContentServlet.generateBrowserURL( - AVMNodeConverter.ToNodeRef(-1, avmRef.getPath()), name)); + AVMNodeConverter.ToNodeRef(-1, path), name)); this.files.add(node); } + + // common properties + String assetPath = path.substring(rootPathIndex); + String previewUrl = MessageFormat.format( + AVMConstants.PREVIEW_ASSET_URL, dns, this.wcmDomain, this.wcmPort, assetPath); + node.getProperties().put("previewUrl", previewUrl); } // commit the transaction diff --git a/source/java/org/alfresco/web/bean/wcm/AVMConstants.java b/source/java/org/alfresco/web/bean/wcm/AVMConstants.java index 7a23b20c31..07ee2e62e1 100644 --- a/source/java/org/alfresco/web/bean/wcm/AVMConstants.java +++ b/source/java/org/alfresco/web/bean/wcm/AVMConstants.java @@ -67,19 +67,28 @@ public final class AVMConstants public static String buildAVMStoreUrl(String store) { - String url = null;; + ClientConfigElement config = Application.getClientConfig(FacesContext.getCurrentInstance()); + return MessageFormat.format(PREVIEW_SANDBOX_URL, lookupStoreDNS(store), config.getWCMDomain(), config.getWCMPort()); + } + + public static String buildAVMAssetUrl(String store, String assetPath) + { + ClientConfigElement config = Application.getClientConfig(FacesContext.getCurrentInstance()); + return MessageFormat.format(PREVIEW_ASSET_URL, lookupStoreDNS(store), config.getWCMDomain(), config.getWCMPort(), assetPath); + } + + public static String lookupStoreDNS(String store) + { + String dns = null; - FacesContext fc = FacesContext.getCurrentInstance(); - AVMService avmService = Repository.getServiceRegistry(fc).getAVMService(); - ClientConfigElement config = Application.getClientConfig(fc); + AVMService avmService = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getAVMService(); Map props = avmService.queryStorePropertyKey(store, QName.createQName(null, PROP_DNS + '%')); if (props.size() == 1) { - String dns = props.entrySet().iterator().next().getKey().getLocalName().substring(PROP_DNS.length()); - url = MessageFormat.format(PREVIEW_SANDBOX_URL, dns, config.getWCMDomain(), config.getWCMPort()); + dns = props.entrySet().iterator().next().getKey().getLocalName().substring(PROP_DNS.length()); } - return url; + return dns; } // names of the stores representing the layers for an AVM website diff --git a/source/java/org/alfresco/web/ui/wcm/component/UIUserSandboxes.java b/source/java/org/alfresco/web/ui/wcm/component/UIUserSandboxes.java index 936df87fcc..98bcc16e8f 100644 --- a/source/java/org/alfresco/web/ui/wcm/component/UIUserSandboxes.java +++ b/source/java/org/alfresco/web/ui/wcm/component/UIUserSandboxes.java @@ -18,6 +18,7 @@ package org.alfresco.web.ui.wcm.component; import java.io.IOException; import java.text.DateFormat; +import java.text.MessageFormat; import java.util.Date; import java.util.HashSet; import java.util.List; @@ -46,6 +47,7 @@ import org.alfresco.web.bean.BrowseBean; import org.alfresco.web.bean.repository.Repository; import org.alfresco.web.bean.wcm.AVMConstants; import org.alfresco.web.bean.wcm.AVMNode; +import org.alfresco.web.config.ClientConfigElement; import org.alfresco.web.ui.common.ComponentConstants; import org.alfresco.web.ui.common.ConstantMethodBinding; import org.alfresco.web.ui.common.PanelGenerator; @@ -317,6 +319,11 @@ public class UIUserSandboxes extends SelfRenderingComponent String userStore = userStorePrefix + ":/"; String stagingStore = AVMConstants.buildAVMStagingStoreName(storeRoot) + ":/"; + // info we need to calculate preview paths for assets + String dns = AVMConstants.lookupStoreDNS(userStorePrefix); + int rootPathIndex = AVMConstants.buildAVMStoreRootPath(userStorePrefix).length() + 1; + ClientConfigElement config = Application.getClientConfig(fc); + // get the UIActions component responsible for rendering context related user actions // TODO: we may need a component per user instance? (or use evaluators for roles...) UIActions uiFileActions = aquireUIActions(ACTIONS_FILE, userStorePrefix); @@ -384,6 +391,13 @@ public class UIUserSandboxes extends SelfRenderingComponent out.write(df.format(new Date(node.getModDate()))); out.write(""); + // build node context required for actions + AVMNode avmNode = new AVMNode(node); + String assetPath = sourcePath.substring(rootPathIndex); + String previewUrl = MessageFormat.format( + AVMConstants.PREVIEW_ASSET_URL, dns, config.getWCMDomain(), config.getWCMPort(), assetPath); + avmNode.getProperties().put("previewUrl", previewUrl); + // size of files if (node.isFile()) { @@ -391,7 +405,7 @@ public class UIUserSandboxes extends SelfRenderingComponent out.write(""); // add UI actions for this item - uiFileActions.setContext(new AVMNode(node)); + uiFileActions.setContext(avmNode); Utils.encodeRecursive(fc, uiFileActions); } else @@ -399,7 +413,7 @@ public class UIUserSandboxes extends SelfRenderingComponent out.write(""); // add UI actions for this item - uiFolderActions.setContext(new AVMNode(node)); + uiFolderActions.setContext(avmNode); Utils.encodeRecursive(fc, uiFolderActions); } out.write(""); diff --git a/source/web/jsp/wcm/browse-sandbox.jsp b/source/web/jsp/wcm/browse-sandbox.jsp index ef23555f95..c40de90d0c 100644 --- a/source/web/jsp/wcm/browse-sandbox.jsp +++ b/source/web/jsp/wcm/browse-sandbox.jsp @@ -165,7 +165,7 @@ - <%-- Space Actions column --%> + <%-- Folder Actions column --%>