/[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 21 by dpavlin, Sun Feb 23 00:00:51 2003 UTC revision 35 by dpavlin, Sun Feb 23 15:47:40 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 $line_delimiter;
82    
83                    my ($swish,$display);
84    
85                  foreach my $x (@{$config->{indexer}->{$field}->{isis}}) {                  foreach my $x (@{$config->{indexer}->{$field}->{isis}}) {
86    
87                          my $format = $x->{content};                          my $format = $x->{content};
88                          my ($s,$d,$i) = (1,1,0);        # swish, display default                          my $delimiter = $x->{delimiter} || ' ';
                         $s = 0 if (lc($x->{type}) eq "display");  
                         $d = 0 if (lc($x->{type}) eq "swish");  
                         ($s,$d,$i) = (0,0,1) if (lc($x->{type}) eq "index");  
 #print STDERR "## s: $s d: $d i: $i ## $format ##\n";    
89    
90                          # FIX: this is ugly, UGLY, cludge string is returned                          # FIX: this is ugly, UGLY, cludge string is returned
91                          # in UTF8 encoding , but as if source charset                          # in UTF8 encoding , but as if source charset
92                          # is ISO8859-1 and not some other. This break other                          # is ISO8859-1 and not some other. This break other
93                          # character encodings, so we convert it first                          # character encodings, so we convert it first
94                          # back to ISO8859-1                          # back to ISO8859-1
95                          $format = $cludge_codepage->convert($format);                          $format = $xml_codepage->convert($format);
96                            $delimiter = $xml_codepage->convert($delimiter) if ($delimiter);
97    
98                            my $isis_i = 0;         # isis repeatable offset
99    
100                            my ($s,$d,$i) = (1,1,0);        # swish, display default
101                            $s = 0 if (lc($x->{type}) eq "display");
102                            $d = 0 if (lc($x->{type}) eq "swish");
103                            ($s,$d,$i) = (0,0,1) if (lc($x->{type}) eq "index");
104    #print STDERR "## s: $s d: $d i: $i ## $format ##\n";  
105    
106                            # what will separate last line from this one?
107                            if ($display_data && $x->{append} && $x->{append} eq "1") {
108                                    $line_delimiter = ' ';
109                            } elsif ($display_data) {
110                                    $line_delimiter = '<br/>';
111                            }
112    
113                          my ($swish,$display) = parse_format($format,$row);                          # init vars so that we go into while...
114                            ($swish,$display) = (1,1);
115    
116                            while ($swish || $display) {
117                                    ($swish,$display) = parse_format($format,$row,$isis_i++);
118  #print STDERR "s: $swish\nd: $display\n" if ($swish);  #print STDERR "s: $swish\nd: $display\n" if ($swish);
119    
120  #print STDERR "swish: $swish<-- display: $display<--\n";  #print STDERR "swish: $swish<-- display: $display<--\n";
121    
122                          # filter="name" ; filter this field through                                  # filter="name" ; filter this field through
123                          # filter/[name].pm                                  # filter/[name].pm
124                          my $filter;                                  my $filter = $x->{filter};
                         if ($x->{filter}) {  
                                 $filter = "filter/".$x->{filter}.".pm";  
                                 require $filter;  
                         }  
                         # type="swish" ; field for swish  
                         if ($s && $swish) {  
125                                  if ($filter) {                                  if ($filter) {
126                                          $swish_data .= join(" ",&filter($swish));                                          require "filter/".$filter.".pm";
127                                  } else {                                  }
128                                          $swish_data .= $swish if ($s && $swish);                                  # type="swish" ; field for swish
129                                    if ($s && $swish) {
130                                            if ($filter) {
131    #print STDERR "using filter '$filter'\n";
132                                                    no strict 'refs';
133                                                    $swish_data .= join(" ",&$filter($swish));
134                                            } else {
135                                                    $swish_data .= $swish;
136                                            }
137                                  }                                  }
                         }  
138    
139                          # type="display" ; field for display                                  # type="display" ; field for display
140                          if ($d && $display) {                                  if ($d && $display) {
141                                  if ($filter) {                                          if ($line_delimiter && $display_data) {
142                                          $display_data .= join(" ",&filter($display));                                                  $display_data .= $line_delimiter;
143                                  } else {                                                  undef $line_delimiter;
144                                          $display_data .= $display;                                          }
145                                            if ($filter) {
146                                                    no strict 'refs';
147                                                    $display_data .= join($delimiter,&$filter($display));
148                                            } else {
149                                                    if ($display_data) {
150                                                            $display_data .= $delimiter.$display;
151                                                    } else {
152                                                            $display_data .= $display;
153                                                    }
154                                            }
155                                  }                                  }
156                          }                                                  
157                                                                            # type="index" ; insert into index
158                          # type="index" ; insert into index                                  if ($i && $display) {
159                          if ($i && $display) {                                          my $index_data = $index_codepage->convert($display) || $display;
160                                  my $index_data = $index_codepage->convert($display) || $display;                                          if ($filter) {
161                                  if ($filter) {                                                  no strict 'refs';
162                                          foreach my $d (&filter($index_data)) {                                                  foreach my $d (&$filter($index_data)) {
163                                                  $index->insert($field, $d, $db_dir);                                                          $index->insert($field, $d, $db_dir);
164                                                    }
165                                            } else {
166                                                    $index->insert($field, $index_data, $db_dir);
167                                          }                                          }
                                 } else {  
                                         $index->insert($field, $index_data, $db_dir);  
168                                  }                                  }
169                          }                          }
170                  }                  }
# Line 131  sub isis2xml { Line 172  sub isis2xml {
172    
173  #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);
174                  if ($display_data) {                  if ($display_data) {
175                          $display_data = $isis_codepage->convert($display_data) || die "Can't convert '$display_data' !";  
176    #                       $display_data = $isis_codepage->convert($display_data) || die "Can't convert '$display_data' !";
177                          # FIX: this is removed and replaced by html tag.                          # FIX: this is removed and replaced by html tag.
178                          #$xml .= xmlify($field."_display", $display_data);                          #$xml .= xmlify($field."_display", $display_data);
179    
# Line 197  foreach my $database ($cfg->Sections) { Line 239  foreach my $database ($cfg->Sections) {
239    
240          # read configuration for this type          # read configuration for this type
241          $config=XMLin("./import_xml/$type.xml", forcearray => [ 'isis' ], forcecontent => 1);          $config=XMLin("./import_xml/$type.xml", forcearray => [ 'isis' ], forcecontent => 1);
242          $isis_codepage = Text::Iconv->new($config->{isis_codepage},'UTF8');          $isis_codepage = Text::Iconv->new($config->{isis_codepage},$XML_CHARSET);
243          $index_codepage = Text::Iconv->new($config->{isis_codepage},$config->{index_codepage});          $index_codepage = Text::Iconv->new($config->{isis_codepage},$config->{index_codepage});
244          $xml_codepage = Text::Iconv->new($cfg->val($database,'xml_codepage'),'UTF8');          $xml_codepage = Text::Iconv->new($cfg->val($database,'xml_codepage'),$XML_CHARSET);
245    
246          my $db = OpenIsis::open( $isis_db );          my $db = OpenIsis::open( $isis_db );
247          if (0) {          if (0) {
# Line 232  foreach my $database ($cfg->Sections) { Line 274  foreach my $database ($cfg->Sections) {
274    
275                          if (my $xml = isis2xml($row,$add_xml)) {                          if (my $xml = isis2xml($row,$add_xml)) {
276  #print STDERR "--ret-->$xml\n";  #print STDERR "--ret-->$xml\n";
277                                    use bytes;      # as opposed to chars
278                                  print "Path-Name: $path#".int($row->{mfn})."\n";                                  print "Path-Name: $path#".int($row->{mfn})."\n";
279                                  print "Content-Length: ".(length($xml)+1)."\n";                                  print "Content-Length: ".(length($xml)+1)."\n";
280                                  print "Document-Type: XML\n\n$xml\n";                                  print "Document-Type: XML\n\n$xml\n";

Legend:
Removed from v.21  
changed lines
  Added in v.35

  ViewVC Help
Powered by ViewVC 1.1.26