Wednesday, July 25, 2012

How to enable DQL tracing

I am currently analyzing some Documentum performance issues. To be able to reconstruct the problem maybe more easier or to check the database indexes it is useful to identify the problematic DQL queries. DQL is Documentum's Query Language. In fact a DQL statement is translated into an SQL one. The Documentum Administrator can return you the SQL for every running DQL. So what you need to get the DQL is to add the following lines to your dfc.properties file on side of your Content Server installation (E.G. ./product/6.5/shared/config/dfc.properties):
dfc.tracing.enabled = false
dfc.tracing.recordParameters = on
dfc.tracing.recordReturnValue = on
dfc.tracing.stackDepth = 100
dfc.tracing.combineDMCL = on
dfc.tracing.dir = /tmp/dfclogs
Any further ideas how to trace the DQL? Then just post a comment to this article!

Wednesday, June 20, 2012

A simple pinboard dashlet

0.) Preamble

This example shows how you could develop simple Alfresco Dashlets. So here some requirements:

  • A dashlet is required to see and post short messages
  • Everybody should be able to post messages to the specific site where the dashlet is available.
1.) Define the Content Model 

At first we need to define the content model for our pinboard entry type. The content model looks as the following:


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

<!-- Model definition -->
<model name="ecg:pinboardmodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">

    <!-- Optional meta-data about the model -->
    <description> The pinboard model </description>
    <author> David Maier </author>
    <version> 1.0 </version>

    <!-- Imports are required to reference definitions in other models -->
    <imports>
           <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d" />
           <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm" />
    </imports>

    <!-- The name space of our model -->
    <namespaces>
           <namespace uri="http://www.ecmgeek.de/model/content/1.0" prefix="ecg" />
    </namespaces>
   

    <!-- Content types -->
    <types>
   
           <!-- Default types -->
          <type name="ecg:document">
            <title>Document</title>
            <parent>cm:content</parent>
         </type>
        
         <type name="ecg:folder">
            <title>Folder</title>
            <parent>cm:folder</parent>        
         </type>

           <!-- Specific types -->
           <type name="ecg:pinboardentry">
              <title>PinboardEntry</title>
              <parent>ecg:document</parent>
              <properties>
                 <property name="ecg:subject">
                    <type>d:text</type>
                 </property>
                 <property name="ecg:description">
                    <type>d:text</type>
                 </property>
              </properties>
           </type>         
</types>
</model>

You can see that we just extended the default types by deriving the type 'ecg:pinboardentry'.

I deployed the model by just adding it to the Data Dictionary.

2.) Prepare the site 

The next step is to prepare the site which you would like to use. This I just created a subfolder 'pinBoard' inside the site's folder.

3.) Create Data Web Scripts

Two Web Scripts are required. One to add a pinboard entry to a specific site and another one to get all pinboard entries from a specific site.

3.1.) Add entry Web Script 

Here the descriptor:
pinboardadd.get.desc.xml
<?xml version="1.0" encoding="UTF-8"?>
<webscript>
    <shortname>Add Pinboard entry</shortname>
    <description>To add a pinboard entry</description>
    <url>/alfintra/pinboard/add?name={nameArgument}&amp;desc={descArgument}&amp;site={siteArgument}</url>
    <format default="xml">extension</format>
    <authentication>user</authentication>
    <transaction>required</transaction>
</webscript>

And the Java Script controller:

pinboardadd.get.js
/**
 * Arguments
 */
//The target site name
var siteName = args["site"];

//The name of the future entry
var entryName = args["name"];

//The description of the future entry
var entryDesc = args["desc"];


/**
 * Argument validation
 */
var siteFolder = companyhome.childByNamePath("Sites/" + siteName + "/pinBoard" );

