Ns adp parse

From AOLserver Wiki
Jump to: navigation, search

Man page: http://aolserver.com/docs/tcl/ns_adp_parse.html


ns_adp_parse - Parse an ADP file or string and return its output


ns_adp_parse ?-file|-string? ?-safe? ?-savedresult varName? ?-cwd path? arg ?arg ...?


This command processes an ADP from either a file or a string, returning the output. The first arg specifies the filename or contains the string to parse, depending on -file or -string.
Note that ns_adp_parse will ignore any directives to turn on streaming. Tcl_Eval() is used to evaluate the Tcl commands in the ADP.
If you use the -string syntax, then arg is a string containing ADP syntax to be parsed. Note that when you call this command with the -string syntax from inside an ADP, the string cannot contain the "<% ... %>" syntax in versions of AOLserver prior to 4.5. The -string syntax is the default.
If you use the -file syntax, then arg can either be an absolute path to the file containing the ADP to be parsed or, starting with AOLserver 4.0, a path relative to the current adp directory (as returned by ns_adp_dir, which in AOLserver 4.5+ returns the pageroot when executed outside of an adp page). You can also temporarily override the current adp directory for the duration of the ns_adp_parse execution by using the -cwd path switch.
If you specify the -safe flag, then only registered tags are executed; inline scripts using "<% ... %>" or "<%= ... %>" are ignored.
You can pass optional arguments to the ADP. The arguments can be accessed within the ADP using the ns_adp_argc, ns_adp_argv and ns_adp_bind_args commands.
If this call is a nested ADP evaluation (where one ADP calls another), an error will be thrown if the depth exceeds 256, the maximum number of nested ADP evaluations.


   % ns_adp_parse -string {<% return expr 2 + 2 %>}
   % ns_adp_parse -file ns_info pageroot/index.adp
   ... output of index.adp ...


In AOLserver versions prior to 4.5, -safe flag had no effect when used in combination with -file. In addition, -safe restriction could be bypassed in either a string or file by using this syntax: <script runat=server>...</script>


Using the -file option is preferrable to opening and reading the file yourself (even from an in-memory cache) and then parsing with -string because, with -file, it takes advantage of the adp page byte-compiled cache the same way ns_adp_include does.
ns_adp_parse -file differs from ns_adp_include in three key ways:
  1. ns_adp_include will throw an error if executed outside of an adp, though it will work when the calling adp block is itself being ns_adp_parsed.
  2. ns_adp_parse evaluates the adp in the current stack frame (with access to the same local variables), whereas ns_adp_include evaluates in one stack level below the caller.
  3. ns_adp_include writes to the adp buffer and returns the adp return value (i.e. the value from return, ns_adp_return or the last tcl command), whereas ns_adp_parse does not write to the adp buffer and instead returns what would have been normally written to the buffer. The adp return value is placed into a variable specified with -savedresult.
Contrary to older documentation, ns_adp_parse -file goes through the same relative path resolution as ns_adp_include.


ns_adp_abort, ns_adp_append, ns_adp_argc, ns_adp_argv, ns_adp_bind_args, ns_adp_break, ns_adp_debug, ns_adp_debuginit, ns_adp_dir, ns_adp_dump, ns_adp_eval, ns_adp_exception, ns_adp_include, ns_adp_mime, ns_adp_mimetype, ns_adp_puts, ns_adp_registeradp, ns_adp_registerproc, ns_adp_registertag, ns_adp_return, ns_adp_safeeval, ns_adp_stats, ns_adp_stream, ns_adp_tell, ns_adp_trunc

Category Documentation - Category Core Tcl API