Internet Publishing - PPI  

"Materials used in this course are the property of the author. These lessons may be used only by course participants for self-study purposes. Application for permission to use these materials for other educational purposes such as for teaching or as a basis for teaching should be directly submitted to the author." 

Lesson 11


This lesson covers Java and WAIS. The material about Java is taken from Sun's WWW server

This lesson also contains Java Script code. It seems that this code is destroying the printout of the lesson from some browsers. I have not been able to correct this problem. So - to be sure to read the lesson correctly - you should read it directly from the computer screen - and not from a printing.

The material dealing with WAIS is taken from the book Managing INERNET Information Services by Liu, Peek, Jones, Buus & Nye published by O'Reilly & Associates. 

11 Java and WAIS


11.1 Java

Java is a further development of WWW technology. Up to now, we have used HTTP or other protocols to send data from a server to a client. This data is for the most static; that means that it does not change very often. In this way, one can well imagine that all Internet users share a common amount of data which they can use, or one may perhaps say a common disk space

What's new about Java is that we don't just transfer data between client and server, but also program code which can be run on the client machine after it is transferred from the server. In this way, common executable code is introduced to Internet users. Now - the users does not only have a "common diskspace" - it seems as if they have a "common processing space". For the users it seems like they all are running the same machine. This gives WWW technology an entirely new dimension. It makes possible, the transfer of code which can, in principle, do "whatever you want". Many of the existing demos use this technique for running animated images. 

The technique makes it possible to download and run the programcode "on-the-fly". In this way it will also be possible to introduce entirely new communication protocols or new versions of an application "on-the-fly". A new protocol could be downloaded to the client with the help of HTTP and is started. In this manner, clients can be expanded to support new protocols without having to make special upgrades or installations. All this could happens as a result of one click from the user on an appropriate link.

The technology is developed by Sun, and it is created in its own language, Java. Programs created in Java are called Applets (small applications). 

In order to be able to use the technology, a browser which supports Java is needed. Sun distributes its HotJava and Netscape and Internet Explorer supports Java from version 2.0 and up. 

Use Sun's "Whitepaper" documentation to learn about Java. You can start at the top at Sun/Java, or go directly to individual areas: 

Read about  Java language 
Read about HotJava 

For those of you running Windows95 or WindowsNT, you can try downloading applets from Sun. Or search Lycos for the keywords "Java applets", and you will find plenty. 

JavaScript

JavaScript is a script language which can be placed in HTML code. JavaScript is interpreted as it is being run and is therefor slower than compiled code. Script language is object based, but unlike Java, it doesn't have classes and inheritance. Type checking is simpler than with Java. 

This lesson deals with JavaScript, and the material here is largely taken from Netscape' "Release Notes" on JavaScript. I have created some of my own examples in addition. 

Later, you will work with JavaScript on a practical level, and it will be necessary for you to have access to this documentation while you work. 

Therefore, do the following immediately:  In order to run JavaScript, you must use a client which supports it. If you don't have one, you can, for example, download Netscape Navigator. It is available for Windows 3.1 and Windows95. 

Placing code

JavaScript is program code placed between the start and end markers: 
<SCRIPT language="JavaScript">
Script...
</SCRIPT>
The code can be placed anywhere. This can be utilized to avoid problems with "browsers" which don't support JavaScript, because the script code can be placed inside comment tags: 
<SCRIPT language="JavaScript">
<!-- comments begin - hide script codes from old browsers...
Script...
// the comments and hiding of scripts ends here -->
</SCRIPT>

Example

In order to print to the screen, use: 
<SCRIPT language="JavaScript">
document.write ("Hi - I am learning JavaScript!")
</SCRIPT>
Between the lines below, you will see the result of running this code. 

Functions

JavaScript can utilize functions. The functions should be defined in the header of the HTML file which will be processed first by the browser. The function call may appear later in the HTML file. 

Example

Definition of print function in the header in the HTML file: 
<HEAD>
<SCRIPT language="JavaScript">
function line() {
        document.write ("<HR Width=75%>")
}
function printcentered (header, level, text ) {
        document.write ("<CENTER><H" + level + ">" + header + "</H" + level + "><P>" + text + "</CENTER>")
}
</SCRIPT>
</HEAD>
Now you can call these functions: 
<SCRIPT language="JavaScript">
line()
printcentered ("Hurrah!", 4, " I am learning JavaScript")
line()
</SCRIPT>
Between the lines below appears the result of running this code. 


Scripting Event Handlers

JavaScript applications can be run with the help events. 
Events can be: 
Event  Occur when...  Event HANDLER 
blur  The user removes focus from a form element  onBlur 
click  User clicks on form element or link  onClick 
change  Users edits value in a text field or a selection element  onChange 
focus  User sets focus on an input element  onFocus 
load  User loads the page into the client (Netscape)  onLoad 
mouseover  User moves mouse over a link or anchor  onMouseOver 
select  User chooses an input field in a form  onSelect 
submit  User submits a form  onSubmit 
unload  User leaves a page  onUnload 
The handler which can be used is stated in the HTML code for the related object, for example, an input text field. What should be done is stated in an attribute. 

