Friday, January 9, 2009

Tutorial: Building Alfresco web scripts, deploying as Liferay Portlets - Part 2

Creating a Web Script using JavaScript API

Step 1: Define the Web Script
As you know, to define a web script, we need to have:
  1. A description xml file, in our case the name would be helloworld.get.desc.xml
  2. An FTL file generating HTML code, in our case the name would be helloworld.get.html.ftl
  3. A JS file, in our case the name would be helloworld.get.js. Note that, this JS is technically not mandatory; however, in practical situation you cannot live without this, because this is only place where you write the business logic of your web script, and return some data.
These files need to be created in C:\mystackroot\webapps\alfresco\WEB-INF\classes\alfresco\templates\webscripts\ folder hierarchy.
  • Create subfolder hierarchy com\infoaxon\repository under C:\mystackroot\webapps\alfresco\WEB-INF\classes\alfresco\templates\webscripts\ folder.
  • Note that, maintaining this folder hierarchy is not mandatory; this is just because of good practice to group your web scripts. Technically as per alfresco, it will pick up all items which are defined as web scripts under the templates\webscripts\ folder.
  • Under the repository folder, create the following three files:


helloworld.get.desc.xml
<webscript>
<shortname>helloworld</shortname>
<description>helloworld</description>
<url>/infoaxon/helloworld</url>
</webscript>

helloworld.get.html.ftl
<html>
<body>
<p>Wow, this is quite ${jstext}, rather.</p>
</body>
</html>

helloworld.get.js
model.jstext = "Simple";

Step 2: Start Server, Test your Web Script
That’s it, that’s really it, you have just created your first JavaScript based custom web script.
  • Start tomcat server
  • In your favourite browser, navigate to http://localhost:8080/alfresco/service/index. Find your web script and test whether it is working, but just clicking on it.
  • Since, you have created a HTTP GET Web Script, you can invoke and test the service by typing URL in your browser http://localhost:8080/alfresco/service/infoaxon/helloworld. Note that, this is the URL which you have defined in your configuration XML file.
In the next installment of this tutorial, we will discuss about how we can create a simple helloworld web script using java.

Sunday, September 28, 2008

Tutorial: Building Alfresco web scripts, deploying as Liferay Portlets - Part 1

Web Script Architecture


A Web Script is simply a service bound to a URI which responds to HTTP methods such as GET, POST, PUT and DELETE; which also can be deployed as a JSR portlet is any standard and compatible container.

The basic components of a Web Script are
  1. Declaration XML File.
  2. Presentation Freemarker Template.
  3. Implementation JavaScript and/or Java Code segments, technically optional.
For example, here are three files created for implementing a Web Script, named (everybody's favorite) helloworld.


helloworld.get.xml

helloworld.get.html.ftl

helloworld.get.js



The XML file defines the URI and other behaviors of the web script.
The Freemarker (FTL) file constructs final contents returned by the web script.
The JavaScript (JS) file builds the business rules implementations for the web script.

You can return a variety of different data from the web script, by defining different FTL templates. In our example, we have defined only one output type - HTML, since we have created one FTL file - helloworld.get.html.ftl. Similarly define other templates to return other data structures such as
  • text => text/plain
  • xml => text/xml
  • atom => application/atom+xml
  • rss => application/rss+xml
  • json => application/json
The JS file is a plain JavaScript file written using JavaScript APIs.

The business layer of the Web Script can be developed either or both in JavaScript and Java. In this tutorial, we would discuss both the approaches and how to deploy the web script as a JSR-168 portlet in Liferay.

In the next installment of this tutorial, we will discuss about how we can create a simple helloworld web script using javascript.

Saturday, September 20, 2008

Tutorial: Building Alfresco Web Scripts, deploying as Liferay Portlets - Introduction

Today, in ever-growing world of Knowledge Management Alfresco has established itself as the most competent Open Source alternative.

In addition of being Open Source and its flexible licensing model (GPL), its dynamic design and extensibility makes it one of the most palpable choices in this domain today.

As it says
  • 5 Times Faster than Traditional Closed Systems
  • 10 Times Cheaper than Traditional Closed Systems
One of its smart innovation is the Web Scripts. A few cool features are offered by this model:
  • Web Scripts are by default exposed as REST services which can return data in various formats like HTML, XML, ATOM, JSON
  • Web Scripts, after a little pain, can be deployed as JSR portlets in any JSR container
Thus, this makes a commendable choice to develop applications over Alfresco.

This set of posts discusses how Web Scripts can be developed in Alfresco, and deployed in a JSR container such as Liferay.

However, this does assume that you have knowledge about Alfresco Web Scripts, Liferay Portal and a brief knowledge on their architecture. This also assumes you have already deployed Alfresco in Liferay context.