Полезная информация


Special Edition Using HTML 4

Previous chapterNext chapterContents


- 32 -
Building Netscape Netcaster Channels

by Jerry Honeycutt


Designing Your Channel

Most users have grown to expect a certain amount of fluctuation in the quality of the Web sites they visit. The push audience is a bit more sophisticated, however, and its expectations are much higher. They expect better information and more of an eye-popping experience. The content is totally up to you, but HTML 4.0 provides many features you can use to provide the experience:


TIP: Netcaster downloads fresh content in the background. You're freer to use images and other objects because the user won't perceive them as a performance problem.

Users Are Browsing Offline

As you're building your site, keep in mind that the user will not be connected to the Internet in most cases. The Netcaster crawler, which is responsible for following and downloading the links on your site, does not parse JavaScript code. If you use a script to load an image in your Web page, the crawler won't download it. To solve this problem, hide an element in your HTML document that references the image, as shown in Listing 32.1. Likewise, the crawler won't download any class files that a Java applet references. The only solution to this problem is to package all your class files in a single JAR file.

Listing 32.1  Forcing Netcaster to Load Images

<DIV STYLE="position: relative; visibility: hidden;">
  <IMG SRC="theimage.gif">
<DIV>

Special Considerations

Developing a channel is different from developing an ordinary Web site. Because your pages are viewed in Netcaster and might even be displayed for long periods of time on the user's desktop, take these considerations into mind:

<A HREF="myfile.htm"></A>

Putting the Add Channel Button on Your Site

To get people to subscribe to your channel, you need to provide an easy mechanism for them to do so. Netscape recommends you put a button on your site labeled Add Channel as shown in Figure 32.1.

You can download the graphic for this button from Netscape's Web site at http://developer.netscape.com/one/dynhtml/images/ncnow.gif. Then, embed it using the HTML in Listing 32.2.

Listing 32.2   The Add Channel Button

<A HREF="#" onClick="subscribe(); return( false );">
  <IMG NAME="ncnowimage" SRC="ncnow.gif" 
    WIDTH=117 HEIGHT=55 BORDER=0 ALT="Add Channel">
</A>

Adding Your Channel to Netcaster with a Script

The button you added in the preceding section launches a script that adds your channel to Netcaster. You write the script using a new JavaScript 1.2 object called Channel. The function shown in Listing 32.3 is an example of the typical subscription function.

FIG. 32.1
Clicking the Add Channel button launches the script that you write in the next section.

Listing 32.3   Subscription Function