Example

Suppose that we have a text field with the name mynumber and a button beside it marked count. When I press the button, mynumber should be increased by 1. 

I can do this by defining a form with these fields. Notice that the definition of even handler and function increasecount which will be run. 
<FORM>
Text field <I>mynumber</I>:
<INPUT TYPE="text" NAME="mynumber"  VALUE="1" SIZE=20>
<INPUT TYPE="button" VALUE="<- count " ONCLICK="increasecount(this.form)">
</FORM>

Text field mynumber
 
The actual function increasecount() is defined in the header for the HTML file. It can, in principle, be called by several forms, so I name this.form in the call so that the function can return the value to the correct form. 

The increasecount(form) function looks like this: 


function increasecount(form) {
        form.mynumber.value = parseInt (form.mynumber.value, 10) + 1
}

This may be a good time to consult the on-line documentation for JavaScript to study the parseInt() function. I suggest that you open a new window in Netscape where you can open the documentation which you hopefully have saved to your local disk. If you haven't done this yet, do it now

Crossword

To teach myself more about JavaScript, I created a crossword. Use this as an example for a "beginner's code" in that you look at the source code (View | Document Source) while you try to solve the crossword.
 
Across   Down 
1 - Acronym for the "Publishing On the Internet " course  1 - Author's first name 
3 - Move fast  3 - Small part of an atom 

1
2
3

Objects

There are a hierarchy of standard objects which are generated for a window: 
window
|
+- parent, frames, self, top
|
+- location
|
+- history
|
+- document
   |
   +- forms
   |  |
   |  +- text fields, textarea, checkbox, password
   |     radio, select, button, submit, reset
   +- links
   |
   +- anchors
These objects can have properties and methods which are named in the standard manner: 

Example

A form can have the name myform, and an input field FirstName. In a document file, this will be an object which we can refer to. We could for example use the value property, like this: 

Name = document.myform.FirstName.value 

NB! 
A HTML page is , by a browser, "written" on the screen from top to bottom - and some objects which have already been written will not change on the screen even though a script may edit its value. The value in the input fields on a form will change, while the title of the document (document.title = "New title") will not be edited on the screen. 

Read more about objects in the on-line documentation! 

Exercise

In lesson 7 you have created an order form for reserving a room at a hotel. We shall now create a dynamic form with Java Script. The main point in this exercise is that the price shall be updatet immediatly when selecting options in the form.

Below you will find a picture of the solution. Under the picture you will find a description of the manner of operation. Also be aware of the "skeleton" of the solution which you can use if you like.
 
The exercise is created as a form. However, a submit button is omitted since transferring data is not the subject of this exercise.. 
This form can be created in two ways: 
  1. The user fills in the appropriate data - and clicks on the "Calculate Price" button so that the field for price is updated.
  2. The user fills in the appropriate data - and the field for price is continually updated every time changes are made ot the form. Then, the "Calculate Price" button will be extraneous. 
Here is a "HTML skeleton" for the exercise, so your task will be to enter the JavaScript which will satisfy the functionality in points 1 or 2 above. 

Due date: 3 June 1997 

11.2 WAIS

Lesson 9 dealt with, among other things, robots which run around the Internet and collect information and save pointers. Such information is collected from the links or headers. However, it is also possible to collect entire documents to make these searchable. If you have collected documents within a certain subject area, or you have an organization with a lot of internal documents, it may be wise to make all the document text searchable

WAIS stands for Wide Area Information Server. This is a system to make entire texts (or tables of contents) searchable. Try WAIS at the University of Bergen . This searches all the HTML documents on the server (This is a norwegian server). Try to search for HotJava. 

WAIS is divided into 3 parts: 
  1. Indexes
  2. Servers
  3. Client
Figur av WAIS komponenter 

The indexer in WAIS can read files with different formats and create tables for effective searching. The result is a list of all the words which appear in the texts together with lists of where these words can be found. This collection of tables becomes very large; in fact, it can take twice as much space as the original documents. However, they will be quicker to search through. There are lists for words that should not be included in the tables. It is common to enter words such as the, an, a, and, but, etc.

A characteristic of the indexer is that it is simple to update the tables as new documents are added. 

The client and the server communicate using a TCP/IP protocol with the name "Z39.50". There are WAIS clients which speak the Z39.50 protocol directly, but it is more usual for the WWW server to be used as a  front-end and for the WAIS server to take care of the client task. The users are offered a HTML interface on a WWW client:  
Figur av WAIS komponenter 

The WAIS client can formulate free text searches by naming the words which to be searched for. The search can be made more precise with the help of logical operators AND, OR and NOT

The server can also be set up to interpret stems of words so that it is possible to search for variants of words, for example find boys when the word to be searched for is boy.
It is possible to limit the number of hits in the database.. 

WAIS was originally developed by Thinking Machines. Later, WAIS Inc. was started up to offer the commercial version of  WAIS, but a free version is also available - freeWAIS

FAQ for freeWAIS . More information on where you can get the software and other good documentation can be found at these links.
20 May 1997 Per Borgesen