ShowSource.asp
1@ Language=JavaScript
1
2// get the page to display from the URL
3var sPage = "" + Request.QueryString ( "page" );
4
5// make sure it's a page we allow them to view!
6switch ( sPage )
7{
8case "Wider":
9case "COM":
10case "Handle404":
11case "Categories":
12case "CategoryPage":
13case "Columns":
14case "ResultsPage":
15case "Date":
16case "Contact":
17case "Subscribe":
18case "MailToList":
19break;
20
21default:
22Response.Redirect ( "NaughtyNaughty!" );
23}
24
25// output relevant meta tags
26Init( "ASP source example" );
27
28// output common top of page
29Header( '
<a href="work.asp">Work</a>
1\-->
<a href="' + sPage + '.asp">"' + sPage + '.asp"</a>
1\--> Source', 3 );
2
3// output page content
4Content ( );
5
6// output common bottom of page
7Footer ( );
1 /* standard page elements */
1
2// ============================================
3// the content of this page
4// ============================================
5function Content ( )
6{
7Out ( '
<td width="20%"> </td>
1' );
2Out ( '
<td width="60%">' );
// create handle to FileSystemObject
var oFSO = Server.CreateObject ( 'Scripting.FileSystemObject' );
// each source file that we show source for could have a related
// documentation file for us to display before and after the
// source. for now, I use a generic header and footer file. the
// 'true' tells ShowFile to pass through any HTML to the browser.
ShowFile ( oFSO, 'Generic.pre', true, false );
switch ( sPage )
{
case "Categories":
case "CategoryPage":
case "Columns":
Out ( '<p><img src="images/new.gif"/> <a href="Categories.zip">Download</a> all the source for the category demonstration!<p>' );
break;
}
ShowSource ( oFSO, sPage + '.asp', true );
// show any extra utility file(s) too
switch ( sPage )
{
case "Wider":
ShowSource ( oFSO, 'include/SetGlobals.asp', true );
ShowSource ( oFSO, 'utils/Header.asp', true );
break;
case "Categories":
case "CategoryPage":
case "Columns":
case "Subscribe":
case "MailToList":
ShowSource ( oFSO, 'utils/Database.asp', true );
break;
case "Categories":
case "CategoryPage":
case "Columns":
ShowSource ( oFSO, 'utils/ShowCategory.asp', true );
break;
}
// show the generic footer
ShowFile ( oFSO, 'Generic.pst', true, false );
// we've finished with the object so free the resource
oFSO = null;
Out ( '<p><center><a href="FSO.asp"><img border="0" src="images/source.gif"/></a></center>' );
Out ( '</p></p></p></td>
1' );
2Out ( '
<td width="20%"> </td>
1' );
2}
utils/ShowFile.asp
1
2// have we advertized our mailing list yet?
3var bDoneLink = false;
4
5// ============================================
6// display the contents of the given file
7// ============================================
8function ShowFile ( oFSO, sFile, bPassHTML, bShowName )
9{
10var ForReading = 1;
11// var ForWriting = 2;
12// var ForAppending = 8;
13
14// open asp file for reading
15var fFile = oFSO.OpenTextFile ( Server.MapPath( sFile ), ForReading );
16
17// read entire file contents into variable
18var s = fFile.ReadAll ( );
19
20if ( !bPassHTML )
21{
22// replace & with & so HTML displayed, not interpreted
23s = s.replace ( /&/g, '&' );
24
25// replace < with < so HTML displayed, not interpreted
26s = s.replace ( /
27' );
28
29// replace tabs with 3 spaces
30s = s.replace ( /\t/g, ' ' );
31
32// show filename and change font color for source code
33s = '
<font color="black">' + s + '</font>
1';
2
3if ( bShowName )
4s = '
<h4>' + sFile + '</h4>
1' + s;
2}
3
4Out ( s );
5
6fFile.Close ( );
7}
8
9// ============================================
10// show a source file outside the table
11// ============================================
12function ShowSource ( oFSO, sFile, bShowName )
13{
14// advertize our mailing list before the first source file
15if ( !bDoneLink )
16{
17bDoneLink = true;
18Out ( '
<p><b>Get informed when the source code below changes!</b> <a href="subscribe.asp">Subscribe to our mailing list.</a>' );
}
Out ( '' );
Out ( '<td width="20%"> </td><tr><td bgcolor="#ff9900" colspan="3" width="100%">' );
// show news file
ShowFile ( oFSO, sFile, false, bShowName );
Out ( '</td></tr><tr><td width="20%"> </td>' );
Out ( '<td width="60%">' );
}