version 1.16, 2000/08/03 19:34:11
|
version 1.18, 2000/08/11 14:24:50
|
Line 29 use Apache::scripttag;
|
Line 29 use Apache::scripttag;
|
|
|
sub xmlparse { |
sub xmlparse { |
|
|
my ($target,$content_file_string,%style_for_target) = @_; |
my ($target,$content_file_string,$safeinit,%style_for_target) = @_; |
my @pars = (); |
my @pars = (); |
push (@pars,HTML::TokeParser->new(\$content_file_string)); |
push (@pars,HTML::TokeParser->new(\$content_file_string)); |
my $currentstring = ''; |
my $currentstring = ''; |
Line 39 sub xmlparse {
|
Line 39 sub xmlparse {
|
my $safeeval = new Safe; |
my $safeeval = new Safe; |
$safeeval->permit("entereval"); |
$safeeval->permit("entereval"); |
$safeeval->permit(":base_math"); |
$safeeval->permit(":base_math"); |
|
if ( $safeinit ne '') {&Apache::run::run($safeinit,$safeeval);} |
#-------------------- Redefinition of the target in the case of compound target |
#-------------------- Redefinition of the target in the case of compound target |
|
|
($target, my @tenta) = split('&&',$target); |
($target, my @tenta) = split('&&',$target); |
|
|
my @stack = (); |
my @stack = (); |
my @parstack = (); |
my @parstack = (); |
|
&initdepth; |
my $token; |
my $token; |
print $#pars; |
|
while ( $#pars > -1 ) { |
while ( $#pars > -1 ) { |
while ($token = $pars[$#pars]->get_token) { |
while ($token = $pars[$#pars]->get_token) { |
if ($token->[0] eq 'T') { |
if ($token->[0] eq 'T') { |
Line 57 sub xmlparse {
|
Line 58 sub xmlparse {
|
push (@stack,$token->[1]); |
push (@stack,$token->[1]); |
# add parameters list to another stack |
# add parameters list to another stack |
push (@parstack,&parstring($token)); |
push (@parstack,&parstring($token)); |
|
&increasedepth(); |
if (exists $style_for_target{$token->[1]}) { |
if (exists $style_for_target{$token->[1]}) { |
$finaloutput .= &recurse($style_for_target{$token->[1]}, |
$finaloutput .= &recurse($style_for_target{$token->[1]}, |
$target,$safeeval,\%style_for_target, |
$target,$safeeval,\%style_for_target, |
@parstack); |
@parstack); |
} else { |
} else { |
my $result = &callsub("start_$token->[1]", $target, $token,\@parstack, |
$result = &callsub("start_$token->[1]", $target, $token,\@parstack, |
\@pars, $safeeval, \%style_for_target); |
\@pars, $safeeval, \%style_for_target); |
} |
} |
} elsif ($token->[0] eq 'E') { |
} elsif ($token->[0] eq 'E') { |
#clear out any tags that didn't end |
#clear out any tags that didn't end |
while ($token->[1] ne $stack[$#stack] |
while ($token->[1] ne $stack[$#stack] |
&& ($#stack > -1)) {pop @stack;pop @parstack;} |
&& ($#stack > -1)) {pop @stack;pop @parstack;&decreasedepth;} |
|
|
if (exists $style_for_target{'/'."$token->[1]"}) { |
if (exists $style_for_target{'/'."$token->[1]"}) { |
$finaloutput .= &recurse($style_for_target{'/'."$token->[1]"}, |
$finaloutput .= &recurse($style_for_target{'/'."$token->[1]"}, |
$target,$safeeval,\%style_for_target, |
$target,$safeeval,\%style_for_target, |
@parstack); |
@parstack); |
} else { |
} else { |
my $result = &callsub("end_$token->[1]", $target, $token, \@parstack, |
$result = &callsub("end_$token->[1]", $target, $token, \@parstack, |
\@pars,$safeeval, \%style_for_target); |
\@pars,$safeeval, \%style_for_target); |
} |
} |
} |
} |
Line 89 sub xmlparse {
|
Line 90 sub xmlparse {
|
} |
} |
$result = ''; |
$result = ''; |
} |
} |
if ($token->[0] eq 'E') { pop @stack;pop @parstack; } |
if ($token->[0] eq 'E') { pop @stack;pop @parstack;&decreasedepth;} |
} |
} |
pop @pars; |
pop @pars; |
} |
} |
Line 114 sub recurse {
|
Line 115 sub recurse {
|
} elsif ($tokenpat->[0] eq 'S') { |
} elsif ($tokenpat->[0] eq 'S') { |
push (@innerstack,$tokenpat->[1]); |
push (@innerstack,$tokenpat->[1]); |
push (@innerparstack,&parstring($tokenpat)); |
push (@innerparstack,&parstring($tokenpat)); |
|
&increasedepth(); |
$partstring = &callsub("start_$tokenpat->[1]", |
$partstring = &callsub("start_$tokenpat->[1]", |
$target, $tokenpat, \@innerparstack, |
$target, $tokenpat, \@innerparstack, |
\@pat, $safeeval, $style_for_target); |
\@pat, $safeeval, $style_for_target); |
} elsif ($tokenpat->[0] eq 'E') { |
} elsif ($tokenpat->[0] eq 'E') { |
#clear out any tags that didn't end |
#clear out any tags that didn't end |
while ($tokenpat->[1] ne $innerstack[$#innerstack] |
while ($tokenpat->[1] ne $innerstack[$#innerstack] |
&& ($#innerstack > -1)) {pop @innerstack;pop @innerparstack;} |
&& ($#innerstack > -1)) {pop @innerstack;pop @innerparstack; |
|
&decreasedepth;} |
$partstring = &callsub("end_$tokenpat->[1]", |
$partstring = &callsub("end_$tokenpat->[1]", |
$target, $tokenpat, \@innerparstack, |
$target, $tokenpat, \@innerparstack, |
\@pat, $safeeval, $style_for_target); |
\@pat, $safeeval, $style_for_target); |
Line 144 sub recurse {
|
Line 147 sub recurse {
|
$output .= &Apache::run::evaluate($partstring,$safeeval,$decls); |
$output .= &Apache::run::evaluate($partstring,$safeeval,$decls); |
$partstring = ''; |
$partstring = ''; |
} |
} |
if ($tokenpat->[0] eq 'E') { pop @innerstack;pop @innerparstack; } |
if ($tokenpat->[0] eq 'E') { pop @innerstack;pop @innerparstack; |
|
&decreasedepth;} |
} |
} |
pop @pat; |
pop @pat; |
} |
} |
Line 159 sub callsub {
|
Line 163 sub callsub {
|
if (my $space=$Apache::lonxml::alltags{$token->[1]}) { |
if (my $space=$Apache::lonxml::alltags{$token->[1]}) { |
#print "Calling sub $sub in $space \n"; |
#print "Calling sub $sub in $space \n"; |
$sub="$space\:\:$sub"; |
$sub="$space\:\:$sub"; |
|
$Apache::lonxml::curdepth=join('_',@Apache::lonxml::depthcounter); |
$currentstring = &$sub($target,$token,$parstack,$parser, |
$currentstring = &$sub($target,$token,$parstack,$parser, |
$safeeval,$style); |
$safeeval,$style); |
} else { |
} else { |
Line 174 sub callsub {
|
Line 179 sub callsub {
|
return $currentstring; |
return $currentstring; |
} |
} |
|
|
|
sub initdepth { |
|
@Apache::lonxml::depthcounter=(); |
|
$Apache::lonxml::depth=-1; |
|
$Apache::lonxml::olddepth=-1; |
|
} |
|
|
|
sub increasedepth { |
|
if ($Apache::lonxml::depth<$Apache::lonxml::olddepth-1) { |
|
$#Apache::lonxml::depthcounter--; |
|
$Apache::lonxml::olddepth=$Apache::lonxml::depth; |
|
} |
|
$Apache::lonxml::depth++; |
|
$Apache::lonxml::depthcounter[$Apache::lonxml::depth]++; |
|
if ($Apache::lonxml::depthcounter[$Apache::lonxml::depth]==1) { |
|
$Apache::lonxml::olddepth=$Apache::lonxml::depth; |
|
} |
|
} |
|
|
|
sub decreasedepth { |
|
$Apache::lonxml::depth--; |
|
} |
|
|
sub parstring { |
sub parstring { |
my ($token) = @_; |
my ($token) = @_; |
my $temp=''; |
my $temp=''; |