Web Scripts:

- samples
- fix "execute" javascript error
- fix hidden exception when status template had errors
- addition of 'roothome' script & template root object

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6011 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
David Caruana
2007-06-18 22:34:29 +00:00
parent 5dc16190ef
commit 2de8f8402c
17 changed files with 373 additions and 13 deletions

View File

@@ -21,7 +21,7 @@
<view:properties>
<app:editInline>true</app:editInline>
<cm:description>What are Web Scripts and how do you develop them?</cm:description>
<cm:content>contentUrl=classpath:alfresco/bootstrap/webscripts/readme.html|mimetype=text/html|size=1344|encoding=UTF-8|locale=en_US_</cm:content>
<cm:content>contentUrl=classpath:alfresco/bootstrap/webscripts/readme.html|mimetype=text/html|size=|encoding=UTF-8|locale=en_US_</cm:content>
<cm:title></cm:title>
<cm:author></cm:author>
<cm:name>readme.html</cm:name>
@@ -64,6 +64,103 @@
</view:properties>
<view:associations>
<cm:contains>
<cm:content view:childName="cm:blogsearch.get.js">
<view:aspects>
<cm:titled></cm:titled>
<app:inlineeditable></app:inlineeditable>
<cm:author></cm:author>
</view:aspects>
<view:properties>
<app:editInline>true</app:editInline>
<cm:description></cm:description>
<cm:content>contentUrl=classpath:alfresco/bootstrap/webscripts/blogsearch.get.js|mimetype=application/x-javascript|size=|encoding=UTF-8|locale=en_US_</cm:content>
<cm:title>blogsearch.get.js</cm:title>
<cm:author></cm:author>
<cm:name>blogsearch.get.js</cm:name>
</view:properties>
<view:associations></view:associations>
</cm:content>
<cm:content view:childName="cm:blogsearch.get.atom.ftl">
<view:aspects>
<cm:titled></cm:titled>
<cm:author></cm:author>
<app:inlineeditable></app:inlineeditable>
</view:aspects>
<view:properties>
<app:editInline>true</app:editInline>
<cm:description></cm:description>
<cm:content>contentUrl=classpath:alfresco/bootstrap/webscripts/blogsearch.get.atom.ftl|mimetype=text/plain|size=|encoding=UTF-8|locale=en_US_</cm:content>
<cm:title>blogsearch.get.atom.ftl</cm:title>
<cm:author></cm:author>
<sys:store-protocol>workspace</sys:store-protocol>
<cm:name>blogsearch.get.atom.ftl</cm:name>
</view:properties>
<view:associations></view:associations>
</cm:content>
<cm:content view:childName="cm:blogsearch.get.desc.xml">
<view:aspects>
<cm:titled></cm:titled>
<cm:author></cm:author>
<app:inlineeditable></app:inlineeditable>
</view:aspects>
<view:properties>
<app:editInline>true</app:editInline>
<cm:description></cm:description>
<cm:content>contentUrl=classpath:alfresco/bootstrap/webscripts/blogsearch.get.desc.xml|mimetype=text/xml|size=|encoding=UTF-8|locale=en_US_</cm:content>
<cm:title>blogsearch.get.desc.xml</cm:title>
<cm:author></cm:author>
<cm:name>blogsearch.get.desc.xml</cm:name>
</view:properties>
<view:associations></view:associations>
</cm:content>
<cm:content view:childName="cm:blogsearch.get.html.ftl">
<view:aspects>
<cm:titled></cm:titled>
<cm:author></cm:author>
<app:inlineeditable></app:inlineeditable>
</view:aspects>
<view:properties>
<app:editInline>true</app:editInline>
<cm:description></cm:description>
<cm:content>contentUrl=classpath:alfresco/bootstrap/webscripts/blogsearch.get.html.ftl|mimetype=text/plain|size=|encoding=UTF-8|locale=en_US_</cm:content>
<cm:title>blogsearch.get.html.ftl</cm:title>
<cm:author></cm:author>
<cm:name>blogsearch.get.html.ftl</cm:name>
</view:properties>
<view:associations></view:associations>
</cm:content>
<cm:content view:childName="cm:blogsearch.get.html.400.ftl">
<view:aspects>
<cm:titled></cm:titled>
<cm:author></cm:author>
<app:inlineeditable></app:inlineeditable>
</view:aspects>
<view:properties>
<app:editInline>true</app:editInline>
<cm:description></cm:description>
<cm:content>contentUrl=classpath:alfresco/bootstrap/webscripts/blogsearch.get.html.400.ftl|mimetype=text/plain|size=|encoding=UTF-8|locale=en_US_</cm:content>
<cm:title>blogsearch.get.html.400.ftl</cm:title>
<cm:author></cm:author>
<cm:name>blogsearch.get.html.400.ftl</cm:name>
</view:properties>
<view:associations></view:associations>
</cm:content>
<cm:content view:childName="cm:blogsearch.get.atom.400.ftl">
<view:aspects>
<cm:titled></cm:titled>
<cm:author></cm:author>
<app:inlineeditable></app:inlineeditable>
</view:aspects>
<view:properties>
<app:editInline>true</app:editInline>
<cm:description></cm:description>
<cm:content>contentUrl=classpath:alfresco/bootstrap/webscripts/blogsearch.get.atom.400.ftl|mimetype=text/plain|size=|encoding=UTF-8|locale=en_US_</cm:content>
<cm:title>blogsearch.get.atom.400.ftl</cm:title>
<cm:author></cm:author>
<cm:name>blogsearch.get.atom.400.ftl</cm:name>
</view:properties>
<view:associations></view:associations>
</cm:content>
<cm:content view:childName="cm:categorysearch.get.js">
<view:aspects>
<cm:titled></cm:titled>
@@ -73,7 +170,7 @@
<view:properties>
<app:editInline>true</app:editInline>
<cm:description></cm:description>
<cm:content>contentUrl=classpath:alfresco/bootstrap/webscripts/categorysearch.get.js|mimetype=application/x-javascript|size=121|encoding=UTF-8|locale=en_US_</cm:content>
<cm:content>contentUrl=classpath:alfresco/bootstrap/webscripts/categorysearch.get.js|mimetype=application/x-javascript|size=|encoding=UTF-8|locale=en_US_</cm:content>
<cm:title>categorysearch.get.js</cm:title>
<cm:author></cm:author>
<cm:name>categorysearch.get.js</cm:name>
@@ -89,7 +186,7 @@
<view:properties>
<app:editInline>true</app:editInline>
<cm:description></cm:description>
<cm:content>contentUrl=classpath:alfresco/bootstrap/webscripts/categorysearch.get.atom.ftl|mimetype=text/plain|size=778|encoding=UTF-8|locale=en_US_</cm:content>
<cm:content>contentUrl=classpath:alfresco/bootstrap/webscripts/categorysearch.get.atom.ftl|mimetype=text/plain|size=|encoding=UTF-8|locale=en_US_</cm:content>
<cm:title>categorysearch.get.atom.ftl</cm:title>
<cm:author></cm:author>
<sys:store-protocol>workspace</sys:store-protocol>
@@ -106,7 +203,7 @@
<view:properties>
<app:editInline>true</app:editInline>
<cm:description></cm:description>
<cm:content>contentUrl=classpath:alfresco/bootstrap/webscripts/categorysearch.get.desc.xml|mimetype=text/xml|size=375|encoding=UTF-8|locale=en_US_</cm:content>
<cm:content>contentUrl=classpath:alfresco/bootstrap/webscripts/categorysearch.get.desc.xml|mimetype=text/xml|size=|encoding=UTF-8|locale=en_US_</cm:content>
<cm:title>categorysearch.get.desc.xml</cm:title>
<cm:author></cm:author>
<cm:name>categorysearch.get.desc.xml</cm:name>
@@ -122,13 +219,110 @@
<view:properties>
<app:editInline>true</app:editInline>
<cm:description></cm:description>
<cm:content>contentUrl=classpath:alfresco/bootstrap/webscripts/categorysearch.get.html.ftl|mimetype=text/plain|size=364|encoding=UTF-8|locale=en_US_</cm:content>
<cm:content>contentUrl=classpath:alfresco/bootstrap/webscripts/categorysearch.get.html.ftl|mimetype=text/plain|size=|encoding=UTF-8|locale=en_US_</cm:content>
<cm:title>categorysearch.get.html.ftl</cm:title>
<cm:author></cm:author>
<cm:name>categorysearch.get.html.ftl</cm:name>
</view:properties>
<view:associations></view:associations>
</cm:content>
<cm:content view:childName="cm:categorysearch.get.html.404.ftl">
<view:aspects>
<cm:titled></cm:titled>
<cm:author></cm:author>
<app:inlineeditable></app:inlineeditable>
</view:aspects>
<view:properties>
<app:editInline>true</app:editInline>
<cm:description></cm:description>
<cm:content>contentUrl=classpath:alfresco/bootstrap/webscripts/categorysearch.get.html.404.ftl|mimetype=text/plain|size=|encoding=UTF-8|locale=en_US_</cm:content>
<cm:title>categorysearch.get.html.404.ftl</cm:title>
<cm:author></cm:author>
<cm:name>categorysearch.get.html.404.ftl</cm:name>
</view:properties>
<view:associations></view:associations>
</cm:content>
<cm:content view:childName="cm:categorysearch.get.atom.404.ftl">
<view:aspects>
<cm:titled></cm:titled>
<cm:author></cm:author>
<app:inlineeditable></app:inlineeditable>
</view:aspects>
<view:properties>
<app:editInline>true</app:editInline>
<cm:description></cm:description>
<cm:content>contentUrl=classpath:alfresco/bootstrap/webscripts/categorysearch.get.atom.404.ftl|mimetype=text/plain|size=|encoding=UTF-8|locale=en_US_</cm:content>
<cm:title>categorysearch.get.atom.404.ftl</cm:title>
<cm:author></cm:author>
<cm:name>categorysearch.get.atom.404.ftl</cm:name>
</view:properties>
<view:associations></view:associations>
</cm:content>
<cm:content view:childName="cm:folder.get.js">
<view:aspects>
<cm:titled></cm:titled>
<app:inlineeditable></app:inlineeditable>
<cm:author></cm:author>
</view:aspects>
<view:properties>
<app:editInline>true</app:editInline>
<cm:description></cm:description>
<cm:content>contentUrl=classpath:alfresco/bootstrap/webscripts/folder.get.js|mimetype=application/x-javascript|size=|encoding=UTF-8|locale=en_US_</cm:content>
<cm:title>folder.get.js</cm:title>
<cm:author></cm:author>
<cm:name>folder.get.js</cm:name>
</view:properties>
<view:associations></view:associations>
</cm:content>
<cm:content view:childName="cm:folder.get.atom.ftl">
<view:aspects>
<cm:titled></cm:titled>
<cm:author></cm:author>
<app:inlineeditable></app:inlineeditable>
</view:aspects>
<view:properties>
<app:editInline>true</app:editInline>
<cm:description></cm:description>
<cm:content>contentUrl=classpath:alfresco/bootstrap/webscripts/folder.get.atom.ftl|mimetype=text/plain|size=|encoding=UTF-8|locale=en_US_</cm:content>
<cm:title>folder.get.atom.ftl</cm:title>
<cm:author></cm:author>
<sys:store-protocol>workspace</sys:store-protocol>
<cm:name>folder.get.atom.ftl</cm:name>
</view:properties>
<view:associations></view:associations>
</cm:content>
<cm:content view:childName="cm:folder.get.desc.xml">
<view:aspects>
<cm:titled></cm:titled>
<cm:author></cm:author>
<app:inlineeditable></app:inlineeditable>
</view:aspects>
<view:properties>
<app:editInline>true</app:editInline>
<cm:description></cm:description>
<cm:content>contentUrl=classpath:alfresco/bootstrap/webscripts/folder.get.desc.xml|mimetype=text/xml|size=|encoding=UTF-8|locale=en_US_</cm:content>
<cm:title>folder.get.desc.xml</cm:title>
<cm:author></cm:author>
<cm:name>folder.get.desc.xml</cm:name>
</view:properties>
<view:associations></view:associations>
</cm:content>
<cm:content view:childName="cm:folder.get.html.ftl">
<view:aspects>
<cm:titled></cm:titled>
<cm:author></cm:author>
<app:inlineeditable></app:inlineeditable>
</view:aspects>
<view:properties>
<app:editInline>true</app:editInline>
<cm:description></cm:description>
<cm:content>contentUrl=classpath:alfresco/bootstrap/webscripts/folder.get.html.ftl|mimetype=text/plain|size=|encoding=UTF-8|locale=en_US_</cm:content>
<cm:title>folder.get.html.ftl</cm:title>
<cm:author></cm:author>
<cm:name>folder.get.html.ftl</cm:name>
</view:properties>
<view:associations></view:associations>
</cm:content>
</cm:contains>
</view:associations>
</cm:folder>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<response>
<code>${status.code}</code>
<codeName>${status.codeName}</codeName>
<codeDescription>${status.codeDescription}</codeDescription>
<message>${status.message}</message>
</response>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<generator version="${server.version}">Alfresco (${server.edition})</generator>
<title>Blog query: ${args.q}</title>
<updated>${xmldate(date)}</updated>
<icon>${absurl(url.context)}/images/logo/AlfrescoLogo16.ico</icon>
<#list resultset as node>
<entry>
<title>${node.name}</title>
<link rel="alternate" href="${absurl(url.serviceContext)}/api/node/content/${node.nodeRef.storeRef.protocol}/${node.nodeRef.storeRef.identifier}/${node.nodeRef.id}/${node.name?url}"/>
<icon>${absurl(url.context)}${node.icon16}</icon>
<id>urn:uuid:${node.id}</id>
<updated>${xmldate(node.properties.modified)}</updated>
<summary>${node.properties.description!""}</summary>
<author>
<name>${node.properties.creator}</name>
</author>
</entry>
</#list>
</feed>