if (siteFolder == undefined )
{
   status.code = 404;
   logger.log(status.code);
   status.message = "The site's pinBoard folder was not found. Did you prepare your site in order to use the pinboard?";
   logger.log(status.message);
   status.redirect = true;
}
else
{
    addPinboardEntry(siteFolder, entryName, entryDesc);
}


/**
 * Script logic
 */
function addPinboardEntry(siteFolder, entryName, entryDesc)
{
    logger.log("Entering addPinboardEntry");
   
    logger.log("Setting properties");
      var props = new Array();
    props["ecg:subject"] = entryName;
    props["ecg:description"]= entryDesc;
       
    logger.log("Creating node");
      siteFolder.createNode(entryName,"ecg:pinboardentry", props);

    logger.log("Setting model");
     model.created = "true";

    logger.log("Leaving addPinboardEntry");
}

Finally the presentation template. This template shows nothing. It just redirects to the page from which the html page was called.

pinboardadd.get.html.ftl
<script type="text/javascript">

  var ref = document.referrer;
  location.replace(ref);
</script>

3.2.) Get entries Web Script

Here the descriptor:

pinboardlist.get.desc.xml 
<?xml version="1.0" encoding="UTF-8"?>
<webscript>
    <shortname>List pinboard entries</shortname>
    <description>To list the pinboard entries of a site</description>
    <url>/alfintra/pinboard/list?site={siteArgument}</url>
    <format default="xml">extension</format>
    <authentication>user</authentication>
    <transaction>required</transaction>
</webscript>

 The Java Script controller:

pinboardlist.get.js
/**
 * Arguments
 */

//The target site name
var siteName = args["site"];

/**
 * Argument validation
 */
var siteFolder = companyhome.childByNamePath("Sites/" + siteName + "/pinBoard" );

if (siteFolder == undefined )
{
   status.code = 404;
   logger.log(status.code);
   status.message = "The site's pinBoard folder was not found.";
   logger.log(status.message);
   status.redirect = true;
}
else
{
    listPinboardEntries(siteFolder);
}

function listPinboardEntries(siteFolder)
{
    logger.log("Entering listPinboardEntries");
      logger.log("Getting all childs");
    model.entries = siteFolder.children;
    logger.log("Leaving listPinboardEntries");   
}

The JSON output:

pinboardlist.get.json.ftl
<#escape x as jsonUtils.encodeJSONString(x)>
{
"pinboard":
  {
   "entries":
    [
        <#list entries as node>
              <#if node.properties["ecg:subject"]?exists>
                   <#if node.properties["ecg:description"]?exists>  
        {"name":"${node.properties['ecg:subject']}", "desc":"${node.properties['ecg:description']}", "site":"${args.site}"}
       <#if node_has_next>,</#if>                  
                  </#if>
            </#if>
    </#list>
    ]
 }
}
</#escape>

4.) Create the Dashlet
The idea is now that that the controller of the Web Script accesses the data which is provided by the data web script. The controller passes the data to the model and the presentation template renders it inside a dashlet. The content is presented within the dashlet's body container.

To create a new entry the URL of the 'Add Entry' Web Script is called as a form action. Here we do not use AJAX, instead a simple HTML form is used to call the entry creating Web Script. After this Web Script is called, it just redirects back to the previous page. By using additional Java Script inside the presentation template, it should be also possible to perform such an action without the need to redirect to the previous called page by refreshing this one. However, the dashlet shows how the interaction with the Data Web Scripts can basically work. The form is presented within the dashlet' toolbar container.

So what we need at first is a Dashlet Descriptor:

.../site-webscripts/de/ecmgeek/components/dashlets/pinboardlist.get.desc.xml
 <webscript>
    <shortname>List pinboard entries</shortname>
    <description>To list pinboard entries</description>
    <family>site-dashlet</family>
    <url>/components/dashlets/pinboardlist</url>
</webscript>

We also need a controller which gets the data from our Data Web Script and passes it to the model:

