--- trunk/all2xml.pl 2003/02/22 23:49:22 20 +++ trunk/all2xml.pl 2003/02/23 15:47:40 35 @@ -40,13 +40,14 @@ Text::Iconv->raise_error(1); # Conversion errors raise exceptions -#my $isis_codepage = Text::Iconv->new($config->{isis_codepage},'UTF8'); -#my $index_codepage = Text::Iconv->new($config->{isis_codepage},$config->{index_codepage}); my $isis_codepage; my $index_codepage; my $cludge_codepage = Text::Iconv->new('UTF8','ISO8859-1'); my $xml_codepage; +my $XML_CHARSET = 'UTF8'; + + sub isis2xml { use xmlify; @@ -62,68 +63,108 @@ my %field_usage; # counter for usage of each field - foreach my $field (keys %{$config->{indexer}}) { + # sort subrouting using order="" attribute + sub by_order { + return 0 if (! $config->{indexer}->{$a}->{order}); + return 0 if (! $config->{indexer}->{$b}->{order}); + + return $config->{indexer}->{$a}->{order} <=> + $config->{indexer}->{$b}->{order} ; + } + + foreach my $field (sort by_order keys %{$config->{indexer}}) { $field_usage{$field}++; my $swish_data = ""; my $display_data = ""; + my $line_delimiter; + + my ($swish,$display); foreach my $x (@{$config->{indexer}->{$field}->{isis}}) { my $format = $x->{content}; - my ($s,$d,$i) = (1,1,0); # swish, display default - $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"; + my $delimiter = $x->{delimiter} || ' '; # FIX: this is ugly, UGLY, cludge string is returned # in UTF8 encoding , but as if source charset # is ISO8859-1 and not some other. This break other # character encodings, so we convert it first # back to ISO8859-1 - $format = $cludge_codepage->convert($format); + $format = $xml_codepage->convert($format); + $delimiter = $xml_codepage->convert($delimiter) if ($delimiter); + + my $isis_i = 0; # isis repeatable offset + + my ($s,$d,$i) = (1,1,0); # swish, display default + $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"; + + # what will separate last line from this one? + if ($display_data && $x->{append} && $x->{append} eq "1") { + $line_delimiter = ' '; + } elsif ($display_data) { + $line_delimiter = '
'; + } - my ($swish,$display) = parse_format($format,$row); + # init vars so that we go into while... + ($swish,$display) = (1,1); + + while ($swish || $display) { + ($swish,$display) = parse_format($format,$row,$isis_i++); #print STDERR "s: $swish\nd: $display\n" if ($swish); #print STDERR "swish: $swish<-- display: $display<--\n"; - # filter="name" ; filter this field through - # filter/[name].pm - my $filter; - if ($x->{filter}) { - $filter = "filter/".$x->{filter}.".pm"; - require $filter; - } - # type="swish" ; field for swish - if ($s && $swish) { + # filter="name" ; filter this field through + # filter/[name].pm + my $filter = $x->{filter}; if ($filter) { - $swish_data .= join(" ",&filter($swish)); - } else { - $swish_data .= $swish if ($s && $swish); + require "filter/".$filter.".pm"; + } + # type="swish" ; field for swish + if ($s && $swish) { + if ($filter) { +#print STDERR "using filter '$filter'\n"; + no strict 'refs'; + $swish_data .= join(" ",&$filter($swish)); + } else { + $swish_data .= $swish; + } } - } - # type="display" ; field for display - if ($d && $display) { - if ($filter) { - $display_data .= join(" ",&filter($display)); - } else { - $display_data .= $display if ($s && $display); + # type="display" ; field for display + if ($d && $display) { + if ($line_delimiter && $display_data) { + $display_data .= $line_delimiter; + undef $line_delimiter; + } + if ($filter) { + no strict 'refs'; + $display_data .= join($delimiter,&$filter($display)); + } else { + if ($display_data) { + $display_data .= $delimiter.$display; + } else { + $display_data .= $display; + } + } } - } - - # type="index" ; insert into index - if ($i && $display) { - my $index_data = $index_codepage->convert($display) || $display; - if ($filter) { - foreach my $d (&filter($index_data)) { - $index->insert($field, $d, $db_dir); + + # type="index" ; insert into index + if ($i && $display) { + my $index_data = $index_codepage->convert($display) || $display; + if ($filter) { + no strict 'refs'; + foreach my $d (&$filter($index_data)) { + $index->insert($field, $d, $db_dir); + } + } else { + $index->insert($field, $index_data, $db_dir); } - } else { - $index->insert($field, $index_data, $db_dir); } } } @@ -131,7 +172,8 @@ #print STDERR "s_d: $swish_data\nd_d: $display_data\n" if ($swish_data); if ($display_data) { - $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' !"; # FIX: this is removed and replaced by html tag. #$xml .= xmlify($field."_display", $display_data); @@ -197,9 +239,9 @@ # read configuration for this type $config=XMLin("./import_xml/$type.xml", forcearray => [ 'isis' ], forcecontent => 1); - $isis_codepage = Text::Iconv->new($config->{isis_codepage},'UTF8'); + $isis_codepage = Text::Iconv->new($config->{isis_codepage},$XML_CHARSET); $index_codepage = Text::Iconv->new($config->{isis_codepage},$config->{index_codepage}); - $xml_codepage = Text::Iconv->new($cfg->val($database,'xml_codepage'),'UTF8'); + $xml_codepage = Text::Iconv->new($cfg->val($database,'xml_codepage'),$XML_CHARSET); my $db = OpenIsis::open( $isis_db ); if (0) { @@ -232,6 +274,7 @@ if (my $xml = isis2xml($row,$add_xml)) { #print STDERR "--ret-->$xml\n"; + use bytes; # as opposed to chars print "Path-Name: $path#".int($row->{mfn})."\n"; print "Content-Length: ".(length($xml)+1)."\n"; print "Document-Type: XML\n\n$xml\n";