0% found this document useful (0 votes)
159 views6 pages

Alfresco Java WebScript for Folder Listing

This document describes the files created for an Alfresco custom Java-based webscript, including: 1. A javadir-context.xml file that defines the webscript bean. 2. A javadir.get.desc.xml file that describes the webscript. 3. A javadir.get.html.ftl FreeMarker template to render the response. 4. A JavaDir.class file implementing the webscript Java code. The webscript returns a folder listing, taking optional verbose and folder path parameters, and renders the results using the FTL template. The Java code validates the folder, constructs a model, and returns it for template rendering.

Uploaded by

Anurag Koushik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
159 views6 pages

Alfresco Java WebScript for Folder Listing

This document describes the files created for an Alfresco custom Java-based webscript, including: 1. A javadir-context.xml file that defines the webscript bean. 2. A javadir.get.desc.xml file that describes the webscript. 3. A javadir.get.html.ftl FreeMarker template to render the response. 4. A JavaDir.class file implementing the webscript Java code. The webscript returns a folder listing, taking optional verbose and folder path parameters, and renders the results using the FTL template. The Java code validates the folder, constructs a model, and returns it for template rendering.

Uploaded by

Anurag Koushik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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;

You might also like