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

albertel lon-capa-cvs@mail.lon-capa.org
Sun, 18 Feb 2007 02:07:15 -0000


albertel		Sat Feb 17 21:07:15 2007 EDT

  Modified files:              
    /loncom/xml	lonxml.pm 
  Log:
  - switch to using xml description of insertionabilities
  
  
Index: loncom/xml/lonxml.pm
diff -u loncom/xml/lonxml.pm:1.437 loncom/xml/lonxml.pm:1.438
--- loncom/xml/lonxml.pm:1.437	Mon Jan 29 18:51:04 2007
+++ loncom/xml/lonxml.pm	Sat Feb 17 21:07:11 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # XML Parser Module 
 #
-# $Id: lonxml.pm,v 1.437 2007/01/29 23:51:04 albertel Exp $
+# $Id: lonxml.pm,v 1.438 2007/02/18 02:07:11 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -550,7 +550,6 @@
     }
 
     my $deleted=0;
-    $Apache::lonxml::curdepth=join('_',@Apache::lonxml::depthcounter);
     if (($token->[0] eq 'S') && ($target eq 'modified')) {
       $deleted=&Apache::edit::handle_delete($space,$target,$token,$tagstack,
 					     $parstack,$parser,$safeeval,
@@ -906,8 +905,14 @@
   $Apache::lonxml::olddepth=-1;
 }
 
+
 my @timers;
 my $lasttime;
+# $Apache::lonxml::depth -> current stack depth
+# @Apache::lonxml::depthcounter -> count of tags that exist so
+#                                  far at each level
+# $Apache::lonxml::olddepth -> when ascending, need to remember the count for the level below the current level (for example going from 1_2 -> 1 -> 1_3 need to rember that ) 
+
 sub increasedepth {
   my ($token) = @_;
   $Apache::lonxml::depth++;
@@ -922,8 +927,8 @@
       $lasttime=[&gettimeofday()];
   }
   my $spacing='  'x($Apache::lonxml::depth-1);
-  my $curdepth=join('_',@Apache::lonxml::depthcounter);
-  &Apache::lonxml::debug("s$spacing$Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1] : $time : \n");
+  $Apache::lonxml::curdepth=join('_',@Apache::lonxml::depthcounter);
+  &Apache::lonxml::debug("s$spacing$Apache::lonxml::depth : $Apache::lonxml::olddepth : $Apache::lonxml::curdepth : $token->[1] : $time");
 #print "<br />s $Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1]\n";
 }
 
@@ -945,8 +950,9 @@
       $lasttime=[&gettimeofday()];
   }
   my $spacing='  'x$Apache::lonxml::depth;
-  my $curdepth=join('_',@Apache::lonxml::depthcounter);
-  &Apache::lonxml::debug("e$spacing$Apache::lonxml::depth : $Apache::lonxml::olddepth : $curdepth : $token->[1] : $time : ".&tv_interval($timer)."\n");
+  $Apache::lonxml::curdepth=
+      join('_',@Apache::lonxml::depthcounter[0..$Apache::lonxml::depth]);
+  &Apache::lonxml::debug("e$spacing$Apache::lonxml::depth : $Apache::lonxml::olddepth : $Apache::lonxml::curdepth : $token->[1] : $time : ".&tv_interval($timer));
 #print "<br />e $Apache::lonxml::depth : $Apache::lonxml::olddepth : $token->[1] : $curdepth\n";
 }
 
@@ -1694,7 +1700,7 @@
   }
 }
 
-sub register_insert {
+sub register_insert_tab {
   my @data = split /\n/, &Apache::lonnet::getfile('/home/httpd/lonTabs/insertlist.tab');
   my $i;
   my $tagnum=0;
@@ -1734,6 +1740,110 @@
   }
 }
 
