From 346bfe2c33ddc6ceb2f13ac6bb7b882c150dbdbe Mon Sep 17 00:00:00 2001 From: Kevin Roast Date: Tue, 24 Oct 2006 16:33:37 +0000 Subject: [PATCH] . Removed implicit servlet ROOT folder if present from Preview URLs . Refactored preview generating code to use same entry point from all relevant classes git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@4214 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco/web/bean/wcm/AVMBrowseBean.java | 7 +-- .../alfresco/web/bean/wcm/AVMConstants.java | 46 ++++++++++++------- .../web/ui/wcm/component/UIUserSandboxes.java | 5 +- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/source/java/org/alfresco/web/bean/wcm/AVMBrowseBean.java b/source/java/org/alfresco/web/bean/wcm/AVMBrowseBean.java index 45698afaf3..f978f0a0d8 100644 --- a/source/java/org/alfresco/web/bean/wcm/AVMBrowseBean.java +++ b/source/java/org/alfresco/web/bean/wcm/AVMBrowseBean.java @@ -16,12 +16,10 @@ */ package org.alfresco.web.bean.wcm; -import java.io.Serializable; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Date; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.ResourceBundle; @@ -33,7 +31,6 @@ import javax.transaction.UserTransaction; import org.alfresco.model.ContentModel; import org.alfresco.repo.avm.AVMNodeConverter; -import org.alfresco.repo.avm.actions.StartAVMWorkflowAction; import org.alfresco.service.cmr.action.Action; import org.alfresco.service.cmr.action.ActionService; import org.alfresco.service.cmr.avm.AVMNodeDescriptor; @@ -47,7 +44,6 @@ import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.cmr.workflow.WorkflowService; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; -import org.alfresco.util.GUID; import org.alfresco.service.namespace.RegexQNamePattern; import org.alfresco.web.app.Application; import org.alfresco.web.app.context.IContextListener; @@ -617,8 +613,7 @@ public class AVMBrowseBean implements IContextListener // common properties String assetPath = path.substring(rootPathIndex); - String previewUrl = MessageFormat.format( - AVMConstants.PREVIEW_ASSET_URL, dns, this.wcmDomain, this.wcmPort, assetPath); + String previewUrl = AVMConstants.buildAVMAssetUrl(assetPath, this.wcmDomain, this.wcmPort, dns); node.getProperties().put("previewUrl", previewUrl); } diff --git a/source/java/org/alfresco/web/bean/wcm/AVMConstants.java b/source/java/org/alfresco/web/bean/wcm/AVMConstants.java index 1a1c9cd174..22f49c72dd 100644 --- a/source/java/org/alfresco/web/bean/wcm/AVMConstants.java +++ b/source/java/org/alfresco/web/bean/wcm/AVMConstants.java @@ -75,21 +75,6 @@ public final class AVMConstants return MessageFormat.format(PREVIEW_SANDBOX_URL, lookupStoreDNS(store), config.getWCMDomain(), config.getWCMPort()); } - public static String buildAVMAssetUrl(String store, String assetPath) - { - if (assetPath.startsWith('/' + DIR_APPBASE + '/' + DIR_WEBAPPS)) - { - assetPath = assetPath.substring(('/' + DIR_APPBASE + '/' + DIR_WEBAPPS).length()); - } - if (assetPath.length() == 0 || assetPath.charAt(0) != '/') - { - assetPath = '/' + assetPath; - } - - ClientConfigElement config = Application.getClientConfig(FacesContext.getCurrentInstance()); - return MessageFormat.format(PREVIEW_ASSET_URL, lookupStoreDNS(store), config.getWCMDomain(), config.getWCMPort(), assetPath); - } - public static String buildAVMAssetUrl(final String avmPath) { final String[] s = avmPath.split(":"); @@ -100,6 +85,30 @@ public final class AVMConstants return AVMConstants.buildAVMAssetUrl(s[0], s[1]); } + public static String buildAVMAssetUrl(String store, String assetPath) + { + ClientConfigElement config = Application.getClientConfig(FacesContext.getCurrentInstance()); + return buildAVMAssetUrl(assetPath, config.getWCMDomain(), config.getWCMPort(), lookupStoreDNS(store)); + } + + public static String buildAVMAssetUrl(String assetPath, String domain, String port, String dns) + { + if (assetPath.startsWith('/' + DIR_APPBASE + '/' + DIR_WEBAPPS)) + { + assetPath = assetPath.substring(('/' + DIR_APPBASE + '/' + DIR_WEBAPPS).length()); + } + if (assetPath.startsWith('/' + DIR_ROOT)) + { + assetPath = assetPath.substring(('/' + DIR_ROOT).length()); + } + if (assetPath.length() == 0 || assetPath.charAt(0) != '/') + { + assetPath = '/' + assetPath; + } + + return MessageFormat.format(PREVIEW_ASSET_URL, dns, domain, port, assetPath); + } + public static String lookupStoreDNS(String store) { String dns = null; @@ -123,6 +132,9 @@ public final class AVMConstants public final static String DIR_APPBASE = "appBase"; public final static String DIR_WEBAPPS = "avm_webapps"; + // servlet implicit root directory + public final static String DIR_ROOT = "ROOT"; + // system property keys for sandbox identification and DNS virtualisation mapping public final static String PROP_SANDBOXID = ".sandbox-id."; public final static String PROP_SANDBOX_STAGING_MAIN = ".sandbox.staging.main"; @@ -135,6 +147,6 @@ public final class AVMConstants public final static String SPACE_ICON_WEBSITE = "space-icon-website"; // URLs for preview of sandboxes and assets - public final static String PREVIEW_SANDBOX_URL = "http://www-{0}.avm.{1}:{2}"; - public final static String PREVIEW_ASSET_URL = "http://www-{0}.avm.{1}:{2}{3}"; + private final static String PREVIEW_SANDBOX_URL = "http://www-{0}.avm.{1}:{2}"; + private final static String PREVIEW_ASSET_URL = "http://www-{0}.avm.{1}:{2}{3}"; } 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 aa15a82165..abfcd8da51 100644 --- a/source/java/org/alfresco/web/ui/wcm/component/UIUserSandboxes.java +++ b/source/java/org/alfresco/web/ui/wcm/component/UIUserSandboxes.java @@ -18,7 +18,6 @@ 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; @@ -415,8 +414,8 @@ public class UIUserSandboxes extends SelfRenderingComponent // 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); + String previewUrl = AVMConstants.buildAVMAssetUrl( + assetPath, config.getWCMDomain(), config.getWCMPort(), dns); avmNode.getProperties().put("previewUrl", previewUrl); // size of files