--- trunk2/lib/WebPAC.pm 2004/06/16 16:50:30 362 +++ trunk2/lib/WebPAC.pm 2004/06/16 20:05:19 363 @@ -3,6 +3,7 @@ use Carp; use Text::Iconv; use Config::IniFiles; +use XML::Simple; use Data::Dumper; @@ -34,6 +35,15 @@ =cut +# mapping between data type and tag which specify +# format in XML file +my %type2tag = ( + 'isis' => 'isis', +# 'excel' => 'column', +# 'marc' => 'marc', +# 'feed' => 'feed' +); + sub new { my $class = shift; my $self = {@_}; @@ -67,18 +77,6 @@ $self->{indexer_config_file} = new Config::IniFiles( -file => $self->{config_file} ) || croak "can't open '$self->{config_file}'"; - # read global config parametars - foreach my $var (qw( - dbi_dbd - dbi_dsn - dbi_user - dbi_passwd - show_progress - my_unac_filter - )) { - $self->{global_config}->{$var} = $self->{global_config_file}->val('global', $var); - } - return $self; } @@ -127,12 +125,16 @@ # create Text::Iconv object my $cp = Text::Iconv->new($code_page,$self->{'code_page'}); + print STDERR "reading ISIS database '",$arg->{'filename'},"'\n" if ($self->{'debug'}); + my $isis_db = OpenIsis::open($arg->{'filename'}); my $maxmfn = OpenIsis::maxRowid( $isis_db ) || 1; $maxmfn = $self->{limit_mfn} if ($self->{limit_mfn}); + print STDERR "processing $maxmfn records...\n" if ($self->{'debug'}); + # read database for (my $mfn = 1; $mfn <= $maxmfn; $mfn++) { @@ -193,6 +195,39 @@ return $self->{'data'}->{$mfn}; } +=head2 open_import_xml + +Read file from C directory and parse it. + + $webpac->open_import_xml(type => 'isis'); + +=cut + +sub open_import_xml { + my $self = shift; + + my $arg = {@_}; + confess "need type to load file from import_xml/" if (! $arg->{'type'}); + + my $type = $arg->{'type'}; + + my $type_base = $type; + $type_base =~ s/_.*$//g; + + my $f = "./import_xml/$type.xml"; + confess "import_xml file '$f' doesn't exist!" if (! -e "$f"); + + print STDERR "reading '$f'\n" if ($self->{'debug'}); + + $self->{'import_xml'} = XMLin($f, + ForceArray => [ $type2tag{$type_base}, 'config', 'format' ], + ForceContent => 1 + ); + + print Dumper($self->{'import_xml'}); + +} + =head2 create_lookup Create lookup from record using lookup definition.