Alfresco Custom Java Based WebScript
For ease of reference here are the standalone files that were created in this project, along with
their locations:
./tomcat/shared/classes/alfresco/extension/[Link]
./tomcat/shared/classes/alfresco/extension/templates/webscripts/org/example/javadi
[Link]
./tomcat/shared/classes/alfresco/extension/templates/webscripts/org/example/javadi
[Link]
./tomcat/webapps/alfresco/WEB-INF/classes/org/example/[Link]
Step 1:
Location: ./tomcat/shared/classes/alfresco/extension/[Link]
[Link]
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN 2.0//EN'
'[Link]
<beans>
<bean id="[Link]"
class="[Link]" parent="webscript">
<property name="repository" ref="repositoryHelper"/>
</bean>
</beans>
Step 2:
Location:
./tomcat/shared/classes/alfresco/extension/templates/webscripts/org/example/javadi
[Link]
[Link]
<webscript>
<shortname>Folder Listing Utility</shortname>
<description>Java-backed implementation of listing folder contents
</description>
<url>/javadir/{folderpath}?verbose={verbose?}</url>
<authentication>user</authentication>
</webscript>
Step 3:
Location:
./tomcat/shared/classes/alfresco/extension/templates/webscripts/org/example/javadi
[Link]
[Link]
<html>
<head>
<title>Folder ${[Link]}/${[Link]}</title>
</head>
<body>
<p>Alfresco ${[Link]} Edition v${[Link]} : dir</p>
<p>Contents of folder ${[Link]}/${[Link]}</p>
<table>
<#list [Link] as child>
<tr>
<td><#if [Link]>d</#if></td>
<#if verbose>
<td>${[Link]}</td>
<td><#if [Link]>
${[Link]}</#if></td>
<td>${[Link]?date}</td>
</#if>
<td>${[Link]}</td>
</tr>
</#list>
</table>
</body>
</html>
Step 4:
Create .class file for [Link] from eclipse
Location : ./tomcat/webapps/alfresco/WEB-
INF/classes/org/example/[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class JavaDir extends DeclarativeWebScript
private Repository repository;
public void setRepository(Repository repository)
[Link] = repository;
}
protected Map<String, Object> executeImpl(WebScriptRequest req,
Status status, Cache cache)
NodeRef folder;
// extract folder listing arguments from URI
String verboseArg = [Link]("verbose");
Boolean verbose = [Link](verboseArg);
Map<String, String> templateArgs =
[Link]().getTemplateVars();
String folderPath = [Link]("folderpath");
if ([Link]("Company Home")){
folder = [Link]();
else {
String nodePath = "workspace/SpacesStore/" + folderPath;
folder = [Link]("path",
[Link]("/"));
// validate that folder has been found
if (folder == null)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND,
"Folder " + folderPath + " not found");
// construct model for response template to render
Map<String, Object> model = new HashMap<String, Object>();
[Link]("verbose", verbose);
[Link]("folder", folder);
return model;