Issue #00005425

New WGA.File() Utility object

For imports and exports you often need access to files in the servers file system.

You can do this using objects together with some FileReaders and FileWriters and Input-/Output Streams ...

As a TMLScript developer you wound do this.

We now added a utility object


to handle files. WGA.File() creates a WGAFile object that implements some useful utility method to read from and write to files.

Note: All files are treated relative to the OpenWGA config folder. If you need to assess folders outside we advise to create a symbolic link in the WGA config folder to do this.

The default encoding if not explicitly specified is the configured OpenWGA output encoding (normally UTF-8).

Currently we implemented the following methods:


Returns the file content as String.


Reads the file content as XML and returns a DOM4J Document.

WGAFile.write(string [, encoding])
WGAFile.write(XMLDocument [, encoding])

Writes the given String or DOM4J Document to the file.

WGAFile.append(string [, encoding])

Appends the given String to the end of the file.

WGAFile.copy(WGDocument, filename_to_copy)
WGAFile.copy(TMLContext, filename_to_copy)

Copies filedata from an imput steam or content attachment to the file.


Returns a directory listing as list of WGAFile objects. The optional filter argument can be a JS-Function that is called with the current object as argument. It must return true or false.


Returns or sets the wrapped object.


var json_text = WGA.File("data.json").asString();
var data = JSON.parse(json_text)
// reads a json object from a file

var doc = context("name:home");
WGA.File("export.html").copy(doc, "mail.html");
// exports a content attachment "mail.html" to the file system as file "export.html"

var files = WGA.File("import").listFiles();
for(let file in Iterator(files){
    var xml = file.asXMLDocument();
    // process the xml ...
//Processes a list of XML files in the file system from folder "import"