[LON-CAPA-cvs] cvs: loncom /homework structuretags.pm /xml lonxml.pm scripttag.pm

albertel lon-capa-cvs@mail.lon-capa.org
Wed, 06 Nov 2002 23:05:02 -0000


This is a MIME encoded message

--albertel1036623902
Content-Type: text/plain

albertel		Wed Nov  6 18:05:02 2002 EDT

  Modified files:              
    /loncom/xml	lonxml.pm scripttag.pm 
    /loncom/homework	structuretags.pm 
  Log:
  - Fixes most of BUG#793
  - added new global var that controls wheter syle files defs are used
  - use new tag <LONCAPA_INTERNAL_TURN_STYLE_ON /> to turn style def use back on
  - removed recurse sub completely 
  - get_all_text now understands the Parser stack
  
  Bugs:
  - get_all_unbalanced_text needs to use parser stack
  - get_all_text uses need to pass entrie parser stack
  - style defs that have a tag that ends in a different style def can't use get_all_text
  
  
  Need To Test:
  - pars stack pops in end tags looking for start tags in get_all_text
  
  
--albertel1036623902
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20021106180502.txt"

Index: loncom/xml/lonxml.pm
diff -u loncom/xml/lonxml.pm:1.211 loncom/xml/lonxml.pm:1.212
--- loncom/xml/lonxml.pm:1.211	Wed Nov  6 17:36:08 2002
+++ loncom/xml/lonxml.pm	Wed Nov  6 18:05:02 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # XML Parser Module 
 #
-# $Id: lonxml.pm,v 1.211 2002/11/06 22:36:08 albertel Exp $
+# $Id: lonxml.pm,v 1.212 2002/11/06 23:05:02 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -148,6 +148,9 @@
 $Apache::lonxml::counter=0;
 $Apache::lonxml::counter_changed=0;
 
+#internal check on whether to look at style defs
+$Apache::lonxml::usestyle=1;
+
 sub xmlbegin {
   my $output='';
   if ($ENV{'browser.mathml'}) {
@@ -630,15 +633,12 @@
 	# add parameters list to another stack
 	push (@$parstack,&parstring($token));
 	&increasedepth($token);
-	if (exists $$style_for_target{$token->[1]}) {
-	  if ($Apache::lonxml::redirection) {
-	    $Apache::lonxml::outputstack['-1'] .=
-	      &recurse($$style_for_target{$token->[1]},$target,$safeeval,
-		       $style_for_target,@$parstack);
-	  } else {
-	    $finaloutput .= &recurse($$style_for_target{$token->[1]},$target,
-				     $safeeval,$style_for_target,@$parstack);
-	  }
+	if ($Apache::lonxml::usestyle &&
+	    exists($$style_for_target{$token->[1]})) {
+	    $Apache::lonxml::usestyle=0;
+	    my $string=$$style_for_target{$token->[1]}.
+	      '<LONCAPA_INTERNAL_TURN_STYLE_ON />';
+	    &Apache::lonxml::newparser($pars,\$string);
 	} else {
 	  $result = &callsub("start_$token->[1]", $target, $token, $stack,
 			     $parstack, $pars, $safeeval, $style_for_target);
@@ -656,16 +656,12 @@
 	  }
 	}
 
-	if (exists($$style_for_target{'/'."$token->[1]"})) {
-	  if ($Apache::lonxml::redirection) {
-	    $Apache::lonxml::outputstack['-1'] .=  
-	      &recurse($$style_for_target{'/'."$token->[1]"},
-		       $target,$safeeval,$style_for_target,@$parstack);
-	  } else {
-	    $finaloutput .= &recurse($$style_for_target{'/'."$token->[1]"},
-				     $target,$safeeval,$style_for_target,
-				     @$parstack);
-	  }
+	if ($Apache::lonxml::usestyle &&
+	    exists($$style_for_target{'/'."$token->[1]"})) {
+	    $Apache::lonxml::usestyle=0;
+	    my $string=$$style_for_target{'/'.$token->[1]}.
+	      '<LONCAPA_INTERNAL_TURN_STYLE_ON />';
+	    &Apache::lonxml::newparser($pars,\$string);
 	} else {
 	  $result = &callsub("end_$token->[1]", $target, $token, $stack,
 			     $parstack, $pars,$safeeval, $style_for_target);
@@ -702,8 +698,10 @@
 	&end_tag($stack,$parstack,$token);
       }
     }
-    pop @$pars;
-    pop @Apache::lonxml::pwd;
+    if ($#$pars > -1) {
+	pop @$pars;
+	pop @Apache::lonxml::pwd;
+    }
   }
 
   # if ($target eq 'meta') {
@@ -717,78 +715,6 @@
   return $finaloutput;
 }
 
