Annotation of loncom/xml/lonxml.pm, revision 1.63

1.2       sakharuk    1: # The LearningOnline Network with CAPA
1.3       sakharuk    2: # XML Parser Module 
1.2       sakharuk    3: #
1.3       sakharuk    4: # last modified 06/26/00 by Alexander Sakharuk
1.33      www         5: # 11/6 Gerd Kortemeyer
1.45      www         6: # 6/1/1 Gerd Kortemeyer
1.56      albertel    7: # 2/21,3/13 Guy
1.2       sakharuk    8: 
1.4       albertel    9: package Apache::lonxml; 
1.33      www        10: use vars 
1.60      albertel   11: qw(@pwd @outputstack $redirection $import @extlinks $metamode);
1.1       sakharuk   12: use strict;
                     13: use HTML::TokeParser;
1.3       sakharuk   14: use Safe;
1.40      albertel   15: use Safe::Hole;
1.13      albertel   16: use Opcode;
1.46      www        17: use Apache::Constants qw(:common);
1.7       albertel   18: 
                     19: sub register {
                     20:   my $space;
                     21:   my @taglist;
                     22:   my $temptag;
                     23:   ($space,@taglist) = @_;
                     24:   foreach $temptag (@taglist) {
                     25:     $Apache::lonxml::alltags{$temptag}=$space;
                     26:   }
                     27: }
1.48      albertel   28: 
                     29: sub printalltags {
                     30:   my $temp;
                     31:   foreach $temp (sort keys %Apache::lonxml::alltags) {
1.63    ! sakharuk   32: #    &Apache::lonxml::debug("$temp -- $Apache::lonxml::alltags{$temp}");
1.48      albertel   33:   }
                     34: }
1.4       albertel   35: use Apache::style;
1.3       sakharuk   36: use Apache::lontexconvert;
1.7       albertel   37: use Apache::run;
1.4       albertel   38: use Apache::londefdef;
1.7       albertel   39: use Apache::scripttag;
1.59      albertel   40: use Apache::edit;
1.3       sakharuk   41: #==================================================   Main subroutine: xmlparse  
1.33      www        42: @pwd=();
1.55      albertel   43: @outputstack = ();
                     44: $redirection = 0;
                     45: $import = 1;
