classindex.pl 2.4 KB

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