RSS Applet Configurator (3/4) - exploring XML | WebReference

RSS Applet Configurator (3/4) - exploring XML

RSS Applet Configurator

The Configurator Script

Let's dissect the Perl script and see how it works:

#!/opt/bin/perl
require CGI;
my $query = new CGI;
The first line tells the CGI runtime in the Web server where to find the perl interpreter. CGI is a package that encapsulates the parameter passing so that the variable query will contain a hashtable of all the query parameters, keyed by parameter name.
my @colourParams = ( 'box_foreground', 'box_background', 
		     'title_foreground', 'title_backgound',
		     'title_foreground_mouseover', 'title_background_mouseover',
		     'item_foreground', 'item_backgound',
		     'item_foreground_mouseover', 'item_background_mouseover',
		   );
my @fontParams = ( 'title', 'item' );
print "Content-Type: text/html\n\n";
Next we define the applet's color and font parameters and write an HTTP header explaining that HTML will be coming your browser's way.
if ($query->param('preview') eq '') {
  &PrintConfigPage;
}
else {
  &PrintPreviewPage;
}
exit(1);
The preview parameter determines whether we send the configuration page, or display the resulting preview.
sub PrintConfigPage {
  &PrintHeader;
  &PrintConfig;
  &PrintFooter;
}
sub PrintPreviewPage {
  &PrintHeader;
  &PrintPreview;
  &PrintFooter;
}
Both pages contain header and footer parts, so we factored that out.
sub PrintHeader {
  print <<EOF;
<HTML><HEAD><TITLE>RSSViewerApplet Configurator</TITLE>
<SCRIPT type="text/javascript"><!--
  var field;
  function setFormField(f) {
    field = f;
  }
  function changeBG(what) {
    document.forms[0].output.value = what;
    field.value = what;
  }
// -->
</SCRIPT>
</HEAD><BODY>
EOF
}
sub PrintFooter {
  print <<EOF;
</BODY></HTML>
EOF
}
The header contains JavaScript code to move the chosen color from the color table to the selected applet property. The footer just closes the HTML page.
sub PrintConfig {
  open(FH, "colorchooser.html");
  @colorchooser = <FH>;
This poor man's version of including code retrieves the color chooser part of this page, some fairly repetitive HTML with some onclick() JavaScript for setting the respective RGB value in the text field.
  print <<EOF;
<FORM>
<INPUT type="hidden" name="preview">
<H2>RSS source</H2>
<SELECT name="src">
<OPTION value="https://$ENV{SERVER_NAME}/xml/index.rss">
XML column at WebReference</OPTION>
<OPTION value="https://$ENV{SERVER_NAME}/webreference.rdf">
WebReference News</OPTION>
<OPTION value="https://$ENV{SERVER_NAME}/js/tips/channels/last1512.rdf">
JavaScript Tip of the Day</OPTION>
</SELECT>
Here we populate the drop-down list with the currently available news feeds.

More script.

https://www.internet.com

Produced by Michael Claßen

URL: https://www.webreference.com/xml/column28/3.html
Created: Jan 27, 2000
Revised: Jan 27, 2000