Help is available for each task, or you can go straight to
the solution source code.
Task 1
Import Netscape's security package to provide access to the capabilities API.
import netscape.security.*;
Task 2
At the beginning of the block of code that does the word counting, in the getCount
method of the skeleton code, enable the
appropriate privilege for accessing any network connection.
The name of the privilege is UniversalConnect
.
PrivilegeManager.enablePrivilege ("UniversalConnect");
Task 3
At the end of the block of code, disable the same privilege.
If you forget to disable the privilege, the program could attempt to access a network connection from a place where it should not be
privileged.
PrivilegeManager.revertPrivilege ("UniversalConnect");
Task 4
In the popupMessage
method, enable the appropriate privilege for disabling the applet warning message for dialogs.
The name of the privilege is UniversalTopLevelWindow
.
PrivilegeManager.enablePrivilege (
"UniversalTopLevelWindow");
Task 5
After the source code for creating the dialog, disable the privilege.
PrivilegeManager.revertPrivilege (
"UniversalTopLevelWindow");
Task 6
Add Netscape's capabilities classes to
your CLASSPATH
.
If you place the classes in the same directory as you compile, the following command will add the package to the end of your
CLASSPATH
.
set CLASSPATH=
%CLASSPATH%;capsapi_classes.zip
Task 7
Compile the program.
javac WordCount.java
Task 8
Create an HTML
loader for the applet.
<applet code=WordCount width=300 height=100>
</applet>
Task 9
Load program into Communicator and try it out.
Counting words takes time. You can comment out the print statement in the source to print each word as it is counted.
Copyright © 1998 MageLang Institute.
All Rights Reserved.