--- loncom/xml/lonxml.pm 2002/10/17 14:42:07 1.203 +++ loncom/xml/lonxml.pm 2002/10/21 17:10:35 1.206 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # XML Parser Module # -# $Id: lonxml.pm,v 1.203 2002/10/17 14:42:07 sakharuk Exp $ +# $Id: lonxml.pm,v 1.206 2002/10/21 17:10:35 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -60,7 +60,7 @@ package Apache::lonxml; use vars -qw(@pwd @outputstack $redirection $import @extlinks $metamode $evaluate %insertlist @namespace $prevent_entity_encode); +qw(@pwd @outputstack $redirection $import @extlinks $metamode $evaluate %insertlist @namespace $prevent_entity_encode $errorcount $warningcount); use strict; use HTML::LCParser(); use HTML::TreeBuilder(); @@ -106,6 +106,10 @@ use Apache::lonmsg(); #debugging control, to turn on debugging modify the correct handler $Apache::lonxml::debug=0; +# keeps count of the number of warnings and errors generated in a parse +$warningcount=0; +$errorcount=0; + #path to the directory containing the file currently being processed @pwd=(); @@ -140,6 +144,10 @@ $Apache::lonxml::registered=0; # a pointer the the Apache request object $Apache::lonxml::request=''; +# a problem number counter, and check on hether it is used +$Apache::lonxml::counter=0; +$Apache::lonxml::counter_changed=0; + sub xmlbegin { my $output=''; if ($ENV{'browser.mathml'}) { @@ -555,6 +563,7 @@ sub xmlparse { if ($ENV{'request.uri'}) { &writeallows($ENV{'request.uri'}); } + if ($Apache::lonxml::counter_changed) { &store_counter() } return $finaloutput; } @@ -847,14 +856,9 @@ sub setup_globals { my ($request,$target)=@_; $Apache::lonxml::request=$request; $Apache::lonxml::registered = 0; - if ($ENV{'form.counter'}) { - $Apache::lonxml::counter=$ENV{'form.counter'} - } elsif (not defined $Apache::lonxml::counter) { - $Apache::lonxml::counter=1; - my %moreenv; - $moreenv{'form.counter'}=$Apache::lonxml::counter; - &Apache::lonnet::appenv(%moreenv); - } + $errorcount=0; + $warningcount=0; + &init_counter(); @Apache::lonxml::pwd=(); @Apache::lonxml::extlinks=(); if ($target eq 'meta') { @@ -1038,6 +1042,26 @@ sub get_all_text_unbalanced { return $result } +sub increment_counter { + $Apache::lonxml::counter++; + $Apache::lonxml::counter_changed=1; +} + +sub init_counter { + if (defined($ENV{'form.counter'})) { + $Apache::lonxml::counter=$ENV{'form.counter'}; + } elsif (not defined($Apache::lonxml::counter)) { + $Apache::lonxml::counter=1; + &store_counter(); + } + $Apache::lonxml::counter_changed=0; +} + +sub store_counter { + &Apache::lonnet::appenv(('form.counter' => $Apache::lonxml::counter)); + return ''; +} + sub get_all_text { my($tag,$pars)= @_; my $depth=0; @@ -1334,6 +1358,7 @@ sub debug { } sub error { + $errorcount++; if (($Apache::lonxml::debug eq 1) || ($ENV{'request.state'} eq 'construct') ) { # If printing in construction space, put the error inside

     print "ERROR:".join("\n",@_)."\n";
@@ -1359,6 +1384,7 @@ sub error {
 }
 
 sub warning {
+  $warningcount++;
   if ($ENV{'request.state'} eq 'construct') {
     print "WARNING:".join('
',@_)."
\n"; }