Detailed reference of prototypes, properties and methods available in the
Javascript environment of your Helma web applications.

Objects and functions made available in the global scope of the Helma environment.
Object global. global
Built-in reference to the global object.

Useful as a way to access the global scope from within the local scope of a function.

The global object is based on a library scope, compiled from the application's code repositories and is updated automatically whenever any code repositories are modified, without the need to restart/reset a running application. Each request receives a fresh global scope based on the application's library scope.

Modifications to global variables that are defined at compile-time are synchronized between requests, while global variables newly created at runtime are cleared when the current request scope is purged. For global variables created at runtime to survive between requests, they need to be declared once using defineLibraryScope().
see
Object helma
Library object for the HelmaLib javascript library.

HelmaLib is organized into two groups of modules:
  • modules/core which contains extensions to core JavaScript types such as Object, Array, or Date.
  • modules/helma which provides new functionality to JavaScript, usually by wrapping a Java library.


To use a HelmaLib module in your Helma application, you need to add it to the app's repositories. The simplest way to do so is by using the app.addRepository() method:
app.addRepository("modules/helma/Search.js");


If you are looking for more Helma libraries, be sure to check out the Jala project!
see
HopObject root
Represents the root of the object model hierarchy.

Each application has only one root object. This single instance of the root object inherits its properties from the Root prototype, which itself inherits from the HopObject prototype.

The root object serves as the starting point against which the URI path of incoming requests are resolved.
see
PathWrapper path
Accessing objects in the URI path.

The objects in the URI request path are accessible as array members of the global path object as well as named properties of path via their prototype name.

When Helma receives an HTTP request e.g. from a browser, it maps the URI path of the URL to HopObjects. This way, the path is interpreted as an hierarchy of HopObjects.

For instance, if an object in the URI path has a prototype called "story", it will be accessible as path["story"] or path.story.

for (var i=0; i < path.length; i++)
  res.writeln(path[i]);
 
HopObject file
HopObject document
HopObject story
HopObject note
 
var obj = path.story;
res.write(obj);
 
HopObject story
The path object behaves similar to a Javascript array, but it is actually an instance of the Packages.helma.scripting.rhino.PathWrapper Java class.
see
app app
This object is automatically instantiated as the app property of the global object (or global.app) and there is no constructor to instantiate further instances.

The app object is a host object representing the application for which the current scripting environment is provided.

For further details also see the JavaDocs for Packages.helma.framework.core.ApplicationBean. Since that class is a JavaBean all of its get- and set-methods are also directly available as properties of this object.
see
req req
This object is automatically instantiated as the req property of the global object (or global.req) and there is no constructor to instantiate further instances.

The req object is a host object representing the request that is currently handled by the scripting environment.

For further details also see the JavaDocs for Packages.helma.framework.RequestBean. Since that class is a JavaBean all of its get- and set-methods are also directly available as properties of this object.

see
res res
This object is automatically instantiated as the res property of the global object (or global.res) and there is no constructor to instantiate further instances.

The res object is a host object representing the response for the request that is currently handled by the scripting environment.

For further details also see the JavaDocs for Packages.helma.framework.ResponseBean. Since that class is a JavaBean all of its get- and set-methods are also directly available as properties of this object.
see
session session
This object is automatically instantiated as the session property of the global object (or global.session).

The session object is a host object representing the session for the request that is currently handled by the scripting environment.

Each web request is associated with a SessionObject representing a 'user session'. Helma recognises requests being made from the same client within the same session through a session cookie named 'HopSession'. If no such cookie is sent with the request, Helma will set that a cookie with a random hash with the next response.

Within the scripting environment 'session' always represents the current session of the user, who initiated the web request.

Besides that default session object, it is also possible to fetch active sessions of other clients through the method app.getSessions(), and to create additional SessionObjects through app.createSession().

For further details also see the JavaDocs for Packages.helma.framework.core.SessionBean. Since that class is a JavaBean all get- and set-methods are also directly available as properties of that object.
see
Xml Xml
The Xml object provides easy means to convert XML to HopObject and HopObjects to XML.
see
HopObject()
Constructor for HopObject objects, providing the building blocks of the Helma framework.

