Ignore:
Timestamp:
2008-06-05T09:29:32+12:00 (16 years ago)
Author:
kjdon
Message:

plugin overhaul: plugins renamed to xxPlugin, and in some cases the names are made more sensible. They now use the new base plugins. Hopefully we have better code reuse. Some of the plugins still need work done as I didn't want to spend another month doing this before committing it. Alos, I haven't really tested anything yet...

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gsdl/trunk/perllib/plugins/DBPlugin.pm

    r15865 r15872  
    11###########################################################################
    22#
    3 # DBPlug.pm -- plugin to import records from a database
     3# DBPlugin.pm -- plugin to import records from a database
    44#
    55# A component of the Greenstone digital library software
     
    3434# Mar, Apr 2003
    3535
    36 package DBPlug;
     36package DBPlugin;
    3737
    3838use strict;
    3939no strict 'refs'; # allow variable as a filehandle
    4040
    41 use BasPlug;
     41use AutoExtractMetadata;
    4242use unicode;
    4343
    44 #use DBI; # database independent stuff
    45 
    4644sub BEGIN {
    47     @DBPlug::ISA = ('BasPlug');
     45    @DBPlugin::ISA = ('AutoExtractMetadata');
    4846}
    4947
    5048my $arguments =
    5149    [ { 'name' => "process_exp",
    52     'desc' => "{BasPlug.process_exp}",
     50    'desc' => "{AutoExtractMetadata.process_exp}",
    5351    'type' => "regexp",
    5452    'deft' => &get_default_process_exp(),
    5553    'reqd' => "no" }];
    5654
    57 my $options = { 'name'     => "DBPlug",
    58         'desc'     => "{DBPlug.desc}",
     55my $options = { 'name'     => "DBPlugin",
     56        'desc'     => "{DBPlugin.desc}",
    5957        'abstract' => "no",
    6058        'inherits' => "yes",
     
    6664    push(@$pluginlist, $class);
    6765
    68     if(defined $arguments){ push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});}
    69     if(defined $options) { push(@{$hashArgOptLists->{"OptList"}},$options)};
    70 
    71     my $self = new BasPlug($pluginlist, $inputargs, $hashArgOptLists);
     66    push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
     67    push(@{$hashArgOptLists->{"OptList"}},$options);
     68
     69    my $self = new AutoExtractMetadata($pluginlist, $inputargs, $hashArgOptLists);
    7270
    7371    return bless $self, $class;
     
    7876
    7977    return q^(?i)\.dbi$^;
    80 }
    81 # we don't have a per-greenstone document process() function!
    82 sub process {
    83 
    8478}
    8579
     
    9589    my $verbosity = $self->{'verbosity'};
    9690
    97     print $outhandle "DBPlug: processing $file\n"
     91    print $outhandle "DBPlugin: processing $file\n"
    9892    if $self->{'verbosity'} > 1;
    9993   
     
    114108    my $db=undef;
    115109
    116 # get id of pages from "nonempty", get latest version number from "recent", and
    117 # then get pagename from "page" and content from "version" !
     110    # get id of pages from "nonempty", get latest version number from
     111    # "recent", and then get pagename from "page" and content from "version" !
    118112
    119113    my $sql_query_prime = undef ;
     
    126120    # read in config file.
    127121    if (!open (CONF, $filename)) {
    128         print $outhandle "DBPlug: can't read $filename: $!\n";
     122        print $outhandle "DBPlugin: can't read $filename: $!\n";
    129123        return 0;
    130124    }
     
    145139        $callback =~ /[\`]|\|\-/) {
    146140        # no backticks or functions that start new processes allowed
    147         print $outhandle "DBPlug: bad function in callback\n";
     141        print $outhandle "DBPlugin: bad function in callback\n";
    148142        return 0;
    149143        }
     
    152146        my $ret = eval "\$callbacks{'$fieldname'} = $callback ; 1";
    153147        if (!defined($ret)) {
    154         print $outhandle "DBPlug: error eval'ing callback: $@\n";
     148        print $outhandle "DBPlugin: error eval'ing callback: $@\n";
    155149        exit(1);
    156150        }
    157151        $callback="";
    158         print $outhandle "DBPlug: callback registered for '$fieldname'\n"
     152        print $outhandle "DBPlugin: callback registered for '$fieldname'\n"
    159153            if $dbplug_debug;
    160154    } elsif ($callback) {
     
    176170            chomp $err;
    177171            $err =~ s/\.$//; # remove a trailing .
    178             print $outhandle "DBPlug: error evaluating `$statement'\n";
     172            print $outhandle "DBPlugin: error evaluating `$statement'\n";
    179173            print $outhandle " $err (in $filename)\n";
    180174            return 0; # there was an error reading the config file
     
    185179        $statement = "";
    186180        } else {
    187         print $outhandle "DBPlug: skipping statement `$statement'\n";
     181        print $outhandle "DBPlugin: skipping statement `$statement'\n";
    188182        }
    189183        $statement = "";
     
    194188   
    195189    if (!defined($db)) {
    196     print $outhandle "DBPlug: error: $filename does not specify a db!\n";
     190    print $outhandle "DBPlugin: error: $filename does not specify a db!\n";
    197191    return 0;
    198192    }
    199193    if (!defined($sql_query)) {
    200         print $outhandle "DBPlug: error: no SQL query specified!\n";
     194        print $outhandle "DBPlugin: error: no SQL query specified!\n";
    201195    return 0;
    202196    }
     
    205199
    206200    if (!defined($dbhandle)) {
    207     die "DBPlug: could not connect to database, exiting.\n";
     201    die "DBPlugin: could not connect to database, exiting.\n";
    208202    }
    209203    if (defined($dbplug_debug) && $dbplug_debug==1) {
    210     print $outhandle "DBPlug (debug): connected ok\n";
     204    print $outhandle "DBPlugin (debug): connected ok\n";
    211205    }
    212206
     
    238232    if (defined($db_to_greenstone_fields{$fieldname})) {
    239233        if (defined($dbplug_debug) && $dbplug_debug==1) {
    240         print $outhandle "DBPlug (debug): mapping db field "
     234        print $outhandle "DBPlugin (debug): mapping db field "
    241235            . "'$fieldname' to "
    242236            . $db_to_greenstone_fields{$fieldname} . "\n";
     
    255249    while (scalar(@row_array)) {
    256250    if (defined($dbplug_debug) && $dbplug_debug==1) {
    257         print $outhandle "DBPlug (debug): retrieved a row from query\n";
     251        print $outhandle "DBPlugin (debug): retrieved a row from query\n";
    258252    }
    259253
     
    263257    my $cursection = $doc_obj->get_top_section();
    264258
    265     # if $language not set in config file, will use BasPlug's default
     259    # if $language not set in config file, will use BasePlugin's default
    266260    if (defined($language)) {
    267261        $doc_obj->add_utf8_metadata($cursection, "Language", $language);
    268262    }
    269     # if $encoding not set in config file, will use BasPlug's default
     263    # if $encoding not set in config file, will use BasePlugin's default
    270264    if (defined($encoding)) {
    271265        # allow some common aliases
     
    274268        $doc_obj->add_utf8_metadata($cursection, "Encoding", $encoding);
    275269    }
    276     $doc_obj->add_utf8_metadata($cursection,
    277                     "Source", &ghtml::dmsafe($db));
     270    $self->set_Source_metadata($doc_obj, $db, $encoding);
     271
    278272    if ($self->{'cover_image'}) {
    279273        $self->associate_cover_image($doc_obj, $filename);
     
    358352    # check "$sth->err" if empty array for error
    359353    if ($statement_hand->err) {
    360     print $outhandle "DBPlug: received error: \"" .
     354    print $outhandle "DBPlugin: received error: \"" .
    361355        $statement_hand->errstr . "\"\n";
    362356    }
     
    370364
    371365    if (defined($dbplug_debug) && $dbplug_debug==1) {
    372         print $outhandle "DBPlug: imported $count DB records as documents.\n";
     366        print $outhandle "DBPlugin: imported $count DB records as documents.\n";
    373367    }
    374368    $count;
Note: See TracChangeset for help on using the changeset viewer.