-sub recurse {
-  my @innerstack = (); 
-  my @innerparstack = ();
-  my ($newarg,$target,$safeeval,$style_for_target,@parstack) = @_;
-  my @pat = ();
-  &newparser(\@pat,\$newarg);
-  my $tokenpat;
-  my $partstring = '';
-  my $output='';
-  my $decls='';
-  &Apache::lonxml::debug("Recursing");
-  while ( $#pat > -1 ) {
-    while  ($tokenpat = $pat[$#pat]->get_token) {
-      if (($tokenpat->[0] eq 'T') || ($tokenpat->[0] eq 'C') || ($tokenpat->[0] eq 'D') ) {
-	if ($metamode<1) { $partstring=$tokenpat->[1]; }
-      } elsif ($tokenpat->[0] eq 'PI') {
-	if ($metamode<1) { $partstring=$tokenpat->[2]; }
-      } elsif ($tokenpat->[0] eq 'S') {
-	push (@innerstack,$tokenpat->[1]);
-	push (@innerparstack,&parstring($tokenpat));
-	&increasedepth($tokenpat);
-	$partstring = &callsub("start_$tokenpat->[1]", $target, $tokenpat,
-			       \@innerstack, \@innerparstack, \@pat,
-			       $safeeval, $style_for_target);
-      } elsif ($tokenpat->[0] eq 'E') {
-	#clear out any tags that didn't end
-	while ($tokenpat->[1] ne $innerstack[$#innerstack]
-	       && ($#innerstack > -1)) {
-	  my $lasttag=$innerstack[-1];
-	  if ($tokenpat->[1] =~ /^$lasttag$/i) {
-	    &Apache::lonxml::warning('Using tag &lt;/'.$tokenpat->[1].'&gt; as end tag to &lt;'.$innerstack[-1].'&gt;');
-	    last;
-	  } else {
-	    &Apache::lonxml::warning('Found tag &lt;/'.$tokenpat->[1].'&gt; when looking for &lt;/'.$innerstack[-1].'&gt; in file');
-	    &end_tag(\@innerstack,\@innerparstack,$tokenpat);
-	  }
-	}
-	$partstring = &callsub("end_$tokenpat->[1]", $target, $tokenpat,
-			       \@innerstack, \@innerparstack, \@pat,
-			       $safeeval, $style_for_target);
-      } else {
-	&Apache::lonxml::error("Unknown token event :$tokenpat->[0]:$tokenpat->[1]:");
-      }
-      #pass both the variable to the style tag, and the tag we 
-      #are processing inside the <definedtag>
-      if ( $partstring ne "" ) {
-	if ( $#parstack > -1 ) { 
-	  if ( $#innerparstack > -1 ) { 
-	    $decls= $parstack[$#parstack].$innerparstack[$#innerparstack];
-	  } else {
-	    $decls= $parstack[$#parstack];
-	  }
-	} else {
-	  if ( $#innerparstack > -1 ) { 
-	    $decls=$innerparstack[$#innerparstack];
-	  } else {
-	    $decls='';
-	  }
-	}
-	$output .= &Apache::run::evaluate($partstring,$safeeval,$decls);
-	$partstring = '';
-      }
-      if ($tokenpat->[0] eq 'E') { pop @innerstack;pop @innerparstack;
-				 &decreasedepth($tokenpat);}
-    }
-    pop @pat;
-    pop @Apache::lonxml::pwd;
-  }
-  &Apache::lonxml::debug("Exiting Recursing");
-  return $output;
-}
-
 sub callsub {
   my ($sub,$target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
   my $currentstring='';
@@ -862,6 +788,7 @@
   $errorcount=0;
   $warningcount=0;
   $Apache::lonxml::default_homework_loaded=0;
+  $Apache::lonxml::usestyle=1;
   &init_counter();
   @Apache::lonxml::pwd=();
   @Apache::lonxml::extlinks=();
@@ -1080,48 +1007,68 @@
 
 sub get_all_text {
  my($tag,$pars)= @_;
+ &Apache::lonxml::debug("Got a ".ref($pars));
+ if (ref($pars) ne 'ARRAY') {
+     $pars=[$pars];
+ }
  my $depth=0;
  my $token;
  my $result='';
  if ( $tag =~ m:^/: ) { 
    my $tag=substr($tag,1); 
-#   &Apache::lonxml::debug("have:$tag:");
-   while (($depth >=0) && ($token = $pars->get_token)) {
-#     &Apache::lonxml::debug("e token:$token->[0]:$depth:$token->[1]");
-     if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
-       $result.=$token->[1];
-     } elsif ($token->[0] eq 'PI') {
-       $result.=$token->[2];
-     } elsif ($token->[0] eq 'S') {
-       if ($token->[1] =~ /^$tag$/i) { $depth++; }
-       $result.=$token->[4];
-     } elsif ($token->[0] eq 'E')  {
-       if ( $token->[1] =~ /^$tag$/i) { $depth--; }
-       #skip sending back the last end tag
-       if ($depth > -1) { $result.=$token->[2]; } else {
-	 $pars->unget_token($token);
+   #&Apache::lonxml::debug("have:$tag:");
+   while (($depth >=0) && ($#$pars > -1)) {
+     while (($depth >=0) && ($token = $$pars[-1]->get_token)) {
+       #&Apache::lonxml::debug("e token:$token->[0]:$depth:$token->[1]:".$#$pars.":".$#Apache::lonxml::pwd);
+       if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
+	 $result.=$token->[1];
+       } elsif ($token->[0] eq 'PI') {
+	 $result.=$token->[2];
+       } elsif ($token->[0] eq 'S') {
+	 if ($token->[1] =~ /^$tag$/i) { $depth++; }
+	 $result.=$token->[4];
+       } elsif ($token->[0] eq 'E')  {
+	 if ( $token->[1] =~ /^$tag$/i) { $depth--; }
+	 #skip sending back the last end tag
+	 if ($depth > -1) { $result.=$token->[2]; } else {
+	   $$pars[-1]->unget_token($token);
+	 }
        }
      }
+     if (($depth >=0) && ($#$pars > 0) ) {
+       pop(@$pars);
+       pop(@Apache::lonxml::pwd);
+     }
    }
  } else {
-   while ($token = $pars->get_token) {
-#     &Apache::lonxml::debug("s token:$token->[0]:$depth:$token->[1]");
-     if (($token->[0] eq 'T')||($token->[0] eq 'C')||($token->[0] eq 'D')) {
-       $result.=$token->[1];
-     } elsif ($token->[0] eq 'PI') {
-       $result.=$token->[2];
-     } elsif ($token->[0] eq 'S') {
-       if ( $token->[1] =~ /^$tag$/i) {
-	 $pars->unget_token($token); last;
-       } else {
-	 $result.=$token->[4];
-       }
-     } elsif ($token->[0] eq 'E')  {
-       $result.=$token->[2];
+     while ($#$pars > -1) {
+	 while ($token = $$pars[-1]->get_token) {
+	     #&Apache::lonxml::debug("s token:$token->[0]:$depth:$token->[1]");
+	     if (($token->[0] eq 'T')||($token->[0] eq 'C')||
+		 ($token->[0] eq 'D')) {
+		 $result.=$token->[1];
+	     } elsif ($token->[0] eq 'PI') {
+		 $result.=$token->[2];
+	     } elsif ($token->[0] eq 'S') {
+		 if ( $token->[1] =~ /^$tag$/i) {
+		     $$pars[-1]->unget_token($token); last;
+		 } else {
+		     $result.=$token->[4];
+		 }
+	     } elsif ($token->[0] eq 'E')  {
+		 $result.=$token->[2];
+	     }
+	 }
+	 if (($#$pars > 0) ) {
+	     pop(@$pars);
+	     pop(@Apache::lonxml::pwd);
+	 } else { last; }
      }
-   }
  }
-# &Apache::lonxml::debug("Exit:$result:");
+ if ($result =~ m|<LONCAPA_INTERNAL_TURN_STYLE_ON />|) {
+     $Apache::lonxml::usestyle=1;
+ }
+ #&Apache::lonxml::debug("Exit:$result:");
  return $result
 }
 
Index: loncom/xml/scripttag.pm
diff -u loncom/xml/scripttag.pm:1.80 loncom/xml/scripttag.pm:1.81
--- loncom/xml/scripttag.pm:1.80	Wed Oct 30 18:37:57 2002
+++ loncom/xml/scripttag.pm	Wed Nov  6 18:05:02 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # <script> definiton
 #
-# $Id: scripttag.pm,v 1.80 2002/10/30 23:37:57 albertel Exp $
+# $Id: scripttag.pm,v 1.81 2002/11/06 23:05:02 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -43,7 +43,17 @@
   &Apache::lonxml::register('Apache::scripttag',
 			    ('script','scriptlib','parserlib','import',
 			     'window','display','storetc','physnet',
-			     'standalone','comment'));
+			     'standalone','comment',
+			     'LONCAPA_INTERNAL_TURN_STYLE_ON'));
+}
+
+sub start_LONCAPA_INTERNAL_TURN_STYLE_ON {
+    $Apache::lonxml::usestyle=1;
+    return ('','no');
+}
+
+sub end_LONCAPA_INTERNAL_TURN_STYLE_ON {
+    return ('','no');
 }
 
 sub start_script {
Index: loncom/homework/structuretags.pm
diff -u loncom/homework/structuretags.pm:1.131 loncom/homework/structuretags.pm:1.132
--- loncom/homework/structuretags.pm:1.131	Wed Nov  6 17:58:36 2002
+++ loncom/homework/structuretags.pm	Wed Nov  6 18:05:02 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # definition of tags that give a structure to a document
 #
-# $Id: structuretags.pm,v 1.131 2002/11/06 22:58:36 albertel Exp $
+# $Id: structuretags.pm,v 1.132 2002/11/06 23:05:02 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -290,10 +290,11 @@
     my $expression='$external::datestatus="'.$status.'";';
     $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.0.solved"}.'";';
     &Apache::run::run($expression,$safeeval);
+    &Apache::lonxml::debug("Got $status");
     if (( $status eq 'CLOSED' ) ||
         ( $status eq 'UNCHECKEDOUT') ||
         ( $status eq 'BANNED')) {
-      my $bodytext=&Apache::lonxml::get_all_text("/problem",$$parser[$#$parser]);
+      my $bodytext=&Apache::lonxml::get_all_text("/problem",$parser);
       if ( $target eq "web" ) {
 	$result.= $head_tag_start.'</head>';
         my $msg=$body_tag_start.

--albertel1036623902--