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

global.defineLibraryScope

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

Array
Date
Number
Object
String
helma.Aspects
helma.Chart
helma.Color
helma.Database
helma.File
helma.Ftp
helma.Group
helma.Html
helma.Http
helma.Image
helma.Mail
helma.Search
helma.Skin
helma.Ssh
helma.Url
helma.Zip

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

HopObject

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

Packages.helma.scripting.rhino.PathWrapper

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

app

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

req

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

res

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

session

Xml Xml
The Xml object provides easy means to convert XML to HopObject and HopObjects to XML.
see

Xml

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

HopObject

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

File

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

helma.Ftp
FtpClient

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

Image

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

helma.Mail
Mail

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

Packages.helma.scripting.rhino.extensions.XmlRpcObject

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

User

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

Skin
renderSkin
renderSkinAsString

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

global

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
encodeXml
format
formatParagraphs

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

encode
encodeXml
format
formatParagraphs

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

encode
encodeForm
format
formatParagraphs

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

encode
encodeForm
encodeXml
formatParagraphs

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

| String the modified string

see

encode
encodeForm
encodeXml
format

getDBConnection(datasource) deprecated use helma.Database instead
Connects to a relational database, and returns a DatabaseObject representing that connection.
The Direct DB interface allows the developer to directly access relational databases defined in the db.properties file without going through the Helma object model layer.
The passed string must match one of the data sources being defined in [AppDir]/db.properties, or an error will be thrown. Also see the reference on the DatabaseObject and the documentation for the methods of the returned dbConnection and dbIterator objects.
Example:

    var dbConnection = getDBConnection("db_source_name");

    var dbRowset = dbConnection.executeRetrieval("select title from dummy");
    while (dbRowset.next())
      res.writeln(dbRowset.getColumnItem("title"));

    var deletedRows = dbConnection.executeCommand("delete from foobar");
    if(deletedRows){
      res.writeln(deletedRows + " rows successfully deleted");
    }

See the documentation of the databaseObject for a list of the available methods and properties of the returned object.
parameters

String | datasource | name as String

returns

| Packages.helma.scripting.rhino.extensions.DatabaseObject - a reference to the created db connection

see

Packages.helma.scripting.rhino.extensions.DatabaseObject
DatabaseObject
DatabaseObject.RowSet
helma.Database

getHtmlDocument(source)
Parses an HTML string to an XML DOM tree.
Tries to parse a string to a XML DOM tree using Xerces' HTML parser (nekohtml). The argument must be either a URL, a piece of XML, an InputStream or a Reader. Returns an instance of org.apache.html.dom.HTMLDocumentImpl.
See the JavaDocs for that class for further details.
FIXME: Links to other recommended HTML parsers
parameters

String | source | as String, HTML formatted

returns

| Packages.org.apache.html.dom.HTMLDocumentImpl XML DOM tree object

see

Packages.org.apache.html.dom.HTMLDocumentImpl
getXmlDocument

getProperty(property, defaultvalue)
Looks up a property that was set in app.properties or server.properties Returns any property defined in [AppDir]/app.properties, resp. [HelmaHome]/server.properties that matches the passed property name. This lookup is case-insensitive. Through the optional second parameter it is possible to define a default value that is being returned, in case the property has not been set.
parameters

String | property | as String, the name of the property to look up
String | defaultvalue | as String, optional default/fallback value

returns

| String with the resulting value for the checked property

getURL(url, etagOrDate)
Retrieves a file/document from the passed URL as a MimePart Object, and therefore functions as a minimalist version of a HttpClient. The optional second parameter can either contain a (last-modified) date object, or an eTag string, which will be passed along with the Http request to the specified URL. Also see the reference on the MimePart Object
parameters

String | url | as String
String | etagOrDate | either the etag as String or a Date object

returns

| Packages.helma.util.MimePart MimePart object of received Http response

see

Packages.helma.util.MimePart
mimePart

getXmlDocument(source)
Parses an XML string to an XML DOM tree.
Tries to parse a string to a XML DOM tree using the Crimson' Parser. The argument must be either a URL, a piece of XML, an InputStream or a Reader. Returns an instance of org.apache.crimson.tree.XmlDocument.
See the JavaDocs for that class for further details.
FIXME: Link to JavaDocs and other recommended XML parsers
parameters

String | source | as String, using XML syntax

returns

| Packages.org.apache.crimson.tree.XmlDocument XML DOM tree object

see

getHtmlDocument