.../site-webscripts/de/ecmgeek/components/dashlets/pinboardlist.get.js
var siteName = page.url.templateArgs.site;
var data = remote.call("/alfintra/pinboard/list.json?site=" + siteName);
var results = eval('(' + data + ')');

model.entries = results.pinboard.entries;
Finally we need to create the dashlet's UI. You could basically add any HTML which you want to the dashlet's html template. But to integrate better with Alfresco, you should at least define the following containers:
  • dashlet
    • toolbar
    • body
 If you want that your dashlet is resizable you should also instantiate an Alfresco Dashlet Resizer by using the following line inside a JavaScript block:
  •  new Alfresco.widget.DashletResizer("${args.htmlid}", "${instance.object.id}");)
Interesting to know is that Alfresco Share comes with a Proxy servlet which allows you to access the Data Web Scripts of the Alfresco Repository. This proxy can be also used to avoid problems with the same origin policy if using client side Java Script to access the Data Web Script.

Our dashlet code looks now as the following:

 .../site-webscripts/de/ecmgeek/components/dashlets/pinboardlist.get.html.ftl

<script type="text/javascript">//<![CDATA[
   
   //Make the dashlet resizeable
   new Alfresco.widget.DashletResizer("${args.htmlid}", "${instance.object.id}");
//]]>
</script>
 
<div class="dashlet">
    <div class="title">
        ${msg("title")}
    </div>
     
    <div class="toolbar">
        
           <form name="postToPinboardForm" method="get" action="/share/proxy/alfresco/alfintra/pinboard/add.html">
             <table>
                <tr>
                   <td> ${msg("subject")} </td>
                   <td>  ${msg("desc")} </td>
                   <td> &nbsp; </td>        
                </tr>
 
                <tr> 
                   <td> <input type="text" name="name"> </td>
                   <td> <input type="text" name="desc"> </td>
                   <td> <input type="hidden" name="site" value="${page.url.templateArgs.site}"></td>
                   <td> <input type="submit" value="Post"> </td>
                </tr>
             </table>
            </form>        
    </div>
     
 
    <div class="body  scrollableList" id="${args.htmlid}-body">
  
        <table>
       
        <#list entries as e>
              <tr> <td> <b> ${e.name} </b> </td> </tr>
              <tr> <td> ${e.desc} </td> </tr>
              <tr> <td> &nbsp; </td> </tr>
        </#list>
 
        </table>
     
    </div>
</div>

The template reads some properties from the following properties file (or message bundle):

 .../site-webscripts/de/ecmgeek/components/dashlets/pinboardlist.get.properties
title=Pinboard
subject=Subject
desc=Description

Even if this is not the most complicated dashlet, I hope that it may help you to get started with dashlet development. Finally the dashlet looks this way:








 

Tuesday, June 12, 2012

Theme it

Today I had to investigate how to add a custom theme to my Alfresco 4.x installation. Some parts were a bit tricky, but the most of it was quite simple. Here some useful steps:

  1. Navigate to $WEBAPPS/share/WEB-INF/classes/alfresco/site-data/themes . BTW: $WEBAPPS is the deployment folder of your servlet container.
  2. Copy the file yellowTheme.xml to myTheme.xml
  3. Edit the file myTheme.xml by setting the title and the id. The id has to be 'theme.myTheme'
  4. Navigate to $WEBAPPS/themes!
  5. Make a copy of the complete folder 'yellowTheme' by naming it to 'myTheme'.
  6. Naviagate to $WEBAPPS/themes/myTheme/images!
  7. Open all the images by using E.G. the G(nu) I(mage) M(anipulation) P(rogram) . The Command is 'gimp'. Then colorize the images to fit your required base color. I just colorized every image which had a yellow color before. The main loge image is named 'app_logo.png' and can be replaced by your prefered one.
  8. Navigate back to $WEBAPPS/themes/myTheme!
  9. Edit the file presentation.css by setting the required colors. Again, I just copied the color codes to GIMP by only replacing the yellow color tones with my prefered ones.
  10. Now the tricky part. There are some css dependencies those need to be changed inside this file. So just replace every occurrence of 'yellowTheme' with 'myTheme' inside this file.
  11. Naviagete to $WEBAPPS/themes/myTheme/yui/assets
  12. Inside the file 'skin.css', also replace every occurrence of 'yellowTheme' with 'myTheme'.
  13. Restart Alfresco
  14. Open Alfresco Share, create a new site and choose the entry 'myTheme' as the site theme.
  15. Perform some CSS changes by being able to test your changes immediately by refreshing the just created site.
  16. Open the Administration Console and set the theme 'myTheme' as the gloabl one.