Function subscribe()
{
  var Netcaster = components[`netcaster'];
  var Channel = Netcaster.getChannelObject();
  Channel.url = "http://www.server.com/channel/home.html";
  Channel.name = "XYZ Channel";
  Channel.desc = "This channel is for people who use XYZ."
  Channel.intervalTime = 60;
  Channel.macCacheSize = 1024000;
  Channel.depth = 3;
  Channel.topHint = 0;
  Channel.leftHint = 0;
  Channel.widthHint = 400;
  Channel.heightHint = 600;
  Channel.mode = "window";
  Netcaster.addChannel( Channel );
}

Examine Listing 32.3 line-by-line:

Table 32.1  Channel Modes

Mode Description
full Displays in a full-screen Navigator window.
webtop Displays in a Webtop, which has no title bar or window borders and occupies the entire desktop.
window Displays in a normal Navigator window; you suggest a window shape using the hints.

Generating the Code with the Add Channel Wizard

No need to write the subscription script yourself; you can use Netscape's Netcaster Add Channel Wizard to generate all the HTML and scripts for you. Then, you copy the code into your HTML. Here's how:

1. Go to http://developer.netscape.com/one/netcaster/index.html and click Netcaster Add Channel Wizard.

2. Read the overview, and click Start the Add Channel Wizard. You see the first page of the Add Channel Wizard. Click Next, and you see the page shown in Figure 32.2.

3. Fill in the name of your channel and the URL. Click Next to continue, and you see the next page, which allows you to choose an update interval.

4. Select how often you want to update your channel on the user's computer: 30 minutes, 1 hour, 2 hours, 3 hours, 12 hours, day, or week. Click Next, and you see page shown in Figure 32.3.

FIG. 32.2
Don't worry too much about creating a fancy URL because the user will never see it.

FIG. 32.3
The user is able to customize these settings.

Type the depth to which you want Netcaster crawler to scan your site, and type the maximum cache size you recommend for it. Don't forget to specify whether the size you typed is in kilobytes or megabytes. Click Next.

6. Select a display mode: Webtop or Default Window. The Add Channel Wizard shows you an example of your selection on the left-hand side. Click Next.

7. Type the width, height, left-hand coordinate, and top coordinate in the spaces provided. You can provide any combination of these values because they are all optional. Click Next to continue.

8. In the space provided, type the text that you want to display on your Add Channel button. Click Next.

9. Click Finish, and the Add Channel Wizard opens the source for your subscription script and Add Channel button in a canvas window. It also asks you if you want to notify Netscape about your Channel; click OK if you do or Cancel if you don't.

10. Copy and paste the source from the canvas window into your HTML file. You'll find all the scripts required for your channel at the top of the file and the Add Channel button at the bottom.


CAUTION: The code shown in Listing 32.4 is an example only; don't use it for your channel. Netscape updates the Add Channel Wizard frequently, and thus the code it produces will probably vary from that shown in the listing.

The scripts that the Add Channel Wizard creates are much more complicated and thorough than what you created in the previous section. Listing 32.4 shows you the results. Here's a brief description of each function you find in the code that the Add Channel Wizard creates:

needNetcaster Opens a new browser window that tells the user how to install Netcaster if he doesn't already have it.
addChannelAPI Adds your channel to Netcaster. This function is very similar to the one you created in Listing 32.3.
activateNetcaster Opens Netcaster.
pollActive Continuously checks to see if Netcaster is currently active on the user's desktop.
netcasterSniffer Checks to see if the user has installed Netcaster and, if not, calls needNetcaster to help him get it.

Listing 32.4  Add Channel Wizard Results

<SCRIPT LANGUAGE="JavaScript">
 function needNetcaster() {
    window.open("http://netcaster.netscape.com/finder/need_netcaster.html",
    "need_netcaster","width=500,height=400,titlebar=yes,toolbar=no,
    location=no,directories=no,status=yes,menubar=no,scrollbars=yes");
    }
  function addChannelAPI() {
   needNetcaster(); }
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript1.2">
    var chanURL = "http://www.myserver.com/channel/home";
    var chanName = "My Channel";
    var chanIntervalTime = 720;
    var chanMaxCacheSize = 1048576;
    var chanDepth = 3;
    var chanActive = 1;
    var chanMode = "window";
    var chanType=1;
    var getChannelObject = null;
    var addChannel = null;
    var nc = null;
    var ncActive = 0;
    var poller = null;
 function activateNetcaster() {
    nc.activate();
    }
 function pollActive() {
    if (nc.active) {
        ncActive=1;
        setTimeout(addChannelAPI,10000);
        clearInterval(poller);
        }
 }
 function netcasterSniffer() {
    if (!components["netcaster"]) {
    alert("This page requires the Netcaster component.");
    needNetcaster();
     }
     else {
         nc = components["netcaster"];
         if (nc.active == false) {
             activateNetcaster();
        poller=setInterval(pollActive,500);
         } 
         else {
              ncActive = 1;
              addChannelAPI();
         }
     }
 }
 function addChannelAPI() {
     if (ncActive == 0) netcasterSniffer();
     else {
         nc = components["netcaster"];
         import nc.getChannelObject;
         import nc.addChannel;
         var chan = getChannelObject();
         chan.url = chanURL;
         chan.name = chanName;
         chan.intervalTime = chanIntervalTime;
         chan.maxCacheSize = chanMaxCacheSize;
         chan.depth = chanDepth;
         chan. active = chanActive;
         chan.mode=chanMode;
         chan.type=chanType;
         addChannel(chan);
     }
     ncActive = 0;
 }
function clikImg() {}
</SCRIPT>
<TABLE><TR><TD ALIGN="CENTER">
<A HREF="#" onClick="addChannelAPI(); clikImg(); return(false);">
<IMG NAME="ncnowimage" SRC="http://home.netscape.com/inserts/images/ncnow.gif"
 WIDTH=117 HEIGHT=55 BORDER=0 ALT="Add My Channel Now!"><br>
Add My Channel Now!
</a></td></tr></table>
<SCRIPT LANGUAGE="JavaScript1.1">
// This code helps Netscape track use of button
document.ncnowimage.src=
  "http://home.netscape.com/inserts/images/ncnow.gif?"+document.location;
function clikImg() {
document.ncnowimage.src="http://home.netscape.com/inserts/
images/ncnow.gif?AddedChannelName=My%20Channel&AddedChannelURL=
http://www.myserver.com/channel/home";
}
</script>


NOTE: Netcaster also supports Castanet channels. Developing Castanet channels is much more complex than building Netcaster channels because you have to learn a bunch of new technologies and purchase a Castanet server. You can get more information about creating Castanet channels at http://www.marimba.com.

Interacting with Netcaster via JavaScript

You can interact with Netcaster from your channel by using the JavaScript extensions Netscape introduces into JavaScript 1.2 as well as the new Channel object.

Before using Netcaster's methods, you have to import them into your document. In your script, make sure Netcaster is active, see the functions pollActive and activateNetcaster in the previous section, and then execute the following two lines:

import components["netcaster"].getChannelObject;
import components["netcaster"].addChannel;


NOTE: This chapter gives you an overview of Netscape's extensions. For a complete reference on Netcaster extensions, open http://developer.netscape.com/library/documentation/netcast/devguide/contents.htm in your Web browser.

Netcaster Component

The Netcaster component provides information about and access to Netcaster. Table 32.2 describes its properties and methods. Note that you can make your code easier to read by getting the Netcaster component first and then using that to access its properties:

nc = components["Netcaster"]

Table 32.2 etcaster Properties and Methods

Name Example Description
Properties
active nc.active Returns True if Netcaster is installed and running; otherwise, returns False.
componentVersion nc.componentVersion Returns the version number of Netcaster as a string: 1.0.
name nc.name Returns the string netcaster.
Methods
activate(); nc.activate(); Activates Netcaster.
addChannel(obj) nc.addChannel(channel); Adds the channel represented by the channel object, obj, to Netcaster. Netcaster adds the channel to the My Channels container.
getChannelObject() new = nc.getChannelObject(); Returns a new channel object that's initialized with the default values.

Channel Object

The Channel object provides access to all a channel's properties. As you saw in "Adding Your Channel to Netcaster with a Script," earlier in this chapter, you use the getChannelObject() method to create a new channel and the addChannel() method to add a channel to Netcaster. In Table 32.3, which describes the channel object's properties, assume that a new channel was created and assigned to the variable called ch.

Table 32.3  Channel Object Properties

Name Example Description
absoluteTime ch.absoluteTime = 720; Specifies the time for daily or weekly updates. You must set this property if you set the update interval daily or weekly. You calculate this value by adding a value from each column in Table 32.4.
cardURL ch.cardURL = icon.gif Specifies a graphical icon for the channel that is displayed in the My Channels. You can set it to the URL of any image. This property is not implemented in Netcaster 1.0.
depth ch.depth = 2 Specifies the number of levels that the Netcaster crawler will download from your channel.
desc ch.desc = "A really great channel" Provides a description for the channel that appears as tool-tip style help in the My Channels.
estCachSize ch.estCacheSize = 1024000 Describes the estimated amount of disk space that your channel will occupy on the user's computer. This value is in kilobytes. Set it to -1 if you don't your know channel's estimated size.
heightHint ch.heightHint = 200 Specifies the preferred height for your channel's window.
intervalTime ch.intervalTime = 60 Specifies the number of minutes to wait between each update. You can use one of the special negative numbers to represent predefined times: -2 for every 15 minutes, -3 for every 30 minutes, -4 for every hour, -5 for daily, and -6 for weekly.
leftHint ch.leftHint = 0 Specifies the preferred coordinate of the channel window's left edge.
maxCacheSize ch.maxCacheSize = 1024000 Describes the maximum amount of disk space required by the channel. This value is in kilobytes.
mode ch.mode = "webtop" Specifies the type of window in which Netcaster displays your channel. Possible values include window, full, or webtop.
name ch.name = "my channel" Assigns a name to your channel.
topHint ch.topHint = 120 Specifies the preferred coordinate of the channel window's top edge.
url ch.url = "http://server/ mychannel" Points to the top-level page of your channel. It must be an absolute URL.
widthHint ch.widthHint = 240 Specifies the preferred width of the channel's window.

Table 32.4  Values for Absolute Times

Day Hour
0 (Sunday) 0 (Midnight)
1440 (Monday) 60 (1am)
2880 (Tuesday) 120 (2am)
4320 (Wednesday) 180 (3am)
5760 (Thursday) 240 (4am)
7200 (Friday) 300 (5am)
8640 (Saturday) 360 (6am)

420 (7am)

480 (8am)

540 (9am)

600 (10am)

660 (11am)

720 (12am)

800 (1pm)

860 (2pm)

920 (3pm)

980 (4pm)

1020 (5pm)

1080 (6pm)

1120 (7pm)

1200 (8pm)

1260 (9pm)

1320 (10pm)

1380 (11pm)


TIP: The values in Table 32.4 are actually the number of minutes since 12:00AM Sunday that elapses up to any point during a week. Thus, you can specify a time such as 12:15am Sunday with a value of 15 or a time such as 11:45 Wednesday with a value of 4320 + 1380 + 45 = 5745.

Understanding How the Netcaster Crawler Works

The Netcaster Crawler downloads the home page of your site. Then, it follows the links it finds down to the level you specify in depth. Crawler downloads all the HTML files first, and then it downloads any images and objects to which those documents are linked. It takes this approach so that the user will at least have the text content of your channel if the download fails for any reason.

As indicated earlier in the chapter, server redirection causes problems for Netcaster Crawler. Netcaster caches your channel and indexes each page by URL returned from the server instead of the URL specified in a link. Thus, if you have a link to http://netcasteriscool that the server redirects to http://netcasteriscool/stuff.html, Netcaster won't find the page in the cache. Netcaster goes online and opens the URL again. If it can't go online, Netcaster notifies the user that it can't connect to the network, even though the page is actually cached on the user's disk.

Page aliases cause similar problems for Netcaster Crawler. If you write a URL that specifies a host such as http://netcaster, relying on the host to open index.html, Netcaster will store the page in the cache as http://netcaster/index.html but won't find it because it looks up the page as http://netcaster.

If while viewing a channel, the user causes Netcaster to follow a link or open a Java class that isn't cached, Netcaster tries to connect to the Internet to download it. If Netcaster can't download the item, it notifies the user and retrieves the item the next time it updates the channel.


TIP: You can use ROBOTS.TXT, described in Chapter 40, "Listing Your Web Site in the Search Tools," to control what the Crawler downloads from your site.


Previous chapterNext chapterContents


© Copyright, Macmillan Computer Publishing. All rights reserved.