[LON-CAPA-cvs] cvs: loncom /xml lonxml.pm
sakharuk
lon-capa-cvs@mail.lon-capa.org
Wed, 21 May 2003 20:41:55 -0000
sakharuk Wed May 21 16:41:55 2003 EDT
Modified files:
/loncom/xml lonxml.pm
Log:
I included variable interpolation for tags defined in the style file. The absence of this variable interpolation was the reason of strange output for CBI files. I did variable interpolation in the simplest way - I mean that this (added by me) chunck of code can probably be rewritten in more reasonable way but at least it works fine (I've checked on 43 different CBI files - it works). Guy, would you be so kind send me by e-mail your estimation and critical opinion of these cxhanges? I am very interested. Thanks.
Index: loncom/xml/lonxml.pm
diff -u loncom/xml/lonxml.pm:1.254 loncom/xml/lonxml.pm:1.255
--- loncom/xml/lonxml.pm:1.254 Fri May 16 16:51:25 2003
+++ loncom/xml/lonxml.pm Wed May 21 16:41:55 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# XML Parser Module
#
-# $Id: lonxml.pm,v 1.254 2003/05/16 20:51:25 albertel Exp $
+# $Id: lonxml.pm,v 1.255 2003/05/21 20:41:55 sakharuk Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -421,8 +421,7 @@
}
}
}
-
- #&printalltags();
+#&printalltags();
my @pars = ();
my $pwd=$ENV{'request.filename'};
$pwd =~ s:/[^/]*$::;
@@ -441,6 +440,7 @@
my $finaloutput = &inner_xmlparse($target,\@stack,\@parstack,\@pars,
$safeeval,\%style_for_target);
+
if ($ENV{'request.uri'}) {
&writeallows($ENV{'request.uri'});
}
@@ -520,6 +520,12 @@
$Apache::lonxml::usestyle=0;
my $string=$$style_for_target{$token->[1]}.
'<LONCAPA_INTERNAL_TURN_STYLE_ON />';
+##### LETS TRY VARIABLE INTERPOLATION (it may be stupid but at least it works)
+ my %localhash=%{$token->[2]};
+ foreach my $localkey (keys %localhash) {
+ $string=~s/\$$localkey/$localhash{$localkey}/g;
+ }
+#####
&Apache::lonxml::newparser($pars,\$string);
} else {
$result = &callsub("start_$token->[1]", $target, $token, $stack,
@@ -543,6 +549,14 @@
$Apache::lonxml::usestyle=0;
my $string=$$style_for_target{'/'.$token->[1]}.
'<LONCAPA_INTERNAL_TURN_STYLE_ON />';
+##### LETS TRY VARIABLE INTERPOLATION (it may be stupid but at least it works)
+ my @localarray = split /;/, $$parstack[-1];
+ foreach my $localelement (@localarray) {
+ $localelement=~/my\s+\$([^=]+)=\"(.*)\"$/;
+ my ($whatchange,$tochange) = ($1,$2);
+ $string=~s/\$$whatchange/$tochange/g;
+ }
+#####
&Apache::lonxml::newparser($pars,\$string);
} else {
$result = &callsub("end_$token->[1]", $target, $token, $stack,
@@ -1182,37 +1196,37 @@
}
sub handler {
- my $request=shift;
-
- my $target=&get_target();
-
- $Apache::lonxml::debug=0;
-
- if ($ENV{'browser.mathml'}) {
- $request->content_type('text/xml');
- } else {
- $request->content_type('text/html');
- }
- &Apache::loncommon::no_cache($request);
- $request->send_http_header;
-
- return OK if $request->header_only;
+ my $request=shift;
+
+ my $target=&get_target();
+
+ $Apache::lonxml::debug=0;
+
+ if ($ENV{'browser.mathml'}) {
+ $request->content_type('text/xml');
+ } else {
+ $request->content_type('text/html');
+ }
+ &Apache::loncommon::no_cache($request);
+ $request->send_http_header;
+
+ return OK if $request->header_only;
- my $file=&Apache::lonnet::filelocation("",$request->uri);
+ my $file=&Apache::lonnet::filelocation("",$request->uri);
#
# Edit action? Save file.
#
- unless ($ENV{'request.state'} eq 'published') {
- if (($ENV{'form.savethisfile'}) || ($ENV{'form.attemptclean'})) {
- &storefile($file,$ENV{'form.filecont'});
- }
- }
- my %mystyle;
- my $result = '';
- my $filecontents=&Apache::lonnet::getfile($file);
- if ($filecontents eq -1) {
- $result=(<<ENDNOTFOUND);
+ unless ($ENV{'request.state'} eq 'published') {
+ if (($ENV{'form.savethisfile'}) || ($ENV{'form.attemptclean'})) {
+ &storefile($file,$ENV{'form.filecont'});
+ }
+ }
+ my %mystyle;
+ my $result = '';
+ my $filecontents=&Apache::lonnet::getfile($file);
+ if ($filecontents eq -1) {
+ $result=(<<ENDNOTFOUND);
<html>
<head>
<title>File not found</title>
@@ -1223,41 +1237,41 @@
</html>
ENDNOTFOUND
$filecontents='';
- if ($ENV{'request.state'} ne 'published') {
- $filecontents=&createnewhtml();
- $ENV{'form.editmode'}='Edit'; #force edit mode
- }
- } else {
- unless ($ENV{'request.state'} eq 'published') {
- if ($ENV{'form.attemptclean'}) {
- $filecontents=&htmlclean($filecontents,1);
- }
- }
- if (!$ENV{'form.editmode'} || $ENV{'form.viewmode'}) {
- $result = &Apache::lonxml::xmlparse($request,$target,$filecontents,
- '',%mystyle);
+ if ($ENV{'request.state'} ne 'published') {
+ $filecontents=&createnewhtml();
+ $ENV{'form.editmode'}='Edit'; #force edit mode
+ }
+ } else {
+ unless ($ENV{'request.state'} eq 'published') {
+ if ($ENV{'form.attemptclean'}) {
+ $filecontents=&htmlclean($filecontents,1);
+ }
+ }
+ if (!$ENV{'form.editmode'} || $ENV{'form.viewmode'}) {
+ $result = &Apache::lonxml::xmlparse($request,$target,$filecontents,
+ '',%mystyle);
+ }
}
- }
-
+
#
# Edit action? Insert editing commands
#
- unless ($ENV{'request.state'} eq 'published') {
- if ($ENV{'form.editmode'} && (!($ENV{'form.viewmode'}))) {
- my $displayfile=$request->uri;
- $displayfile=~s/^\/[^\/]*//;
- $result='<html><body bgcolor="#FFFFFF"><h3>'.$displayfile.
- '</h3></body></html>';
- $result=&inserteditinfo($result,$filecontents);
+ unless ($ENV{'request.state'} eq 'published') {
+ if ($ENV{'form.editmode'} && (!($ENV{'form.viewmode'}))) {
+ my $displayfile=$request->uri;
+ $displayfile=~s/^\/[^\/]*//;
+ $result='<html><body bgcolor="#FFFFFF"><h3>'.$displayfile.
+ '</h3></body></html>';
+ $result=&inserteditinfo($result,$filecontents);
+ }
}
- }
-
- writeallows($request->uri);
-
-
- $request->print($result);
-
- return OK;
+
+ writeallows($request->uri);
+
+
+ $request->print($result);
+
+ return OK;
}
sub display_title {