-#!/usr/bin/perl -w
+#!/usr/bin/perl
+
+use warnings;
+use strict;
use Net::Z3950::SimpleServer;
use Net::Z3950::OID;
+use Data::Dumper;
use COBISS;
-use strict;
+
+my $databases = {
+ 'COBISS' => 'COBISS',
+ 'NSK01' => 'Aleph',
+ 'NSK10' => 'Aleph',
+ 'ZAG01' => 'Aleph',
+};
my $max_records = 3; # XXX configure this
my $max_result_sets = 10;
my $session = {};
$this->{HANDLE} = $session;
- $this->{IMP_NAME} = "Z39.50 HTML scraping bot";
- $this->{IMP_VER} = "0.1";
+ $this->{IMP_NAME} = "Biblio Z39.50";
+ $this->{IMP_VER} = "0.2";
$session->{SETS} = {};
}
-use Data::Dumper;
-
sub SearchHandle {
my $this = shift;
my $rpn = $this->{RPN};
my $query;
- eval { $query = $rpn->{query}->render(); };
+ my $database = $this->{DATABASES}->[0];
+ my $module = $databases->{$database} || 'COBISS';
+ my $from = $module->new;
+
+diag "using $module for $database ", Dumper( $from );
+
+ eval { $query = $rpn->{query}->render( $from->usemap ); };
+ warn "ERROR: $@" if $@;
if ( $@ && ref($@) ) { ## Did someone/something report any errors?
$this->{ERR_CODE} = $@->{errcode};
$this->{ERR_STR} = $@->{errstr};
my $setname = $this->{SETNAME};
my $repl_set = $this->{REPL_SET};
- my $result;
- unless ( $result = COBISS->search( $query ) ) {
+diag "SETNAME $setname REPL_SET $repl_set";
+ my $hits;
+ unless ( $hits = $from->search( $query ) ) {
$this->{ERR_CODE} = 108;
return;
}
- my $hits = $COBISS::hits || diag "no results for $query";
diag "got $hits hits";
my $rs = {
lower => 1,
upper => $hits < $max_records ? $max_records : $hits,
- data => $result->{'resultElements'}, # FIXME
+ hits => $hits,
+ from => $from,
};
my $sets = $session->{SETS};
my $rs;
my $record;
-diag Dumper( $this );
-
if ( !defined( $rs = $sets->{$setname} ) ) {
$this->{ERR_CODE} = 30;
return;
$this->{ERR_CODE} = 13;
return;
}
+
+ my $from = $rs->{from} || die "no from?";
+
$this->{BASENAME} = "HtmlZ3950";
# if ( !defined($req_form) || ( $req_form eq &Net::Z3950::OID::xml ) )
}
elsif ( $req_form eq &Net::Z3950::OID::unimarc ) { # FIXME convert to usmarc
$this->{REP_FORM} = &Net::Z3950::OID::unimarc;
- $this->{RECORD} = COBISS->fetch_rec('unimarc');
+ $this->{RECORD} = $from->next_marc('unimarc');
}
elsif ( $req_form eq &Net::Z3950::OID::usmarc ) { # FIXME convert to usmarc
$this->{REP_FORM} = &Net::Z3950::OID::usmarc;
- $this->{RECORD} = COBISS->fetch_rec('usmarc');
+ $this->{RECORD} = $from->next_marc('usmarc');
}
else { ## Unsupported record format
$this->{ERR_CODE} = 239;
package Net::Z3950::RPN::Term;
+use Data::Dump qw(dump);
use COBISS;
sub render {
- my $this = shift;
+ my ($this,$usemap) = @_;
-print "render ", $this;
+warn "# render ", dump($this);
+warn "# usemap ", dump($usemap);
my $attributes = {};
my $prefix = "";
$attributes->{$type} = $value;
}
if ( defined( my $use = $attributes->{1} ) ) {
- if ( defined( my $field = COBISS::usemap($use) ) ) {
+ if ( defined( my $field = $usemap->{$use} ) ) {
$prefix = $field;
}
else {