classindex.pl 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #! /usr/bin/perl
  2. use strict;
  3. # Get list of links to class src packages from Javadoc
  4. #system("curl http://static.springsource.org/spring-security/site/docs/3.0.x/apidocs/allclasses-frame.html > allclasses-frame.html");
  5. my @all_classes = `cat allclasses-frame.html`;
  6. $#all_classes > 0 || die "No lines in Javadoc";
  7. # Src XREF format
  8. #<a href="org/springframework/security/vote/AbstractAccessDecisionManager.html" target="classFrame">AbstractAccessDecisionManager</a>
  9. # Javadoc format
  10. #<A HREF="org/springframework/security/acls/afterinvocation/AbstractAclProvider.html" title="class in org.springframework.security.acls.afterinvocation" target="classFrame">AbstractAclProvider</A>
  11. my %classnames_to_src;
  12. while ($_ = pop @all_classes) {
  13. next unless $_ =~ /<A HREF="(.*)" title.*>(([a-zA-Z0-9_]+?))<\/A>/;
  14. print "Adding class $1, $2\n";
  15. $classnames_to_src{$2} = $1;
  16. }
  17. #my @docbook = glob("*.xml");
  18. my @docbook;
  19. # Read the includes rather than using globbing to get the ordering right for the index.
  20. open MAINDOC, "<springsecurity.xml";
  21. while(<MAINDOC>) {
  22. if (/href="(.*\.xml)"/) {
  23. push @docbook, $1;
  24. }
  25. }
  26. # Hash of xml:id (i.e. anchor) to filename.html#anchor
  27. my %id_to_html;
  28. my %class_index;
  29. # Build map of html pages links
  30. while (my $file = pop @docbook) {
  31. open FILE, $file or die "$!";
  32. print "\nProcessing: $file\n\n";
  33. my $file_id;
  34. while(<FILE>) {
  35. if (/.* xml:id="([a-z0-9-]+?)"/) {
  36. $file_id = $1;
  37. last;
  38. }
  39. }
  40. $id_to_html{$file_id} = "$file_id.html#$file_id";
  41. while (<FILE>) {
  42. next unless /.* xml:id="([a-z0-9-]+?)"/;
  43. print "$1\n";
  44. $id_to_html{$1} = "$file_id.html#$1";
  45. }
  46. close FILE;
  47. }
  48. # Get the list of class/interface names and their section ids/titles
  49. my @class_references = split /;/,`xsltproc --xinclude index-classes.xsl springsecurity.xml`;
  50. # Get unique values
  51. my %seen = ();
  52. @class_references = grep { !$seen{$_}++} @class_references;
  53. print "\nThere are $#class_references references to classes and interfaces.\n";
  54. my %id_to_title;
  55. my %classnames_to_ids = ();
  56. foreach my $class_id_title (@class_references) {
  57. (my $class, my $id, my $title) = split /:/, $class_id_title;
  58. $title =~ s/</&lt;/;
  59. $title =~ s/>/&gt;/;
  60. $id_to_title{$id} = $title;
  61. push( @{$classnames_to_ids{$class}}, $id );
  62. }
  63. open INDEX, ">classindex.xml" || die "Couldn't open output file\n";
  64. print INDEX "<index>\n";
  65. foreach my $class (sort keys %classnames_to_ids) {
  66. print INDEX "<class name='$class'";
  67. if (exists $classnames_to_src{$class}) {
  68. print INDEX " src-xref='$classnames_to_src{$class}'";
  69. }
  70. print INDEX ">\n";
  71. foreach my $id (@{$classnames_to_ids{$class}}) {
  72. print INDEX " <link href='$id_to_html{$id}' title='$id_to_title{$id}'/>\n";
  73. }
  74. print INDEX "</class>\n"
  75. }
  76. print INDEX "</index>\n";
  77. close INDEX;