Chapter 3 DynaScript Predefined Objects


document methods

The document object has these methods:

ExportTo method

Syntax

document.ExportTo(pathName [, newName])

Description

For files, saves the file as an external (disk) file in the pathName disk directory. For folders, saves the contained document tree (all nested files and folders) as an external directory tree (disk files and folders) in the pathName disk directory. newname allows you to optionally rename the file in its new location.

Return

Boolean. This method returns true or false, indicating whether the method succeeded or not.

Example

This example exports /site/products.stm to the c:\ drive:

<!--SCRIPT 
productDoc = site.GetDocument ( "/site/products.stm" );
productDoc.ExportTo( "c:" )
-->

GetDirectory method

Syntax

document.GetDirectory( [fileMask, sortOrder] )

Description

For folder documents, returns an array of contained documents (for example, a directory listing) matched by the string fileMask. fileMask can contain the wildcard characters "*" and "?". The sort order may be name or type. Name is the sortOrder default.

For information on the wildcards, see "Wildcards".

Return

Array of document objects. Returns a list of contained documents.

Example

This example displays all the documents in the /site folder that begin with the letter a and then sorts them alphabetically:

<!--SCRIPT 
siteDoc = site.GetDocument( "/site" );
dirList = siteDoc.GetDirectory( "a*", "name" );
for ( i in dirList ) {
document.WriteLn( dirList[i].name );
}
-->

GetGenerated method

Syntax

document.GetGenerated( )

Description

Returns the interpreted output from a document as a string. You cannot run this method from within the same document from which you are calling GetGenerated .

Return

String. Returns the interpreted output.

Example

This example runs the script /site/products.ssc and places the output in the variable "part1". /site/products.ssc takes two parameters; name and password.

myDoc = site.GetDocument( "/site/products.ssc" );
myDoc.value.name = "open";
myDoc.value.password = "sesame";
part1 = myDoc.GetGenerated();

Inside products.ssc you would use "document.value.name ", and "document.value.password " to access the parameter values.

See also

The "Include method".

GetServerVariable method

Syntax

document.GetServerVariable( )

Description

Returns a value from a server. The server variable name is dependent on which server interface is being used. This method is not supported by CGI servers.

CGI Equivalent

ISAPI

NSAPI (native)

NSAPI (Dynamo cover for NSAPI)

Personal Web Server

AUTH_TYPE

AUTH_TYPE

auth-type

AUTH_TYPE

CONTENT_LENGTH

CONTENT_LENGTH

content-length

CONTENT_LENGTH

CONTENT_LENGTH

CONTENT_TYPE

CONTENT_TYPE

content-type

CONTENT_TYPE

CONTENT_TYPE

GATEWAY_INTERFACE

GATEWAY_INTERFACE

GATEWAY_INTERFACE

HTTP_USER_AGENT

HTTP_USER_AGENT

user-agent

HTTP_USER_AGENT

HTTP_USER_AGENT

PATH_INFO

PATH_INFO

path

PATH_INFO

PATH_INFO

PATH_TRANSLATED

PATH_TRANSLATED

QUERY_STRING

QUERY_STRING

query

QUERY_STRING

QUERY_STRING

REMOTE_ADDR

REMOTE_ADDR

ip

REMOTE_ADDR

REMOTE_ADDR

REMOTE_HOST

REMOTE_HOST

REMOTE_USER

REMOTE_USER

auth-user

REMOTE_USER

REQUEST_METHOD

REQUEST_METHOD

method

REQUEST_METHOD

REQUEST_METHOD

SCRIPT_NAME

SCRIPT_NAME

SCRIPT_NAME

SCRIPT_NAME

SERVER_NAME

SERVER_NAME

SERVER_PORT

SERVER_PORT

SERVER_PORT

SERVER_PROTOCOL

SERVER_PROTOCOL

protocol

SERVER_PROTOCOL

SERVER_PROTOCOL

SERVER_SOFTWARE

SERVER_SOFTWARE

SERVER_SOFTWARE

SERVER_SOFTWARE

HTTP_COOKIE

cookie

COOKIE

COOKIE

URL

URL_PREFIX

UNMAPPED_REMOTE_USER