1.33      www        46: @extlinks=();
1.59      albertel   47: $metamode = 0;
1.31      sakharuk   48: 
1.3       sakharuk   49: sub xmlparse {
                     50: 
1.18      albertel   51:  my ($target,$content_file_string,$safeinit,%style_for_target) = @_;
1.41      albertel   52:  if ($target eq 'meta') {
1.59      albertel   53:    # meta mode is a bit weird only some output is to be turned off
1.60      albertel   54:    #<output> tag turns metamode off (defined in londefdef.pm)
1.59      albertel   55:    $Apache::lonxml::redirection = 0;
                     56:    $Apache::lonxml::metamode = 1;
1.55      albertel   57:    $Apache::lonxml::import = 0;
1.47      albertel   58:  } elsif ($target eq 'grade') {
1.55      albertel   59:    &startredirection;
1.59      albertel   60:    $Apache::lonxml::metamode = 0;
1.55      albertel   61:    $Apache::lonxml::import = 1;
1.44      albertel   62:  } else {
1.59      albertel   63:    $Apache::lonxml::metamode = 0;
1.55      albertel   64:    $Apache::lonxml::redirection = 0;
                     65:    $Apache::lonxml::import = 1;
1.32      sakharuk   66:  }
1.48      albertel   67:  #&printalltags();
1.16      albertel   68:  my @pars = ();
1.23      albertel   69:  @Apache::lonxml::pwd=();
                     70:  my $pwd=$ENV{'request.filename'};
                     71:  $pwd =~ s:/[^/]*$::;
                     72:  &newparser(\@pars,\$content_file_string,$pwd);
1.3       sakharuk   73:  my $currentstring = '';
                     74:  my $finaloutput = ''; 
                     75:  my $newarg = '';
1.16      albertel   76:  my $result;
1.24      sakharuk   77: 
1.3       sakharuk   78:  my $safeeval = new Safe;
1.40      albertel   79:  my $safehole = new Safe::Hole;
1.6       albertel   80:  $safeeval->permit("entereval");
1.13      albertel   81:  $safeeval->permit(":base_math");
1.19      albertel   82:  $safeeval->deny(":base_io");
1.40      albertel   83:  $safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT');
1.19      albertel   84: #need to inspect this class of ops
                     85: # $safeeval->deny(":base_orig");
1.21      albertel   86:  $safeinit .= ';$external::target='.$target.';';
1.26      albertel   87:  $safeinit .= ';$external::randomseed='.&Apache::lonnet::rndseed().';';
1.21      albertel   88:  &Apache::run::run($safeinit,$safeeval);
1.3       sakharuk   89: #-------------------- Redefinition of the target in the case of compound target
                     90: 
                     91:  ($target, my @tenta) = split('&&',$target);
                     92: 
                     93:  my @stack = (); 
                     94:  my @parstack = ();
1.17      albertel   95:  &initdepth;
1.3       sakharuk   96:  my $token;
1.16      albertel   97:  while ( $#pars > -1 ) {
                     98:    while ($token = $pars[$#pars]->get_token) {
1.57      albertel   99:      if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) {
1.61      albertel  100:        if ($metamode<1) { $result=$token->[1]; }
1.57      albertel  101:      } elsif ($token->[0] eq 'PI') {
1.61      albertel  102:        if ($metamode<1) { $result=$token->[2]; }
1.16      albertel  103:      } elsif ($token->[0] eq 'S') {
                    104:        # add tag to stack 	    
                    105:        push (@stack,$token->[1]);
                    106:        # add parameters list to another stack
                    107:        push (@parstack,&parstring($token));
1.19      albertel  108:        &increasedepth($token);       
1.63    ! sakharuk  109: #       &Apache::lonxml::debug("Checking for $token->[1] style");
1.16      albertel  110:        if (exists $style_for_target{$token->[1]}) {
1.63    ! sakharuk  111: #	   &Apache::lonxml::debug("Found $token->[1] style");
1.61      albertel  112: 	 if ($Apache::lonxml::redirection) {
1.55      albertel  113: 	   $Apache::lonxml::outputstack['-1'] .=  
                    114: 	     &recurse($style_for_target{$token->[1]},$target,$safeeval,
                    115: 		      \%style_for_target,@parstack);
1.41      albertel  116: 	 } else {
1.55      albertel  117: 	   $finaloutput .= &recurse($style_for_target{$token->[1]},$target,
                    118: 				    $safeeval,\%style_for_target,@parstack);
1.41      albertel  119: 	 }
1.16      albertel  120:        } else {
1.63    ! sakharuk  121: #	   &Apache::lonxml::debug("No style for for $token->[1]");
1.17      albertel  122: 	 $result = &callsub("start_$token->[1]", $target, $token,\@parstack,
1.41      albertel  123: 			    \@pars, $safeeval, \%style_for_target);
1.16      albertel  124:        }              
                    125:      } elsif ($token->[0] eq 'E')  {
                    126:        #clear out any tags that didn't end
1.55      albertel  127:        while ($token->[1] ne $stack[$#stack] && ($#stack > -1)) {
                    128: 	 &Apache::lonxml::warning("Unbalanced tags in resource $stack['-1']");
1.43      albertel  129: 	 pop @stack;pop @parstack;&decreasedepth($token);
                    130:        }
1.16      albertel  131:        
                    132:        if (exists $style_for_target{'/'."$token->[1]"}) {
1.61      albertel  133: 	 if ($Apache::lonxml::redirection) {
1.55      albertel  134: 	   $Apache::lonxml::outputstack['-1'] .=  
                    135: 	     &recurse($style_for_target{'/'."$token->[1]"},
                    136: 		      $target,$safeeval,\%style_for_target,@parstack);
                    137: 	 } else {
                    138: 	   $finaloutput .= &recurse($style_for_target{'/'."$token->[1]"},
                    139: 				    $target,$safeeval,\%style_for_target,
                    140: 				    @parstack);
                    141: 	 }
1.59      albertel  142: 
1.16      albertel  143:        } else {
1.17      albertel  144: 	 $result = &callsub("end_$token->[1]", $target, $token, \@parstack,
1.55      albertel  145: 			    \@pars,$safeeval, \%style_for_target);
1.13      albertel  146:        }
1.57      albertel  147:      } else {
                    148:        &Apache::lonxml::error("Unknown token event :$token->[0]:$token->[1]:");
1.16      albertel  149:      }
1.55      albertel  150:      #evaluate variable refs in result
1.25      sakharuk  151:      if ($result ne "") {
1.24      sakharuk  152:        if ( $#parstack > -1 ) {
1.55      albertel  153: 	 if ($Apache::lonxml::redirection) {
                    154: 	   $Apache::lonxml::outputstack['-1'] .= 
                    155: 	     &Apache::run::evaluate($result,$safeeval,$parstack[$#parstack]);
                    156: 	 } else {
                    157: 	   $finaloutput .= &Apache::run::evaluate($result,$safeeval,
                    158: 						  $parstack[$#parstack]);
                    159: 	 }
1.16      albertel  160:        } else {
                    161: 	 $finaloutput .= &Apache::run::evaluate($result,$safeeval,'');
1.13      albertel  162:        }
1.16      albertel  163:        $result = '';
1.55      albertel  164:      } 
                    165:      if ($token->[0] eq 'E') { 
                    166:        pop @stack;pop @parstack;&decreasedepth($token);
1.2       sakharuk  167:      }
1.5       albertel  168:    }
1.16      albertel  169:    pop @pars;
1.23      albertel  170:    pop @Apache::lonxml::pwd;
1.3       sakharuk  171:  }
1.24      sakharuk  172: 
1.59      albertel  173: # if ($target eq 'meta') {
                    174: #   $finaloutput.=&endredirection;
                    175: # }
1.3       sakharuk  176:  return $finaloutput;
1.15      albertel  177: }
                    178: 
                    179: sub recurse {
                    180:   
                    181:   my @innerstack = (); 
                    182:   my @innerparstack = ();
                    183:   my ($newarg,$target,$safeeval,$style_for_target,@parstack) = @_;
1.16      albertel  184:   my @pat = ();
1.23      albertel  185:   &newparser(\@pat,\$newarg);
1.15      albertel  186:   my $tokenpat;
                    187:   my $partstring = '';
                    188:   my $output='';
1.16      albertel  189:   my $decls='';
                    190:   while ( $#pat > -1 ) {
                    191:     while  ($tokenpat = $pat[$#pat]->get_token) {
1.57      albertel  192:       if (($tokenpat->[0] eq 'T') || ($tokenpat->[0] eq 'C') || ($tokenpat->[0] eq 'D') ) {
1.61      albertel  193: 	if ($metamode<1) { $partstring=$tokenpat->[1]; }
1.57      albertel  194:       } elsif ($tokenpat->[0] eq 'PI') {
1.61      albertel  195: 	if ($metamode<1) { $partstring=$tokenpat->[2]; }
1.16      albertel  196:       } elsif ($tokenpat->[0] eq 'S') {
                    197: 	push (@innerstack,$tokenpat->[1]);
                    198: 	push (@innerparstack,&parstring($tokenpat));
1.19      albertel  199: 	&increasedepth($tokenpat);
1.16      albertel  200: 	$partstring = &callsub("start_$tokenpat->[1]", 
                    201: 			       $target, $tokenpat, \@innerparstack,
                    202: 			       \@pat, $safeeval, $style_for_target);
                    203:       } elsif ($tokenpat->[0] eq 'E') {
                    204: 	#clear out any tags that didn't end
                    205: 	while ($tokenpat->[1] ne $innerstack[$#innerstack] 
1.43      albertel  206: 	       && ($#innerstack > -1)) {
1.49      albertel  207: 	  &Apache::lonxml::warning("Unbalanced tags in resource $innerstack['-1']");
1.43      albertel  208: 	  pop @innerstack;pop @innerparstack;&decreasedepth($tokenpat);
                    209: 	}
1.16      albertel  210: 	$partstring = &callsub("end_$tokenpat->[1]",
                    211: 			       $target, $tokenpat, \@innerparstack,
                    212: 			       \@pat, $safeeval, $style_for_target);
1.57      albertel  213:       } else {
                    214: 	&Apache::lonxml::error("Unknown token event :$tokenpat->[0]:$tokenpat->[1]:");
1.16      albertel  215:       }
                    216:       #pass both the variable to the style tag, and the tag we 
                    217:       #are processing inside the <definedtag>
                    218:       if ( $partstring ne "" ) {
                    219: 	if ( $#parstack > -1 ) { 
                    220: 	  if ( $#innerparstack > -1 ) { 
                    221: 	    $decls= $parstack[$#parstack].$innerparstack[$#innerparstack];
                    222: 	  } else {
                    223: 	    $decls= $parstack[$#parstack];
                    224: 	  }
                    225: 	} else {
                    226: 	  if ( $#innerparstack > -1 ) { 
                    227: 	    $decls=$innerparstack[$#innerparstack];
                    228: 	  } else {
                    229: 	    $decls='';
                    230: 	  }
                    231: 	}
                    232: 	$output .= &Apache::run::evaluate($partstring,$safeeval,$decls);
                    233: 	$partstring = '';
                    234:       }
1.17      albertel  235:       if ($tokenpat->[0] eq 'E') { pop @innerstack;pop @innerparstack;
1.19      albertel  236: 				 &decreasedepth($tokenpat);}
1.15      albertel  237:     }
1.16      albertel  238:     pop @pat;
1.23      albertel  239:     pop @Apache::lonxml::pwd;
1.15      albertel  240:   }
                    241:   return $output;
1.7       albertel  242: }
                    243: 
                    244: sub callsub {
1.14      albertel  245:   my ($sub,$target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.7       albertel  246:   my $currentstring='';
                    247:   {
1.59      albertel  248:     my $sub1;
1.7       albertel  249:     no strict 'refs';
1.59      albertel  250:     if ($target eq 'edit' && $token->[0] eq 'S') {
                    251:       $currentstring = &Apache::edit::tag_start($target,$token,$parstack,$parser,
                    252: 						$safeeval,$style);
                    253:     }
1.7       albertel  254:     if (my $space=$Apache::lonxml::alltags{$token->[1]}) {
1.63    ! sakharuk  255: #      &Apache::lonxml::debug("Calling sub $sub in $space $metamode<br />\n");
1.24      sakharuk  256:       $sub1="$space\:\:$sub";
1.17      albertel  257:       $Apache::lonxml::curdepth=join('_',@Apache::lonxml::depthcounter);
1.59      albertel  258:       $currentstring .= &$sub1($target,$token,$parstack,$parser,
1.16      albertel  259: 			     $safeeval,$style);
1.7       albertel  260:     } else {
1.63    ! sakharuk  261: #      &Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode<br />\n");
1.62      sakharuk  262:       if ($metamode <1) {
                    263: 	if (defined($token->[4]) && ($metamode < 1)) {
                    264: 	  $currentstring .= $token->[4];
                    265: 	} else {
                    266: 	  $currentstring .= $token->[2];
                    267: 	}
1.7       albertel  268:       }
1.59      albertel  269:     }
                    270:     if ($target eq 'edit' && $token->[0] eq 'E') {
1.61      albertel  271:       $currentstring .= &Apache::edit::tag_end($target,$token,$parstack,$parser,
1.59      albertel  272: 						$safeeval,$style);
1.7       albertel  273:     }
                    274:     use strict 'refs';
                    275:   }
                    276:   return $currentstring;
1.17      albertel  277: }
                    278: 
1.55      albertel  279: sub startredirection {
                    280:   $Apache::lonxml::redirection++;
                    281:   push (@Apache::lonxml::outputstack, '');
                    282: }
                    283: 
                    284: sub endredirection {
                    285:   if (!$Apache::lonxml::redirection) {
                    286:     &Apache::lonxml::error("Endredirection was called, before a startredirection, perhaps you have unbalanced tags. Some debuggin information:".join ":",caller);
                    287:     return '';
                    288:   }
                    289:   $Apache::lonxml::redirection--;
                    290:   pop @Apache::lonxml::outputstack;
                    291: }
                    292: 
1.17      albertel  293: sub initdepth {
                    294:   @Apache::lonxml::depthcounter=();
                    295:   $Apache::lonxml::depth=-1;
                    296:   $Apache::lonxml::olddepth=-1;
                    297: }
                    298: 
                    299: sub increasedepth {
1.19      albertel  300:   my ($token) = @_;
1.17      albertel  301:   $Apache::lonxml::depth++;
                    302:   $Apache::lonxml::depthcounter[$Apache::lonxml::depth]++;
                    303:   if ($Apache::lonxml::depthcounter[$Apache::lonxml::depth]==1) {
                    304:     $Apache::lonxml::olddepth=$Apache::lonxml::depth;
                    305:   }
1.42      albertel  306:   my $curdepth=join('_',@Apache::lonxml::depthcounter);
1.63    ! sakharuk  307: #  &Apache::lonxml::debug("s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n");
1.54      albertel  308: #print "<br />s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n";
1.17      albertel  309: }
                    310: 
                    311: sub decreasedepth {
1.19      albertel  312:   my ($token) = @_;
1.17      albertel  313:   $Apache::lonxml::depth--;
1.36      albertel  314:   if ($Apache::lonxml::depth<$Apache::lonxml::olddepth-1) {
                    315:     $#Apache::lonxml::depthcounter--;
                    316:     $Apache::lonxml::olddepth=$Apache::lonxml::depth+1;
                    317:   }
1.43      albertel  318:   if (  $Apache::lonxml::depth < -1) {
1.49      albertel  319:     &Apache::lonxml::warning("Unbalanced tags in resource");   
1.43      albertel  320:     $Apache::lonxml::depth='-1';
                    321:   }
1.42      albertel  322:   my $curdepth=join('_',@Apache::lonxml::depthcounter);
1.63    ! sakharuk  323: #  &Apache::lonxml::debug("e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n");
1.54      albertel  324: #print "<br />e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n";
1.1       sakharuk  325: }
1.19      albertel  326: 
                    327: sub get_all_text {
                    328: 
                    329:  my($tag,$pars)= @_;
                    330:  my $depth=0;
                    331:  my $token;
                    332:  my $result='';
1.57      albertel  333:  if ( $tag =~ m:^/: ) { 
                    334:    my $tag=substr($tag,1); 
                    335: #   &Apache::lonxml::debug("have:$tag:");
                    336:    while (($depth >=0) && ($token = $pars->get_token)) {
                    337: #     &Apache::lonxml::debug("e token:$token->[0]:$depth:$token->[1]");
                    338:      if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
                    339:        $result.=$token->[1];
                    340:      } elsif ($token->[0] eq 'PI') {
                    341:        $result.=$token->[2];
                    342:      } elsif ($token->[0] eq 'S') {
                    343:        if ($token->[1] eq $tag) { $depth++; }
                    344:        $result.=$token->[4];
                    345:      } elsif ($token->[0] eq 'E')  {
                    346:        if ( $token->[1] eq $tag) { $depth--; }
                    347:        #skip sending back the last end tag
                    348:        if ($depth > -1) { $result.=$token->[2]; } else {
                    349: 	 $pars->unget_token($token);
                    350:        }
                    351:      }
                    352:    }
                    353:  } else {
                    354:    while ($token = $pars->get_token) {
                    355: #     &Apache::lonxml::debug("s token:$token->[0]:$depth:$token->[1]");
                    356:      if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
                    357:        $result.=$token->[1];
                    358:      } elsif ($token->[0] eq 'PI') {
                    359:        $result.=$token->[2];
                    360:      } elsif ($token->[0] eq 'S') {
                    361:        if ( $token->[1] eq $tag) { 
                    362: 	 $pars->unget_token($token); last;
                    363:        } else {
                    364: 	 $result.=$token->[4];
                    365:        }
                    366:      } elsif ($token->[0] eq 'E')  {
                    367:        $result.=$token->[2];
1.36      albertel  368:      }
1.19      albertel  369:    }
                    370:  }
1.49      albertel  371: # &Apache::lonxml::debug("Exit:$result:");
1.19      albertel  372:  return $result
                    373: }
                    374: 
1.23      albertel  375: sub newparser {
                    376:   my ($parser,$contentref,$dir) = @_;
                    377:   push (@$parser,HTML::TokeParser->new($contentref));
1.56      albertel  378:   $$parser['-1']->xml_mode('1');
1.23      albertel  379:   if ( $dir eq '' ) {
                    380:     push (@Apache::lonxml::pwd, $Apache::lonxml::pwd[$#Apache::lonxml::pwd]);
                    381:   } else {
                    382:     push (@Apache::lonxml::pwd, $dir);
                    383:   } 
                    384: #  &Apache::lonxml::debug("pwd:$#Apache::lonxml::pwd");
                    385: #  &Apache::lonxml::debug("pwd:$Apache::lonxml::pwd[$#Apache::lonxml::pwd]");
                    386: }
1.1       sakharuk  387: 
1.8       albertel  388: sub parstring {
                    389:   my ($token) = @_;
                    390:   my $temp='';
1.20      albertel  391:   map {
1.35      www       392:     unless ($_=~/\W/) {
1.42      albertel  393:       my $val=$token->[2]->{$_};
1.53      albertel  394:       $val =~ s/([\%\@\\])/\\$1/g;
1.51      albertel  395:       #if ($val =~ m/^[\%\@]/) { $val="\\".$val; }
1.42      albertel  396:       $temp .= "my \$$_=\"$val\";"
1.20      albertel  397:     }
                    398:   } @{$token->[3]};
1.8       albertel  399:   return $temp;
                    400: }
1.22      albertel  401: 
1.34      www       402: sub writeallows {
                    403:     my $thisurl='/res/'.&Apache::lonnet::declutter(shift);
                    404:     my $thisdir=$thisurl;
                    405:     $thisdir=~s/\/[^\/]+$//;
                    406:     my %httpref=();
                    407:     map {
                    408:        $httpref{'httpref.'.
                    409:  	        &Apache::lonnet::hreflocation($thisdir,$_)}=$thisurl;              } @extlinks;
                    410:     &Apache::lonnet::appenv(%httpref);
                    411: }
                    412: 
1.24      sakharuk  413: sub handler {
                    414:   my $request=shift;
1.44      albertel  415:   
1.63    ! sakharuk  416:   my $target='tex';
        !           417:   $Apache::lonxml::debug=1;
1.25      sakharuk  418:   if ($ENV{'browser.mathml'}) {
1.27      albertel  419:     $request->content_type('text/xml');
                    420:   } else {
                    421:     $request->content_type('text/html');
1.25      sakharuk  422:   }
1.29      sakharuk  423: 
                    424: #  $request->print(<<ENDHEADER);
                    425: #<html>
                    426: #<head>
                    427: #<title>Just test</title>
                    428: #</head>
                    429: #<body bgcolor="#FFFFFF">
                    430: #ENDHEADER
                    431: #  &Apache::lonhomework::send_header($request);
1.27      albertel  432:   $request->send_http_header;
                    433: 
1.45      www       434:   return OK if $request->header_only;
1.27      albertel  435: 
1.63    ! sakharuk  436: ##  $request->print(&Apache::lontexconvert::header());
1.27      albertel  437: 
1.63    ! sakharuk  438: ##  $request->print('<body bgcolor="#FFFFFF">'."\n");
        !           439: 
        !           440:   if ($target eq 'tex') {
        !           441: 
        !           442: 
        !           443: 
        !           444:   } else {
        !           445:          $request->print(&Apache::lontexconvert::header());
        !           446:          $request->print('<body bgcolor="#FFFFFF">'."\n");
        !           447:   }
1.27      albertel  448: 
1.50      albertel  449:   my $file=&Apache::lonnet::filelocation("",$request->uri);
1.24      sakharuk  450:   my %mystyle;
1.50      albertel  451:   my $result = ''; 
                    452:   my $filecontents=&Apache::lonnet::getfile($file);
                    453:   if ($filecontents == -1) {
                    454:     &Apache::lonxml::error("<b> Unable to find <i>$file</i></b>");
                    455:     $filecontents='';
                    456:   } else {
                    457:     $result = &Apache::lonxml::xmlparse($target,$filecontents,'',%mystyle);
                    458:   }
1.24      sakharuk  459:   $request->print($result);
1.29      sakharuk  460: 
1.50      albertel  461: 
1.63    ! sakharuk  462: ##  $request->print('</body>');
        !           463:   if ($target eq 'tex') {
        !           464: #    $request->print('\end{document}'."\n");
        !           465:   } else {
        !           466:     $request->print('</body>');
        !           467:     $request->print(&Apache::lontexconvert::footer());
        !           468:   }
        !           469: ##  $request->print(&Apache::lontexconvert::footer());
1.34      www       470:   writeallows($request->uri);
1.45      www       471:   return OK;
1.24      sakharuk  472: }
                    473:  
1.22      albertel  474: $Apache::lonxml::debug=0;
                    475: sub debug {
                    476:   if ($Apache::lonxml::debug eq 1) {
1.54      albertel  477:     print "DEBUG:".$_[0]."<br />\n";
1.22      albertel  478:   }
                    479: }
1.49      albertel  480: 
1.22      albertel  481: sub error {
1.52      albertel  482:   if ($Apache::lonxml::debug eq 1) {
1.55      albertel  483:     print "<b>ERROR:</b>".$_[0]."<br />\n";
1.52      albertel  484:   } else {
                    485:     print "<b>An Error occured while processing this resource. The instructor has been notified.</b> <br />";
                    486:     #notify author
                    487:     &Apache::lonmsg::author_res_msg($ENV{'request.filename'},$_[0]);
                    488:     #notify course
                    489:     if ( $ENV{'request.course.id'} ) {
                    490:       my $users=$ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'};
                    491:       foreach my $user (split /\,/, $users) {
                    492: 	($user,my $domain) = split /:/, $user;
1.54      albertel  493: 	&Apache::lonmsg::user_normal_msg($user,$domain,"Error in $ENV{'request.filename'}",$_[0]);
1.52      albertel  494:       }
                    495:     }
                    496:     
                    497:     #FIXME probably shouldn't have me get everything forever.
1.54      albertel  498:     &Apache::lonmsg::user_normal_msg('albertel','msu',"Error in $ENV{'request.filename'}",$_[0]);
                    499:     #&Apache::lonmsg::user_normal_msg('albertel','103',"Error in $ENV{'request.filename'}",$_[0]);   
1.52      albertel  500:   }
1.22      albertel  501: }
1.49      albertel  502: 
1.22      albertel  503: sub warning {
                    504:   if ($Apache::lonxml::debug eq 1) {
1.55      albertel  505:     print "<b>W</b>ARNING<b>:</b>".$_[0]."<br />\n";
1.22      albertel  506:   }
                    507: }
                    508: 
1.1       sakharuk  509: 1;
                    510: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>