Surf Code Camp Lab 4 is the final lab in which a pages are added to the Green Energy site that facilitate browsing through the repository hierarchy using CMIS and Surf object associations.
Full solution source code is at http://ecmarchitect.com/images/green-energy-code-camp.zip
2. Objectives
Build an Object Viewer page in Surf
Add a CMIS Browser Component
Add a CMIS Display Component
Work with XML streams and process them in
FreeMarker
Experiment with linking to object instances
07/11/08 2
3. Green Energy
We will further extend the Green Energy site
• We started this in Lab #3
• It was extended in the walkthrough with introductory CMIS
Sample location:
• /opt/tomcat/webapps/alfwf
• http://labs3c:8580/alfwf
07/11/08 3
4. Directories
Green Energy Web Application
• /opt/tomcat/webapps/alfwf
site-data
• /WEB-INF/classes/alfresco/site-data
site-webscripts
• /WEB-INF/classes/alfresco/site-webscripts
FreeMarker templates
• /WEB-INF/classes/alfresco/templates
07/11/08 4
5. Update the FolderList Component
folderlist.get.js
<import resource=quot;classpath:alfresco/site-webscripts/age/feed.utils.jsquot;>
var path = quot;/Company%20Homequot;;
// load the feel
var connector = remote.connect(quot;alfrescoquot;);
var feed = connector.get(quot;/api/path/workspace/SpacesStorequot; + path + quot;/childrenquot;);
// parse the feed and set namespace
var xml = loadFeed(feed);
// set up the model
model.title = xml.*::title.toString();
var items = new Array();
for each (entry in xml.*::entry)
{
var item = { };
item[quot;titlequot;] = entry.*::title.toString();
item[quot;iconquot;] = entry.*::icon.toString();
item[“id”] = null; // TODO
item[“url”] = null; // TODO
items.push(item);
}
model.items = items;
07/11/08 5
6. Update the FolderList Component
Fill in the “id” property for each item in the array
• We can use the “content” property
• Syntax: node.*::childElement.toString();
Fill in the “url” property for each item in the array
• Use the LinkBuilder API
• Creates a link to an object
• context.linkBuilder.object(“workspace://SpacesStore/” +
item[“id”]);
07/11/08 6
8. Update the FolderList Component
TODO
Insert value of url from model
●
Syntax: ${variableName} or ${object.variableName}
●
07/11/08 8
9. Try it out
Start Alfresco
• http://labs3c:8080/alfresco
Start Surf Tomcat
• http://labs3c:8580/sample
Browse to
• http://labs3c:8580/alfwf/service/index
Click on ‘Refresh’ to reset the Web Scripts cache
Test your site
• http://labs3c:8580/sample
07/11/08 9
11. Content Association: cm:content
Add a Content Association for cm:content
Points to a page: content-details
cm_content.details.xml
• /WEB-INF/classes/alfresco/site-data/content-associations
<?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?>
<content-association>
<source-id>{http://www.alfresco.org/model/content/1.0}content</source-id>
<dest-id>content-details</dest-id>
<assoc-type>page</assoc-type>
</content-association>
This tells the framework to use the page ‘content-
details’ whenever it is told to display content of type
• {http://www.alfresco.org/model/content/1.0}content
07/11/08 11
12. Content Association: cm:folder
Add a Content Association for cm:folder
Points to a page: content-details
cm_folder.details.xml
• /WEB-INF/classes/alfresco/site-data/content-associations
<?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?>
<content-association>
<source-id>{http://www.alfresco.org/model/content/1.0}folder</source-id>
<dest-id>content-details</dest-id>
<assoc-type>page</assoc-type>
</content-association>
This tells the framework to use the page ‘content-
details’ whenever it is told to display content of type
• {http://www.alfresco.org/model/content/1.0}folder
07/11/08 12
14. Tools Template
navigation template scope
left content
page scope page scope
footer global scope
07/11/08 14
15. Two Components Side by Side
We would like to add two components to this page
• Content Browser
• Content Details
Using the content browser on the left, users select
documents and folders
By selecting folders, they drill down in the browser
Clicking on a document tells the content details
component to show the content details
07/11/08 15
16. Add a CMIS Browser Component
Navigate to the site-webscripts directory
• /WEB-INF/classes/alfresco/site-webscripts
Create a path called age/content
Navigate into the age/content path
• /WEB-INF/classes/alfresco/site-webscripts/age/content
Create a Web Script:
• browser
07/11/08 16
21. Add a CMIS Details Component
Navigate to the site-webscripts directory
• /WEB-INF/classes/alfresco/site-webscripts
Create a path called age/content
Navigate into the age/content path
• /WEB-INF/classes/alfresco/site-webscripts/age/content
Create a Web Script:
• details
07/11/08 21
24. Add a CMIS Details Component
Set up model variables
Name
• {http://www.alfresco.org/model/content/1.0}name
Description
• {http://www.alfresco.org/model/content/1.0}description
Id
• {http://www.alfresco.org/model/system/1.0}node-uuid
Download URL
• url.context +
quot;/proxy/alfresco/api/node/content/workspace/SpacesStore/quot; +
model.id;
07/11/08 24
25. Add a CMIS Details Component
Use the object data that was automatically loaded by
the framework
Variable: context.content
Useful JSON Tool - http://www.jsonlint.com/
• Copy-and-paste JSON into a form and JSON lint makes it pretty
JSON Example – Company Home
• http://labs3c:8080/alfresco/service/webframework/content/meta
data
JSON Example – Guest Space
• http://labs3c:8080/alfresco/service/webframework/content/meta
data?id=workspace://SpacesStore/ba5a95a3-3931-4ba3-8db7-
c5eb95a156a3
JSON Example – Guest Tutorial PDF
• http://labs3c:8080/alfresco/service/webframework/content/meta
data?id=workspace://SpacesStore/a7824f47-e929-4c64-
b789-19b7f22e5b07
07/11/08 25
30. Try it out
Start Alfresco
• http://labs3c:8080/alfresco
Start Surf Tomcat
• http://labs3c:8580/alfwf
Browse to
• http://labs3c:8580/alfwf/service/index
Click on ‘Refresh’ to reset the Web Scripts cache
Test your site
• http://labs3c:8580/alfwf
07/11/08 30
33. Wrap-up
In this lab, you...
• Associated cm:folder with a specific page
• Associated cm:content with a specific page
• Created a “browse” and a “details” component and bound them to
regions on the Tools page
07/11/08 Optaros and Client confidential. All rights reserved. 33