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