Active Pages
WebSuite's Active Pages provide a powerful method for the creation of dynamic content and web-based applications. Additionally, Active Pages go beyond Microsoft's ASP by allowing their inclusion at the workstation level and in the creation of Windows-based applications.
Active Pages are standard ASCII text files that include some combination of HTML, Java, JavaScript, and FGL. The default file extension for Active Page source code is .AP, and .APX for pre-compiled source. They can be created using any program that utilizes standard ASCII text format, as well as the IDE and program editor included in the FGL VMSDK.
Typical Active Pages utilize the following structure:
<[
// Program Comments
// External libraries
// Local object definitions
// Local function definitions
// Primary source code
]>
<!-- HTML instructions with embedded FGL -->
|
Essentially, Active Pages are standard web pages enhanced with programming instructions. Optionally, Active Pages can exclusively contain program instructions without any HTML instructions.
For example, the following HTML program:
<html>
<body>
<font size=2>Hello World!</font>
</body>
</html>
|
can be represented utilizing Active Pages as:
<[
! webHeader( )
! "<font size=2>Hello World!</font>"
! webFooter( )
]>
|
and can also be represented as:
<[
// Define a local variable
str = "Hello World!"
]>
<html>
</body>
<!-- Now use the variable within standard HTML -->
<font size=2><[ ! str ]></font>
</body>
</html>
|
In each case, the previous examples produce exactly the same results. A more detailed example using all of the Active Page structures can be represented as:
<[
// This is a sample Active Page source file
// Reference an external library
LIBRARY mylib.flb
// Define a local class
CLASS myclass
PUBLIC:
local fname, lname
METHOD new( )
::fname = ""
::lname = ""
return( 1 )
END
END
// Define a local function
FUNCTION GetTheDate( )
return( date( ) )
END
// Now do some programmatic processing
session = new( "session", param( 1 ), param( 2 ) )
myobj = new( "myclass" )
myobj.fname = session.var( "fname" )
myobj.lname = session.var( "lname" )
curdate = GetTheDate( )
// Now do some standard HTML stuff
]>
<html>
<body>
The user's name is <[ ! myobj.fname + " " + myobj.lname ]>,
and the Current date is: <[ ! curdate ]>.
</body>
</html>
|
The above example is a bit contrived in order to demonstrate the various sections within an Active Page, but nevertheless is a valid Active Page.
When a user accesses the above page through their browser by entering the address of the WebSuite server where the file resides, the server loads the page and begins processing of the program instructions. Active Page code blocks are marked using the "<[" and "]>" characters to designate the beginning and end of the block. The "!" character instructs the system to insert the results of the operation into the web page itself, which is ultimately returned to the user in pure HTML format (including any embedded Java or JavaScript) as a web page.
All instructions contained within an Active Page format must be valid FGL program instructions and are not otherwise restricted. Commands can be distributed over a number of lines or contained within a single blocked line. In the latter case, only one code block per line is allowed, for example, the following code will generate an error:
The first name is <[ ! myobj.fname ]> and the last name is <[ ! myobj.lname ]>
The above line can be written without error as follows:
The first name is <[ ! myobj.fname + " and the last name is " + myobj.lname ]>
Optionally, it could also be represented as:
<html>
<body>
The first name is
<[
! myobj.fname
! " and the last name is "
! myobj.lname
]>
</body>
</html>
|
WebSuite utilizes a powerful tool for optimizing performance when dealing with Active Pages. An internal just-in-time compiler (JIT) is used in conjunction with an Active Page cache substantially enhances performance. When an Active Page is requested, WebSuite will first check the internal AP Cache to see if the file has been previously been requested and pre-compiled. If found, the binary instructions are executed directly out of memory. Otherwise, the file is loaded, compiled, stored in the cache, and then executed. The results are an order of magnitude increase in performance and reduction of disk activity.
By default, the AP Cache is active and automatically optimizes Active Page use. This is a problem, however, when interactively developing Active Pages, since the changes will not update the cache. Therefore, you must disable the AP Cache through the SYSTEM option of the WebSuite mini-console while developing Active Pages.
Additionally, WebSuite optimizes the visibility of Active Pages to users and in particular search engines. Files saved with the .AP file extension can nonetheless be accessed by referencing them as .HTM or .HTML files, and WebSuite will automatically retrieve the corresponding .AP page. This is provided no HTML files of the same name are residing in the same directory. For example, a file named INDEX.AP can be accessed as INDEX.HTML as long as there is no actual INDEX.HTML in the specified directory.
Caution must be exercised when dealing with Active Pages as there are file size limitations. In general, compiled AP source code cannot exceed 64k, nor can the resulting computed page that is returned to the user.
When creating an AP-based application, source is exposed to the end user since the file is a standard ASCII file. This may be desirable but you may also wish to hide your source code from the end user. This can be accomplished through externalizing your code in binary libraries, or by pre-compiling your Active Pages into .APX files. Use the apCreateCompiledFile( ) function to accomplish this.
If an Active Page is going to use low-level disk functions, such as drive, directory, database, or file functions, you must tell WebSuite that this is authorized to do this by including the _apGenerate( ) function at the top of your program (following any library, local object definitions, or local function definitions). Otherwise, low-level access will generate a runtime error.
Individual Active Pages can be password protected through the SECURE method of the SESSION OBJECT, as in:
<[
session = new( "session", param( 1 ), param( 2 ) )
if ( ! session.secure( "MySecurityRealm" ) )
return( 0 )
end
// Your secure code here…
]>
|
By default, WebSuite will not allow requests beyond the edge of the firewall to be processed. However, through the use of Active Pages, resources located anywhere on your system can be accessed, including CD/ROMs and other peripherals.
For advanced additional information regarding the programming of Active Pages, see the FGL documentation located at the West Coast Web Adventures web site.
(c) 2001 by West Coast Web Adventures, Inc., All Rights Reserved
|