+sub register_insert_xml {
+    my $parser = HTML::LCParser->new($Apache::lonnet::perlvar{'lonTabDir'}
+				     .'/insertlist.xml');
+    my ($tagnum,$in_help)=(0,0);
+    my $tag;
+    while (my $token = $parser->get_token()) {
+	if ($token->[0] eq 'S') {
+	    my $key;
+	    if      ($token->[1] eq 'tag') {
+		$tag = $token->[2]{'name'};
+		$insertlist{"$tagnum.tag"} = $tag;
+		$insertlist{"$tag.num"}   = $tagnum;
+	    } elsif ($in_help && $token->[1] eq 'file') {
+		$key = $tag.'.helpfile';
+	    } elsif ($in_help && $token->[1] eq 'description') {
+		$key = $tag.'.helpdesc';
+	    } elsif ($token->[1] eq 'description' ||
+		     $token->[1] eq 'color'       ||
+		     $token->[1] eq 'show'          ) {
+		$key = $tag.'.'.$token->[1];
+	    } elsif ($token->[1] eq 'insert_sub') {
+		$key = $tag.'.function';
+	    } elsif ($token->[1] eq 'help') {
+		$in_help=1;
+	    } elsif ($token->[1] eq 'allow') {
+		my $allow = $parser->get_text();
+		foreach my $element (split(',',$allow)) {
+		    $element =~ s/(^\s*|\s*$ )//gx;
+		    push(@{ $insertlist{$tag.'.which'} },$element);
+		}
+	    }
+	    if (defined($key)) {
+		$insertlist{$key} = $parser->get_text();
+		$insertlist{$key} =~ s/(^\s*|\s*$ )//gx;
+	    }
+	} elsif ($token->[0] eq 'E') {
+	    if      ($token->[1] eq 'tag') {
+		undef($tag);
+		$tagnum++;
+	    } elsif ($token->[1] eq 'help') {
+		undef($in_help);
+	    }
+	}
+    }
+}
+
+sub register_insert {
+#    &register_insert_tab(@_);
+#    &dump_insertlist('1');
+#    undef(%insertlist);
+    return &register_insert_xml(@_);
+#    &dump_insertlist('2');
+}
+
+sub dump_insertlist {
+    my ($ext) = @_;
+    open(XML,">/tmp/insertlist.xml.$ext");
+    print XML ("<insertlist>");
+    my $i=0;
+
+    while (exists($insertlist{"$i.tag"})) {
+	my $tag = $insertlist{"$i.tag"};
+	print XML ("
+\t<tag name=\"$tag\">");
+	if (defined($insertlist{"$tag.description"})) {
+	    print XML ("
+\t\t<description>".$insertlist{"$tag.description"}."</description>");
+	}
+	if (defined($insertlist{"$tag.color"})) {
+	    print XML ("
+\t\t<color>".$insertlist{"$tag.color"}."</color>");
+	}
+	if (defined($insertlist{"$tag.function"})) {
+	    print XML ("
+\t\t<insert_sub>".$insertlist{"$tag.function"}."</insert_sub>");
+	}
+	if (defined($insertlist{"$tag.show"})
+	    && $insertlist{"$tag.show"} ne 'yes') {
+	    print XML ("
+\t\t<show>".$insertlist{"$tag.show"}."</show>");
+	}
+	if (defined($insertlist{"$tag.helpfile"})) {
+	    print XML ("
+\t\t<help>
+\t\t\t<file>".$insertlist{"$tag.helpfile"}."</file>");
+	    if ($insertlist{"$tag.helpdesc"} ne '') {
+		print XML ("
+\t\t\t<description>".$insertlist{"$tag.helpdesc"}."</description>");
+	    }
+	    print XML ("
+\t\t</help>");
+	}
+	if (defined($insertlist{"$tag.which"})) {
+	    print XML ("
+\t\t<allow>".join(',',sort(@{ $insertlist{"$tag.which"} }))."</allow>");
+	}
+	print XML ("
+\t</tag>");
+	$i++;
+    }
+    print XML ("\n</insertlist>\n");
+    close(XML);
+}
+
 sub description {
     my ($token)=@_;
     my $tag = &get_tag($token);