classindex.pl 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #! /usr/bin/perl
  2. # Intended to generate an index of classnames to references in the manual (using the interfacename and classname elements).
  3. #
  4. # Builds an index of classnames to Javadoc (or src xref) links, from the allclasses-frame.html file.
  5. # Processes the ref manual docbook files, building an index of classname to section ids where the class is referenced
  6. #
  7. #
  8. use strict;
  9. # Get list of links to class src packages from Javadoc
  10. #system("curl http://static.springsource.org/spring-security/site/docs/3.0.x/apidocs/allclasses-frame.html > allclasses-frame.html");
  11. # Manual front page gives us section numbers
  12. #system("curl http://static.springsource.org/spring-security/site/docs/3.0.x/reference/springsecurity.html > springsecurity.html");
  13. my $index_page = `cat springsecurity.html`;
  14. my @all_classes = `cat allclasses-frame.html`;
  15. $#all_classes > 0 || die "No lines in Javadoc";
  16. # Src XREF format
  17. #<a href="org/springframework/security/vote/AbstractAccessDecisionManager.html" target="classFrame">AbstractAccessDecisionManager</a>
  18. # Javadoc format
  19. #<A HREF="org/springframework/security/acls/afterinvocation/AbstractAclProvider.html" title="class in org.springframework.security.acls.afterinvocation" target="classFrame">AbstractAclProvider</A>
  20. my %classnames_to_src;
  21. print "Extracting classnames to links map from Javadoc...\n";
  22. while ($_ = pop @all_classes) {
  23. chomp;
  24. # Get rid of the italic tags round interface names
  25. $_ =~ s/<I>//;
  26. $_ =~ s/<\/I>//;
  27. next unless $_ =~ /<A HREF="(.*)" title=.*>(([a-zA-Z0-9_]+?))<\/A>.*/;
  28. # print "Adding class $1, $2\n";
  29. $classnames_to_src{$2} = $1;
  30. }
  31. #my @docbook = glob("*.xml");
  32. # The list of docbook files xincluded in the manual
  33. my @docbook;
  34. print "Building list of docbook source files...\n";
  35. # Read the includes rather than using globbing to get the ordering right for the index.
  36. open MAINDOC, "<springsecurity.xml";
  37. while(<MAINDOC>) {
  38. if (/href="(.*\.xml)"/) {
  39. push @docbook, $1;
  40. }
  41. }
  42. # Hash of xml:id (i.e. anchor) to filename.html#anchor
  43. my %id_to_html;
  44. # Build map of html pages links
  45. print "Building map of section xml:ids to reference manual links...\n";
  46. while (my $file = pop @docbook) {
  47. open FILE, $file or die "$!";
  48. # print "\nProcessing: $file\n\n";
  49. my $file_id;
  50. while(<FILE>) {
  51. if (/.* xml:id="([a-z0-9-]+?)"/) {
  52. $file_id = $1;
  53. last;
  54. }
  55. }
  56. $id_to_html{$file_id} = "$file_id.html";
  57. while (<FILE>) {
  58. next unless /.* xml:id="([a-z0-9-]+?)"/;
  59. # print "$1\n";
  60. $id_to_html{$1} = "$file_id.html#$1";
  61. }
  62. close FILE;
  63. }
  64. # Get the list of class/interface names and their section ids/titles
  65. print "Obtaining class and interface references from manual...\n";
  66. my @class_references = split /;/,`xsltproc --xinclude index-classes.xsl springsecurity.xml`;
  67. # Get unique values
  68. my %seen = ();
  69. @class_references = grep { !$seen{$_}++} @class_references;
  70. print "There are $#class_references references to classes and interfaces.\n";
  71. my %id_to_title;
  72. my %classnames_to_ids = ();
  73. foreach my $class_id_title (@class_references) {
  74. (my $class, my $id, my $title) = split /:/, $class_id_title;
  75. $title =~ s/</&lt;/;
  76. $title =~ s/>/&gt;/;
  77. $id_to_title{$id} = $title;
  78. push( @{$classnames_to_ids{$class}}, $id );
  79. }
  80. print "Writing index file...\n";
  81. open INDEX, ">classindex.xml" || die "Couldn't open output file\n";
  82. print INDEX "<index>\n";
  83. foreach my $class (sort keys %classnames_to_ids) {
  84. print INDEX "<class name='$class'";
  85. if (exists $classnames_to_src{$class}) {
  86. print INDEX " src-xref='$classnames_to_src{$class}'";
  87. }
  88. print INDEX ">\n";
  89. foreach my $id (@{$classnames_to_ids{$class}}) {
  90. my $href = $id_to_html{$id};
  91. $index_page =~ /$href">([AB0-9\.]* )/;
  92. my $section = $1 ? "$1" : "";
  93. # print "$id $href $section\n";
  94. my $title = $id_to_title{$id};
  95. # print "$section$title\n";
  96. print INDEX " <link href='$href' title='$section$title'/>\n";
  97. }
  98. print INDEX "</class>\n"
  99. }
  100. print INDEX "</index>\n";
  101. close INDEX;
  102. print "Generating HTML file...\n"; 
  103. system("xsltproc class-index-html.xsl classindex.xml > class-index.html");