1 | package AbstractPlugin;
|
---|
2 |
|
---|
3 | use ReadTextFile;
|
---|
4 | use niupepautil;
|
---|
5 | use doc;
|
---|
6 |
|
---|
7 | use strict;
|
---|
8 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
9 | no strict 'subs';
|
---|
10 |
|
---|
11 | sub BEGIN {
|
---|
12 | @AbstractPlugin::ISA = ('ReadTextFile');
|
---|
13 | }
|
---|
14 |
|
---|
15 | my $arguments =
|
---|
16 | [
|
---|
17 | { 'name' => "process_exp",
|
---|
18 | 'desc' => "{BasePlugin.process_exp}",
|
---|
19 | 'type' => "regexp",
|
---|
20 | 'deft' => &get_default_process_exp(),
|
---|
21 | 'reqd' => "no" } ,
|
---|
22 |
|
---|
23 | ];
|
---|
24 |
|
---|
25 | my $options = { 'name' => "AbstractPlugin",
|
---|
26 | 'desc' => "Simple plugin for processing abstracts in niupepa collection",
|
---|
27 | 'abstract' => "no",
|
---|
28 | 'inherits' => "yes",
|
---|
29 | 'args' => $arguments };
|
---|
30 |
|
---|
31 | sub new {
|
---|
32 | my ($class) = shift (@_);
|
---|
33 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
34 | push(@$pluginlist, $class);
|
---|
35 |
|
---|
36 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
37 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
38 |
|
---|
39 | my $self = new ReadTextFile($pluginlist, $inputargs, $hashArgOptLists);
|
---|
40 |
|
---|
41 | return bless $self, $class;
|
---|
42 | }
|
---|
43 |
|
---|
44 | sub get_default_process_exp {
|
---|
45 | my $self = shift (@_);
|
---|
46 |
|
---|
47 | return q^(?i)\.abstract$^;
|
---|
48 | }
|
---|
49 |
|
---|
50 | # do plugin specific processing of doc_obj
|
---|
51 | sub process {
|
---|
52 | my $self = shift (@_);
|
---|
53 | my ($textref, $pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
|
---|
54 | my $outhandle = $self->{'outhandle'};
|
---|
55 |
|
---|
56 | my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
|
---|
57 | # filename is like 01_1_1.abstract, OID is 01_1_1abstract
|
---|
58 | my $OID = $filename_no_path;
|
---|
59 | $OID =~ s/\.//;
|
---|
60 | $doc_obj->set_OID ($OID);
|
---|
61 | print STDERR "set oid $OID\n";
|
---|
62 | my ($full_dir) = $filename_full_path =~ /^(.*?)([^\/\\]*)$/;
|
---|
63 | # set metadata from meta.txt
|
---|
64 | &niupepautil::set_main_metadata($doc_obj, $full_dir, $self->{'verbosity'});
|
---|
65 |
|
---|
66 | my $cursection = $doc_obj->get_top_section();
|
---|
67 | $doc_obj->set_utf8_metadata_element ($cursection, "DocType", "Description");
|
---|
68 |
|
---|
69 | my $paper_id = $OID;
|
---|
70 | $paper_id =~ s/abstract//;
|
---|
71 | $doc_obj->set_utf8_metadata_element ($cursection, 'Title', &niupepautil::get_title_string($paper_id));
|
---|
72 |
|
---|
73 | # just add the html text as is to the section
|
---|
74 |
|
---|
75 | $doc_obj->add_utf8_text($cursection, $$textref);
|
---|
76 |
|
---|
77 | return 1;
|
---|
78 | }
|
---|
79 |
|
---|
80 | 1;
|
---|
81 |
|
---|