Merge WCM_SERVICES into HEAD 11697, 11698, 11702, 11751, 11801, 11924, 12023, 12073

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@12076 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Mark Rogers
2008-11-21 13:59:09 +00:00
parent 16de2cc1e1
commit cad991db0c
29 changed files with 4443 additions and 692 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
* Copyright (C) 2005-2008 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -24,21 +24,16 @@
*/
package org.alfresco.repo.template;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.alfresco.config.JNDIConstants;
import org.alfresco.repo.domain.PropertyValue;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
import org.alfresco.service.cmr.avm.AVMService;
import org.alfresco.service.cmr.avm.AVMStoreDescriptor;
import org.alfresco.service.cmr.avmsync.AVMDifference;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.NameMatcher;
import org.alfresco.util.ParameterCheck;
import org.alfresco.wcm.sandbox.SandboxService;
import org.alfresco.wcm.util.WCMUtil;
/**
* AVM root object access for a template model.
@@ -48,7 +43,6 @@ import org.alfresco.util.ParameterCheck;
public class AVM extends BaseTemplateProcessorExtension
{
private ServiceRegistry services;
private NameMatcher matcher;
/**
* Sets the service registry
@@ -60,11 +54,6 @@ public class AVM extends BaseTemplateProcessorExtension
this.services = services;
}
public void setNameMatcher(NameMatcher matcher)
{
this.matcher = matcher;
}
/**
* @return a list of all AVM stores in the system
*/
@@ -152,28 +141,17 @@ public class AVM extends BaseTemplateProcessorExtension
ParameterCheck.mandatoryString("Username", username);
ParameterCheck.mandatoryString("Webapp", webapp);
List<AVMTemplateNode> items;
AVMService avmService = this.services.getAVMService();
// build the paths to the stores to compare - filter by current webapp
String userStore = userSandboxStore(storeId, username);
String userStorePath = getStoreRootWebappPath(userStore, webapp);
String stagingStore = stagingStore(storeId);
String stagingStorePath = getStoreRootWebappPath(stagingStore, webapp);
SandboxService sbService = this.services.getSandboxService();
List<AVMDifference> diffs = this.services.getAVMSyncService().compare(
-1, userStorePath, -1, stagingStorePath, this.matcher);
items = new ArrayList<AVMTemplateNode>(diffs.size());
for (AVMDifference diff : diffs)
// get modified items - not including deleted
List<AVMNodeDescriptor> nodes = sbService.listChangedItemsWebApp(storeId, webapp, false);
List<AVMTemplateNode> items = new ArrayList<AVMTemplateNode>(nodes.size());
for (AVMNodeDescriptor node : nodes)
{
// convert each diff record into an AVM Node template wrapper
String sourcePath = diff.getSourcePath();
AVMNodeDescriptor node = avmService.lookup(-1, sourcePath);
if (node != null)
{
items.add(new AVMTemplateNode(node, this.services, getTemplateImageResolver()));
}
// convert each diff/node record into an AVM Node template wrapper
items.add(new AVMTemplateNode(node, this.services, getTemplateImageResolver()));
}
return items;
@@ -186,8 +164,7 @@ public class AVM extends BaseTemplateProcessorExtension
*/
public static String stagingStore(String storeId)
{
ParameterCheck.mandatoryString("Store ID", storeId);
return storeId;
return WCMUtil.buildStagingStoreName(storeId);
}
/**
@@ -198,9 +175,7 @@ public class AVM extends BaseTemplateProcessorExtension
*/
public static String userSandboxStore(String storeId, String username)
{
ParameterCheck.mandatoryString("Store ID", storeId);
ParameterCheck.mandatoryString("Username", username);
return storeId + "--" + username;
return WCMUtil.buildUserMainStoreName(storeId, username);
}
/**
@@ -210,9 +185,7 @@ public class AVM extends BaseTemplateProcessorExtension
*/
public String websiteStagingUrl(String storeId)
{
ParameterCheck.mandatoryString("Store ID", storeId);
return MessageFormat.format(JNDIConstants.PREVIEW_SANDBOX_URL,
lookupStoreDNS(storeId), getVServerDomain(), getVServerPort());
return WCMUtil.buildStoreUrl(this.services.getAVMService(), storeId, getVServerDomain(), getVServerPort());
}
/**
@@ -236,25 +209,7 @@ public class AVM extends BaseTemplateProcessorExtension
*/
public String assetUrl(String store, String assetPath)
{
ParameterCheck.mandatoryString("Store", store);
ParameterCheck.mandatoryString("Asset Path", assetPath);
if (assetPath.startsWith('/' + JNDIConstants.DIR_DEFAULT_WWW +
'/' + JNDIConstants.DIR_DEFAULT_APPBASE))
{
assetPath = assetPath.substring(('/' + JNDIConstants.DIR_DEFAULT_WWW +
'/' + JNDIConstants.DIR_DEFAULT_APPBASE).length());
}
if (assetPath.startsWith("/ROOT"))
{
assetPath = assetPath.substring(("/ROOT").length());
}
if (assetPath.length() == 0 || assetPath.charAt(0) != '/')
{
assetPath = '/' + assetPath;
}
return MessageFormat.format(JNDIConstants.PREVIEW_ASSET_URL,
lookupStoreDNS(store), getVServerDomain(), getVServerPort(), assetPath);
return WCMUtil.buildAssetUrl(assetPath, getVServerDomain(), getVServerPort(), WCMUtil.lookupStoreDNS(this.services.getAVMService(), store));
}
/**
@@ -304,27 +259,6 @@ public class AVM extends BaseTemplateProcessorExtension
*/
public static String getWebappsFolderPath()
{
return '/' + JNDIConstants.DIR_DEFAULT_WWW +
'/' + JNDIConstants.DIR_DEFAULT_APPBASE;
return JNDIConstants.DIR_DEFAULT_WWW_APPBASE;
}
private static String getStoreRootPath(String store)
{
return store + ":" + getWebappsFolderPath();
}
private static String getStoreRootWebappPath(String store, String webapp)
{
return getStoreRootPath(store) + '/' + webapp;
}
private String lookupStoreDNS(String store)
{
Map<QName, PropertyValue> props =
this.services.getAVMService().queryStorePropertyKey(store, QName.createQName(null, PROP_DNS + '%'));
return (props.size() == 1
? props.keySet().iterator().next().getLocalName().substring(PROP_DNS.length()) : null);
}
private final static String PROP_DNS = ".dns.";
}