Chapter 3 DynaScript Predefined Objects
The document
object
has these methods:
document.ExportTo(pathName [, newName])
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.
Boolean. This method returns true or false, indicating whether the method succeeded or not.
This example exports /site/products.stm to the c:\ drive:
<!--SCRIPT
productDoc = site.GetDocument ( "/site/products.stm" );
productDoc.ExportTo( "c:" )
-->
document.GetDirectory( [fileMask, sortOrder] )
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".
Array of document objects. Returns a list of contained documents.
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 );
}
-->
document.GetGenerated( )
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
.
String. Returns the interpreted output.
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.
The "Include method".
document.GetServerVariable( )
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.
String. Returns a value from the server.
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
document.ImportFrom(fileName[, replaceOption, newName ])
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:
newer
Replaces
existing file if incoming one is newer. This is the default if you
do not specify replaceOption.
all
Replaces
existing file regardless of modification dates.
You can rename an imported file or folder with the optional newName parameter.
Boolean. This method returns true or false, indicating whether the method succeeded or not.
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' );
-->
document.IncludeGenerated( )
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.
Boolean. This method returns true or false, indicating whether the method succeeded or not.
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>
...
document.Write(outputString)
Appends outputString to the output generated by this document.
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.
document.WriteLn(outputString)
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
.
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.
The "Write method".
Copyright © 1999 Sybase, Inc. All rights reserved. |
![]() |