Version 12 (modified by tobi, 6 years ago)

Fixed false wiki links and page outline

AsyncRequest

This module provides a neat way to process time-consuming tasks which otherwise would pose the risk of a request timeout. Instead of fiddling around with scheduler or cron methods, you simply call the desired method from within a client's request. AsyncRequest then starts the method and immediately returns from the method call. Thus, the response can be quickly sent back to the browser - of course without stopping the running method.

Example:

global.hare = function(msg) {
   var n = 0;
   while (n++ < 100000) {
      app.log(msg);
   }
   return;
};
var async = new jala.AsyncRequest(global, "hare", ["Zzzzzz!"]);
async.evaluate();
res.write("...he saw the Tortoise had reached the goal, and was comfortably dozing after his fatigue.");

Captcha

A captcha (an acronym for "completely automated public Turing test to tell computers and humans apart") is a type of challenge-response test used in computing to determine whether or not the user is human.

Example:

Root.prototype.main_action = function() {
   res.write('<form action="validate" method="post">');
   res.write('<img id="captcha" src="captcha" border="1" /><br />');
   res.write('<input type="text" name="input" />');
   res.write('<input type="submit" name="submit" />');
   res.write('</form>');
   return;
};

Root.prototype.image_action = function() {
   session.data.captcha  = new onLib.Captcha();
   session.data.captcha.renderImage();
   return;
};

Root.prototype.validate_action = function() {
   if (session.data.captcha && 
       req.data.input && 
       session.data.captcha.validate(req.data.input)) {
      res.write("OK");
   } else {
      res.write("KO");
   }
   return;
};

History

This class is an implementation of a Browser-like history stack suitable to use in any Helma application. The difference to a Browser's history is that this implementation ignores POST requests and checks if URLs in the stack are still valid to prevent eg. redirections to a HopObject's url that has been deleted. Plus it is capable to create new "intermediate" history-stacks and this way maintain a "history of histories" which is needed for eg. editing sessions in a popup window that should use their own request history without interfering with the history of the main window.

HtmlDocument

This class provides easy access to the elements of an arbitrary HTML document. By using TagSoup, Dom4J and Jaxen even invalid HTML can be parsed, turned into an object tree and easily be processed with XPath expressions.

Example:

var mime = getURL("http://helma.org");
var doc = new jala.HtmlDocument(mime.getText());
var links = doc.getLinks();
var i, l;
for (i in links) {
   l = links[i];
   res.write('<a href="' + l.url + '">' + l.text + '</a><br />');
}

I18n

Jala I18n is a JavaScript library providing functionality to internationalize Helma applications. It is compatible with Gnu gettext in that it produces standard PO files for translation purposes and converts PO files into JavaScript message catalog files that can be used within Helma applications.

Being compatible with the widely used GNU gettext format means first of all that translation messages will appear in a readable manner in code and skins of a Helma application, so instead of needing to define more or less cryptic message keys like user.login.error you can put the localized message directly into the application code or skins, eg. "The login failed. Please make sure to specify the correct username and password". As an additional benefit Jala I18n supports parameter substitution, which allows to add dynamic content to translated messages (eg. the current date formatted in a locale specific way, or values formatted using the appropriate currency symbol).

Internationalization based on Jala I18n is done in six steps:

  1. Include the library into your application
  2. Wrap messages that should be translated in specific method calls and/or macros.
  3. Use Jala's HopKit? to generate a PO template file (.pot) containing all messages that should be translated.
  4. Translate the messages using a standard PO file editor (eg. PoEdit) for the desired locales.
  5. Convert the PO files containing the translations into JavaScript message catalog files using Jala's HopKit?.
  6. Include the message catalog files in the application.

ImageFilter

This class provides several image manipulating methods. Most of this filter library is based on filters created by Janne Kipinä for JAlbum. For more information have a look at http://www.ratol.fi/~jakipina/java.

Example:

var filter = new jala.ImageFilter("/tmp/image.gif");
filter.gaussianBlur(30, 0.5);
var img = filter.getImage();
res.writeBinary(img);

IndexManager

This class basically sits on top of a helma.Search.Index instance and provides methods for adding, removing, optimizing and rebuilding the underlying index. All methods except rebuilding are executed asynchronously using an internal queue that contains jobs created for each call of add/remove/optimize. Rebuilding is somehow different as it puts this manager into rebuilding mode where all following calls of add/remove/optimize are queued, but the queue is not flushed until rebuilding has finished. This ensures that objects that have been modified during a rebuilding process are re-indexed properly afterwards.

ListRenderer

This class eases the rendering of arbitrary lists. Such lists can be represented by HopObject collections or Arrays of HopObjects. Various arguments provide customization of the number of items per page, the maximum of pages and so on.

Mp3Info

Wrapper class for the ID3Reader Java package. This class provides easy access to the ID3 tags of an arbitrary MP3-encoded audio file.

Example:

var mp3 = new jala.Mp3Info("/tmp/dolby.mp3");
res.write("'" + mp3.title + "' by " + mp3.artist + 
          " is track no. " + mp3.track + " on the album " + mp3.album);

PodcastWriter

Class to create, modify and render standard-compliant RSS 2.0 feeds including support for Apple's Podcast specification.

RemoteContent

API to define, fetch and update content from a remote site.

Rss20Writer

Class to create, modify and render standard-compliant RSS 2.0 feeds.

XmlRpcRequest

Instances of this class provide the necessary functionality for issueing XmlRpc requests to a remote service.

XmlWriter

This class defines a generic interface to write arbitrary and validating XML source code. This is done by first applying data objects onto template objects, both in a specified format. Then, the resulting object tree is transformed into XML. Moreover, template objects can be extended with other template objects to provide full flexibility in inheriting subclasses.