/[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 13 by dpavlin, Sun Feb 16 22:41:37 2003 UTC revision 32 by dpavlin, Sun Feb 23 07:53:01 2003 UTC
# Line 40  my $db_dir; Line 40  my $db_dir;
40    
41  Text::Iconv->raise_error(1);     # Conversion errors raise exceptions  Text::Iconv->raise_error(1);     # Conversion errors raise exceptions
42    
 #my $isis_codepage = Text::Iconv->new($config->{isis_codepage},'UTF8');  
 #my $index_codepage = Text::Iconv->new($config->{isis_codepage},$config->{index_codepage});  
43  my $isis_codepage;  my $isis_codepage;
44  my $index_codepage;  my $index_codepage;
45  my $cludge_codepage = Text::Iconv->new('UTF8','ISO8859-1');  my $cludge_codepage = Text::Iconv->new('UTF8','ISO8859-1');
46  my $xml_codepage;  my $xml_codepage;
47    
48    my $XML_CHARSET = 'UTF8';
49    
50    
51  sub isis2xml {  sub isis2xml {
52    
53          use xmlify;          use xmlify;
# Line 62  sub isis2xml { Line 63  sub isis2xml {
63    
64          my %field_usage;        # counter for usage of each field          my %field_usage;        # counter for usage of each field
65    
66          foreach my $field (keys %{$config->{indexer}}) {          # sort subrouting using order="" attribute
67            sub by_order {
68                    return 0 if (! $config->{indexer}->{$a}->{order});
69                    return 0 if (! $config->{indexer}->{$b}->{order});
70    
71                    return $config->{indexer}->{$a}->{order} <=>
72                            $config->{indexer}->{$b}->{order} ;
73            }
74    
75            foreach my $field (sort by_order keys %{$config->{indexer}}) {
76    
77                  $field_usage{$field}++;                  $field_usage{$field}++;
78    
79                  my $swish_data = "";                  my $swish_data = "";
80                  my $display_data = "";                  my $display_data = "";
81                  my $index_data = "";                  my $line_delimiter = "";
82    
83                  foreach my $x (@{$config->{indexer}->{$field}->{isis}}) {                  foreach my $x (@{$config->{indexer}->{$field}->{isis}}) {
84    
85                          my $format = $x->{content};                          my $format = $x->{content};
86                            my $delimiter = $x->{delimiter} || ' ';
87    
88                            # FIX: this is ugly, UGLY, cludge string is returned
89                            # in UTF8 encoding , but as if source charset
90                            # is ISO8859-1 and not some other. This break other
91                            # character encodings, so we convert it first
92                            # back to ISO8859-1
93                            $format = $xml_codepage->convert($format);
94                            $delimiter = $xml_codepage->convert($delimiter) if ($delimiter);
95    
96                            my $isis_i = 0;         # isis repeatable offset
97    
98                          my ($s,$d,$i) = (1,1,0);        # swish, display default                          my ($s,$d,$i) = (1,1,0);        # swish, display default
99                          $s = 0 if (lc($x->{type}) eq "display");                          $s = 0 if (lc($x->{type}) eq "display");
100                          $d = 0 if (lc($x->{type}) eq "swish");                          $d = 0 if (lc($x->{type}) eq "swish");
101                          ($s,$d,$i) = (0,0,1) if (lc($x->{type}) eq "index");                          ($s,$d,$i) = (0,0,1) if (lc($x->{type}) eq "index");
102  #print STDERR "## s: $s d: $d i: $i ## $format ##\n";    #print STDERR "## s: $s d: $d i: $i ## $format ##\n";  
103    
104                          $format = $cludge_codepage->convert($format);                          $display_data .= $line_delimiter if ($display_data && $display_data !~ /$line_delimiter$/);
105                          my ($swish,$display) = parse_format($format,$row);  
106                            my ($swish,$display) = (1,1);
107    
108                            while ($swish || $display) {
109                                    ($swish,$display) = parse_format($format,$row,$isis_i++);
110  #print STDERR "s: $swish\nd: $display\n" if ($swish);  #print STDERR "s: $swish\nd: $display\n" if ($swish);
111    
112  #print STDERR "swish: $swish<-- display: $display<--\n";  #print STDERR "swish: $swish<-- display: $display<--\n";
113                          # FIX: this is ugly, UGLY, cludge: OpenIsis return  
114                          # UTF8 encoding of strings, but as if source charset                                  # filter="name" ; filter this field through
115                          # is ISO8859-1 and not some other. This breaks our                                  # filter/[name].pm
116                          # isis character encoding, so we convert it first                                  my $filter = $x->{filter};
117                          # back to ISO8859-1 (which can actually be different                                  if ($filter) {
118                          # encoding in isis)                                          require "filter/".$filter.".pm";
119                                    }
120                          $swish_data .= $swish if ($s && $swish);                                  # type="swish" ; field for swish
121                          $display_data .= $display if ($d && $display);                                  if ($s && $swish) {
122                          $index_data .= $display if ($i && $display);                                          if ($filter) {
123    #print STDERR "using filter '$filter'\n";
124                                                    no strict 'refs';
125                                                    $swish_data .= join(" ",&$filter($swish));
126                                            } else {
127                                                    $swish_data .= $swish;
128                                            }
129                                    }
130    
131                                    # type="display" ; field for display
132                                    if ($d && $display) {
133                                            if ($filter) {
134                                                    no strict 'refs';
135                                                    $display_data .= join($delimiter,&$filter($display));
136                                            } else {
137                                                    if ($display_data) {
138                                                            $display_data .= $delimiter.$display;
139                                                    } else {
140                                                            $display_data .= $display;
141                                                    }
142                                            }
143                                    }
144                                                    
145                                    # type="index" ; insert into index
146                                    if ($i && $display) {
147                                            my $index_data = $index_codepage->convert($display) || $display;
148                                            if ($filter) {
149                                                    no strict 'refs';
150                                                    foreach my $d (&$filter($index_data)) {
151                                                            $index->insert($field, $d, $db_dir);
152                                                    }
153                                            } else {
154                                                    $index->insert($field, $index_data, $db_dir);
155                                            }
156                                    }
157                            }
158                            if ($x->{append}) {
159                                    $line_delimiter = ' ';
160                            } else {
161                                    $line_delimiter = '<br/>';
162                            }
163                  }                  }
164    
165    
166  #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);
167                  if ($display_data) {                  if ($display_data) {
168    
169                            # remove last <br>
170                            $display_data =~ s/$line_delimiter$//;
171    
172                          $display_data = $isis_codepage->convert($display_data) || die "Can't convert '$display_data' !";                          $display_data = $isis_codepage->convert($display_data) || die "Can't convert '$display_data' !";
173                          # FIX: this is removed and replaced by html tag.                          # FIX: this is removed and replaced by html tag.
174                          #$xml .= xmlify($field."_display", $display_data);                          #$xml .= xmlify($field."_display", $display_data);
# Line 113  sub isis2xml { Line 183  sub isis2xml {
183                                          $field_name = $config->{indexer}->{$field}->{name_singular}."#-#";                                          $field_name = $config->{indexer}->{$field}->{name_singular}."#-#";
184                                  } elsif ($config->{indexer}->{$field}->{name_plural}) {                                  } elsif ($config->{indexer}->{$field}->{name_plural}) {
185                                          $field_name = $config->{indexer}->{$field}->{name_plural}."#-#";                                          $field_name = $config->{indexer}->{$field}->{name_plural}."#-#";
186                                  } else {                                  } elsif ($config->{indexer}->{$field}->{name}) {
187                                          $field_name = $config->{indexer}->{$field}->{name}."#-#";                                          $field_name = $config->{indexer}->{$field}->{name}."#-#";
188                                    } else {
189                                            print STDERR "WARNING: field '$field' doesn't have 'name' attribute!";
190                                  }                                  }
191                                  if ($field_name) {                                  if ($field_name) {
192                                          $html .= $xml_codepage->convert($field_name);                                          $html .= $xml_codepage->convert($field_name);
193    #                                       $html .= "-->".$field_name."<--";
194                                  }                                  }
195                                  $html .= $display_data."###\n";                                  $html .= $display_data."###\n";
196                          }                          }
197                  }                  }
198                  if ($swish_data) {                  if ($swish_data) {
199                          my $i = Text::Iconv->new($config->{isis_codepage},'ISO8859-2');                          my $i = Text::Iconv->new($config->{isis_codepage},'ISO8859-2');
200                            # remove extra spaces
201                            $swish_data =~ s/ +/ /g;
202                            $swish_data =~ s/ +$//g;
203    
204                          $swish_data = $i->convert($swish_data);                          $swish_data = $i->convert($swish_data);
205                          $xml .= xmlify($field."_swish",unac_string('ISO8859-2',$swish_data));                          $xml .= xmlify($field."_swish",unac_string('ISO8859-2',$swish_data));
206                          #$swish_data = $isis_codepage->convert($swish_data)."##" || $swish_data;                          #$swish_data = $isis_codepage->convert($swish_data)."##" || $swish_data;
207                          #$xml .= xmlify($field."_swish",unac_string($config->{isis_codepage},$swish_data));                          #$xml .= xmlify($field."_swish",unac_string($config->{isis_codepage},$swish_data));
208                  }                  }
209    
                 # index  
                 if ($index_data && $index_data ne "") {  
                         $index_data = $index_codepage->convert($index_data) || $index_data;  
                         $index->insert($field, $index_data, $db_dir);  
                 }  
