My Forms template now opens website virtualisation URL when icon clicked.

New Template AVM API methods added to generate staging, user sandbox and path asset URLs for virtualisation server.
Some refactoring of constants used in AVMConstants into JNDIConstants to allow repository classes to also use them.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5624 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast 2007-05-04 11:27:46 +00:00
parent 5615885916
commit 431f990806
3 changed files with 149 additions and 0 deletions

View File

@ -26,6 +26,7 @@ package org.alfresco.repo.service;
import java.util.Collection;
import org.alfresco.mbeans.VirtServerRegistry;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.action.ActionService;
import org.alfresco.service.cmr.attributes.AttributeService;
@ -370,4 +371,12 @@ public class ServiceDescriptorRegistry
{
return (AVMLockingService)getService(AVM_LOCKING_SERVICE);
}
/* (non-Javadoc)
* @see org.alfresco.service.ServiceRegistry#getVirtServerRegistry()
*/
public VirtServerRegistry getVirtServerRegistry()
{
return (VirtServerRegistry)getService(VIRT_SERVER_REGISTRY);
}
}

View File

@ -24,10 +24,16 @@
*/
package org.alfresco.repo.template;
import java.text.MessageFormat;
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.AVMStoreDescriptor;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.ParameterCheck;
/**
* AVM root object access for a template model.
@ -108,6 +114,121 @@ public class AVM extends BaseTemplateProcessorExtension
return node;
}
/**
* @param storeId Store ID to build staging store name for
*
* @return the Staging Store name for the given store ID
*/
public String stagingStore(String storeId)
{
return storeId;
}
/**
* @param storeId Store ID to build sandbox store name for
* @param username Username of the sandbox user
*
* @return the Sandbox Store name for the given store ID and username
*/
public String userSandboxStore(String storeId, String username)
{
ParameterCheck.mandatoryString("Store ID", storeId);
ParameterCheck.mandatoryString("Username", username);
return storeId + "--" + username;
}
/**
* @param storeId Store ID to build preview URL for
*
* @return the preview URL to the staging store for the specified store ID
*/
public String websiteStagingUrl(String storeId)
{
return MessageFormat.format(JNDIConstants.PREVIEW_SANDBOX_URL,
lookupStoreDNS(storeId), getVServerDomain(), getVServerPort());
}
/**
* @param storeId Store ID to build preview URL for
* @param username Username to build sandbox preview URL for
*
* @return the preview URL to the user sandbox for the specified store ID and username
*/
public String websiteUserSandboxUrl(String storeId, String username)
{
return websiteStagingUrl(userSandboxStore(storeId, username));
}
/**
* @param store Store ID of the asset
* @param assetPath Store relative path to the asset
*
* @return the preview URL to the specified store asset
*/
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);
}
/**
* @param avmPath Fully qualified AVM path of the asset
*
* @return the preview URL to the specified asset
*/
public String assetUrl(String avmPath)
{
ParameterCheck.mandatoryString("AVM Path", avmPath);
String[] s = avmPath.split(":");
if (s.length != 2)
{
throw new IllegalArgumentException("Expected exactly one ':' in " + avmPath);
}
return assetUrl(s[0], s[1]);
}
/**
* @return VServer Port
*/
private String getVServerPort()
{
Integer port = this.services.getVirtServerRegistry().getVirtServerHttpPort();
if (port == null)
{
port = JNDIConstants.DEFAULT_VSERVER_PORT;
}
return port.toString();
}
/**
* @return VServer Domain
*/
private String getVServerDomain()
{
String domain = this.services.getVirtServerRegistry().getVirtServerFQDN();
if (domain == null)
{
domain = JNDIConstants.DEFAULT_VSERVER_IP;
}
return domain;
}
/**
* @return the path to the webapps folder in a standard web store.
*/
@ -116,4 +237,14 @@ public class AVM extends BaseTemplateProcessorExtension
return '/' + JNDIConstants.DIR_DEFAULT_WWW +
'/' + JNDIConstants.DIR_DEFAULT_APPBASE;
}
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.";
}

View File

@ -26,6 +26,7 @@ package org.alfresco.service;
import java.util.Collection;
import org.alfresco.mbeans.VirtServerRegistry;
import org.alfresco.service.cmr.action.ActionService;
import org.alfresco.service.cmr.attributes.AttributeService;
import org.alfresco.service.cmr.audit.AuditService;
@ -108,6 +109,7 @@ public interface ServiceRegistry
static final QName CROSS_REPO_COPY_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "CrossRepositoryCopyService");
static final QName ATTRIBUTE_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "AttributeService");
static final QName AVM_LOCKING_SERVICE = QName.createQName(NamespaceService.ALFRESCO_URI, "AVMLockingService");
static final QName VIRT_SERVER_REGISTRY = QName.createQName(NamespaceService.ALFRESCO_URI, "VirtServerRegistry");
/**
* Get the list of services provided by the Repository
@ -333,4 +335,11 @@ public interface ServiceRegistry
*/
@NotAuditable
AVMLockingService getAVMLockingService();
/**
* Get the Virtualisation Server registry service bean
* @return
*/
@NotAuditable
VirtServerRegistry getVirtServerRegistry();
}