Instructions for enabling Crafter rivet Alfresco WCM (Creating a Preview Server)
In Alfresco
- Install the ACP attached to this space (or from source control) in the web scripts directory.
- This web script library currently contains a script that enables WCPr (Crafter rivet's XML Engine) to traverse directory structure within AVM stores.
- configure the preview Icon
- in ./alfresco/tomcat/shared/classes/alfresco/extension/preview-context.xml place the following contents (Create this file if not already present)
<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'> <beans> <bean id="PreviewURIService" class="org.alfresco.web.bean.wcm.preview.StoreSpecificPreviewURIService"> <constructor-arg index="0"> <list> <bean class="org.alfresco.util.Pair"> <constructor-arg index="0" value=".*" /> <constructor-arg index="1"> <bean class="org.alfresco.web.bean.wcm.preview.URITemplatePreviewURIService"> <constructor-arg index="0" value="http://{storeId}.www--sandbox.127-0-0-1.ip.alfrescodemo.net:8080/" /> </bean> </constructor-arg> </bean> </list> </constructor-arg> </bean> </beans>
- in ./alfresco/tomcat/shared/classes/alfresco/extension/preview-context.xml place the following contents (Create this file if not already present)
Install the webscript attached to this space in alfresco webscript space - pre Crafter-1.5.4
- in ./alfresco/tomcat/shared/classes/alfresco/extension/templates/webscripts (Create the directory structure and files if not already present)
- create file: listdir.get.desc.xml with the following content
<webscript> <shortname>wcpr-listfiles</shortname> <description>List Files Web Script for Rivet Logic Web Content Processing rivet</description> <url>/com/rivetlogic/wcpr/listdir/{storeid}/{path}</url> <authentication>user</authentication> <transaction>required</transaction> </webscript>
- create a file: listdir.get.js with the following contents
// extract avm store id and path var fullpath = url.extension.split("/"); if (fullpath.length == 0) { status.code = 400; status.message = "Store id has not been provided."; status.redirect = true; } else { var storeid = fullpath[0]; var path = (fullpath.length == 1 ? "/" : "/" + fullpath.slice(1).join("/")); // locate avm node from path var store = avm.lookupStore(storeid); if (store == undefined) { status.code = 404; status.message = "Store " + storeid + " not found."; status.redirect = true; } else { path = path.replace(/-DOT-/g, '.'); var node = avm.lookupNode(storeid + ":" + path); if (node == undefined) { status.code = 404; status.message = "Path " + path + " within store " + storeid + " not found ("+storeid + ":" + path+")."; status.redirect = true; } else { model.node = node } } }
- create a file: listdir.get.html.ftl with the following content
<items> <#list node.children as child> <item> <name><![CDATA[${child.name}]]></name> <#if child.isContainer == true> <isFolder>true</isFolder> </#if> <#if child.isContainer != true> <isFolder>false</isFolder> </#if> <path><![CDATA[${child.displayPath}]]></path> </item> </#list> </items>
- create file: listdir.get.desc.xml with the following content
Use Alfresco inbuilt webscript - from Crafter-1.5.4 onwards
- In the Alfresco installation, copy the attached asset.lib.ftl file to the following location. This will be replacing an existing file.
- ./alfresco/tomcat/shared/classes/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/
Note: The reason for this is because there is a bug existing with the webscript where if a filesize is greater that 1000, the number is comma separated. The format returned is JSON, and so this renders the JSON invalid. Alfresco JIRA item ALF-3818 has been opened to address this.
- In the application, the following configuration will need to be updated.
- crafter.preview.wcm.adapter.listFileServiceUrl=/api/wcm/webprojects
/\{awcm.webproject.path\}/sandboxes/\{awcm.sandbox.path\}/assets/www/avm_webapps/ROOT/
- crafter.preview.wcm.adapter.listFileServiceUrl=/api/wcm/webprojects
If there was anything after ROOT (or whatever the webapp name is), it should stay. By webapp we are referring to the webapp name within the Alfresco web project. This is generally ROOT but Alfresco does allow you to create additional webapps within a given project.
-
- Add the macro resolver for the {awcm.webproject.path} macro to the spring configuration.
To the pathMacroResolverMap bean the following should be added.<entry key="awcm.webproject.path"> <ref bean="currentAlfrescoWebProjectMacroResolver" /> </entry>
- Add the following bean to the spring configuration.
<bean id="currentAlfrescoWebProjectMacroResolver" class="org.rivetlogic.crafter.core.path.impl.AlfrescoWebProjectPathMacroResolver"> <property name="sandboxPathMacroResolver"> <ref bean="currentAlfrescoAvmSandboxMacroResolver"/> </property> </bean>
- Add the macro resolver for the {awcm.webproject.path} macro to the spring configuration.
In Application
In your application you have to configure servlet filter and mappings like this
Filter
<filter> <filter-name>Servlet Pipeline Filter</filter-name> <filter-class> org.rivetlogic.crafter.core.servlet.VariableResolverServletFilterWrapper </filter-class> <init-param> <param-name>componentName</param-name> <param-value>servletPipelineServletFilter</param-value> </init-param> </filter>
Filter mapping - Make sure this mapping is on the top of the list
<filter-mapping> <filter-name>Servlet Pipeline Filter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>INCLUDE</dispatcher> <dispatcher>FORWARD</dispatcher> </filter-mapping>
In JBoss
- Install Crafter rivet
- In the conf directory for the server create the following folder structure
- ./crafter/extension
- Add the a file called application-custom-context.xml with the following content
<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'> <beans> <!-- load common properties --> <bean id="systemProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="ignoreUnresolvablePlaceholders"> <value>true</value> </property> <property name="locations"> <list> <value>classpath:core/system-cfg.properties</value> <value>classpath:crafter/custom-system-cfg.properties</value> </list> </property> </bean> <import resource="classpath:core/virtual-server.xml" /> </beans>
- Add a file to the directory called system-custom-properties with the following content. If the file already exists simply add the additional content.
alfresco.preview.endpoint.username=admin alfresco.preview.endpoint.password=admin alfresco.preview.endpoint.servicebaseurl=http://localhost:9080/alfresco/s alfresco.preview.endpoint.downloadbaseurl=http://localhost:9080/alfresco/s/api/node/content/avm
- Modify the user name,password urls, and ports as needed (to match your alfresco instance)
- Default values assume localhost, port 8080 and admin/admin
Restart Server
You must restart the your alfresco and JBoss servers in order to pick up the changes
Coding Consideration
The following guidelines should be followed when coding
Facelet Template Paths
Facelets allows you to use relative paths when doing includes and template imports. Assumptions within Alfresco's REST services and deep assumptions within the facelet library do not agree with each other and thus relative paths to templates do not work via preview. Please use the full path (relative to your store root.)
Assuming the active path is [WCRAFT:TEMPLATE STORE BASE]/web
Working example:
/web/templates/mytemplate.seam
Broken example:
templates/mytemplate.seam