|
Introduction to APGen |
|
See Also: |
Microsoft's Active Server Pages (ASP) is the de facto standard for dynamic web site development on Windows platforms. The ASP technology is easy-to-use, very popular, and powerful enough for any web development project.
Like Microsoft Active Server Pages, Active Page Generator generates output documents. APGen was designed to allow developers to leverage the skills, tools, languages, and components used in ASP programming. Accordingly, there are many similarities between ASPs and APG scripts.
Following is a high-level comparison of ASP to APGen:
| Topic | ASP | APGen |
| Purpose | Dynamic web server content generation. | Programmatic content generation. |
| Executes | ASP files. | APG files. |
| Script Execution Engine | ASP.dll ISAPI filter. | APGen COM component. |
| Input | ASP file; user query strings, cookies, and other data from a browser (encapsulated in Request, Session, and Application objects). | APG file; parameters and objects that are passed to the script (via the Script, Script.Arguments, and APGen objects). |
| Output | HTTP Stream, encapsulated in the Response object. | File, encapsulated in the Output object. Output can also be written to a custom stream. |
| Script Run When | An HTTP Request is received. | The APGen COM component is called, or a user directs script execution. |
| Executed By | Web server. | Program or user. |
| Script/Content Delimiter | <% ... %> | <%# ... #%> |
| Script Languages | VBScript, JScript, PerlScript, Python | VBScript, JScript, PerlScript, Python |
| Intrinsic Script Objects | Request, Response, Session, Application, Server, ObjectContext * | APGen, Output, Script, Log, Util, ObjectContext |
| Method used to Append Content | Response.Write | Output.Write |
| Extensible with ActiveX Components | yes | yes |
| Debugger | MS Script Debugger, Visual InterDev 98, Visual Studio.NET. | MS Script Debugger, Visual InterDev 98, Visual Studio.NET. |
| Authoring Tools | notepad, Visual InterDev, any text editor, 3rd party tools. | notepad, Visual InterDev, any text editor, 3rd party tools. |
APG scripts can be run from any program - for example, a SQL trigger can run an APG script, and a user can run an APG script from the command line. A web server is not assumed or required. The APGen object model accurately models the execution environment for pre-rendered web pages.
The ASP object model was designed for interactive web pages - thus it has support for forms, HTTP POSTs, cookies, Sessions, etc. It was not designed for pre-rendering or generic content generation. Thus, there are some features of the ASP object model that do not map to the APGen object model.
An example may help further explain the differences: When an ASP page is executed, the ASP Request object provides access to the HTTP request headers and body in IIS. Similarly, the ASP Session object provides a state model by reading and writing HTTP cookies. In the APG script execution environment, the presence of an HTTP request and response are not assumed. APG scripts are executed interactively or programatically, much like BAT files or other programs. Instead of program input being retrieved from the ASP Request object, program input is retrieved from the Script.Arguments collection or one of the other object collections. Instead of program output being written to a HTTP response, output is written to a file - since there is no HTTP, there is no equivalent to Response.AddHeader.
Accordingly, there is not a 100% direct conversion between ASP files and APG scripts. Every attempt has been made to provide all the relevant conveniences of ASP, so that ASP programmers will feel at home. APGen also adds a number of features that are not present in ASP. Due to the differences in execution environment, some manual work will be required for most real-world conversion projects. In addition, all pages that use Two-Phase Content Generation require manual conversion.
That being said, ASP objects can be accessed in APG scripts, as long as the APG script is run from an ASP page. For more information, see Executing APG Scripts in Active Server Pages.
The ASPToAPG Example can help automate conversion of ASP files to APG scripts. It converts all ASP blocks to APG script blocks, using the following syntax conversion table:
| ASP Term | APG Script Equivalent |
| <% | <%# |
| %> | #%> |
| <SCRIPT Language= "VBScript" RUNAT=Server > | <SCRIPT Language= "VBScript" RUNAT=APGen > |
| <!-- #include file="file.inc" --> | <!-- #include apg="file.inc" --> |
| Response.Write | Output.Write |
| Response.BinaryWrite | Output.BinaryWrite |
| Response.Buffer | Output.Buffer |
| Response.Clear | Output.ClearBuffer() |
| Response.Flush | Output.FlushBuffer() |
| Response.AppendToLog | Log.Write |
| Response.End | Script.Abort |
| Server.CreateObject() | Script.CreateObject() |
| Server.HTMLEncode | Util.HTMLEncode |
| Server.URLEncode | Util.URLEncode |
| Application(key) | APGen(key) |
| Session(key) | APGen(key) |
| Request(key) | Script(key) |
| Request.QueryString(key) | Script(key) |
| Request.Form(key) | Script(key) |
| Server.MapPath(path) | Util.ConcatPath(Script.Dir, path) |