SDSU CS 683 Emerging Technologies: Embracing Change
Spring Semester, 2001
Assignment 3
    Assignment Index        
© 2001, All Rights Reserved, SDSU & Roger Whitney
San Diego State University -- This page last updated 05-Mar-01

Assignment 3

Due March 22

0. Background. The expression:

Compiler evaluate: aString 

will compile and evaluate aString. So the expression:

Compiler evaluate: '1 + 3'

when evaluated will return 4.

1. Script Files. Add a method "evaluate" to FileStream. This method should return the result of evaluating the contents of the file that FileStream represents.

2. Simple Active Squeak Pages (asp). A file with the extension ".asp" will contain html and Squeak code. The Squeak code will be inside <% tags. When processed all the text between <% and %> will be evaluated as Squeak code. The result returned by the Squeak code will replace the entire <% %> tag. So the following:

<html>
<body>
<B>Parents</B> it is now <% Time now %> <% Date today %>. Do you know where your children are?
</body> </html>

would become:

<html>
<body>
<B>Parents</B> it is now 10:12:29 pm 4 March 2001. Do you know where your children are?
</body> </html>

with the date and time depending on when the file was processed. Write Squeak code that will read an file ending in ".asp", find all <% %> tags, evaluate the code in the <% %> tags and replace the tags with the result of evaluating the code.

You can use the following to test your result. This code will open a web browser on the given html.

| browser document |
document := MIMEDocument 
   contentType: (MIMEDocument contentTypeHtml)
   content: '<html>
<body>
<B>Parents</B> it is now 10:12:29 pm 4 March 2001. Do you know where your children are?
</body> </html>'
   url: 'http://www.eli.sdsu.edu'.
browser := Scamper new.
browser 
   displayTextHtmlPage: document;
   openAsMorph

3. Serving Simple Active Squeak Pages. Active Squeak pages are more interesting when on can access them through a regular web browser. In this problem you will implement a Web server that serves active Squeak pages. Here is a simple exercise.

Add the following class to you image.

Object subclass: #SampleWebApplication
   instanceVariableNames: ''
   classVariableNames: ''
   poolDictionaries: ''
   category: CS683-ASP'
   
process: aRequest
   Transcript show: aRequest message.
   aRequest 
      inspect;
      reply: PWS success;
      reply: PWS contentHTML, PWS crlf;
      reply: '<HTML><BODY> Hi Mom </BODY> </HTML>'

The method above first prints in the Transcript the path in the URL that requests a page. The inspect message opens a window on the aRequest object, so you can see what it contains. The rest of the messages get PWS (Pluggable Web Server) to return your response. In Squeak execute the following code:

PWS link: 'test' to: SampleWebApplication new.
PWS serveOnPort: 8080 loggingTo: 'log'.
The first line tells PWS to use the SampleWebApplication object to process all requests with URL starting with test. The second line starts PWS running on port 8080 and creates a log file with the name 'log'. Now use your favorite web browser to access the page. If you run the web browser on the same machine as your Squeak image you can use the URL:

http://127.0.0.1:8080/test/me/now

The IP 127.0.0.1 refers to the local host. That is the computer the web browser is running on. To stop the PWS server use:

PWS stopServer

Modify the above example to return processed active Squeak pages. The request URL will indicate what file to process. For example the URL:

http://127.0.0.1/test/sample.asp

requests the file sample.asp. The URL:

http://127.0.0.1:8080/test/cs683/sample2.asp

requests the file sample2.asp in the directory cs683. Your code should read the given file, process all the active Squeak tags, and return the resulting page to the browser. See pages 245-249 of the Squeak text or PWS source in your Squeak image for more details.

Copyright ©, All rights reserved.
2001 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA.
OpenContent license defines the copyright on this document.

    visitors since 05-Mar-01