. 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
This commit is contained in:
Kevin Roast
2006-10-24 16:33:37 +00:00
parent eeec32d5ce
commit 346bfe2c33
3 changed files with 32 additions and 26 deletions

View File

@@ -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);
}

View File

@@ -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}";
}

View File

@@ -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