renderSkin(skin, params)
Renders the passed SkinObject or a global skin matching the passed name to the response buffer. The properties of the optional parameter object are accessible within the skin through the 'param' macro handler.
parameters

String | skin | as SkinObject or the name of the skin as String
Object | params | as Object, optional properties to be passed to the skin

see

global.renderSkinAsString
HopObject.renderSkin
HopObject.renderSkinAsString

renderSkinAsString(skin, params)
Returns the result of the rendered SkinObject or a rendered global skin matching the passed name. The properties of the optional parameter object are accessible within the skin through the 'param' macro handler.
parameters

String | skin | as SkinObject or the name of the skin as String
Object | params | as Object, optional properties to be passed to the skin

returns

| String of the rendered skin

see

global.renderSkin
HopObject.renderSkin
HopObject.renderSkinAsString

seal(obj)
Seals an object, and prevents any further modifications of that object. If any property is tried to be modified after it has been sealed, an error is thrown.
parameters

Object | obj | that is to be sealed

serialize(obj, filename)
Serialize a JavaScript object to a file.
parameters

Object | obj | as Object, the object to be serialized
String | filename | as String, the file to serialize the object to

stripTags(markup)
Removes any markup tags contained in the passed string, and returns the modified string.
parameters

String | markup | as String, the text that is to be stripped of tags

returns

| String with the tags stripped out

toJava(obj)
Converts a Javascript String, Date, etc to its Java counterpart.
Converts an object into a wrapper that exposes the java methods of the object to JavaScript. This is useful for treating native numbers, strings, etc as their java counterpart such as java.lang.Double, java.lang.String etc.
parameters

Object | obj | as String, Date, Boolean, Number, etc.

returns

| NativeJavaObject wrapping the provided object

unwrapJavaMap(obj)
Unwrap a map previously wrapped using wrapJavaMap().
parameters

Object | obj | as Object, a map previously wrapped using wrapJavaMap()

returns

| Packages.java.util.Map the unwrapped map object

see

Packages.java.util.Map
wrapJavaMap

wrapJavaMap(obj)
Wrap a java.util.Map so that it looks and behaves like a native JS object.
parameters

Packages.java.util.Map | obj | as Packages.java.util.Map to be wrapped

returns

| Object wrapping the map, making it look like a JS object

see

unwrapJavaMap

write(text)
Writes a string to java.lang.System.out, i.e. to the console. Useful for debugging purposes.
parameters

String | text | as String, the message that is to be output

writeln(text)
Writes a string together with a line break to java.lang.System.out, i.e. to the console. Useful for debugging purposes.
parameters

String | text | as String, the message that is to be output

onLogout()
If defined, the onLogout() function is called when a user is logged out.
onStart()
If defined, the onStart() function is called when the application is started.
This is most useful for any initialization purposes your application may require.
onStop()
If defined, the onStop() function is called when the application is stopped.
onUnhandledMacro(name)
If defined, the onUnhandledMacro() function is called when a global macro call can not be handled.
For macros that are not global, an onUnhandledMacro() method would need to be defined on the handler object.
parameters

String | name | as String, the name of the unhandled macro

Tue, 25 Nov 2008 16:50:14 GMT.

### core framework

- global
- app (application)
- req (request)
- res (response)
- session
- path
- root
- HopObject
- User
- File
- FtpClient
- Image
- Mail
- Remote
- Xml
- DatabaseObject
- MimePart
- Skin
- Object

### optional modules

- Array extensions
- Date extensions
- Number extensions
- Object extensions
- String extensions
- HopObject extensions
- global macros
- macro filters
- JSON methods
- helma.Aspects
- helma.Chart
- helma.Color
- helma.Database
- helma.File
- helma.Ftp
- helma.Group
- helma.Html
- helma.Http
- helma.Image
- helma.Mail
- helma.Search
- helma.Skin
- helma.Ssh
- helma.Url
- helma.Zip
- jala.BitTorrent
- jala.Captcha
- jala.Date
- jala.db
- jala.DnsClient
- jala.Form
- jala.History
- jala HopObject extensions
- jala.HtmlDocument
- jala.I18n
- jala.ImageFilter
- jala.IndexManager
- jala.ListRenderer
- jala.Mp3
- jala.PodcastWriter
- jala.RemoteContent
- jala.Rss20Writer
- jala.Utilities
- jala.XmlRpcRequest
- jala.XmlWriter

### java libraries

- browse docjar