--- loncom/xml/lonxml.pm	2000/10/09 14:07:02	1.24
+++ loncom/xml/lonxml.pm	2000/10/26 14:01:40	1.29
@@ -27,6 +27,9 @@ use Apache::londefdef;
 use Apache::scripttag;
 #==================================================   Main subroutine: xmlparse  
 @Apache::lonxml::pwd=();
+$Apache::lonxml::outputstack = '';
+$Apache::lonxml::redirection = 1;
+
 sub xmlparse {
 
  my ($target,$content_file_string,$safeinit,%style_for_target) = @_;
@@ -40,9 +43,6 @@ sub xmlparse {
  my $newarg = '';
  my $result;
 
- my $indicator = 1;
- my $pocketbox = '';
-
  my $safeeval = new Safe;
  $safeeval->permit("entereval");
  $safeeval->permit(":base_math");
@@ -50,6 +50,7 @@ sub xmlparse {
 #need to inspect this class of ops
 # $safeeval->deny(":base_orig");
  $safeinit .= ';$external::target='.$target.';';
+ $safeinit .= ';$external::randomseed='.&Apache::lonnet::rndseed().';';
  &Apache::run::run($safeinit,$safeeval);
 #-------------------- Redefinition of the target in the case of compound target
 
@@ -72,12 +73,12 @@ sub xmlparse {
        &increasedepth($token);       
        if (exists $style_for_target{$token->[1]}) {
 
-	if ($indicator == 1) {
+	if ($Apache::lonxml::redirection == 1) {
 	  $finaloutput .= &recurse($style_for_target{$token->[1]},
 		  		  $target,$safeeval,\%style_for_target,
 	 		 	  @parstack);
         } else {
-          $pocketbox .=  &recurse($style_for_target{$token->[1]},
+          $Apache::lonxml::outputstack .=  &recurse($style_for_target{$token->[1]},
 		  		  $target,$safeeval,\%style_for_target,
 	 		 	  @parstack);
         }
@@ -85,9 +86,6 @@ sub xmlparse {
        } else {
 	 $result = &callsub("start_$token->[1]", $target, $token,\@parstack,
 			       \@pars, $safeeval, \%style_for_target);
-
-         if ($result eq "footnote") { &Apache::lonxml::debug($result);}
-
        }              
      } elsif ($token->[0] eq 'E')  {
        #clear out any tags that didn't end
@@ -96,12 +94,12 @@ sub xmlparse {
        
        if (exists $style_for_target{'/'."$token->[1]"}) {
 
-	if ($indicator == 1) {
+	if ($Apache::lonxml::redirection == 1) {
 	 $finaloutput .= &recurse($style_for_target{'/'."$token->[1]"},
 				  $target,$safeeval,\%style_for_target,
 				  @parstack);
         } else {
-         $pocketbox .=  &recurse($style_for_target{'/'."$token->[1]"},
+         $Apache::lonxml::outputstack .=  &recurse($style_for_target{'/'."$token->[1]"},
 				  $target,$safeeval,\%style_for_target,
 				  @parstack);
         }
@@ -111,14 +109,14 @@ sub xmlparse {
 			       \@pars,$safeeval, \%style_for_target);
        }
      }
-     if ($result ne "" ) {
+     if ($result ne "") {
        if ( $#parstack > -1 ) {
  
-	if ($indicator == 1) {
+	if ($Apache::lonxml::redirection == 1) {
 	 $finaloutput .= &Apache::run::evaluate($result,$safeeval,
 						$parstack[$#parstack]);
         } else {
-         $pocketbox .= &Apache::run::evaluate($result,$safeeval,
+         $Apache::lonxml::outputstack .= &Apache::run::evaluate($result,$safeeval,
 						$parstack[$#parstack]);
         }
 
@@ -126,6 +124,8 @@ sub xmlparse {
 	 $finaloutput .= &Apache::run::evaluate($result,$safeeval,'');
        }
        $result = '';
+     } else {
+         $finaloutput .= $result;
      }
      if ($token->[0] eq 'E') { pop @stack;pop @parstack;&decreasedepth($token);}
    }
@@ -202,17 +202,11 @@ sub callsub {
       my $sub1;
     no strict 'refs';
     if (my $space=$Apache::lonxml::alltags{$token->[1]}) {
-#      &Apache::lonxml::debug("Calling sub $sub in $space<br>\n");
-#      if ( $sub eq "start_parserlib" ) {
-#	  print "me:".%$style.":\n";
-#      }
+      #&Apache::lonxml::debug("Calling sub $sub in $space<br>\n");
       $sub1="$space\:\:$sub";
       $Apache::lonxml::curdepth=join('_',@Apache::lonxml::depthcounter);
       $currentstring = &$sub1($target,$token,$parstack,$parser,
 			     $safeeval,$style);
-#      if ( $sub eq "start_parserlib" ) {
-#	  print "me2:".%$style.":";
-#      }
     } else {
       #&Apache::lonxml::debug("NOT Calling sub $sub in $space<br>\n");
       if (defined($token->[4])) {
@@ -297,30 +291,43 @@ sub parstring {
   } @{$token->[3]};
   return $temp;
 }
-#<<<<<<< lonxml.pm
 
 sub handler {
   my $request=shift;
 
   my $target='web';
   $Apache::lonxml::debug=1;
-  $request->content_type('text/html');
-  $request->send_http_header;  
-  $request->print(<<ENDHEADER);
-<html>
-<head>
-<title>Just test</title>
-</head>
-<body bgcolor="#FFFFFF">
-ENDHEADER
+  if ($ENV{'browser.mathml'}) {
+    $request->content_type('text/xml');
+  } else {
+    $request->content_type('text/html');
+  }
+
+#  $request->print(<<ENDHEADER);
+#<html>
+#<head>
+#<title>Just test</title>
+#</head>
+#<body bgcolor="#FFFFFF">
+#ENDHEADER
 #  &Apache::lonhomework::send_header($request);
+  $request->send_http_header;
+
+  return 'OK' if $request->header_only;
+
+  $request->print(&Apache::lontexconvert::header());
+
+  $request->print('<body bgcolor="#FFFFFF">'."\n");
+
   my $file = "/home/httpd/html".$request->uri;
   my %mystyle;
   my $result = '';
   $result = Apache::lonxml::xmlparse($target, &Apache::lonnet::getfile($file),'',%mystyle);
-#  $request->print("Result follows:");  
   $request->print($result);
-#  $request->print(":Result ends");
+
+  $request->print('</body>');
+  $request->print(&Apache::lontexconvert::footer());
+  return 'OK';
 }
  
 $Apache::lonxml::debug=0;
@@ -343,5 +350,18 @@ __END__
 
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+