Extends the standard JavaScript object with Helma-specific properties and functions. The HopObject is the basic building block of a Helma application. The website root object as well as custom types defined by the application inherit from the HopObject prototype.

HopObjects can be given special Helma specific properties, such as "collections" that can be configured to map to relational databases, and will make such data available when rendering "skins".

HopObjects can be in transient state or are persistently mapped on a database. HopObjects that are directly or indirectly attached to the application's root object are automatically persisted using the built-in XML database, if they are not otherwise mapped to a relational database. see JavaDocs for helma.scripting.rhino.HopObject
see
File(filepath)   deprecated use helma.File instead
Constructor for File objects, providing read and write access to the file system.

Example:
var fileOrDir = new File('static/test.txt');
parameters
String filepath as String
see
FtpClient(server)   deprecated use helma.Ftp instead
Constructor for File objects, to send and receive files from an FTP server.

The FTP client needs Daniel Savarese's NetComponents library in the classpath in order to work.

Example:
var ftp = new FtpClient("ftp.mydomain.com");
parameters
String server as String, the address of the FTP Server to connect to
see
Image(url)
Helma's built-in image object allows you to read, manipulate, and save images.

An image object is created using the Image() constructor.

Example:
var img = new Image("http://helma.org/image.gif");
parameters
String url as String
see
Mail()   deprecated use helma.Mail instead
Helma's built-in mail client enables you to send e-mail via SMTP.

A mail client object is created by using the Mail() constructor. The mail object then can be manipulated and sent using the methods listed below.

You'll need the JavaMail library installed for this to work. Also, don't forget to set your mail server via the smtp property in the app.properties or server.properties file.

Note: Make sure that the SMTP server itself is well-configured, so that it accepts e-mails coming from your server and does not deny relaying. Best and fastest configuration is of course if you run your own SMTP server (e.g. postfix) which might be a bit tricky to set up, however.
see
Remote(server)
Constructor for Remote objects, implementing an XML-RPC client.

XML-RPC is a simple framework to enable one machine to execute remote procedures on another using HTTP and XML.

In Helma such calls are performed using a Remote object. Remote objects are created with the URL of the XML-RPC service. Functions of the remote XML-RPC service then can be called just like local functions.

To compensate for the missing exception handling, Remote objects return result wrappers which contain either the result of the remote function, or a description of the error if one occurred.

Example:
var xr = new Remote("http://helma.domain.tld:5056/");
var msg1 = xr.helmaorg.getXmlRpcMessage();
if (msg1.error)
  res.write(msg1.error);
else
  res.write(msg1.result);
 
Hello, Xml-Rpc World!
 
var msg2 = xr.hotelGuide.hotels.grandimperial.getXmlRpcMessage();
if (!msg2.error)
  res.write(msg2.result);
 
Welcome to the Grand Imperial Hotel, Vienna!
 
var msg3 = xr.kolin.document.comments["23"].getXmlRpcMessage();
if (!msg3.error)
  res.write(msg3.result);
 
Here you can write your comments.
 
var xr = new Remote("http://betty.userland.com/RPC2");
var state = xr.examples.getStateName(23);
if (!state.error)
  res.write(state.result);
 
Minnesota
parameters
String server as String
see
User()
The built-in User prototype.

Normally, the User constructor is never called directly and the app.registerUser method is used instead to create new users.
see
Methods
Object. dontEnum(name)
Prevents the specified property from being enumerated.

Useful for example in order to extend the Object and Array prototypes without breaking for/in loops, since the added methods would otherwise get enumerated together with instance properties.
parameters
String name as String, the name of the property that should not be enumerable
authenticate(username, password)
Authenticates a user against a standard Unix password file.

Returns true if the provided credentials match an according entry in the files [AppDir]/passwd or [HelmaHome]/passwd. The stored passwords in these files must be either encrypted with the unix crypt algorithm, or with the MD5 algorithm. The Apache web server provides the utility tool 'htpasswd' to generate such password files.

Example:
var login = authenticate("user", "pass");
if (login)
   res.write("Welcome back!");
else
   res.write("Oops, please try again...");
 
