Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
120 views

Alfresco Custom Java Based WebScript

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)
120 views

Alfresco Custom Java Based WebScript

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
You are on page 1/ 6

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/javadir-context.xml

./tomcat/shared/classes/alfresco/extension/templates/webscripts/org/example/javadi
r.get.desc.xml

./tomcat/shared/classes/alfresco/extension/templates/webscripts/org/example/javadi
r.get.html.ftl

./tomcat/webapps/alfresco/WEB-INF/classes/org/example/JavaDir.class

Step 1:
Location: ./tomcat/shared/classes/alfresco/extension/javadir-context.xml
javadir-context.xml

<?xml version='1.0' encoding='UTF-8'?>

<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN 2.0//EN'

'http://www.springframework.org/dtd/spring-beans-2.0.dtd'>

<beans>

<bean id="webscript.org.example.javadir.get"

class="org.example.JavaDir" parent="webscript">

<property name="repository" ref="repositoryHelper"/>

</bean>

</beans>
Step 2:
Location:
./tomcat/shared/classes/alfresco/extension/templates/webscripts/org/example/javadi
r.get.desc.xml

javadir.get.desc.xml

<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
r.get.html.ftl

javadir.get.html.ftl

<html>

<head>
<title>Folder ${folder.displayPath}/${folder.name}</title>

</head>

<body>

<p>Alfresco ${server.edition} Edition v${server.version} : dir</p>

<p>Contents of folder ${folder.displayPath}/${folder.name}</p>

<table>

<#list folder.children as child>

<tr>

<td><#if child.isContainer>d</#if></td>

<#if verbose>

<td>${child.properties.modifier}</td>

<td><#if child.isDocument>

${child.properties.content.size}</#if></td>

<td>${child.properties.modified?date}</td>

</#if>

<td>${child.name}</td>

</tr>

</#list>

</table>

</body>

</html>

Step 4:
Create .class file for JavaDir.java from eclipse
Location : ./tomcat/webapps/alfresco/WEB-
INF/classes/org/example/JavaDir.class

package org.example;

import java.util.HashMap;

import java.util.Map;

import org.alfresco.repo.model.Repository;

import org.alfresco.service.cmr.repository.NodeRef;

import org.springframework.extensions.webscripts.Cache;

import org.springframework.extensions.webscripts.DeclarativeWebScript;

import org.springframework.extensions.webscripts.Status;

import org.springframework.extensions.webscripts.WebScriptException;

import org.springframework.extensions.webscripts.WebScriptRequest;

public class JavaDir extends DeclarativeWebScript

private Repository repository;

public void setRepository(Repository repository)

this.repository = repository;

}
protected Map<String, Object> executeImpl(WebScriptRequest req,

Status status, Cache cache)

NodeRef folder;

// extract folder listing arguments from URI

String verboseArg = req.getParameter("verbose");

Boolean verbose = Boolean.parseBoolean(verboseArg);

Map<String, String> templateArgs =

req.getServiceMatch().getTemplateVars();

String folderPath = templateArgs.get("folderpath");

if (folderPath.equals("Company Home")){

folder = repository.getCompanyHome();

else {

String nodePath = "workspace/SpacesStore/" + folderPath;

folder = repository.findNodeRef("path",
nodePath.split("/"));

// 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>();

model.put("verbose", verbose);

model.put("folder", folder);

return model;

You might also like