--- loncom/xml/lonxml.pm 2003/05/21 20:41:55 1.255 +++ loncom/xml/lonxml.pm 2003/05/28 21:05:33 1.258 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # XML Parser Module # -# $Id: lonxml.pm,v 1.255 2003/05/21 20:41:55 sakharuk Exp $ +# $Id: lonxml.pm,v 1.258 2003/05/28 21:05:33 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -494,6 +494,7 @@ sub inner_xmlparse { my $finaloutput = ''; my $result; my $token; + my $dontpop=0; while ( $#$pars > -1 ) { while ($token = $$pars['-1']->get_token) { if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) { @@ -520,57 +521,49 @@ sub inner_xmlparse { $Apache::lonxml::usestyle=0; my $string=$$style_for_target{$token->[1]}. ''; -##### LETS TRY VARIABLE INTERPOLATION (it may be stupid but at least it works) - my %localhash=%{$token->[2]}; - foreach my $localkey (keys %localhash) { - $string=~s/\$$localkey/$localhash{$localkey}/g; - } -##### &Apache::lonxml::newparser($pars,\$string); + $Apache::lonxml::style_values=$$parstack[-1]; } else { $result = &callsub("start_$token->[1]", $target, $token, $stack, $parstack, $pars, $safeeval, $style_for_target); } } elsif ($token->[0] eq 'E') { - #clear out any tags that didn't end - while ($token->[1] ne $$stack['-1'] && ($#$stack > -1)) { - my $lasttag=$$stack[-1]; - if ($token->[1] =~ /^$lasttag$/i) { - &Apache::lonxml::warning('Using tag </'.$token->[1].'> on line '.$token->[3].' as end tag to <'.$$stack[-1].'>'); - last; - } else { - &Apache::lonxml::warning('Found tag </'.$token->[1].'> on line '.$token->[3].' when looking for </'.$$stack[-1].'> in file'); - &end_tag($stack,$parstack,$token); - } - } - if ($Apache::lonxml::usestyle && exists($$style_for_target{'/'."$token->[1]"})) { $Apache::lonxml::usestyle=0; my $string=$$style_for_target{'/'.$token->[1]}. - ''; -##### LETS TRY VARIABLE INTERPOLATION (it may be stupid but at least it works) - my @localarray = split /;/, $$parstack[-1]; - foreach my $localelement (@localarray) { - $localelement=~/my\s+\$([^=]+)=\"(.*)\"$/; - my ($whatchange,$tochange) = ($1,$2); - $string=~s/\$$whatchange/$tochange/g; - } -##### + ''; &Apache::lonxml::newparser($pars,\$string); + $Apache::lonxml::style_values=$$parstack[-1]; + $dontpop=1; } else { - $result = &callsub("end_$token->[1]", $target, $token, $stack, - $parstack, $pars,$safeeval, $style_for_target); + #clear out any tags that didn't end + while ($token->[1] ne $$stack['-1'] && ($#$stack > -1)) { + my $lasttag=$$stack[-1]; + if ($token->[1] =~ /^$lasttag$/i) { + &Apache::lonxml::warning('Using tag </'.$token->[1].'> on line '.$token->[3].' as end tag to <'.$$stack[-1].'>'); + last; + } else { + &Apache::lonxml::warning('Found tag </'.$token->[1].'> on line '.$token->[3].' when looking for </'.$$stack[-1].'> in file'); + &end_tag($stack,$parstack,$token); + } + } + $result = &callsub("end_$token->[1]", $target, $token, $stack, + $parstack, $pars,$safeeval, $style_for_target); } } else { &Apache::lonxml::error("Unknown token event :$token->[0]:$token->[1]:"); } #evaluate variable refs in result if ($result ne "") { + my $extras; + if (!$Apache::lonxml::usestyle) { + $extras=$Apache::lonxml::style_values; + } if ( $#$parstack > -1 ) { - $result=&Apache::run::evaluate($result,$safeeval,$$parstack[-1]); + $result=&Apache::run::evaluate($result,$safeeval,$extras.$$parstack[-1]); } else { - $result= &Apache::run::evaluate($result,$safeeval,''); + $result= &Apache::run::evaluate($result,$safeeval,$extras); } } if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) { @@ -591,9 +584,10 @@ sub inner_xmlparse { } $result = ''; - if ($token->[0] eq 'E') { + if ($token->[0] eq 'E' && !$dontpop) { &end_tag($stack,$parstack,$token); } + $dontpop=0; } if ($#$pars > -1) { pop @$pars; @@ -1031,8 +1025,6 @@ sub newparser { } else { push (@Apache::lonxml::pwd, $dir); } -# &Apache::lonxml::debug("pwd:$#Apache::lonxml::pwd"); -# &Apache::lonxml::debug("pwd:$Apache::lonxml::pwd[$#Apache::lonxml::pwd]"); } sub parstring { @@ -1200,7 +1192,7 @@ sub handler { my $target=&get_target(); - $Apache::lonxml::debug=0; + $Apache::lonxml::debug=$ENV{'user.debug'}; if ($ENV{'browser.mathml'}) { $request->content_type('text/xml'); @@ -1322,7 +1314,7 @@ sub error { sub warning { $warningcount++; - if ($ENV{'request.state'} eq 'construct') { + if ($ENV{'request.state'} eq 'construct' || $Apache::lonxml::debug) { print "WARNING:".join('
',@_)."
\n"; } }