View File

@@ -0,0 +1,11 @@
<webscript>
<shortname>Blog Search Sample</shortname>
<description>Sample that finds all blog entries whose content contains the specified search term</description>
<url>/sample/blog/search?q={searchTerm}</url>
<url>/sample/blog/search.atom?q={searchTerm}</url>
<url>/sample/b/s?q={searchTerm}</url>
<url>/sample/b/s.atom?q={searchTerm}</url>
<format default="html">extension</format>
<authentication>guest</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -0,0 +1,5 @@
<html>
<body>
${status.message}
</body>
</html>

View File

@@ -0,0 +1,15 @@
<html>
<body>
<img src="${url.context}/images/logo/AlfrescoLogo32.png" alt="Alfresco" />
Blog query: ${args.q}
<br>
<table>
<#list resultset as node>
<tr>
<td><img src="${url.context}${node.icon16}"/>
<td><a href="${url.serviceContext}/api/node/content/${node.nodeRef.storeRef.protocol}/${node.nodeRef.storeRef.identifier}/${node.nodeRef.id}/${node.name?url}">${node.name}</a>
</tr>
</#list>
</table>
</body>
</html>

View File

@@ -0,0 +1,13 @@
// check that search term has been provided
if (args.q == undefined || args.q.length == 0)
{
status.code = 400;
status.message = "Search term has not been provided.";
status.redirect = true;
}
else
{
// perform search
var nodes = search.luceneSearch("TEXT:" + args.q);
model.resultset = nodes;
}

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<response>
<code>${status.code}</code>
<codeName>${status.codeName}</codeName>
<codeDescription>${status.codeDescription}</codeDescription>
<message>${status.message}</message>
</response>

