[system] / trunk / pg / lib / Applet.pm Repository:
ViewVC logotype

Diff of /trunk/pg/lib/Applet.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 5594 Revision 5994
1################################################################################ 1################################################################################
2# WeBWorK Online Homework Delivery System 2# WeBWorK Online Homework Delivery System
3# Copyright 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/ 3# Copyright 2000-2007 The WeBWorK Project, http://openwebwork.sf.net/
4# $CVSHeader: pg/lib/Applet.pm,v 1.3 2007/11/06 16:47:19 gage Exp $ 4# $CVSHeader: pg/lib/Applet.pm,v 1.14 2009/01/28 17:07:08 gage Exp $
5# 5#
6# This program is free software; you can redistribute it and/or modify it under 6# This program is free software; you can redistribute it and/or modify it under
7# the terms of either: (a) the GNU General Public License as published by the 7# the terms of either: (a) the GNU General Public License as published by the
8# Free Software Foundation; either version 2, or (at your option) any later 8# Free Software Foundation; either version 2, or (at your option) any later
9# version, or (b) the "Artistic License" which comes with this package. 9# version, or (b) the "Artistic License" which comes with this package.
35 ################################### 35 ###################################
36 # Configure applet 36 # Configure applet
37 ################################### 37 ###################################
38 38
39 #xml data to set up the problem-rac 39 #xml data to set up the problem-rac
40 $applet->xmlString(qq{<XML> 40 $applet->config(qq{<XML>
41 <point xval='$xval_1' yval='$yval_1' /> 41 <point xval='$xval_1' yval='$yval_1' />
42 <point xval='$xval_2' yval='$yval_2' /> 42 <point xval='$xval_2' yval='$yval_2' />
43 </XML>}); 43 </XML>});
44 44
45 45
75 75
76(not yet completed) 76(not yet completed)
77 77
78The module JavaApplet has defaults for inserting java applets. 78The module JavaApplet has defaults for inserting java applets.
79 79
80The module Applet will store common code for the two types of applet. 80The module Applet stores common code for the two types of applet.
81 81
82=head1 USAGE 82=head1 USAGE
83 83
84This file is included by listing it in the modules section of global.conf. 84These modules are activate by listing it in the modules section of global.conf and rebooting the server.
85The companion file to this one is macros/AppletObjects.pl
86
87qw(Applet FlashApplet JavaApplet)
85 88
86=cut 89=cut
87 90
88 91
89 92
90package Applet; 93package Applet;
91 94
95use URI::Escape;
92 96
93package FlashApplet;
94 97
95 98
96use MIME::Base64 qw( encode_base64 decode_base64); 99use MIME::Base64 qw( encode_base64 decode_base64);
97 100
98 101
99=head2 Default javaScript functions placed in header 102=head2 Default javaScript functions placed in header
103
104=pod
100 105
101These functions are automatically defined for use for 106These functions are automatically defined for use for
102any javaScript placed in the text of a PG question. 107any javaScript placed in the text of a PG question.
103 108
104 getFlashMovie(appletName) -- finds the applet path in the DOM 109 getApplet(appletName) -- finds the applet path in the DOM
105 110
106 submitAction() -- calls the submit action of the applet 111 submitAction() -- calls the submit action of the applets
107 -- the submitAction is defined
108 112
109 initialize() -- calls the initialize action of the applet 113 initializeWWquestion() -- calls the initialize action of the applets
110 114
111 getQE(name) -- gets an HTML element of the question by name 115 getQE(name) -- gets an HTML element of the question by name
112 or by id. Be sure to keep all names and ids 116 or by id. Be sure to keep all names and ids
113 unique within a given PG question. 117 unique within a given PG question.
114 118
115 getQuestionElement(name) -- long form of getQE(name) 119 getQuestionElement(name) -- long form of getQE(name)
116 120
117 listQuestionElements() -- for discovering the names of inputs in the 121 listQuestionElements() -- for discovering the names of inputs in the
118 PG question. An alert dialog will list all 122 PG question. An alert dialog will list all
119 of the elements. 123 of the elements.
120 Usage: Place this at the END of the question, 124 Usage: Place this at the END of the question, just before END_DOCUMENT():
121 just before END_DOCUMENT():
122 125
123 TEXT(qq!<script> listQuestionElements() </script>!); 126 TEXT(qq!<script> listQuestionElements() </script>!);
124 ENDDOCUMENT(); 127 ENDDOCUMENT();
128 to obtain a list of all of the HTML elements in the question
129
130 List of accessor methods made available by the FlashApplet class:
131 Usage: $current_value = $applet->method(new_value or empty)
132 These can also be set when creating the class -- for exampe:
133 $applet = new FlashApplet(
134 # can be replaced by $applet =FlashApplet() when using AppletObjects.pl
135 codebase => findAppletCodebase("$appletName.swf"),
136 appletName => $appletName,
137 appletId => $appletName,
138 submitActionAlias => 'checkAnswer',
139 );
140
141
142 appletId for simplicity and reliability appletId and appletName are always the same
143 appletName
144 archive the name of the .jar file containing the applet code
145 code the name of the applet code in the .jar archive
146 codebase a prefix url used to find the archive and the applet itself
147
148 height rectangle alloted in the html page for displaying the applet
149
150 params an anonymous array containing name/value pairs
151 to configure the applet [name =>'value, ...]
152
153 header stores the text to be added to the header section of the html page
154 object stores the text which places the applet on the html page
155
156 debug in debug mode several alerts mark progress through the procedure of calling the applet
157
158 config configuration are those customizable attributes of the applet which don't
159 change as it is used. When stored in hidden answer fields
160 it is usually stored in base64 encoded format.
161 base64_config base64 encode version of the contents of config
162
163 configAlias (default: config ) names the applet command called with the contents of $self->config
164 to configure the applet. The parameters are passed to the applet in plain text using <xml>
165 The outer tags must be <xml> ..... </xml>
166 state state consists of those customizable attributes of the applet which change
167 as the applet is used. It is stored by the calling .pg question so that
168 when revisiting the question the applet
169 will be restored to the same state it was left in when the question was last
170 viewed.
171
172 getStateAlias (default: getState) alias for command called to read the current state of the applet.
173 The state is passed in plain text xml format with outer tags: <xml>....</xml>
174 setStateAlias (default: setState) alias for the command called to reset the state of the applet.
175 The state is passed in plain text in xml format with outer tags: <xml>....</xml>
176
177 base64_state returns the base64 encoded version of the state stored in the applet object.
178
179 initializeActionAlias -- (default: initializeAction) the name of the javaScript subroutine called to initialize the applet (some overlap with config/ and setState
180 submitActionAlias -- (default: submitAction)the name of the javaScript subroutine called when the submit button of the
181 .pg question is pressed.
182 answerBox -- name of answer box to return answer to: default defaultAnswerBox
183 getAnswer -- (formerly sendData) get student answer from applet and place in answerBox
184 returnFieldName -- (deprecated) synonmym for answerBox
125 185
126 186
127=cut 187=cut
128 188
129 189
190
191
192sub new {
193 my $class = shift;
194 my $self = {
195 appletName =>'',
196 code=>'',
197 codebase=>'',
198# appletId =>'', #always use identical applet Id's and applet Names
199 params =>undef,
200 width => 550,
201 height => 400,
202 base64_state => undef, # this is an state to use for initializing the first occurence of the question.
203 base64_config => undef, # this is the initial (and final?) configuration
204 getStateAlias => 'getXML',
205 setStateAlias => 'setXML',
206 configAlias => 'config',
207 initializeActionAlias => 'setXML',
208 submitActionAlias => 'getXML',
209 submitActionScript => '', # script executed on submitting the WW question
210 answerBox => 'answerBox',
211 headerText => DEFAULT_HEADER_TEXT(),
212 objectText => '',
213 debug => 0,
214 @_,
215 };
216 bless $self, $class;
217 $self->state('<xml></xml>');
218 $self->config('<xml></xml>');
219 return $self;
220}
221
222sub header {
223 my $self = shift;
224 if ($_[0] eq "reset") { # $applet->header('reset'); erases default header text.
225 $self->{headerText}='';
226 } else {
227 $self->{headerText} .= join("",@_); # $applet->header(new_text); concatenates new_text to existing header.
228 }
229 $self->{headerText};
230}
231sub object {
232 my $self = shift;
233 if ($_[0] eq "reset") {
234 $self->{objectText}='';
235 } else {
236 $self->{objectText} .= join("",@_);
237 }
238 $self->{objectText};
239}
240sub params {
241 my $self = shift;
242 if (ref($_[0]) =~/HASH/) {
243 $self->{params} = shift;
244 } elsif ( !defined($_[0]) or $_[0] =~ '') {
245 # do nothing (read)
246 } else {
247 warn "You must enter a reference to a hash for the parameter list";
248 }
249 $self->{params};
250}
251
252sub initializeActionAlias {
253 my $self = shift;
254 $self->{initializeActionAlias} = shift ||$self->{initializeActionAlias}; # replace the current contents if non-empty
255 $self->{initializeActionAlias};
256}
257
258sub submitActionAlias {
259 my $self = shift;
260 $self->{submitActionAlias} = shift ||$self->{submitActionAlias}; # replace the current contents if non-empty
261 $self->{submitActionAlias};
262}
263sub submitActionScript {
264 my $self = shift;
265 $self->{submitActionScript} = shift ||$self->{submitActionScript}; # replace the current contents if non-empty
266 $self->{submitActionScript};
267}
268sub getStateAlias {
269 my $self = shift;
270 $self->{getStateAlias} = shift ||$self->{getStateAlias}; # replace the current contents if non-empty
271 $self->{getStateAlias};
272}
273
274sub setStateAlias {
275 my $self = shift;
276 $self->{setStateAlias} = shift ||$self->{setStateAlias}; # replace the current contents if non-empty
277 $self->{setStateAlias};
278}
279sub configAlias {
280 my $self = shift;
281 $self->{configAlias} = shift ||$self->{configAlias}; # replace the current contents if non-empty
282 $self->{configAlias};
283}
284sub returnFieldName {
285 my $self = shift;
286 $self->{answerBox} = shift ||$self->{answerBox}; # replace the current contents if non-empty
287 $self->{answerBox};
288}
289sub answerBox {
290 my $self = shift;
291 $self->{answerBox} = shift ||$self->{answerBox}; # replace the current contents if non-empty
292 $self->{answerBox};
293}
294sub codebase {
295 my $self = shift;
296 $self->{codebase} = shift ||$self->{codebase}; # replace the current codebase if non-empty
297 $self->{codebase};
298}
299sub code {
300 my $self = shift;
301 $self->{code} = shift ||$self->{code}; # replace the current code if non-empty
302 $self->{code};
303}
304sub height {
305 my $self = shift;
306 $self->{height} = shift ||$self->{height}; # replace the current height if non-empty
307 $self->{height};
308}
309sub width {
310 my $self = shift;
311 $self->{width} = shift ||$self->{width}; # replace the current width if non-empty
312 $self->{width};
313}
314sub archive {
315 my $self = shift;
316 $self->{archive} = shift ||$self->{archive}; # replace the current archive if non-empty
317 $self->{archive};
318}
319sub appletName {
320 my $self = shift;
321 $self->{appletName} = shift ||$self->{appletName}; # replace the current appletName if non-empty
322 $self->{appletName};
323}
324sub debug {
325 my $self = shift;
326 my $new_flag = shift;
327 $self->{debug} = $new_flag if defined($new_flag);
328 $self->{debug};
329}
330sub appletId {
331 appletName(@_);
332}
333sub state {
334 my $self = shift;
335 my $str = shift;
336 $self->{base64_state} = encode_base64($str) ||$self->{base64_state}; # replace the current string if non-empty
337 $self->{base64_state} =~ s/\n//g;
338 decode_base64($self->{base64_state});
339}
340
341sub base64_state{
342 my $self = shift;
343 $self->{base64_state} = shift ||$self->{base64_state}; # replace the current string if non-empty
344 $self->{base64_state};
345}
346sub config {
347 my $self = shift;
348 my $str = shift;
349 $self->{base64_config} = encode_base64($str) || $self->{base64_config}; # replace the current string if non-empty
350 $self->{base64_config} =~ s/\n//g;
351 decode_base64($self->{base64_config});
352}
353sub base64_config {
354 my $self = shift;
355 $self->{base64_config} = shift ||$self->{base64_config}; # replace the current string if non-empty
356 $self->{base64_config} =$self->{base64_config};
357 $self->{base64_config};
358}
359#FIXME
360# need to be able to adjust header material
361
362sub insertHeader {
363 my $self = shift;
364 my $codebase = $self->codebase;
365 my $appletId = $self->appletId;
366 my $appletName = $self->appletName;
367 my $base64_initialState = $self->base64_state;
368 my $initializeAction = $self->initializeActionAlias;
369 my $submitAction = $self->submitActionAlias;
370 my $submitActionScript = $self->submitActionScript;
371 my $setState = $self->setStateAlias;
372 my $getState = $self->getStateAlias;
373 my $config = $self->configAlias;
374 my $base64_config = $self->base64_config;
375 my $debugMode = ($self->debug) ? "1": "0";
376 my $returnFieldName = $self->{returnFieldName};
377 my $answerBox = $self->{answerBox};
378 my $headerText = $self->header();
379
380 $headerText =~ s/(\$\w+)/$1/gee; # interpolate variables p17 of Cookbook
381
382 return $headerText;
383
384
385}
386
387sub insertObject {
388 my $self = shift;
389 my $code = $self->{code};
390 my $codebase = $self->{codebase};
391 my $appletId = $self->{appletName};
392 my $appletName = $self->{appletName};
393 my $archive = $self->{archive};
394 my $width = $self->{width};
395 my $height = $self->{height};
396 my $javaParameters = '';
397 my $flashParameters = '';
398 my %param_hash = %{$self->params()};
399 foreach my $key (keys %param_hash) {
400 $javaParameters .= qq!<param name ="$key" value = "$param_hash{$key}">\n!;
401 $flashParameters .= uri_escape($key).'='.uri_escape($param_hash{$key}).'&';
402 }
403 $flashParameters =~ s/\&$//; # trim last &
404
405
406 $objectText = $self->{objectText};
407 $objectText =~ s/(\$\w+)/$1/gee;
408 return $objectText;
409}
410# sub initialize {
411# my $self = shift;
412# return q{
413# <script>
414# initializeAllApplets();
415# // this should really be done in the <body> tag
416# </script>
417# };
418#
419# }
420########################################################
421# HEADER material for one flash or java applet
422########################################################
423
130use constant DEFAULT_HEADER_TEXT =><<'END_HEADER_SCRIPT'; 424use constant DEFAULT_HEADER_TEXT =><<'END_HEADER_SCRIPT';
131 <script language="javascript">AC_FL_RunContent = 0;</script> 425 <script src="/webwork2_files/js/Base64.js" language="javascript">
132 <script src="http://hosted2.webwork.rochester.edu/webwork2_files/applets/AC_RunActiveContent.js" language="javascript"> 426 </script>
427 <script src="/webwork2_files/js/ww_applet_support.js">
428 //upload functions stored in /opt/webwork/webwork2/htdocs/js ...
133 </script> 429 </script>
134
135
136 <script language="JavaScript"> 430 <script language="JavaScript">
137 431
138 var flash; 432 // set debug mode for this applet
139 function getFlashMovie(appletName) { 433 set_debug($debugMode);
140 var isIE = navigator.appName.indexOf("Microsoft") != -1; 434
141 var obj = (isIE) ? window[appletName] : window.document[appletName]; 435 //////////////////////////////////////////////////////////
142 //return window.document[appletName]; 436 //TEST code
143 if (obj.name = appletName) { 437 //
144 return( obj ); 438 //
145 } else { 439 //////////////////////////////////////////////////////////
146 alert ("can't find applet " + appletName);
147 }
148 }
149
150 function submitAction() {
151 getQE("$returnFieldName").value = getFlashMovie("$appletId").$submitAction();
152 }
153 function initialize() {
154 getFlashMovie("$appletId").$initializeAction("$base64_xmlString");
155 }
156 function getQE(name1) { // get Question Element in problemMainForm by name
157 var isIE = navigator.appName.indexOf("Microsoft") != -1;
158 var obj = (isIE) ? document.getElementById(name1)
159 :document.problemMainForm[name1];
160 // needed for IE -- searches id and name space so it can be unreliable if names are not unique
161 if (obj.name = name1 ) {
162 return( obj );
163 } else {
164 alert("Can't find " + name1);
165 listQuestionElements();
166 }
167 440
168 } 441 ww_applet_list["$appletName"] = new ww_applet("$appletName");
169 function getQuestionElement(name1) {
170 return getQE(name1);
171 }
172 442
173 function listQuestionElements() { // list all HTML elements in main problem form
174 var isIE = navigator.appName.indexOf("Microsoft") != -1;
175 var mainForm = (isIE) ? document.getElementsByTagName("input") : document.getElementsByTagName("input");
176 var str=mainForm.length +" Question Elements\n type | name = value < id > \n";
177 for( var i=0; i< mainForm.length; i++) {
178 str = str + " "+i+" " + mainForm[i].type
179 + " | " + mainForm[i].name
180 + "= " + mainForm[i].value +
181 " <" + mainForm[i].id + ">\n";
182 }
183 alert(str +"\n Place listQuestionElements() at end of document in order to get all form elements!");
184 } 443
444 ww_applet_list["$appletName"].code = "$code";
445 ww_applet_list["$appletName"].codebase = "$codebase";
446 ww_applet_list["$appletName"].appletID = "$appletID";
447 ww_applet_list["$appletName"].base64_state = "$base64_initializationState";
448 ww_applet_list["$appletName"].base64_config = "$base64_config";
449 ww_applet_list["$appletName"].getStateAlias = "$getState";
450 ww_applet_list["$appletName"].setStateAlias = "$setState";
451 ww_applet_list["$appletName"].configAlias = "$config";
452 ww_applet_list["$appletName"].initializeActionAlias = "$initializeAction";
453 ww_applet_list["$appletName"].submitActionAlias = "$submitAction";
454 ww_applet_list["$appletName"].submitActionScript = "$submitActionScript";
455 ww_applet_list["$appletName"].answerBox = "$answerBox";
456 ww_applet_list["$appletName"].debug = "$debugMode";
185 457
186 458
459 //////////////////////////////////////////////////////////
460 //CONFIGURATIONS
461 //
462 // configurations are "permanent"
463 //////////////////////////////////////////////////////////
464
465// applet_config_list["$appletName"] = function() {
466// debug_add("applet_config_list:\n attempt to configure $appletName . $config ( $base64_config ) if config function is defined: "
467// );
468// try {
469// if (( typeof(getApplet("$appletName").$config) == "function" ) ) {
470// debug_add("CONFIGURE $appletName");
471// getApplet("$appletName").$config(Base64.decode("$base64_config"));
472// }
473// } catch(e) {
474// alert("Error executing configuration command $config for $appletName: " + e );
475// }
476// }
477// ////////////////////////////////////////////////////////////
478// //
479// //STATE:
480// // state can vary as the applet is manipulated -- it is reset from the questions _state values
481// //
482// //////////////////////////////////////////////////////////
483//
484// applet_setState_list["$appletName"] = function(state) {
485// debug_add("Begin setState for applet $appletName");
486// debug_add("Obtain state from $appletName"+"_state");
487// state = state || getQE("$appletName"+"_state").value;
488// if ( base64Q(state) ) {
489// state=Base64.decode(state);
490// }
491// if (state.match(/<xml/i) || state.match(/<?xml/i) ) { // if state starts with <?xml
492//
493// debug_add("applet_setState_list: \n set (decoded) state for $appletName to " +
494// state +"\nfunction type is " +typeof(getApplet("$appletName").$setState)
495// );
496// try {
497// if (( typeof(getApplet("$appletName").$setState) =="function" ) ) {
498// debug_add("setState for $appletName");
499// getApplet("$appletName").$setState( state );
500// }
501// } catch(e) {
502// alert("Error in setting state of $appletName using command $setState : " + e );
503// }
504// } else if (debug) {
505// alert("new state was empty string or did not begin with <xml-- state was not reset");
506// }
507// };
508// applet_getState_list["$appletName"] = function () {
509// debug_add("get current state for applet $appletName and store it in $appletName"+"_state");
510// var applet = getApplet("$appletName");
511// try {
512// if (( typeof(applet.$getState) == "function" ) ) { // there may be no state function
513// state = applet.$getState(); // get state in xml format
514// debug_add("state has type " + typeof(state));
515// state = String(state); // geogebra returned an object type instead of a string type
516// debug_add("state converted to type " + typeof(state));
517// }
518//
519// if (!debug) {
520// state = Base64.encode(state);
521// }; // replace state by encoded version unless in debug mode
522//
523// debug_add("state is "+state); // this should still be in plain text
524// getQE("$appletName"+"_state").value = state; //place state in input item (debug: textarea, otherwise: hidden)
525// } catch (e) {
526// alert("Error in getting state for $appletName " + e );
527// }
528// };
529//
530// ////////////////////////////////////////////////////////////
531// //
532// //INITIALIZE
533// //
534// ////////////////////////////////////////////////////////////
535//
536//
537// applet_checkLoaded_list["$appletName"] = function() { // this function returns 0 unless:
538// // applet has already been flagged as ready in applet_isReady_list
539// // applet.config is defined (or alias for .config)
540// // applet.setState is defined
541// // applet.isActive is defined
542// // applet reported that it is loaded by calling loadQ()
543// var ready = 0;
544// var applet = getApplet("$appletName");
545// if (!debug && applet_isReady_list["$appletName"]) {return(1)}; // memorize readiness in non-debug mode
546// if ( typeof(applet.$config) == "function") {
547// debug_add( "applet.config is " + typeof(applet.$config) );
548// ready = 1;
549// }
550// if( typeof(applet.$getState) == "function") {
551// debug_add( "applet.getState is " + typeof(applet.$getState) );
552// ready =1;
553// }
554// if (typeof(applet.isActive) == "function" && applet.isActive ) {
555// debug_add( "applet.isActive is " + typeof(applet.isActive) );
556// ready =1;
557// }
558// if (typeof(applet_reportsLoaded_list["$appletName"]) !="undefined" && applet_reportsLoaded_list["$appletName"] != 0 ) {
559// debug_add( "applet reports that it is loaded " + applet_reportsLoaded_list["$appletName"] );
560// ready =1;
561// }
562// applet_isReady_list["$appletName"]= ready;
563// return(ready);
564// }
565//
566// applet_initializeAction_list["$appletName"] = function (state) {
567// applet_setState_list["$appletName"](state);
568// };
569//
570// applet_submitAction_list["$appletName"] = function () {
571// if (! applet_isReady_list["$appletName"] ) {
572// alert("$appletName is not ready");
573// }
574// applet_getState_list["$appletName"]();
575// $submitActionScript
576// //getQE("$answerBox").value = getApplet("$appletName").getAnswer(); //FIXME -- not needed in general?
577// };
187 </script> 578 </script>
188 579
189END_HEADER_SCRIPT 580END_HEADER_SCRIPT
190 581
582package FlashApplet;
583@ISA = qw(Applet);
191 584
192# <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" 585
193# width="550" height="400" id="$appletId" align="middle"> 586=head2 Insertion HTML code for FlashApplet
194# <param name="allowScriptAccess" value="sameDomain" />
195# <param name="allowFullScreen" value="false" />
196# <param name="movie" value="$appletName.swf" />
197# <param name="quality" value="high" />
198# <param name="bgcolor" value="#ffffcc" />
199# <embed src="$codebase/$appletName.swf" quality="high" bgcolor="#ffffcc" width="550" height="400" name="$appletName"
200# align="middle" id="$appletId",
201# align="middle" allowScriptAccess="sameDomain"
202# allowFullScreen="false"
203# type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
204# <param name="quality" value="high" /><param name="bgcolor" value="#ffffcc" />
205# </object>
206 587
207=pod 588=pod
208 589
209The secret to making this applet work with IE in addition to normal browsers 590The secret to making this applet work with IE in addition to normal browsers
210is the addition of the C(<form></form>) construct just before the object. 591is the addition of the C(<form></form>) construct just before the object.
216This follows method2 of the advice given in url(http://kb.adobe.com/selfservice/viewContent.do?externalId=kb400730&sliceId=2) 597This follows method2 of the advice given in url(http://kb.adobe.com/selfservice/viewContent.do?externalId=kb400730&sliceId=2)
217Method1 and methods involving SWFObject(Geoff Stearns) and SWFFormFix (Steve Kamerman) have yet to be fully investigated: 598Method1 and methods involving SWFObject(Geoff Stearns) and SWFFormFix (Steve Kamerman) have yet to be fully investigated:
218http://devel.teratechnologies.net/swfformfix/swfobject_swfformfix_source.js 599http://devel.teratechnologies.net/swfformfix/swfobject_swfformfix_source.js
219http://www.teratechnologies.net/stevekamerman/index.php?m=01&y=07&entry=entry070101-033933 600http://www.teratechnologies.net/stevekamerman/index.php?m=01&y=07&entry=entry070101-033933
220 601
221 use constant DEFAULT_OBJECT_TEXT =><<'END_OBJECT_TEXT'; 602 use constant DEFAULT_OBJECT_TEXT =><<'END_OBJECT_TEXT';
222 <form></form> 603 <form></form>
223 <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 604 <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
224 id="$appletName" width="500" height="375" 605 id="$appletName" width="500" height="375"
225 codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab"> 606 codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">
226 <param name="movie" value="$codebase/$appletName.swf" /> 607 <param name="movie" value="$codebase/$appletName.swf" />
227 <param name="quality" value="high" /> 608 <param name="quality" value="high" />
228 <param name="bgcolor" value="#869ca7" /> 609 <param name="bgcolor" value="#869ca7" />
229 <param name="allowScriptAccess" value="sameDomain" /> 610 <param name="allowScriptAccess" value="sameDomain" />
230 <embed src="$codebase/$appletName.swf" quality="high" bgcolor="#869ca7" 611 <embed src="$codebase/$appletName.swf" quality="high" bgcolor="#869ca7"
231 width="550" height="400" name="$appletName" align="middle" id="$appletID" 612 width="$width" height="$height" name="$appletName" align="middle" id="$appletName"
232 play="true" loop="false" quality="high" allowScriptAccess="sameDomain" 613 play="true" loop="false" quality="high" allowScriptAccess="sameDomain"
233 type="application/x-shockwave-flash" 614 type="application/x-shockwave-flash"
234 pluginspage="http://www.macromedia.com/go/getflashplayer"> 615 pluginspage="http://www.macromedia.com/go/getflashplayer">
235 </embed> 616 </embed>
236 617
237 </object> 618 </object>
238 END_OBJECT_TEXT 619 END_OBJECT_TEXT
620
239 621
240=cut 622=cut
241 623
242use constant DEFAULT_OBJECT_TEXT =><<'END_OBJECT_TEXT'; 624use constant DEFAULT_OBJECT_TEXT =><<'END_OBJECT_TEXT';
243 <form></form> 625 <form></form>
246 codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab"> 628 codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">
247 <param name="movie" value="$codebase/$appletName.swf" /> 629 <param name="movie" value="$codebase/$appletName.swf" />
248 <param name="quality" value="high" /> 630 <param name="quality" value="high" />
249 <param name="bgcolor" value="#869ca7" /> 631 <param name="bgcolor" value="#869ca7" />
250 <param name="allowScriptAccess" value="sameDomain" /> 632 <param name="allowScriptAccess" value="sameDomain" />
633 <param name="FlashVars" value="$flashParameters"/>
251 <embed src="$codebase/$appletName.swf" quality="high" bgcolor="#869ca7" 634 <embed src="$codebase/$appletName.swf" quality="high" bgcolor="#869ca7"
252 width="550" height="400" name="$appletName" align="middle" id="$appletID" 635 width="$width" height="$height" name="$appletName" align="middle" id="$appletName"
253 play="true" loop="false" quality="high" allowScriptAccess="sameDomain" 636 play="true" loop="false" quality="high" allowScriptAccess="sameDomain"
254 type="application/x-shockwave-flash" 637 type="application/x-shockwave-flash"
255 pluginspage="http://www.macromedia.com/go/getflashplayer"> 638 pluginspage="http://www.macromedia.com/go/getflashplayer"
639 FlashVars="$flashParameters">
256 </embed> 640 </embed>
257 641
258 </object> 642 </object>
259END_OBJECT_TEXT 643END_OBJECT_TEXT
260 644
261
262sub new { 645sub new {
263 my $class = shift; 646 my $class = shift;
264 my $self = {
265 host =>'',
266 port => '',
267 path => '',
268 appletName =>'',
269 codebase=>'',
270 appletId =>'',
271 params =>undef,
272 base64_xmlString => 'foobar',
273 initializeActionAlias => 'setupProblem',
274 submitActionAlias => 'checkAnswer',
275 returnFieldName => 'receivedField',
276 headerText => DEFAULT_HEADER_TEXT(),
277 objectText => DEFAULT_OBJECT_TEXT(), 647 $class -> SUPER::new( objectText => DEFAULT_OBJECT_TEXT(),
278 @_, 648 @_
279 }; 649 );
280 bless $self, $class;
281 #$self -> _initialize(@_);
282 return $self;
283}
284 650
285sub header {
286 my $self = shift;
287 if ($_[0] eq "reset") { # $applet->header('reset'); erases default header text.
288 $self->{headerText}='';
289 } else {
290 $self->{headerText} .= join("",@_); # $applet->header(new_text); concatenates new_text to existing header.
291 }
292 $self->{headerText};
293} 651}
294sub object {
295 my $self = shift;
296 if ($_[0] eq "reset") {
297 $self->{objectText}='';
298 } else {
299 $self->{objectText} .= join("",@_);
300 }
301 $self->{objectText};
302}
303sub params {
304 my $self = shift;
305 if (ref($_[0]) =~/HASH/) {
306 $self->{params} = shift;
307 } elsif ( $_[0] =~ '') {
308 # do nothing (read)
309 } else {
310 warn "You must enter a reference to a hash for the parameter list";
311 }
312 $self->{params};
313}
314
315sub initializeActionAlias {
316 my $self = shift;
317 $self->{initializeActionAlias} = shift ||$self->{initializeActionAlias}; # replace the current contents if non-empty
318 $self->{initializeActionAlias};
319}
320 652
321sub submitActionAlias {
322 my $self = shift;
323 $self->{submitActionAlias} = shift ||$self->{submitActionAlias}; # replace the current contents if non-empty
324 $self->{submitActionAlias};
325}
326sub returnFieldName {
327 my $self = shift;
328 $self->{returnFieldName} = shift ||$self->{returnFieldName}; # replace the current contents if non-empty
329 $self->{returnFieldName};
330}
331sub codebase {
332 my $self = shift;
333 $self->{codebase} = shift ||$self->{codebase}; # replace the current codebase if non-empty
334 $self->{codebase};
335}
336sub appletName {
337 my $self = shift;
338 $self->{appletName} = shift ||$self->{appletName}; # replace the current appletName if non-empty
339 $self->{appletName};
340}
341sub appletId {
342 my $self = shift;
343 $self->{appletId} = shift ||$self->{appletId}; # replace the current appletName if non-empty
344 $self->{appletId};
345}
346sub xmlString {
347 my $self = shift;
348 my $str = shift;
349 $self->{base64_xmlString} = encode_base64($str) ||$self->{base64_xmlString}; # replace the current string if non-empty
350 $self->{base64_xmlString} =~ s/\n//g;
351 decode_base64($self->{base64_xmlString});
352}
353 653
354sub base64_xmlString{ 654package JavaApplet;
355 my $self = shift; 655@ISA = qw(Applet);
356 $self->{base64_xmlString} = shift ||$self->{base64_xmlString}; # replace the current string if non-empty
357 $self->{base64_xmlString};
358}
359 656
360#FIXME 657=head2 Insertion HTML code for JavaApplet
361# need to be able to adjust header material
362 658
363sub insertHeader { 659=pod
364 my $self = shift; 660
365 my $codebase = $self->{codebase}; 661The secret to making this applet work with IE in addition to normal browsers
366 my $appletId = $self->{appletId}; 662is the addition of the C(<form></form>) construct just before the object.
367 my $appletName = $self->{appletName}; 663
368 my $base64_xmlString = $self->{base64_xmlString}; 664For some reason IE has trouble locating a flash object which is contained
369 my $initializeAction = $self->{initializeActionAlias}; 665within a form. Adding this second blank form with the larger problemMainForm
370 my $submitAction = $self->{submitActionAlias}; 666seems to solve the problem.
371 my $returnFieldName= $self->{returnFieldName}; 667
372 my $headerText = $self->header(); 668This follows method2 of the advice given in url(http://kb.adobe.com/selfservice/viewContent.do?externalId=kb400730&sliceId=2)
373 $headerText =~ s/(\$\w+)/$1/gee; # interpolate variables p17 of Cookbook 669Method1 and methods involving SWFObject(Geoff Stearns) and SWFFormFix (Steve Kamerman) have yet to be fully investigated:
670http://devel.teratechnologies.net/swfformfix/swfobject_swfformfix_source.js
671http://www.teratechnologies.net/stevekamerman/index.php?m=01&y=07&entry=entry070101-033933
672
673 use constant DEFAULT_OBJECT_TEXT =><<'END_OBJECT_TEXT';
674 <form></form>
675 <applet
676 code = "$code"
677 codebase = "$codebase"
678 archive = "$archive"
679 name = "$appletName"
680 id = "$appletName"
681 width = "$width"
682 height = "$height"
683 MAYSCRIPT
684 >
685 $javaParameters
686 </applet>
687 END_OBJECT_TEXT
688
689=cut
690
691use constant DEFAULT_OBJECT_TEXT =><<'END_OBJECT_TEXT';
692 <form></form>
693 <applet
694 code = "$code"
695 codebase = "$codebase"
696 archive = "$archive"
697 name = "$appletName"
698 id = "$appletName"
699 width = "$width"
700 height = "$height"
701 MAYSCRIPT
702 >
703 $javaParameters
374 704
375 return $headerText; 705 Sorry, the Applet could not be started. Please make sure that
706Java 1.4.2 (or later) is installed and activated.
707(<a href="http://java.sun.com/getjava">click here to install Java now</a>)
708 </applet>
709END_OBJECT_TEXT
376 710
377 711sub new {
378}
379
380
381# <script language="javascript">
382# if (AC_FL_RunContent == 0) {
383# alert("This page requires AC_RunActiveContent.js.");
384# } else {
385# AC_FL_RunContent(
386# 'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
387# 'width', '100%',
388# 'height', '100%',
389# 'src', 'http://$codebase/$appletName',
390# 'quality', 'high',
391# 'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
392# 'align', 'middle',
393# 'play', 'true',
394# 'loop', 'true',
395# 'scale', 'showall',
396# 'wmode', 'window',
397# 'devicefont', 'false',
398# 'id', '$appletId',
399# 'bgcolor', '#ffffcc',
400# 'name', '$appletName',
401# 'menu', 'true',
402# 'allowFullScreen', 'false',
403# 'allowScriptAccess','sameDomain',
404# 'movie', '$appletName',
405# 'salign', ''
406# ); //end AC code
407# }
408# </script>
409sub insertObject {
410 my $self = shift; 712 my $class = shift;
411 my $codebase = $self->{codebase}; 713 $class -> SUPER::new( objectText => DEFAULT_OBJECT_TEXT(),
412 my $appletId = $self->{appletId}; 714 @_
413 my $appletName = $self->{appletName}; 715 );
414 $codebase = findAppletCodebase("$appletName.swf") unless $codebase;
415 $objectText = $self->{objectText};
416 $objectText =~ s/(\$\w+)/$1/gee;
417 return $objectText;
418}
419 716
420sub initialize {
421 my $self = shift;
422 return q{
423 <script>
424 initialize();
425 // this should really be done in the <body> tag
426 </script>
427 };
428
429} 717}
718
719
430 720
4311; 7211;

Legend:
Removed from v.5594  
changed lines
  Added in v.5994

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9