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

RSS Applet Configurator (4/4) - exploring XML

RSS Applet Configurator

More Script

<A name="1"></A>
<H2>Colors</H2>
<TABLE>
<TD>
EOF
  foreach my $colourParam (@colourParams) {
    print <<EOF;
<INPUT type="radio" name="selector" onclick="javascript:setFormField(document.forms[0].$colourParam)">
$colourParam:
<INPUT name="$colourParam" size="8"><br>
EOF
}
  print <<EOF;
<TD>
@colorchooser
</TABLE>
Next we print out the names of the color parameters and add a text field for the RGB value as well as a radio button for interfacing with the color chooser.
<H2>Fonts</H2>
EOF
  foreach my $fontParam (@fontParams) {
    print <<EOF;
    $fontParam: family
<SELECT name="${fontParam}_font_family">
<OPTION>
<OPTION value="sansserif">sansserif</OPTION>
<OPTION value="serif">serif</OPTION>
<OPTION value="dialog">dialog</OPTION>
</SELECT>
size:
<INPUT name="${fontParam}_font_size" size="3">
style:
<SELECT name="${fontParam}_font_style">
<OPTION></OPTION>
<OPTION value="bold">bold</OPTION>
<OPTION value="italic">italic</OPTION>
<OPTION value="bolditalic">bolditalic</OPTION>
</SELECT><BR>
EOF
}
  print <<EOF;
<INPUT type="submit" value="Preview!">
</FORM>
EOF
}
Following the same lines we add controls for each font property: Dropdowns for font family and style, a text box for font size.
sub PrintPreview($query) {
  my $src = $query->param('src');
  my $snippet = "<APPLET code=com.exploringxml.rss.applet.RSSViewerApplet.class archive=/xml/rssApplet.jar>\n<PARAM name=src value=$src>\n";
  foreach my $colourParam (@colourParams) {
    my $colour = $query->param($colourParam);
    $colourParam =~ s/_/./g;
    $snippet .= "<PARAM name=$colourParam value=$colour>\n" if ($colour ne '');
  } 
  foreach my $fontParam (@fontParams) {
    my $family = $query->param($fontParam."_font_family");
    $snippet .= "<PARAM name=$fontParam.font.family value=$family>\n" 
      if ($family ne '');
    my $size = $query->param($fontParam."_font_size");
    $snippet .= "<PARAM name=$fontParam.font.size value=$size>\n"
      if ($size ne '');
    my $style = $query->param($fontParam."_font_style");
    $snippet .= "<PARAM name=$fontParam.font.style value=$style>\n"
      if ($style ne '');
  } 
  $snippet .= "</APPLET>\n";
  print <<EOF;
$snippet
<FORM>
<TEXTAREA rows=10 cols=80>$snippet</TEXTAREA>
</FORM>
EOF
}

The preview page is assembled in the variable snippet that gets both included in the HTML and printed in the text area, so that what-you-see-is-what-you-get. Every CGI parameter that is passed from the configuration page to the preview page is turned into the appropriate applet property.

This is just one example how HTML + JavaScript, Java applets, Perl CGIs and XML-based data can come together to build a coherent solution.

https://www.internet.com

Produced by Michael Claßen

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