I hope this article helps you to get quickly started with customizing your Alfresco theme.

Friday, April 27, 2012

Alfresco cloud service

Alfresco started a cloud service. More detailed it is is an instance of Alfresco Share which is avaiable in the WWW. The smallest offering is for FREE and it allows you to use Share functions like:
  • The document library
  • The dashboard
  • Collaborate on documents
  • Manage site members
Further features and space is available for monthly fees. However, if you want to try it out then it is possible to register here: http://cloud.alfresco.com .

I just created an instance for magicable.de and created two user accounts. However both have to log-in to be able to see the content. So this service is not suitable for sharing your content accross the web. It's more for companies or cloesed communities those need to access and collaborate on their documents inside the web. So there seems to be no guest access to your Share instance in the cloud.

Unfortunately the free instance does not allow to access it via an API. So you can't use it as content repo in the web. As far as I understand this functionality will be available later for the paid version of it.

However, if you want to store some documents online (including meta data - this is something which can't drop box do for you), then Alfresco in the Cloud may be an alternative for you.
 

Are we brain-washed?

In fact I am coming from the database world. This means I worked as an Engineer for the vendor of an relational database and also did Consulting for a No-SQL company. In both cases I had contact with ECM and related systems. So as I worked for Ingres I did Partner Certification work for systems like Alfresco and Liferay. In the past the system borders of an ECM system were very clear to me. So everything beyond the storage of just Meta Data was out of the scope of the Database System itself. I became a 'border liner' during my time as a Senior Consultant for a Graph Database System. The vertices could store not just meta data but also provide you a Content Stream. The system aimed to support unstructured data very well (as mentioned it supported Content streams and also something that was named Undefined Attribute). There were even Document Management use cases those were covered by this system. However ... . During my work with ECM, I realized that ECM companies understand themself more and more as Data Management companies. (Another point seems to be that today everything has to be Social or in the Cloud.) We tend to see everything as document. By definition a document is a set of properties thoses are used to store the meta data and the content itself. This raises questions like:
  • Is a document without content really a document?
  • Is really everything which has meta data and content a document?
I am sure the answer is 'It depends', but I think we should go back to the roots by not using ECM-Systems like Databases. We should ask questions like:
  • Is there a real paper document involved in a given use case?
  • Are there some real workflows with real persons those are handling real documents?
  • What should the person know about the document?
If the answer is 'Yes', then we can be sure that  we are doing right by storing a digital document which has the right set of properties regarding the given processes and requirements.

But what's if the answer is 'No'. In my opinion we should then not use an ECM/DM system to store such data, even if we want to do it because it seems to be close because there is already one available. Just use a Database System (NoSQL or Relational, whatever the use cases are requiring) to store the data regarding the required data model. Be not brain-wahsed! Do not belive that ECM solves all your Data Management problems and the answers to the above questions will be often (but not every time):
  • A document without content should be an object in a datbase (row, vertex, ...).
  • Not everything which has meta data and content is really a document!
What do you think about?


Monday, April 16, 2012

Alfresco Web Scripts

A few days ago I talked about 'Server side Java Script'. This post describes a technique which is named 'Web Script' and explains for which purpose it could be useful. With Web Scripts Alfresco allows to easily deploy content oriented RESTFul Web Services to the Repository. The logic behind these services is then often realized by using Java Script.

A Web Script contains 4 pieces:
  • A descriptor file
  • A Java Script (or a Java Class)
  • A freemarker template
  • Language bundles
The descriptor describes how (which URL) and who can run the Web Script. The Java Script file works as a kind of Controller by setting a model. The Freemarker template contains the presentation logic and the language bundles are allowing multi language support.

Let's begin by investigating the Desctiptor file in detail. Such an descriptor contains:
  • The short name (shortname)
  • The description (description)
  • The url by including the parameters (url)
  • The default format
  • The authentication method
Here some example code:

<webscript>
  <shortname>Hello World</shortname>
  <description>Greet a user</description>
  <url>/helloworld?to={name?}</url>
  <url>/hello/world?to={name?}</url>
  <format default="html">extension</format>
  <authentication>user</authentication>
</webscript>
 Above you can see a Web Script which has the name 'Hello Word'. It 'Greets a user'. The URL is mapped to '/helloworld', whereby one Parameter 'to' is expected. The default response should be 'html' and a user authentication is required in order to execute the script. The value 'extension' means that the requested format is determined by the extension which is used as part of the URL. So for instance 'world.html' or 'world.txt'. As authentication the following values are possible: 'none', 'guest', 'user' or 'admin. Possible formats are: 'html', 'text', 'xml', 'atom', 'rss' or 'json'. There is an optional parameter which is named 'runas'. This parameter is used to execute the Web Script inside the context of another user's session. To be able to fully use this feature it is required that the Web Script is deployed in a static way. (We will talk about the deployment options later in this article.)

What we need next is to investigate the Java Script file. There are specifc naming conventions. So a Java Script which is accessible via HTTP GET should have an Descriptor and a Java Script file which is named as the following:
  • ${id}.${http method}.desc.xml
  • ${id}.${http method}.js
For instance: helloworld.get.desc.xml and helloworld.get.js .



The Java Script file can contain basic Java Script (or even Java because it is interpreted by a Java based engine) and calls of the Alfresco Java Script API.  Let me give you a short overview about this API. It is even useful if you want to implement Actions or Workflows for the Alfresco System. You can think about this Java Script API like a built in language to access Content. If you know Procedural Languages for Database Systems, then you know what I mean. Indeed, the possibilities those are provided by this API are quite beyond the ones of for instance PL/SQL. So even if you are not a Java Script guy, it should be possible to use the API. There are multiple versios of the API available. This article focuses on the 3.4 one.

A script can import another one:

 <import resource="/Company Home/Data Dictionary/Scripts/library.js">
The example above shows a 'dynamic' import. Which means that the imported script is stored in Alfresco itself. It's also possible to just import from the classpath by using "classpath:${path to js}".

 The API provides some root objects. Those objects are available out of the box.

  • companyhome: The company home root folder
  • userhome: The current user's home folder
  • person: The current user object
  • search: The search API
  • people: The people API
  • actions: The action API
  • logger: A logger
  • session: Provides session specific information
  • classification: The classification API
  • utils: Some helpers
  • groups: To access group authorities
  • stites: The sites API
As you can see the API-s can often be accessed by using root object. Often the result of an API call is a document (Or at least the reference to one). If you use the Java Script API, then this is named 'Script Node'. For instance a 'userhome', 'companyhome', 'document', 'space' (Is äquivalent to a folder in Alfresco) or a 'person' is script node. So let's investigate the API-s a little bit more detailed!

The Script Node API has the following important methods:
  • properties
  • children
  • assocs
  • aspects
  • content
  • id
  • nodeRef
  • name
  • type
  • parents
  • childByNamePath
  • getSite
  For all of you who are not such familar with Alfresco: A node has a specific type. A type defines a set of properties. So Properties can be inherited by creating sub-types. An aspect is a bag of properties which can be assigned to a type independent from the inheritance hierarchy.  A node can also have associations to other nodes. A specific association is the child association (if you delete the parent then the childs will become deleted, too).

The properties attribute is an associative array. You can access it by using 'node.properties.propx' or 'node.properties["propx"]'.

Beyond the Script Node API there is also the "Modify and Creating" API. Here some important methods:
  • createFile
  • createFolder
  • createNode
  • addNode (as child)
  • removeNode (remove child assocs)
  • createAssociation
  • move
  • copy
  • addAspect
Also as an extension of the Script Node API, you can think of the Check-in/out and Versioning API
  • checkout
  • checkin
  • cancelCheckout
  • isVersioned
  • versionHistory
  • getVersion
  • createdDate
  • creator
  • label
  • type
  • descrption
  • nodeRef
  • node
The methods are used the same way as the Script node API ones.

The content of the node was accessed by using the content attribute. This one provides the following API:
  • mimetype
  • encoding
  • size
  • url
  • downloadURL
So a node can also have content of a specific mime type.

The search API allows you to search for specific documents. The following methods are part of the search API:
  • luceneSearch
  • xpathSearch
  • savedSearch
  • findNode (by given node reference)
  • query (by using an object which consists a search method and the search query)
The following query is a CMIS one:

var query = {query: "SELECT e.* FROM ecg:mytype AS e WHERE e.ecg:myprop=" + myvar, language: "cmis-alfresco"};

 The people API allows to handle users those are stored inside Alfresco. Here the methods of it:
  • createPerson
  • deletePerson
  • getGroup
  • createGroup
  • parentGroup
  • getMembers
  • isAdmin
  • changePassword
  • setPassword
 The Actions API is used to create an Action object. Then the actions parameters can be set. Afterwards it is possible to execute the action:

var myaction = create("myaction");
myaction.parameters.myparam = 'myvalue';
myaction.execute;
 The classification API provides the following methods:
  • getAllCategoryNodes
  • getAllClassificationAspects
  • createRootCategory
  • isCategory
  • categoryMembers
  • subCategories
  • createSubCategory
  • removeCategory
This section covered not all available API-s. Further more there are the Permission API, the Transformation API, the Thumbnailing API, the Tagging API, the Workflow API, the AVM API and the WCM API.

A special root object for Web Scripts is the one which is named 'model'. It allows you to set the result of the execution of you web script. Here an example:

var username = person.properties.userName;
model.username = username;
The model object is used to transfer data from the controlling Web Script to the Freemarker template. So let's take a closer look on Freemarker templates!

Basically a freemarker template can be anything which is textual. So you can write it as html, as text as xml. The idea behind it is to use some static text with some dynamic text from the model. There is a whole language about this freemarker stuff. We just look on the most important parts:
  • Place holders
  • Data model
  • Variables and Types
  • Sequences
  • Directives
  • Comments
  • Built-ins
Place holders can be found as ${myPlaceholder} inside the template. Such a placeholder will then become replaced regarding the data from the model.

The data model is a Tree and can be set. Every value which you access via a place holder is stored inside the data model. Everything which is not a leaf inside the data model's tree is named 'Hash'. The variables inside the tree those are storing single values (the leafs of the tree) are named 'Scalars'. You can navigate through the model's tree by using indexes. For instance 'animals[0].name'.  Scalars are typed: String, Number, Date/Time, Boolean .

Sequences are lists of strings:

["myval1", ... , "myvaln"]

There are several directives. The 'if' directive looks as the following:

<#if myvar = "mystringval">  My text <#else> My other text </#if>
Possible operators are: <, >, !=, = .

The list directive is used to itterate over elements of the data model.

<# list myhashvar as myvar> ${myvar.myscalarvar} </#list>
 <# list myseq as myvar> ${myvar} </#list>

The include directive can be used to insert content from another file to the template:

<#include "/myfile.html">
It is possible to create user defined directives the following way:

<@mydirective myparam1=myval1, ... myparamn=myvaln>
    <#--   Some commands --#>
</@mydirective>
 Comments are used the following way:
<#-- My comment --#>
The following built in functions are available:

  • myvar!"My optional value": Uses the optional value if  myvar is not set
  • myvar??: Returns true if myvar is set
  • myvar?upper_case: Returns the variable value in upper case letters
  • myvar?cap_first: Converts the first letter to upper case
  • myvar?trim
  • myvar?size
  • myvar?int: The integer part of a number (E.G. 5 in case of 5.432)
  • myvar?string_short: Date to String conversion
  • myvar?foo:string : Boolean to Strng conversion 
Alfresco extended the capabilities of Freemarker templates a bit, so that you can access some specific API elements directly from the Freemarker Template without the need of a Java Script as the controller. However, I would recommend to stay with the MVC-pattern!

Let's now investigate how multiple languages are supported. The default message bundle is a properties-file with the following name:
  • ${id}.${http method}.properties
 To support multiple languages, you can create a new file which is named:
  • ${id}.${method}_${locale}.properties
The messages are then accessible directly from your Freemarker template via a function call:

 ${msg("myprop")}
So the final question of this article is: How can I deploy and use such a Web Script. There are multiple ways to deploy a web script:
  • Dynamic deployment: To the Content Repository itself. Which mean you need to import it to 'Data Dictionary/Web Scripts' or 'Data Dictionary/Web Script Extensions' (The second folder should be used to override scripts from the first folder for testing purposes.)
  • Static deployment by copying the folder which contains the Web Script files  to ${CATALINA_HOME}/webapps/alfresco/WEB-INF/classes/alfresco/templates/webscripts. This can be simplified by bundling the Web Script into an Alfresco Module Package.
  • Extension deployment by copying the folder which contains the Web Script files to ${CATALINA_HOME}/shared/classes/alfresco/extension/templates/webscripts
Afterwards you have to refresh the list of available Web Scripts. No server restart is required:

  • Navigate to 'http://${myhost}:8080/alfresco/service/index'
  • Click on the 'Refresh Web Scripts' button

Sunday, March 11, 2012

Server side JavaScript

I really do not like the idea to use server side Java Script. In fact I am really hating Java Script even on the client side. I everytime worked arround even the client side one by using the GWT framework. (GWT allows you to write Java code which will become translated to JavaScript. So my question was "Why the hell should anybody like to have server side Java Script?". There two different answers from two different perspectives:
  • As a Developer for Alfresco, you just need (not really you can also use the more complicated Java API) to know that it is existent, because they invented something which is called WebScript.
  • Because it is interpreted code, it is really more flexible. So you can just change it on runtime. A JavaScript engine then is used to just execute your code. Such an engine is E.G. Rhino

WebScripts
A WebScript is just a JavaScript file which can be accessed as a RESTFul service. It sets some output model which is then used together with a Freemarker template to generate the response. So it is following a Model View Controller concept. The WebScript takes the role of the controller. It has access to a model. A freemarker template is used for the View. (This could be HTML or just JSON or plain TXT) A WebScript has access to Alfresco-s JavaScript API. (http://wiki.alfresco.com/wiki/3.4_JavaScript_API). So it can access content by providing some output (E.G. the content properties as XML). The advantage is that you can just deploy content oriented RESTFul Web Services without the need to restart your Servlet-Container or Application server. Alfresco is using it quite often, even for their Share-Dahslets. Meanwhile it also became added to the Spring Web-Framework (http://www.springsource.org/extensions/se-surf)

Rhino
Rhino is a JavaScript engine which is implemented in Java. You can just use it to extend your own Java application to support JavaScript. Further information are available here: http://www.mozilla.org/rhino/

What's your opinion about server side JavaScript? Just give me some comments!