Whitebeam Template Reference Documentation

Site Map
 
Home
 
Application Guide
Reference
  Installation
  Configuration
  XML Markup
  JavaScript Classes
  ROM
  Templates
  Environment
  Dev Process
  Tools
  External Links
  Example libraries
Community
Contact Whitebeam
To-Do
Download
Credits
Licence
Whitebeam Users
 
 
 

Whitebeam Template Reference Documentation

System Template

writeraw()

Write dynamic content directly to the browser

See Also

rb.page.sendHTTPheaders,

Syntax

void = rb.page.writeraw(output_data)

Parameters

The 'writeraw' method takes 1 parameter:

Name Type/Value Range/Length Description
output_datastring  Required. The data to be written to the client browsers.

Results

The 'writeraw' method returns no useful information.

Remarks

The usual mechanism for generating page content from the Presentation Engine is to call rb.page.write. The Presentation Engine then executes the page - accumulating the output from each XML element. Once this activity is complete the accumulated output is sent to the browser - preceded by any necessary HTTP headers.

In most cases this mecahnism is adequate. Occassionally however it is useful to bypass this XML processing and write directly to the browser - discarding any output that may be generated by the XML itself. A good example is where the Pattern Page is being used as a wrapper for some other content. For example the page itself does some authentication and if this succeeds it simply wants to send the contents of some file - raw - directly back tp the client.

The parameter to this page may be any JavaScript object. If that parameter is an instance of the binary object then the contents is written directly to the browser. Any other type of object and the Presentation Engine will first convert the contents of that object to text by calling the toString() method on that object.

If you call this method then the HTTP headers accumulated to that point as sent to the browser along with the specified raw data. Any output already generated by the Pattern Page (by any tag) is discard. The rest of the page is executed but the output, if any, will be discarded by the presentation engine.

If the first output on a page is via a call to 'rb.page.writeraw' the Presentation Engine will set the contents-length for the page to be the length of the raw item and then send the HTTP headers. This means that subsequent calls to writeraw will not generate the required output at the client (because the additional output will be over and above the length specified in the header.

If you want to call writeraw multiple times - say in a loot - then call rb.page.sendHTTPheaders. This will send the HTTP headers with no content length - forcing the browser to accept multiple 'chunks' of data from the server.

Example

The following example page will perform some basic validation on a page request. Assuming the validation succeeds the page will then read in a binary image file and return that to the browser. This example shows how to implement secure access to non-Pattern Pages, for example image files, or PDF files.
<rb:script>
   var image = new Binary;

   // Load the binary image from the file system
   var Fname = rb.page.env.PathInfo();

   image.fname(Fname);
   if (!image.load()) {
      image.load("missing.gif");
   }

   rb.page.setMimeType("image/gif");
   rb.page.writeraw(image);
</rb:script>

Note that this example pattern page looks for a filename in the additional 'pathinfo' of the requested URL. If the filename is found then the file is loaded into the binary object. If it is not then the file loads a default file called 'missing.gif'.

Whitebeam release 1.3.36
(loadtime : 123ms)