1 | # This recursive plugin processes all files in a table of contents (toc.txt)
|
---|
2 | # file. The toc.txt file should contain a list of filenames followed by
|
---|
3 | # one or more subject classifications to which that document belongs. The
|
---|
4 | # subject classifications should correspond to those in the first field
|
---|
5 | # of the collections subject file if the Hierarchy classifier plugin is
|
---|
6 | # being used.
|
---|
7 |
|
---|
8 | package TOCPlug;
|
---|
9 |
|
---|
10 | use plugin;
|
---|
11 | use BasPlug;
|
---|
12 | use lang;
|
---|
13 | use doc;
|
---|
14 | use util;
|
---|
15 | use cfgread;
|
---|
16 |
|
---|
17 | sub BEGIN {
|
---|
18 | @ISA = ('BasPlug');
|
---|
19 | }
|
---|
20 |
|
---|
21 | sub new {
|
---|
22 | my ($class) = @_;
|
---|
23 | $self = new BasPlug ();
|
---|
24 |
|
---|
25 | return bless $self, $class;
|
---|
26 | }
|
---|
27 |
|
---|
28 | # return 1 if this class might recurse using $pluginfo
|
---|
29 | sub is_recursive {
|
---|
30 | my $self = shift (@_);
|
---|
31 |
|
---|
32 | return 1;
|
---|
33 | }
|
---|
34 |
|
---|
35 | # return 1 if processed, 0 if not processed
|
---|
36 | # Note that $base_dir might be "" and that $file might
|
---|
37 | # include directories
|
---|
38 | sub read {
|
---|
39 | my $self = shift (@_);
|
---|
40 | my ($pluginfo, $base_dir, $file, $metadata, $processor) = @_;
|
---|
41 |
|
---|
42 | my $tocfile = &util::filename_cat($base_dir, $file, "toc.txt");
|
---|
43 | if (!-f $tocfile) {
|
---|
44 | # not a directory containing a toc file
|
---|
45 | return 0;
|
---|
46 | }
|
---|
47 |
|
---|
48 | # found a toc.txt file
|
---|
49 | print STDERR "TOCPlug: processing $tocfile\n";
|
---|
50 |
|
---|
51 | # read in the toc.txt
|
---|
52 | my $list = &cfgread::read_cfg_file ($tocfile, undef, '^[^#]\w');
|
---|
53 |
|
---|
54 | # process each document
|
---|
55 | foreach $docfile (keys (%$list)) {
|
---|
56 | # note that $list->{$docfile} is an array reference
|
---|
57 | $metadata->{'Subject'} = $list->{$docfile};
|
---|
58 | &plugin::read ($pluginfo, $base_dir, $docfile, $metadata, $processor);
|
---|
59 | }
|
---|
60 |
|
---|
61 | return 1; # was processed
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 | 1;
|
---|