Welcome back!
parameters
String username as String
String password as String
returns
Boolean true or false depending on whether the authentication was successful
createSkin(skin)
Creates a Skin object from the passed String.

The returned object can be passed to the global functions renderSkin, resp. renderSkinAsString.

Skins can also be defined by text files using a *.skin suffix, placed in an application's code repository. The createSkin method provides the ability to create skins dynamically as an alternative.

Example:
var str = "Hello, <% response.body %>!";
var skin = createSkin(str);
res.data.body = "World";
renderSkin(skin);
 
Hello, World!
parameters
String skin as String
returns
Skin generated from the skin string
see
defineLibraryScope(namespace)
Declares a new global variable to not be cleared between requests.
parameters
String namespace as String, the name of the protected namespace
see
deserialize(filename)
Deserialize a JavaScript object that was previously serialized to a file.
parameters
String filename as String, the file to deserialize the object from
returns
Object the deserialized object
encode(text)
Encodes a string for HTML output and inserts linebreak tags.

Performs the following string manipulations:
  • All line breaks (i.e. carriage returns and line feeds) are replaced with <br /> tags.
  • All special characters (i.e. non ASCII) are being replaced with their equivalent HTML entity.
  • Existing markup tags are being encoded.


Example:
var str = encode("<b>Bananer växer\n minsann inte på träd.<b>");
res.write(str);
 
&lt;b&gt;Bananer v&auml;xer
<br /> &lt;br&gt; minsann inte p&aring; tr&auml;d.&lt;/b&gt;
parameters
String text as String
returns
String the modified string
see
encodeForm(text)
Encodes a string for HTML output, leaving linebreaks untouched.

Performs the following string manipulations:
  • Unlike encode, leaves linebreaks untouched. This is what you usually want to do for encoding form content (esp. with text input values).
  • All special characters (i.e. non ASCII) are being replaced with their equivalent HTML entity.
  • Existing markup tags are being encoded.


Example:
var str = encodeForm("<b>Bananer växer\n minsann inte på träd.</b>");
res.write(str);
 
&lt;b&gt;Bananer v&auml;xer
minsann inte p&aring; tr&auml;d.&lt;/b&gt;
parameters
String text as String
returns
String the modified string
see
encodeXml(text)
Encodes a string for XML output.

Performs the following string manipulations:
  • All special characters (i.e. non ASCII) are being replaced with their equivalent HTML entity.
  • Existing tags, single and double quotes, as well as ampersands are being encoded.
  • Some invalid XML characters below '0x20' are removed


Example:
var str = encodeXml("<title>Smørebrød</title>");
res.write(str);
 
&lt;title&gt;Smørebr&amp;oslash:d&lt;/title&gt;
parameters
String text as String
returns
String the modified string
see
format(text)
Encodes a string for HTML output, leaving existing markup tags untouched.

Performs the following string manipulations:
  • All line breaks (i.e. carriage returns and line feeds) are replaced with <br /> tags, with the exception of line breaks that follow certain block tags (e.g. table, div, h1, ..).
  • All special characters (i.e. non ASCII) are being replaced with their equivalent HTML entity.


Example:
var str = format("<b>Bananer växer\n minsann inte på träd.</b>");
res.write(str);
 
<b>Bananer v&auml;xer
<br /> minsann inte p&aring; tr&auml;d.</b>
parameters
String text as String
returns
String the modified string
see
formatParagraphs(text)
Encodes a string for HTML output, inserting paragraph tags.

Performs the following string manipulations:
  • Empty lines (double line breaks) are considered to indicate a paragraph, and are surrounded with <p> tags.
  • All single line breaks (i.e. carriage returns and line feeds) are replaced with <br /> tags, with the exception of line breaks that follow certain block tags (e.g. table, div, h1, ..).
  • All special characters (i.e. non ASCII) are being replaced with their equivalent HTML entity.


Example:
var str = format("Smørebrød:\n\n<b>Bananer växer\n minsann inte på träd.</b>");
res.write(str);
 
<p>Sm&oslash;rebr&oslash;d:</p>
 
<p><b>Bananer v&auml;xer
<br /> minsann inte p&aring; tr&auml;d.</b></p>
parameters
String text as String
returns