View File

@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<generator version="${server.version}">Alfresco (${server.edition})</generator>
<title>Category search: ${args.c}</title>
<title>Category search: ${url.extension}</title>
<updated>${xmldate(date)}</updated>
<icon>${absurl(url.context)}/images/logo/AlfrescoLogo16.ico</icon>
<#list resultset as node>
<entry>
<title>${node.name}</title>
<link rel="alternate" href="${absurl(url.context)}${node.url}"/>
<link rel="alternate" href="${absurl(url.serviceContext)}/api/node/content/${node.nodeRef.storeRef.protocol}/${node.nodeRef.storeRef.identifier}/${node.nodeRef.id}/${node.name?url}"/>
<icon>${absurl(url.context)}${node.icon16}</icon>
<id>urn:uuid:${node.id}</id>
<updated>${xmldate(node.properties.modified)}</updated>

View File

@@ -1,6 +1,6 @@
<webscript>
<shortname>Category Search</shortname>
<description>Find all blog entries tagged with specified categories</description>
<shortname>Category Search Sample</shortname>
<description>Sample that finds all blog entries tagged with specified categories</description>
<url>/sample/blog/category/{category}</url>
<format default="html">argument</format>
<authentication>guest</authentication>

View File

@@ -0,0 +1,5 @@
<html>
<body>
${status.message}
</body>
</html>

