################################################################################ # WeBWorK Online Homework Delivery System # Copyright © 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/ # $CVSHeader: pg/lib/Applet.pm,v 1.1 2007/10/30 15:57:04 gage Exp $ # # This program is free software; you can redistribute it and/or modify it under # the terms of either: (a) the GNU General Public License as published by the # Free Software Foundation; either version 2, or (at your option) any later # version, or (b) the "Artistic License" which comes with this package. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See either the GNU General Public License or the # Artistic License for more details. ################################################################################ =head1 NAME Applet.pl - Provides code for inserting FlashApplets and JavaApplets into webwork problems =head1 SYNPOSIS ################################### # Create link to applet ################################### my $appletName = "LineThruPointsWW"; $applet = new FlashApplet( codebase => findAppletCodebase("$appletName.swf"), appletName => $appletName, appletId => $appletName, submitActionAlias => 'checkAnswer', ); ################################### # Configure applet ################################### #xml data to set up the problem-rac $applet->xmlString(qq{ }); ################################### # insert applet header material ################################### HEADER_TEXT($applet->insertHeader ); ################################### # Text section # ################################### #insert applet into body ################################### TEXT( MODES(TeX=>'object code', HTML=>$applet->insertObject)); =head1 DESCRIPTION This file provides an object to store in one place all of the information needed to call an applet. The object FlashApplet has defaults for inserting flash applets. =over =item * =item * =back (not yet completed) The module JavaApplet has defaults for inserting java applets. The module Applet will store common code for the two types of applet. =head1 USAGE This file is included by listing it in the modules section of global.conf. =cut package Applet; package FlashApplet; use MIME::Base64 qw( encode_base64 decode_base64); use constant DEFAULT_HEADER_TEXT =><<'END_HEADER_SCRIPT'; END_HEADER_SCRIPT # # # # # # # # # use constant DEFAULT_OBJECT_TEXT =><<'END_OBJECT_TEXT';
END_OBJECT_TEXT sub new { my $class = shift; my $self = { host =>'', port => '', path => '', appletName =>'', codebase=>'', appletId =>'', params =>undef, base64_xmlString => 'foobar', initializeActionAlias => 'setupProblem', submitActionAlias => 'checkAnswer', returnFieldName => 'receivedField', headerText => DEFAULT_HEADER_TEXT(), objectText => DEFAULT_OBJECT_TEXT(), @_, }; bless $self, $class; #$self -> _initialize(@_); return $self; } sub header { my $self = shift; if ($_[0] eq "reset") { # $applet->header('reset'); erases default header text. $self->{headerText}=''; } else { $self->{headerText} .= join("",@_); # $applet->header(new_text); concatenates new_text to existing header. } $self->{headerText}; } sub object { my $self = shift; if ($_[0] eq "reset") { $self->{objectText}=''; } else { $self->{objectText} .= join("",@_); } $self->{objectText}; } sub params { my $self = shift; if (ref($_[0]) =~/HASH/) { $self->{params} = shift; } elsif ( $_[0] =~ '') { # do nothing (read) } else { warn "You must enter a reference to a hash for the parameter list"; } $self->{params}; } sub initializeActionAlias { my $self = shift; $self->{initializeActionAlias} = shift ||$self->{initializeActionAlias}; # replace the current contents if non-empty $self->{initializeActionAlias}; } sub submitActionAlias { my $self = shift; $self->{submitActionAlias} = shift ||$self->{submitActionAlias}; # replace the current contents if non-empty $self->{submitActionAlias}; } sub returnFieldName { my $self = shift; $self->{returnFieldName} = shift ||$self->{returnFieldName}; # replace the current contents if non-empty $self->{returnFieldName}; } sub codebase { my $self = shift; $self->{codebase} = shift ||$self->{codebase}; # replace the current codebase if non-empty $self->{codebase}; } sub appletName { my $self = shift; $self->{appletName} = shift ||$self->{appletName}; # replace the current appletName if non-empty $self->{appletName}; } sub appletId { my $self = shift; $self->{appletId} = shift ||$self->{appletId}; # replace the current appletName if non-empty $self->{appletId}; } sub xmlString { my $self = shift; my $str = shift; $self->{base64_xmlString} = encode_base64($str) ||$self->{base64_xmlString}; # replace the current string if non-empty $self->{base64_xmlString} =~ s/\n//g; decode_base64($self->{base64_xmlString}); } sub base64_xmlString{ my $self = shift; $self->{base64_xmlString} = shift ||$self->{base64_xmlString}; # replace the current string if non-empty $self->{base64_xmlString}; } #FIXME # need to be able to adjust header material sub insertHeader { my $self = shift; my $codebase = $self->{codebase}; my $appletId = $self->{appletId}; my $appletName = $self->{appletName}; my $base64_xmlString = $self->{base64_xmlString}; my $initializeAction = $self->{initializeActionAlias}; my $submitAction = $self->{submitActionAlias}; my $returnFieldName= $self->{returnFieldName}; my $headerText = $self->header(); $headerText =~ s/(\$\w+)/$1/gee; # interpolate variables p17 of Cookbook return $headerText; } # sub insertObject { my $self = shift; my $codebase = $self->{codebase}; my $appletId = $self->{appletId}; my $appletName = $self->{appletName}; $codebase = findAppletCodebase("$appletName.swf") unless $codebase; $objectText = $self->{objectText}; $objectText =~ s/(\$\w+)/$1/gee; return $objectText; } sub initialize { my $self = shift; return q{ }; } 1;