/[webpac]/trunk/all2xml.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/all2xml.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 10 by dpavlin, Thu Jan 16 17:35:54 2003 UTC revision 17 by dpavlin, Sat Feb 22 21:33:04 2003 UTC
# Line 7  use Data::Dumper; Line 7  use Data::Dumper;
7  use XML::Simple;  use XML::Simple;
8  use Text::Unaccent 1.02;        # 1.01 won't compile on my platform,  use Text::Unaccent 1.02;        # 1.01 won't compile on my platform,
9  use Text::Iconv;  use Text::Iconv;
10    use Config::IniFiles;
11    
12  $|=1;  $|=1;
13    
14  my $config;  my $config_file = $0;
15    $config_file =~ s/\.pl$/.conf/;
16    die "FATAL: can't find configuration file '$config_file'" if (! -e $config_file);
17    
18  $config=XMLin(undef, forcearray => [ 'isis' ], forcecontent => 1);  my $config;
19    
20  use index_DBI;  # there is no other, right now ;-)  use index_DBI;  # there is no other, right now ;-)
21    
# Line 29  my %opts; Line 31  my %opts;
31    
32  getopts('d:m:qs', \%opts);  getopts('d:m:qs', \%opts);
33    
34  my $db_dir = $opts{d} || "ps";  # FIX  my $db_dir;
35    
36  #die "usage: $0 -d [database_dir] -m [database1,database2] " if (! %opts);  #die "usage: $0 -d [database_dir] -m [database1,database2] " if (! %opts);
37    
# Line 38  my $db_dir = $opts{d} || "ps"; # FIX Line 40  my $db_dir = $opts{d} || "ps"; # FIX
40    
41  Text::Iconv->raise_error(1);     # Conversion errors raise exceptions  Text::Iconv->raise_error(1);     # Conversion errors raise exceptions
42    
43  my $isis_codepage = Text::Iconv->new($config->{isis_codepage},'UTF8');  #my $isis_codepage = Text::Iconv->new($config->{isis_codepage},'UTF8');
44  my $index_codepage = Text::Iconv->new($config->{isis_codepage},$config->{index_codepage});  #my $index_codepage = Text::Iconv->new($config->{isis_codepage},$config->{index_codepage});
45    my $isis_codepage;
46    my $index_codepage;
47  my $cludge_codepage = Text::Iconv->new('UTF8','ISO8859-1');  my $cludge_codepage = Text::Iconv->new('UTF8','ISO8859-1');
48    my $xml_codepage;
49    
50  sub isis2xml {  sub isis2xml {
51    
52          use xmlify;          use xmlify;
53    
54          my $row = shift @_;          my $row = shift @_;
55            my $add_xml = shift @_;
56    
57          my $xml;          my $xml;
         $xml .= xmlify('db_dir',$db_dir);       # FIX remove?  
58    
59          use parse_format;          use parse_format;
60    
61            my $html = "";          # html formatted display output
62    
63            my %field_usage;        # counter for usage of each field
64    
65          foreach my $field (keys %{$config->{indexer}}) {          foreach my $field (keys %{$config->{indexer}}) {
66    
67                    $field_usage{$field}++;
68    
69                  my $swish_data = "";                  my $swish_data = "";
70                  my $display_data = "";                  my $display_data = "";
                 my $index_data = "";  
71    
72                  foreach my $x (@{$config->{indexer}->{$field}->{isis}}) {                  foreach my $x (@{$config->{indexer}->{$field}->{isis}}) {
73    
# Line 83  sub isis2xml { Line 92  sub isis2xml {
92    
93                          $swish_data .= $swish if ($s && $swish);                          $swish_data .= $swish if ($s && $swish);
94                          $display_data .= $display if ($d && $display);                          $display_data .= $display if ($d && $display);
95                          $index_data .= $display if ($i && $display);  
96                            # insert into index
97                            if ($i && $display) {
98                                    my $index_data = $index_codepage->convert($display) || $display;
99                                    $index->insert($field, $index_data, $db_dir);
100                            }
101                  }                  }
102    
103    
104  #print STDERR "s_d: $swish_data\nd_d: $display_data\n" if ($swish_data);  #print STDERR "s_d: $swish_data\nd_d: $display_data\n" if ($swish_data);
105                  if ($display_data) {                  if ($display_data) {
106                          $display_data = $isis_codepage->convert($display_data)."##" || $display_data;                          $display_data = $isis_codepage->convert($display_data) || die "Can't convert '$display_data' !";
107                          $xml .= xmlify($field."_display", $display_data);                          # FIX: this is removed and replaced by html tag.
108                            #$xml .= xmlify($field."_display", $display_data);
109    
110                            if ($field eq "headline") {
111                                    $xml .= xmlify("headline", $display_data);
112                            } else {
113    
114                                    # find field name (signular, plural)
115                                    my $field_name = "";
116                                    if ($config->{indexer}->{$field}->{name_singular} && $field_usage{$field} == 1) {
117                                            $field_name = $config->{indexer}->{$field}->{name_singular}."#-#";
118                                    } elsif ($config->{indexer}->{$field}->{name_plural}) {
119                                            $field_name = $config->{indexer}->{$field}->{name_plural}."#-#";
120                                    } else {
121                                            $field_name = $config->{indexer}->{$field}->{name}."#-#";
122                                    }
123                                    if ($field_name) {
124                                            $html .= $xml_codepage->convert($field_name);
125                                    }
126                                    $html .= $display_data."###\n";
127                            }
128                  }                  }
129                  if ($swish_data) {                  if ($swish_data) {
130                          my $i = Text::Iconv->new($config->{isis_codepage},'ISO8859-2');                          my $i = Text::Iconv->new($config->{isis_codepage},'ISO8859-2');
# Line 99  sub isis2xml { Line 134  sub isis2xml {
134                          #$xml .= xmlify($field."_swish",unac_string($config->{isis_codepage},$swish_data));                          #$xml .= xmlify($field."_swish",unac_string($config->{isis_codepage},$swish_data));
135                  }                  }
136    
                 # index  
                 if ($index_data && $index_data ne "") {  
                         $index_data = $index_codepage->convert($index_data) || $index_data;  
                         $index->insert($field, $index_data, $db_dir);  
                 }  
137    
138          }          }
139    
140            # dump formatted output in <html>
141            if ($html) {
142                    $xml .= xmlify("html",$html);
143            }
144            
145          if ($xml) {          if ($xml) {
146  #print STDERR "x: $xml\n";  #print STDERR "x: $xml\n";
147                    $xml .= $add_xml if ($add_xml);
148                  return "<xml>\n$xml</xml>\n";                  return "<xml>\n$xml</xml>\n";
149          } else {          } else {
150                  return;                  return;
# Line 116  sub isis2xml { Line 153  sub isis2xml {
153    
154  ##########################################################################  ##########################################################################
155    
156  my $last_tell=0;  my $cfg = new Config::IniFiles( -file => $config_file );
   
 my @isis_dirs = ( '.' );        # use dirname as database name  
   
 if ($opts{m}) {  
         @isis_dirs = split(/,/,$opts{m});  
 }  
   
 my @isis_dbs;  
   
 foreach (@isis_dirs) {  
         if (-e $config->{isis_data}."/$db_dir/$_/LIBRI") {  
                 push @isis_dbs,$config->{isis_data}."/$db_dir/$_/LIBRI/LIBRI";  
         }  
         if (-e $config->{isis_data}."/$db_dir/$_/PERI") {  
                 push @isis_dbs,$config->{isis_data}."/$db_dir/$_/PERI/PERI";  
         }  
         if (-e $config->{isis_data}."/$db_dir/$_/AMS") {  
                 push @isis_dbs,$config->{isis_data}."/$db_dir/$_/AMS/AMS";  
         }  
         if (-e $config->{isis_data}."/$db_dir/$_/ARTI") {  
 #               push @isis_dbs,$config->{isis_data}."/$db_dir/$_/ARTI/ARTI";  
         }  
 }  
   
 print STDERR "FATAL: Can't find isis database.\nPerhaps isis_data (".$config->{isis_data}.") has wrong value?\n" if (! @isis_dbs);  
   
 my $db;  
157    
158  foreach my $isis_db (@isis_dbs) {  foreach my $database ($cfg->Sections) {
159    
160            my $isis_db = $cfg -> val($database, 'isis_db');
161            my $type = $cfg -> val($database, 'type');
162            my $add_xml = $cfg -> val($database, 'xml');
163    
164            # read configuration for this type
165            $config=XMLin("./import_xml/$type.xml", forcearray => [ 'isis' ], forcecontent => 1);
166            $isis_codepage = Text::Iconv->new($config->{isis_codepage},'UTF8');
167            $index_codepage = Text::Iconv->new($config->{isis_codepage},$config->{index_codepage});
168            $xml_codepage = Text::Iconv->new($cfg->val($database,'xml_codepage'),'UTF8');
169    
170          my $db = OpenIsis::open( $isis_db );          my $db = OpenIsis::open( $isis_db );
171          if (0) {          if (0) {
# Line 160  foreach my $isis_db (@isis_dbs) { Line 179  foreach my $isis_db (@isis_dbs) {
179    
180          print STDERR "Reading database: $isis_db [$max_rowid rows]\n";          print STDERR "Reading database: $isis_db [$max_rowid rows]\n";
181    
182          my $path = $isis_db;          my $path = $database;                   # was $isis_db
         $path =~ s#$config->{isis_data}/*##g;  
183    
184          my $last_p = 0;          my $last_p = 0;
185    
# Line 178  foreach my $isis_db (@isis_dbs) { Line 196  foreach my $isis_db (@isis_dbs) {
196                                  $last_p = $p;                                  $last_p = $p;
197                          }                          }
198    
199                          if (my $xml = isis2xml($row)) {                          if (my $xml = isis2xml($row,$add_xml)) {
200  #print STDERR "--ret-->$xml\n";  #print STDERR "--ret-->$xml\n";
201                                  print "Path-Name: $path#".int($row->{mfn})."\n";                                  print "Path-Name: $path#".int($row->{mfn})."\n";
202                                  print "Content-Length: ".(length($xml)+1)."\n";                                  print "Content-Length: ".(length($xml)+1)."\n";

Legend:
Removed from v.10  
changed lines
  Added in v.17

  ViewVC Help
Powered by ViewVC 1.1.26