11 |
#use GDBM_File; |
#use GDBM_File; |
12 |
use Fcntl; # for O_RDWR |
use Fcntl; # for O_RDWR |
13 |
use TDB_File; |
use TDB_File; |
14 |
|
use Carp; |
15 |
|
|
16 |
$|=1; |
$|=1; |
17 |
|
|
63 |
'isis' => 'isis', |
'isis' => 'isis', |
64 |
'excel' => 'column', |
'excel' => 'column', |
65 |
'marc' => 'marc', |
'marc' => 'marc', |
66 |
'feed' => 'feed' |
'feed' => 'feed', |
67 |
); |
); |
68 |
|
|
69 |
my $cache; # for cacheing |
my $cache; # for cacheing |
113 |
$cache->{tags_by_order} = \@sorted_tags; |
$cache->{tags_by_order} = \@sorted_tags; |
114 |
} |
} |
115 |
|
|
116 |
|
if (! @sorted_tags) { |
117 |
|
print STDERR "WARNING: no tags for this type found in import_xml file!\n"; |
118 |
|
} |
119 |
|
|
120 |
# lookup key |
# lookup key |
121 |
my $lookup_key; |
my $lookup_key; |
122 |
|
|
225 |
|
|
226 |
my ($swish,$display); |
my ($swish,$display); |
227 |
|
|
228 |
my $tag = $type2tag{$type} || die "can't find which tag to use for type $type"; |
my $tag = $cfg->val($database, 'import_xml_tag') || $type2tag{$type} || die "can't find which tag to use for type $type"; |
229 |
|
|
230 |
# is this field page-by-page? |
# is this field page-by-page? |
231 |
my $iterate_by_page = $config->{indexer}->{$field}->{iterate_by_page}; |
my $iterate_by_page = $config->{indexer}->{$field}->{iterate_by_page}; |
667 |
print STDERR "opening lookup file '$lookup_file'\n"; |
print STDERR "opening lookup file '$lookup_file'\n"; |
668 |
} |
} |
669 |
|
|
670 |
print STDERR "reading ./import_xml/$type.xml\n"; |
my $import_xml_type = $cfg->val($database, 'import_xml_file') || $type; |
671 |
|
my $import_xml_file = "./import_xml/$import_xml_type.xml"; |
672 |
|
|
673 |
|
if (! -r $import_xml_file) { |
674 |
|
print STDERR "ERROR: file $import_xml_file not readable skipping!\n"; |
675 |
|
next; |
676 |
|
} |
677 |
|
|
678 |
|
print STDERR "reading $import_xml_file\n"; |
679 |
|
|
680 |
# extract just type basic |
# extract just type basic |
681 |
my $type_base = $type; |
my $type_base = $type; |
682 |
$type_base =~ s/_.+$//g; |
$type_base =~ s/_.+$//g; |
683 |
|
|
684 |
$config=XMLin("./import_xml/$type.xml", ForceArray => [ $type2tag{$type_base}, 'config', 'format' ], ForceContent => 1 ); |
my $tag = $cfg->val($database, 'import_xml_tag') || $type2tag{$type_base} || die "can't find which tag to use for type $type"; |
685 |
|
$config=XMLin($import_xml_file, ForceArray => [ $tag, 'config', 'format' ], ForceContent => 1 ); |
686 |
|
|
687 |
# helper for progress bar |
# helper for progress bar |
688 |
sub fmt_time { |
sub fmt_time { |
744 |
} |
} |
745 |
|
|
746 |
# now read database |
# now read database |
|
print STDERR "using: $type...\n"; |
|
747 |
|
|
748 |
# erase cache for tags by order in this database |
# erase cache for tags by order in this database |
749 |
delete $cache->{tags_by_order}; |
delete $cache->{tags_by_order}; |
940 |
} |
} |
941 |
# close lookup |
# close lookup |
942 |
untie %lhash if (%lhash); |
untie %lhash if (%lhash); |
943 |
|
|
944 |
|
} elsif ($type_base eq "dbf") { |
945 |
|
|
946 |
|
my $dbf_file = $cfg -> val($database, 'dbf_file') || die "$database doesn't have 'dbf_file' defined!"; |
947 |
|
my $dbf_codepage = $cfg -> val($database, 'dbf_codepage') || die "$database doesn't have 'dbf_codepage' defined!"; |
948 |
|
my $dbf_mapping = $cfg -> val($database, 'dbf_mapping') || die "$database doesn't have 'dbf_mapping' defined!"; |
949 |
|
|
950 |
|
$import2cp = Text::Iconv->new($dbf_codepage,$codepage); |
951 |
|
require XBase; |
952 |
|
my $db = new XBase $dbf_file; |
953 |
|
|
954 |
|
if (! $db) { |
955 |
|
print STDERR "ERROR: can't read DBF database: $dbf_file, skipping...\n"; |
956 |
|
next; |
957 |
|
} |
958 |
|
|
959 |
|
my $max_rowid = $db->last_record; |
960 |
|
|
961 |
|
print STDERR "Reading database: $dbf_file [$max_rowid rows]\n"; |
962 |
|
|
963 |
|
my %dbf2iso; |
964 |
|
foreach my $m (split(/[\n\r]+/,$dbf_mapping)) { |
965 |
|
my ($col,$fld) = split(/\s+/,$m,2); |
966 |
|
$dbf2iso{$col} = $fld; |
967 |
|
} |
968 |
|
|
969 |
|
#print STDERR "## dbf2iso: ",Dumper(\%dbf2iso),"\n## /dbf2iso\n"; |
970 |
|
|
971 |
|
# bad, bad... |
972 |
|
require "to_hash.pm"; |
973 |
|
|
974 |
|
foreach my $row_id (0 .. $max_rowid) { |
975 |
|
my $dbf_row = $db->get_record_as_hash($row_id); |
976 |
|
if ($dbf_row) { |
977 |
|
|
978 |
|
#print STDERR "## dbf_row: ",Dumper($dbf_row),"\n## /dbf_row\n"; |
979 |
|
# apply mapping from config file |
980 |
|
# all unspecified records will get _ in |
981 |
|
# front of them - _DELETE will be __DELETE |
982 |
|
my $rec; |
983 |
|
map { |
984 |
|
my $new_fld = $dbf2iso{$_} || '_'.$_; |
985 |
|
my $data = $dbf_row->{$_}; |
986 |
|
push @{ $rec->{$new_fld} }, $data if ($data && $data !~ /^(?:\s+|\$a\.|)$/); |
987 |
|
} keys %{$dbf_row}; |
988 |
|
#print STDERR "## rec: ",Dumper($rec),"\n## /rec\n"; |
989 |
|
my $row = to_hash($row_id+1, $rec); |
990 |
|
|
991 |
|
$row->{mfn} = $row_id+1; |
992 |
|
$row->{record} = $rec; |
993 |
|
|
994 |
|
#print STDERR "## row: ",Dumper($row),"\n## /row\n"; |
995 |
|
progress($row->{mfn}, $max_rowid); |
996 |
|
|
997 |
|
my $swishpath = $path."#".int($row->{mfn}); |
998 |
|
|
999 |
|
if (my $xml = data2xml($type_base,$row,$add_xml,$cfg,$database)) { |
1000 |
|
$xml = $cp2utf->convert($xml); |
1001 |
|
use bytes; # as opposed to chars |
1002 |
|
print "Path-Name: $swishpath\n"; |
1003 |
|
print "Content-Length: ".(length($xml)+1)."\n"; |
1004 |
|
print "Document-Type: XML\n\n$xml\n"; |
1005 |
|
} |
1006 |
|
} |
1007 |
|
} |
1008 |
|
print STDERR "\n"; |
1009 |
} |
} |
1010 |
} |
} |
1011 |
|
|