View File

@@ -1,13 +1,13 @@
<html>
<body>
<img src="${url.context}/images/logo/AlfrescoLogo32.png" alt="Alfresco" />
Category search: ${args.c}
Category search: ${url.extension}
<br>
<table>
<#list resultset as node>
<tr>
<td><img src="${url.context}${node.icon16}"/>
<td><a href="${url.context}${node.url}">${node.name}</a>
<td><a href="${url.serviceContext}/api/node/content/${node.nodeRef.storeRef.protocol}/${node.nodeRef.storeRef.identifier}/${node.nodeRef.id}/${node.name?url}">${node.name}</a>
</tr>
</#list>
</table>

View File

@@ -1,2 +1,15 @@
// check category exists?
var category = search.luceneSearch("PATH:\"/cm:generalclassifiable//cm:" + url.extension);
if (category is null)
{
status.code = 404;
status.message = "Category " + url.extension + " not found.";
status.redirect = true;
return;
}
else
{
// perform category search
var nodes = search.luceneSearch("PATH:\"/cm:generalclassifiable//cm:" + url.extension + "//member\"");
model.resultset = nodes;
}

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<generator version="${server.version}">Alfresco (${server.edition})</generator>
<title>Folder: ${folder.displayPath}/${folder.name}</title>
<updated>${xmldate(date)}</updated>
<icon>${absurl(url.context)}/images/logo/AlfrescoLogo16.ico</icon>
<#list folder.children as child>
<entry>
<title>${child.name}</title>
<#if child.isContainer>
<link rel="alternate" href="${absurl(url.serviceContext)}/sample/folder<@encodepath node=child/>"/>
<#else>
<link rel="alternate" href="${absurl(url.serviceContext)}/api/node/content/${child.nodeRef.storeRef.protocol}/${child.nodeRef.storeRef.identifier}/${child.nodeRef.id}/${child.name?url}"/>
</#if>
<icon>${absurl(url.context)}${child.icon16}</icon>
<id>urn:uuid:${child.id}</id>
<updated>${xmldate(child.properties.modified)}</updated>
<summary>${child.properties.description!""}</summary>
<author>
<name>${child.properties.creator}</name>
</author>
</entry>
</#list>
</feed>
<#macro encodepath node><#if node.parent?exists><@encodepath node=node.parent/>/${node.name?url}</#if></#macro>

