Inline Callouts in Alfresco WCM
Chris Davidson, Software Consultant 23 Jun 2009
A common requirement in metadata capture is for the user to choose values from a list. In Alfresco WCM these lists are supplied via the XSD definition, an enumeration is included in the XSD of the Web Form with the values required. Sometimes we want this list to be dynamic and pulled in from another source.
Previously in Alfresco WCM the typical way of doing this was through a JSP that is served up by the virtual server and hence the inclusion could only be held within the AVM repo and not in the DM (at least not directly). One of the problems with this is the JSP has to be duplicated across all the web projects that use it. In 3.1 and 2.2 SP3 the ability to import and include Alfresco Web Scripts has been added, this means we can now construct these with Alfresco.
Below I have a look at the alfresco sample and start to think about how to use this functionality to allow business users to manage a list with a simple text document.
Preparing for inline callouts through Web Scripts
As we are going to use web scripts to render XSD we need to add XSD to the list of formats for web scripts as below:
<bean id="webscripts.formats" parent="webscripts.formatmap"> <property name="formats"> <props> <prop key="html">text/html</prop> <prop key="text">text/plain</prop> <prop key="xml">text/xml</prop> <prop key="atom">application/atom+xml</prop> <prop key="rss">application/rss+xml</prop> <prop key="json">application/json</prop> <prop key="opensearchdescription">application/opensearchdescription+xml</prop> <prop key="mediawiki">text/plain</prop> <prop key="portlet">text/html</prop> <prop key="xsd">text/xml</prop> </props> </property> </bean>
The file to edit is web-scripts-application-context.xml for 2.2 or webscript-framework-application-context.xml for 3.* under \tomcat\webapps\alfresco\WEB-INF\classes\alfresco.
Getting something going
First you need to build a web script that will do generic lists so we don’t have to keep creating a web script for every list we want to create.
Start off with by adding the following description getList.get.desc.xml to Data Dictionary/Web Script Extensions space.
<webscript>
<shortname>XSD enumeration For Web Forms</shortname>
<description>Will provide lists for web forms</description>
<url>/ixxus/getList?storeid={storeid}&ticket={ticket}&list={list}</url>
<format default="xsd">any</format>
<authentication>user</authentication>
</webscript>
Now add the javascript getList.get.js to the same space:
// Parse arguments
var storeid = args.storeid;
var listName = args.list;
// Validate arguments
if (storeid == undefined || storeid == "")
{
status.code = 400;
status.message = "Mandatory query string parameter 'storeid' was not provided.";
status.redirect = true;
}
if (listName== undefined || listName== "")
{
status.code = 400;
status.message = "Mandatory query string parameter 'list' was not provided.";
status.redirect = true;
}
var listFile = companyhome.childByNamePath("Data Dictionary/CustomLists/"+listName);
var content = listFile.content;
var array = content.split("\r\n|\r|\n");
model.array = array;
model.listName = listName;
...and finally add the template as getList.get.xsd.ftl:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.ixxus.com" xmlns:ixxus="http://www.ixxus.com" xmlns:alf="http://www.alfresco.org" elementFormDefault="qualified">
<xs:simpleType name="${listName}">
<xs:restriction base="xs:string">
<#list array as val>
<xs:enumeration value="${val?split('=')[0]}" >
<xs:annotation>
<xs:appinfo>
<alf:label>${val?split('=')[1]}</alf:label>
</xs:appinfo>
</xs:annotation>
</xs:enumeration>
</#list>
</xs:restriction>
</xs:simpleType>
</xs:schema>
Create a space in Data Dictionary called CustomLists, this is where the actual data for the lists will live. Now use Create Content to create a file called “colours” (no extension) that is plain text with the following content:
blue=Blue red=Red green=Green black=Black purple=Purple
Also create a file called “sizes” with this content
large=Large medium=Medium small=Small
Go to http://localhost:8080/alfresco/service/index and refresh the webscripts, now browse to the web script and click on it http://localhost:8080/alfresco/service/ixxus/getList?storeid={storeid}&ticket={ticket}&list=colours this should display the XSD being created, notice the simpleType name is the same as the list name. Look at sizes as well by replacing the list parameter with “sizes”. You don’t need to worry about the storied or the ticket parameters as these get injected by Alfresco.
Using the Web Script in a Web Form
Now we can create a Web Form. Create a file on your machine using the XSD below. Under “Data Dictionary/Web Forms” under “Create” click on “Create Web Form” and upload the xsd as the schema and click Next. There is no need for a template so click Next, Next and Finish. Note the includes that pull in our web scripts and the xs:list itemType which matches our list name.
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.ixxus.com"
xmlns:ixxus="http://www.ixxus.com"
xmlns:alf="http://www.alfresco.org" elementFormDefault="qualified">
<xs:include schemaLocation="webscript://ixxus/getList?ticket={ticket}&storeid={storeid}&list=colours" />
<xs:include schemaLocation="webscript://ixxus/getList?ticket={ticket}&storeid={storeid}&list=sizes" />
<xs:element name="Article">
<xs:complexType >
<xs:sequence>
<xs:element name="title" type="xs:normalizedString" />
<xs:element name="Colours" nillable="false">
<xs:annotation>
<xs:appinfo>
<alf:label>Colours</alf:label>
</xs:appinfo>
</xs:annotation>
<xs:simpleType>
<xs:list itemType="ixxus:colours" />
</xs:simpleType>
</xs:element>
<xs:element name="Sizes" nillable="false">
<xs:annotation>
<xs:appinfo>
<alf:label>Sizes</alf:label>
</xs:appinfo>
</xs:annotation>
<xs:simpleType>
<xs:list itemType="ixxus:sizes" />
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Add this form to a Web Project and create some web content in your Sandbox using the form, it should look like the form below. Notice the colours automatically go into a select box when you have five or more elements.

So now a business user can manage this list from a simple name value pair structure in a text file.





Comments
Be the first to comment.
Add your comment