Obsolete Pages{{Obsolete}}
The official documentation is at: http://docs.alfresco.com
{{AVMWarning}}
AVM3.2
Back to WCM Preview
As discussed in WCM Preview#Virtualised Content Retrieval, the virtualised content retrieval approach to in-context preview requires that the Alfresco authoring instance knows how to properly construct deep URIs for an arbitrary external web application. This mechanism is provided by the 'Preview URI Service', that not only provides a way for developers to implement arbitrarily complex preview URI mapping rules, but also provides a number of implementations that may be used as is, or referred to as examples of best practice.
Alfresco Community 3.2 and higher introduces a new WCM Service for generating Preview URIs. For earlier implementations, please refer to Preview URI Service (2.2 to 3.1).
The sys admin can pre-configure a registered list of preview URI service providers. One of these must be specified as the default provider. These will appear in a drop-down when creating/editing web project in the Alfresco WCM client (Alfresco Explorer) and hence can be selected and associated on a per- web project basis.
The WCM Preview URI Service includes an SPI (Service Provider Interface) which provides the ability to develop and pre-register different types of PreviewURI providers. In order to calculate/generate preview URIs, a custom class can implement the following Java interface:
package org.alfresco.wcm.preview;
import java.util.List;
public interface PreviewURIServiceProvider
{
/**
* @param sbStoreId The sandbox store id to generate the preview URI for.
* @param pathToAsset The path to the asset to generate the preview URI for (can be null or empty, to return preview URL to store).
* @param previewContext Additional preview context
*
* @return The Preview URI for the given sandbox and/or asset (may be null).
*/
public String getPreviewURI(String sbStoreId, String pathToAsset, PreviewContext previewContext);
/**
* @param sbStoreId The sandbox store id to generate the preview URI for.
* @param pathsToAssets The paths to the assets to generate the preview URI for.
* @param previewContext Additional preview context
*
* @return The Preview URIs for the given asset paths (may be null).
*/
public List<String> getPreviewURIs(String sbStoreId, List<String> pathsToAssets, PreviewContext previewContext);
For Alfresco WCM (Community 3.2), three implementations of this interface are provided:
The class org.alfresco.wcm.preview.VirtualisationServerPreviewURIService generates virtualisation server preview URIs and is primarily provided for backwards compatibility.
The class org.alfresco.wcm.preview.URITemplatePreviewURIService uses a (configurable) URI template for generating preview URIs. The template language is identical to the one used for Web Scripts - see Web Scripts#URL Templates for more details.
The URITemplatePreviewURIService currently recognises two parameters in URI templates:
Note that both of these parameters are optional - if they're not found in the URI template the replacement value won't appear in the resulting preview URI.</math>
The class org.alfresco.wcm.preview.NullPreviewURIService generates no URI whatsoever. This is useful for Web Projects where preview is disabled or disallowed for some reason.
To ensure backwards compatibility, the Web Client uses an instance of the VirtualisationServicePreviewURIService as the default PreviewURIService. You may override this behaviour by overriding the 'previewURIServiceRegistry' Spring bean in a custom-*-context.xml file (as described at Repository Configuration). For example if you wish to register a new default preview URI service provider called 'myCustomPreviewURIService', you could create the following Spring configuration in a file called custom-wcm-preview-context.xml:
<beans>
<bean id='myCustomPreviewURIService' class='com.mydomain.MyCustomPreviewURIService' parent='basePreviewURIServiceProvider'/>
<bean id='previewURIServiceRegistry' class='org.alfresco.wcm.preview.PreviewURIServiceRegistryImpl'>
<property name='defaultProviderName'>
<value>My Custom Preview</value>
</property>
<property name='previewURIServiceProvidersByName'>
<map>
<entry key='Virtualisation Server Preview'>
<ref bean='virtServerPreviewURIService'/>
</entry>
<entry key='My Custom Preview'>
<ref bean='myCustomPreviewURIService'/>
</entry>
</map>
</property>
</bean>
</beans>
Implementing a custom PreviewURIServiceProvider requires a working knowledge of Java development, as well as an Alfresco SVN Development Environment. You should also be familiar with how Alfresco code extensions are packaged (i.e. as AMP Files) and deployed (i.e. via the Module Management Tool).
If you're familiar with Java you should find implementing a custom PreviewURIServiceProvider straight forward, given the simplicity of the interface.
The following sample implementation shows how you might strip out the 'synthetic' directories that get added to the start of every asset in a Web Project:
package com.mydomain;
import org.alfresco.wcm.preview.AbstractPreviewURIServiceProvider
public class MyCustomPreviewURIService extends AbstractPreviewURIServiceProvider
{
private final static String SYNTHETIC_DIRECTORIES = '/www/avm_webapps/ROOT/';
private final String previewServerHostnameAndPort;
public MyCustomPreviewURIService(String previewServerHostnameAndPort)
{
assert previewServerHostnameAndPort != null : 'previewServerHostnameAndPort must not be null';
this.previewServerHostnameAndPort = previewServerHostnameAndPort;
}
public String getPreviewURI(String storeId, String pathToAsset)
{
StringBuilder result = new StringBuilder('https://' + previewServerHostnameAndPort);
if (pathToAsset.startsWith(SYNTHETIC_DIRECTORIES))
{
result.append(pathToAsset.replace(SYNTHETIC_DIRECTORIES, '/'));
}
else
{
result.append(pathToAsset);
}
return(result.toString());
}
}
Back to WCM Preview
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.