View File

@@ -0,0 +1,8 @@
<webscript>
<shortname>Folder Listing Sample</shortname>
<description>Sample demonstrating the listing of folder contents</description>
<url>/sample/folder/{path}</url>
<format default="html">argument</format>
<authentication>guest</authentication>
<transaction>required</transaction>
</webscript>

View File

@@ -0,0 +1,27 @@
<html>
<head>
<title>${folder.displayPath}/${folder.name}</title>
</head>
<body>
Folder: ${folder.displayPath}/${folder.name}
<br>
<table>
<#if folder.parent.parent?exists>
<tr>
<td><td><a href="${url.serviceContext}/sample/folder<@encodepath node=folder.parent/>">..</a>
</tr>
</#if>
<#list folder.children as child>
<tr>
<#if child.isContainer>
<td>&gt;<td><a href="${url.serviceContext}/sample/folder<@encodepath node=child/>">${child.name}</a>
<#else>
<td><td><a href="${url.serviceContext}/api/node/content/${child.nodeRef.storeRef.protocol}/${child.nodeRef.storeRef.identifier}/${child.nodeRef.id}/${child.name?url}">${child.name}</a>
</#if>
</tr>
</#list>
</table>
</body>
</html>
<#macro encodepath node><#if node.parent?exists><@encodepath node=node.parent/>/${node.name?url}</#if></#macro>

View File

@@ -0,0 +1,10 @@
// locate folder by path
// NOTE: only supports path beneath company home, not from root
var folder = roothome.childByNamePath(url.extension);
if (folder == undefined || !folder.isContainer)
{
status.code = 404;
status.message = "Folder " + url.extension + " not found.";
status.redirect = true;
}
model.folder = folder;