210    
211          }          }
212    
# Line 164  foreach my $database ($cfg->Sections) { Line 236  foreach my $database ($cfg->Sections) {
236    
237          # read configuration for this type          # read configuration for this type
238          $config=XMLin("./import_xml/$type.xml", forcearray => [ 'isis' ], forcecontent => 1);          $config=XMLin("./import_xml/$type.xml", forcearray => [ 'isis' ], forcecontent => 1);
239          $isis_codepage = Text::Iconv->new($config->{isis_codepage},'UTF8');          $isis_codepage = Text::Iconv->new($config->{isis_codepage},$XML_CHARSET);
240          $index_codepage = Text::Iconv->new($config->{isis_codepage},$config->{index_codepage});          $index_codepage = Text::Iconv->new($config->{isis_codepage},$config->{index_codepage});
241          $xml_codepage = Text::Iconv->new($cfg->val($database,'xml_codepage'),'UTF8');          $xml_codepage = Text::Iconv->new($cfg->val($database,'xml_codepage'),$XML_CHARSET);
242    
243          my $db = OpenIsis::open( $isis_db );          my $db = OpenIsis::open( $isis_db );
244          if (0) {          if (0) {

Legend:
Removed from v.13  
changed lines
  Added in v.32

  ViewVC Help
Powered by ViewVC 1.1.26