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.

No comments:

Post a Comment