Annotation of loncom/xml/lonxml.pm, revision 1.70
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.68 www 8: # 3/29,5/4 Gerd Kortemeyer
1.2 sakharuk 9:
1.4 albertel 10: package Apache::lonxml;
1.33 www 11: use vars
1.60 albertel 12: qw(@pwd @outputstack $redirection $import @extlinks $metamode);
1.1 sakharuk 13: use strict;
14: use HTML::TokeParser;
1.3 sakharuk 15: use Safe;
1.40 albertel 16: use Safe::Hole;
1.13 albertel 17: use Opcode;
1.46 www 18: use Apache::Constants qw(:common);
1.7 albertel 19:
1.68 www 20:
21: sub xmlbegin {
22: my $output='';
23: if ($ENV{'browser.mathml'}) {
24: $output='<?xml version="1.0"?>'
25: .'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'
26: .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
27: .'[<!ENTITY mathns "http://www.w3.org/1998/Math/MathML">]>'
28: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
29: .'xmlns="http://www.w3.org/TR/REC-html40">';
30: } else {
31: $output='<html>';
32: }
33: return $output;
34: }
35:
36: sub xmlend {
37: return '</html>';
38: }
39:
1.70 ! www 40: sub fontsettings() {
! 41: my $headerstring='';
! 42: if (($ENV{'browser.os'} eq 'mac') && (!$ENV{'browser.mathml'})) {
! 43: $headerstring.=
! 44: '<meta Content-Type="text/html; charset=x-mac-roman">';
! 45: }
! 46: return $headerstring;
! 47: }
! 48:
1.68 www 49: sub registerurl {
50: return (<<ENDSCRIPT);
51: <script language="JavaScript">
1.69 www 52: function LONCAPAreg() {
53: if (window.location.pathname!="/res/adm/pages/menu.html") {
54: menu=window.open("","LONCAPAmenu");
55: menu.currentURL=window.location.pathname;
56: menu.currentStale=0;
57: }
58: }
59:
60: function LONCAPAstale() {
61: if (window.location.pathname!="/res/adm/pages/menu.html") {
62: menu=window.open("","LONCAPAmenu");
63: menu.currentStale=1;
64: }
1.68 www 65: }
66: </script>
67: ENDSCRIPT
1.69 www 68: }
69:
70: sub loadevents() {
71: return 'LONCAPAreg();';
72: }
73:
74: sub unloadevents() {
75: return 'LONCAPAstale();';
1.68 www 76: }
77:
1.7 albertel 78: sub register {
79: my $space;
80: my @taglist;
81: my $temptag;
82: ($space,@taglist) = @_;
83: foreach $temptag (@taglist) {
84: $Apache::lonxml::alltags{$temptag}=$space;
85: }
86: }
1.48 albertel 87:
88: sub printalltags {
89: my $temp;
90: foreach $temp (sort keys %Apache::lonxml::alltags) {
1.64 albertel 91: &Apache::lonxml::debug("$temp -- $Apache::lonxml::alltags{$temp}");
1.48 albertel 92: }
93: }
1.4 albertel 94: use Apache::style;
1.7 albertel 95: use Apache::run;
1.4 albertel 96: use Apache::londefdef;
1.7 albertel 97: use Apache::scripttag;
1.59 albertel 98: use Apache::edit;
1.3 sakharuk 99: #================================================== Main subroutine: xmlparse
1.33 www 100: @pwd=();
1.55 albertel 101: @outputstack = ();
102: $redirection = 0;
103: $import = 1;
1.33 www 104: @extlinks=();
1.59 albertel 105: $metamode = 0;
1.31 sakharuk 106:
1.3 sakharuk 107: sub xmlparse {
108:
1.18 albertel 109: my ($target,$content_file_string,$safeinit,%style_for_target) = @_;
1.41 albertel 110: if ($target eq 'meta') {
1.59 albertel 111: # meta mode is a bit weird only some output is to be turned off
1.60 albertel 112: #<output> tag turns metamode off (defined in londefdef.pm)
1.59 albertel 113: $Apache::lonxml::redirection = 0;
114: $Apache::lonxml::metamode = 1;
1.55 albertel 115: $Apache::lonxml::import = 0;
1.47 albertel 116: } elsif ($target eq 'grade') {
1.55 albertel 117: &startredirection;
1.59 albertel 118: $Apache::lonxml::metamode = 0;
1.55 albertel 119: $Apache::lonxml::import = 1;
1.44 albertel 120: } else {
1.59 albertel 121: $Apache::lonxml::metamode = 0;
1.55 albertel 122: $Apache::lonxml::redirection = 0;
123: $Apache::lonxml::import = 1;
1.32 sakharuk 124: }
1.48 albertel 125: #&printalltags();
1.16 albertel 126: my @pars = ();
1.23 albertel 127: @Apache::lonxml::pwd=();
128: my $pwd=$ENV{'request.filename'};
129: $pwd =~ s:/[^/]*$::;
130: &newparser(\@pars,\$content_file_string,$pwd);
1.3 sakharuk 131: my $currentstring = '';
132: my $finaloutput = '';
133: my $newarg = '';
1.16 albertel 134: my $result;
1.24 sakharuk 135:
1.3 sakharuk 136: my $safeeval = new Safe;
1.40 albertel 137: my $safehole = new Safe::Hole;
1.6 albertel 138: $safeeval->permit("entereval");
1.13 albertel 139: $safeeval->permit(":base_math");
1.19 albertel 140: $safeeval->deny(":base_io");
1.40 albertel 141: $safehole->wrap(\&Apache::lonnet::EXT,$safeeval,'&EXT');
1.19 albertel 142: #need to inspect this class of ops
143: # $safeeval->deny(":base_orig");
1.21 albertel 144: $safeinit .= ';$external::target='.$target.';';
1.26 albertel 145: $safeinit .= ';$external::randomseed='.&Apache::lonnet::rndseed().';';
1.21 albertel 146: &Apache::run::run($safeinit,$safeeval);
1.3 sakharuk 147: #-------------------- Redefinition of the target in the case of compound target
148:
149: ($target, my @tenta) = split('&&',$target);
150:
151: my @stack = ();
152: my @parstack = ();
1.17 albertel 153: &initdepth;
1.3 sakharuk 154: my $token;
1.16 albertel 155: while ( $#pars > -1 ) {
156: while ($token = $pars[$#pars]->get_token) {
1.57 albertel 157: if (($token->[0] eq 'T') || ($token->[0] eq 'C') || ($token->[0] eq 'D') ) {
1.61 albertel 158: if ($metamode<1) { $result=$token->[1]; }
1.57 albertel 159: } elsif ($token->[0] eq 'PI') {
1.61 albertel 160: if ($metamode<1) { $result=$token->[2]; }
1.16 albertel 161: } elsif ($token->[0] eq 'S') {
162: # add tag to stack
163: push (@stack,$token->[1]);
164: # add parameters list to another stack
165: push (@parstack,&parstring($token));
1.19 albertel 166: &increasedepth($token);
1.16 albertel 167: if (exists $style_for_target{$token->[1]}) {
1.61 albertel 168: if ($Apache::lonxml::redirection) {
1.55 albertel 169: $Apache::lonxml::outputstack['-1'] .=
170: &recurse($style_for_target{$token->[1]},$target,$safeeval,
171: \%style_for_target,@parstack);
1.41 albertel 172: } else {
1.55 albertel 173: $finaloutput .= &recurse($style_for_target{$token->[1]},$target,
174: $safeeval,\%style_for_target,@parstack);
1.41 albertel 175: }
1.16 albertel 176: } else {
1.17 albertel 177: $result = &callsub("start_$token->[1]", $target, $token,\@parstack,
1.41 albertel 178: \@pars, $safeeval, \%style_for_target);
1.16 albertel 179: }
180: } elsif ($token->[0] eq 'E') {
181: #clear out any tags that didn't end
1.55 albertel 182: while ($token->[1] ne $stack[$#stack] && ($#stack > -1)) {
183: &Apache::lonxml::warning("Unbalanced tags in resource $stack['-1']");
1.43 albertel 184: pop @stack;pop @parstack;&decreasedepth($token);
185: }
1.16 albertel 186:
187: if (exists $style_for_target{'/'."$token->[1]"}) {
1.61 albertel 188: if ($Apache::lonxml::redirection) {
1.55 albertel 189: $Apache::lonxml::outputstack['-1'] .=
190: &recurse($style_for_target{'/'."$token->[1]"},
191: $target,$safeeval,\%style_for_target,@parstack);
192: } else {
193: $finaloutput .= &recurse($style_for_target{'/'."$token->[1]"},
194: $target,$safeeval,\%style_for_target,
195: @parstack);
196: }
1.59 albertel 197:
1.16 albertel 198: } else {
1.17 albertel 199: $result = &callsub("end_$token->[1]", $target, $token, \@parstack,
1.55 albertel 200: \@pars,$safeeval, \%style_for_target);
1.13 albertel 201: }
1.57 albertel 202: } else {
203: &Apache::lonxml::error("Unknown token event :$token->[0]:$token->[1]:");
1.16 albertel 204: }
1.55 albertel 205: #evaluate variable refs in result
1.25 sakharuk 206: if ($result ne "") {
1.24 sakharuk 207: if ( $#parstack > -1 ) {
1.55 albertel 208: if ($Apache::lonxml::redirection) {
209: $Apache::lonxml::outputstack['-1'] .=
210: &Apache::run::evaluate($result,$safeeval,$parstack[$#parstack]);
211: } else {
212: $finaloutput .= &Apache::run::evaluate($result,$safeeval,
213: $parstack[$#parstack]);
214: }
1.16 albertel 215: } else {
216: $finaloutput .= &Apache::run::evaluate($result,$safeeval,'');
1.13 albertel 217: }
1.16 albertel 218: $result = '';
1.55 albertel 219: }
220: if ($token->[0] eq 'E') {
221: pop @stack;pop @parstack;&decreasedepth($token);
1.2 sakharuk 222: }
1.5 albertel 223: }
1.16 albertel 224: pop @pars;
1.23 albertel 225: pop @Apache::lonxml::pwd;
1.3 sakharuk 226: }
1.24 sakharuk 227:
1.59 albertel 228: # if ($target eq 'meta') {
229: # $finaloutput.=&endredirection;
230: # }
1.67 www 231:
232: if (($ENV{'QUERY_STRING'}) && ($target eq 'web')) {
233: $finaloutput=&afterburn($finaloutput);
234: }
235:
1.3 sakharuk 236: return $finaloutput;
1.15 albertel 237: }
238:
1.67 www 239:
1.15 albertel 240: sub recurse {
241:
242: my @innerstack = ();
243: my @innerparstack = ();
244: my ($newarg,$target,$safeeval,$style_for_target,@parstack) = @_;
1.16 albertel 245: my @pat = ();
1.23 albertel 246: &newparser(\@pat,\$newarg);
1.15 albertel 247: my $tokenpat;
248: my $partstring = '';
249: my $output='';
1.16 albertel 250: my $decls='';
251: while ( $#pat > -1 ) {
252: while ($tokenpat = $pat[$#pat]->get_token) {
1.57 albertel 253: if (($tokenpat->[0] eq 'T') || ($tokenpat->[0] eq 'C') || ($tokenpat->[0] eq 'D') ) {
1.61 albertel 254: if ($metamode<1) { $partstring=$tokenpat->[1]; }
1.57 albertel 255: } elsif ($tokenpat->[0] eq 'PI') {
1.61 albertel 256: if ($metamode<1) { $partstring=$tokenpat->[2]; }
1.16 albertel 257: } elsif ($tokenpat->[0] eq 'S') {
258: push (@innerstack,$tokenpat->[1]);
259: push (@innerparstack,&parstring($tokenpat));
1.19 albertel 260: &increasedepth($tokenpat);
1.16 albertel 261: $partstring = &callsub("start_$tokenpat->[1]",
262: $target, $tokenpat, \@innerparstack,
263: \@pat, $safeeval, $style_for_target);
264: } elsif ($tokenpat->[0] eq 'E') {
265: #clear out any tags that didn't end
266: while ($tokenpat->[1] ne $innerstack[$#innerstack]
1.43 albertel 267: && ($#innerstack > -1)) {
1.49 albertel 268: &Apache::lonxml::warning("Unbalanced tags in resource $innerstack['-1']");
1.43 albertel 269: pop @innerstack;pop @innerparstack;&decreasedepth($tokenpat);
270: }
1.16 albertel 271: $partstring = &callsub("end_$tokenpat->[1]",
272: $target, $tokenpat, \@innerparstack,
273: \@pat, $safeeval, $style_for_target);
1.57 albertel 274: } else {
275: &Apache::lonxml::error("Unknown token event :$tokenpat->[0]:$tokenpat->[1]:");
1.16 albertel 276: }
277: #pass both the variable to the style tag, and the tag we
278: #are processing inside the <definedtag>
279: if ( $partstring ne "" ) {
280: if ( $#parstack > -1 ) {
281: if ( $#innerparstack > -1 ) {
282: $decls= $parstack[$#parstack].$innerparstack[$#innerparstack];
283: } else {
284: $decls= $parstack[$#parstack];
285: }
286: } else {
287: if ( $#innerparstack > -1 ) {
288: $decls=$innerparstack[$#innerparstack];
289: } else {
290: $decls='';
291: }
292: }
293: $output .= &Apache::run::evaluate($partstring,$safeeval,$decls);
294: $partstring = '';
295: }
1.17 albertel 296: if ($tokenpat->[0] eq 'E') { pop @innerstack;pop @innerparstack;
1.19 albertel 297: &decreasedepth($tokenpat);}
1.15 albertel 298: }
1.16 albertel 299: pop @pat;
1.23 albertel 300: pop @Apache::lonxml::pwd;
1.15 albertel 301: }
302: return $output;
1.7 albertel 303: }
304:
305: sub callsub {
1.14 albertel 306: my ($sub,$target,$token,$parstack,$parser,$safeeval,$style)=@_;
1.7 albertel 307: my $currentstring='';
308: {
1.59 albertel 309: my $sub1;
1.7 albertel 310: no strict 'refs';
1.59 albertel 311: if ($target eq 'edit' && $token->[0] eq 'S') {
312: $currentstring = &Apache::edit::tag_start($target,$token,$parstack,$parser,
313: $safeeval,$style);
314: }
1.68 www 315: my $tag=$token->[1];
316: my $space=$Apache::lonxml::alltags{$tag};
317: if (!$space) {
318: $tag=~tr/A-Z/a-z/;
319: $sub=~tr/A-Z/a-z/;
320: $space=$Apache::lonxml::alltags{$tag}
321: }
322: if ($space) {
323: &Apache::lonxml::debug("Calling sub $sub in $space $metamode<br />\n");
1.24 sakharuk 324: $sub1="$space\:\:$sub";
1.17 albertel 325: $Apache::lonxml::curdepth=join('_',@Apache::lonxml::depthcounter);
1.59 albertel 326: $currentstring .= &$sub1($target,$token,$parstack,$parser,
1.16 albertel 327: $safeeval,$style);
1.7 albertel 328: } else {
1.68 www 329: &Apache::lonxml::debug("NOT Calling sub $sub in $space $metamode<br />\n");
1.62 sakharuk 330: if ($metamode <1) {
331: if (defined($token->[4]) && ($metamode < 1)) {
332: $currentstring .= $token->[4];
333: } else {
334: $currentstring .= $token->[2];
335: }
1.7 albertel 336: }
1.59 albertel 337: }
338: if ($target eq 'edit' && $token->[0] eq 'E') {
1.61 albertel 339: $currentstring .= &Apache::edit::tag_end($target,$token,$parstack,$parser,
1.59 albertel 340: $safeeval,$style);
1.7 albertel 341: }
342: use strict 'refs';
343: }
344: return $currentstring;
1.17 albertel 345: }
346:
1.55 albertel 347: sub startredirection {
348: $Apache::lonxml::redirection++;
349: push (@Apache::lonxml::outputstack, '');
350: }
351:
352: sub endredirection {
353: if (!$Apache::lonxml::redirection) {
354: &Apache::lonxml::error("Endredirection was called, before a startredirection, perhaps you have unbalanced tags. Some debuggin information:".join ":",caller);
355: return '';
356: }
357: $Apache::lonxml::redirection--;
358: pop @Apache::lonxml::outputstack;
359: }
360:
1.17 albertel 361: sub initdepth {
362: @Apache::lonxml::depthcounter=();
363: $Apache::lonxml::depth=-1;
364: $Apache::lonxml::olddepth=-1;
365: }
366:
367: sub increasedepth {
1.19 albertel 368: my ($token) = @_;
1.17 albertel 369: $Apache::lonxml::depth++;
370: $Apache::lonxml::depthcounter[$Apache::lonxml::depth]++;
371: if ($Apache::lonxml::depthcounter[$Apache::lonxml::depth]==1) {
372: $Apache::lonxml::olddepth=$Apache::lonxml::depth;
373: }
1.42 albertel 374: my $curdepth=join('_',@Apache::lonxml::depthcounter);
1.64 albertel 375: &Apache::lonxml::debug("s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n");
1.54 albertel 376: #print "<br />s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n";
1.17 albertel 377: }
378:
379: sub decreasedepth {
1.19 albertel 380: my ($token) = @_;
1.17 albertel 381: $Apache::lonxml::depth--;
1.36 albertel 382: if ($Apache::lonxml::depth<$Apache::lonxml::olddepth-1) {
383: $#Apache::lonxml::depthcounter--;
384: $Apache::lonxml::olddepth=$Apache::lonxml::depth+1;
385: }
1.43 albertel 386: if ( $Apache::lonxml::depth < -1) {
1.49 albertel 387: &Apache::lonxml::warning("Unbalanced tags in resource");
1.43 albertel 388: $Apache::lonxml::depth='-1';
389: }
1.42 albertel 390: my $curdepth=join('_',@Apache::lonxml::depthcounter);
1.64 albertel 391: &Apache::lonxml::debug("e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n");
1.54 albertel 392: #print "<br />e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n";
1.1 sakharuk 393: }
1.19 albertel 394:
395: sub get_all_text {
396:
397: my($tag,$pars)= @_;
398: my $depth=0;
399: my $token;
400: my $result='';
1.57 albertel 401: if ( $tag =~ m:^/: ) {
402: my $tag=substr($tag,1);
403: # &Apache::lonxml::debug("have:$tag:");
404: while (($depth >=0) && ($token = $pars->get_token)) {
405: # &Apache::lonxml::debug("e token:$token->[0]:$depth:$token->[1]");
406: if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
407: $result.=$token->[1];
408: } elsif ($token->[0] eq 'PI') {
409: $result.=$token->[2];
410: } elsif ($token->[0] eq 'S') {
411: if ($token->[1] eq $tag) { $depth++; }
412: $result.=$token->[4];
413: } elsif ($token->[0] eq 'E') {
414: if ( $token->[1] eq $tag) { $depth--; }
415: #skip sending back the last end tag
416: if ($depth > -1) { $result.=$token->[2]; } else {
417: $pars->unget_token($token);
418: }
419: }
420: }
421: } else {
422: while ($token = $pars->get_token) {
423: # &Apache::lonxml::debug("s token:$token->[0]:$depth:$token->[1]");
424: if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
425: $result.=$token->[1];
426: } elsif ($token->[0] eq 'PI') {
427: $result.=$token->[2];
428: } elsif ($token->[0] eq 'S') {
429: if ( $token->[1] eq $tag) {
430: $pars->unget_token($token); last;
431: } else {
432: $result.=$token->[4];
433: }
434: } elsif ($token->[0] eq 'E') {
435: $result.=$token->[2];
1.36 albertel 436: }
1.19 albertel 437: }
438: }
1.49 albertel 439: # &Apache::lonxml::debug("Exit:$result:");
1.19 albertel 440: return $result
441: }
442:
1.23 albertel 443: sub newparser {
444: my ($parser,$contentref,$dir) = @_;
445: push (@$parser,HTML::TokeParser->new($contentref));
1.56 albertel 446: $$parser['-1']->xml_mode('1');
1.23 albertel 447: if ( $dir eq '' ) {
448: push (@Apache::lonxml::pwd, $Apache::lonxml::pwd[$#Apache::lonxml::pwd]);
449: } else {
450: push (@Apache::lonxml::pwd, $dir);
451: }
452: # &Apache::lonxml::debug("pwd:$#Apache::lonxml::pwd");
453: # &Apache::lonxml::debug("pwd:$Apache::lonxml::pwd[$#Apache::lonxml::pwd]");
454: }
1.1 sakharuk 455:
1.8 albertel 456: sub parstring {
457: my ($token) = @_;
458: my $temp='';
1.20 albertel 459: map {
1.35 www 460: unless ($_=~/\W/) {
1.42 albertel 461: my $val=$token->[2]->{$_};
1.53 albertel 462: $val =~ s/([\%\@\\])/\\$1/g;
1.51 albertel 463: #if ($val =~ m/^[\%\@]/) { $val="\\".$val; }
1.42 albertel 464: $temp .= "my \$$_=\"$val\";"
1.20 albertel 465: }
466: } @{$token->[3]};
1.8 albertel 467: return $temp;
468: }
1.22 albertel 469:
1.34 www 470: sub writeallows {
471: my $thisurl='/res/'.&Apache::lonnet::declutter(shift);
472: my $thisdir=$thisurl;
473: $thisdir=~s/\/[^\/]+$//;
474: my %httpref=();
475: map {
476: $httpref{'httpref.'.
477: &Apache::lonnet::hreflocation($thisdir,$_)}=$thisurl; } @extlinks;
478: &Apache::lonnet::appenv(%httpref);
479: }
480:
1.66 www 481: #
482: # Afterburner handles anchors, highlights and links
483: #
484:
485: sub afterburn {
486: my $result=shift;
487: map {
488: my ($name, $value) = split(/=/,$_);
489: $value =~ tr/+/ /;
490: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
491: if (($name eq 'highlight')||($name eq 'anchor')||($name eq 'link')) {
492: unless ($ENV{'form.'.$name}) {
493: $ENV{'form.'.$name}=$value;
494: }
495: }
496: } (split(/&/,$ENV{'QUERY_STRING'}));
497: if ($ENV{'form.highlight'}) {
498: map {
499: my $anchorname=$_;
500: my $matchthis=$anchorname;
501: $matchthis=~s/\_+/\\s\+/g;
502: $result=~s/($matchthis)/\<font color=\"red\"\>$1\<\/font\>/gs;
503: } split(/\,/,$ENV{'form.highlight'});
504: }
505: if ($ENV{'form.link'}) {
506: map {
507: my ($anchorname,$linkurl)=split(/\>/,$_);
508: my $matchthis=$anchorname;
509: $matchthis=~s/\_+/\\s\+/g;
510: $result=~s/($matchthis)/\<a href=\"$linkurl\"\>$1\<\/a\>/gs;
511: } split(/\,/,$ENV{'form.link'});
512: }
513: if ($ENV{'form.anchor'}) {
514: my $anchorname=$ENV{'form.anchor'};
515: my $matchthis=$anchorname;
516: $matchthis=~s/\_+/\\s\+/g;
517: $result=~s/($matchthis)/\<a name=\"$anchorname\"\>$1\<\/a\>/s;
518: $result.=(<<"ENDSCRIPT");
519: <script>
520: document.location.hash='$anchorname';
521: </script>
522: ENDSCRIPT
523: }
524: return $result;
525: }
526:
1.24 sakharuk 527: sub handler {
528: my $request=shift;
1.68 www 529:
1.64 albertel 530: my $target='web';
1.68 www 531:
1.65 albertel 532: $Apache::lonxml::debug=0;
1.68 www 533:
1.25 sakharuk 534: if ($ENV{'browser.mathml'}) {
1.27 albertel 535: $request->content_type('text/xml');
536: } else {
537: $request->content_type('text/html');
1.25 sakharuk 538: }
1.64 albertel 539:
1.29 sakharuk 540: # $request->print(<<ENDHEADER);
541: #<html>
542: #<head>
543: #<title>Just test</title>
544: #</head>
545: #<body bgcolor="#FFFFFF">
546: #ENDHEADER
547: # &Apache::lonhomework::send_header($request);
1.27 albertel 548: $request->send_http_header;
1.64 albertel 549:
1.45 www 550: return OK if $request->header_only;
1.27 albertel 551:
552:
1.50 albertel 553: my $file=&Apache::lonnet::filelocation("",$request->uri);
1.24 sakharuk 554: my %mystyle;
1.50 albertel 555: my $result = '';
556: my $filecontents=&Apache::lonnet::getfile($file);
557: if ($filecontents == -1) {
558: &Apache::lonxml::error("<b> Unable to find <i>$file</i></b>");
559: $filecontents='';
560: } else {
561: $result = &Apache::lonxml::xmlparse($target,$filecontents,'',%mystyle);
1.66 www 562: }
1.50 albertel 563:
1.67 www 564: $request->print($result);
1.64 albertel 565:
1.34 www 566: writeallows($request->uri);
1.45 www 567: return OK;
1.24 sakharuk 568: }
569:
1.22 albertel 570: sub debug {
571: if ($Apache::lonxml::debug eq 1) {
1.54 albertel 572: print "DEBUG:".$_[0]."<br />\n";
1.22 albertel 573: }
574: }
1.49 albertel 575:
1.22 albertel 576: sub error {
1.52 albertel 577: if ($Apache::lonxml::debug eq 1) {
1.55 albertel 578: print "<b>ERROR:</b>".$_[0]."<br />\n";
1.52 albertel 579: } else {
580: print "<b>An Error occured while processing this resource. The instructor has been notified.</b> <br />";
581: #notify author
582: &Apache::lonmsg::author_res_msg($ENV{'request.filename'},$_[0]);
583: #notify course
584: if ( $ENV{'request.course.id'} ) {
585: my $users=$ENV{'course.'.$ENV{'request.course.id'}.'.comment.email'};
586: foreach my $user (split /\,/, $users) {
587: ($user,my $domain) = split /:/, $user;
1.54 albertel 588: &Apache::lonmsg::user_normal_msg($user,$domain,"Error in $ENV{'request.filename'}",$_[0]);
1.52 albertel 589: }
590: }
591:
592: #FIXME probably shouldn't have me get everything forever.
1.54 albertel 593: &Apache::lonmsg::user_normal_msg('albertel','msu',"Error in $ENV{'request.filename'}",$_[0]);
594: #&Apache::lonmsg::user_normal_msg('albertel','103',"Error in $ENV{'request.filename'}",$_[0]);
1.52 albertel 595: }
1.22 albertel 596: }
1.49 albertel 597:
1.22 albertel 598: sub warning {
599: if ($Apache::lonxml::debug eq 1) {
1.55 albertel 600: print "<b>W</b>ARNING<b>:</b>".$_[0]."<br />\n";
1.22 albertel 601: }
602: }
603:
1.1 sakharuk 604: 1;
605: __END__
1.68 www 606:
607:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>