SERVER_PORT_SECURE

HTTP_ACCEPT

ALL_HTTP

Return

String. Returns a value from the server.

Example

This example displays the address of the remote host:

<!--SCRIPT 
REMOTE_ADDR = document.GetServerVariable( "REMOTE_ADDR" );
document.writeln( "<BR>REMOTE_HOST = "+ REMOTE_ADDR );
-->

The output for this example is:

REMOTE_ADDR = 122.47.156.352

ImportFrom method

Syntax

document.ImportFrom(fileName[, replaceOption, newName ])

Description

Imports the external file (or folder and its contents) named fileName into the Web site.

If name conflicts occur, the optional replaceOption determines how to resolve them:

You can rename an imported file or folder with the optional newName parameter.

Return

Boolean. This method returns true or false, indicating whether the method succeeded or not.

Example

This example imports the file d:\test\products.stm into the Site folder:

<!--SCRIPT 
/* Import a document to a folder */
myfolder = site.GetDocument ( "/Site" );
myfolder.ImportFrom ( 'd:\\test\\products.stm','all' );
-->

IncludeGenerated method

Syntax

document.IncludeGenerated( )

Description

Includes the generated output of the document that is called in the output of the currently executing script. A document cannot call document.IncludeGenerated on itself.

Return

Boolean. This method returns true or false, indicating whether the method succeeded or not.

Example

This example gets the include.stm document and then generates and displays the output of that document within the current document:

<!--SCRIPT 
mydoc=site.GetDocument( "~/include.stm" );
mydoc.IncludeGenerated();
-->

Here are the contents of include.stm:

<HTML>
<TITLE>include.stm</TITLE>
<BODY>
<H1></H1>
<!--SQL
SELECT customer.fname, customer.lname
FROM DBA.customer customer

-->
<TABLE BORDER>
<TR>
<TH>fname</TH>
<TH>lname</TH>
</TR>
<!--formatting--><TR>
<TD><!--data--></TD>
<TD><!--data--></TD>
</TR><!--/formatting-->
</TABLE>
</BODY>
</HTML>

The output from this example is:

<HTML>
<TITLE>include.stm</TITLE>
<BODY>
<H1></H1>

<TABLE BORDER>
<TR>
<TH>fname</TH>
<TH>lname</TH>
</TR>
<TR>
<TD>Michaels</TD>
<TD>Devlin</TD>
</TR><TR>
<TD>Beth</TD>
<TD>Reiser</TD>
</TR><TR>
<TD>Erin</TD>
<TD>Niedringhaus</TD>
</TR><TR>
<TD>Meghan</TD>
<TD>Mason</TD>
</TR><TR>
<TD>Laura</TD>
<TD>McCarthy</TD>
...

Write method

Syntax

document.Write(outputString)

Description

Appends outputString to the output generated by this document.

Example

This example generates output without a line break:

<!--SCRIPT 
document.WriteLn( "This is the write method. " );
document.writeLn( "You can use a lower case w." );
-->

The output of this example is:

This is the write method. You can use a lower case w.

WriteLn method

Syntax

document.WriteLn(outputString)

Description

Same as Write , but also adds a line break.

Line breaks produced with WriteLn only work when viewing an HTML document as plain ASCII source (for example, in a text editor).

When this HTML is processed by a Web client, the resulting layout ignores these line breaks, so WriteLn ultimately produces the same output as Write .

To force line breaks in the final output, you must use the HTML <P> or <BR> tag. For example:

document.WriteLn( "<P>This starts on a new line" );

In general, WriteLn makes your HTML source easier to read, but does not reflect how it is formatted by a Web client.

To remain compatible with JavaScript, Dynamo allows you to use write for Write , and writeln for WriteLn .

Example

This example:

<!--SCRIPT 
document.WriteLn( "This is the writeln method. " );
document.writeln( "You can use lower case (writeln) or upper case (WriteLn)," );
document.WriteLn( "but not Writeln." );
-->

outputs:

This is the writeln method. 
You can use lower case (writeln) or upper case (WriteLn),
but not Writeln.

See also

The "Write method".

 


Copyright © 1999 Sybase, Inc. All rights reserved.