From 0d3ea6111fe9f64330e5d75be32fe0612a896333 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 15 Nov 2007 13:32:48 +0000 Subject: [PATCH] =?utf8?q?Report-Generator:=20Spalten=C3=BCberschriften=20?= =?utf8?q?in=20HTML-=20und=20PDF-Ausgaben=20nicht=20erneut=20HTML-Escapen,?= =?utf8?q?=20weil=20die=20=C3=9Cbersetzungen=20meist=20bereits=20HTML-enco?= =?utf8?q?det=20sind.=20Daf=C3=BCr=20aber=20die=20HTML-encodierten=20Zeich?= =?utf8?q?en=20zur=C3=BCckkonvertieren.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Locale.pm | 9 +++-- SL/ReportGenerator.pm | 40 ++++++++++++++++++- .../report_generator/html_report_de.html | 2 +- .../report_generator/html_report_master.html | 2 +- .../report_generator/pdf_report_de.html | 2 +- .../report_generator/pdf_report_master.html | 2 +- 6 files changed, 48 insertions(+), 9 deletions(-) diff --git a/SL/Locale.pm b/SL/Locale.pm index 5454e74c5..f797ed6e6 100644 --- a/SL/Locale.pm +++ b/SL/Locale.pm @@ -70,10 +70,11 @@ sub new { $self->{charset} = Common::DEFAULT_CHARSET; } - my $db_charset = $main::dbcharset; - $db_charset ||= Common::DEFAULT_CHARSET; - $self->{iconv} = Text::Iconv->new($self->{charset}, $db_charset); - $self->{iconv_english} = Text::Iconv->new("ASCII", $db_charset); + my $db_charset = $main::dbcharset || Common::DEFAULT_CHARSET; + + $self->{iconv} = Text::Iconv->new($self->{charset}, $db_charset); + $self->{iconv_english} = Text::Iconv->new('ASCII', $db_charset); + $self->{iconv_iso8859} = Text::Iconv->new('ISO-8859-15', $db_charset); } $self->{NLS_file} = $NLS_file; diff --git a/SL/ReportGenerator.pm b/SL/ReportGenerator.pm index 67d69a9be..7421a78c1 100644 --- a/SL/ReportGenerator.pm +++ b/SL/ReportGenerator.pm @@ -3,6 +3,7 @@ package SL::ReportGenerator; use IO::Wrap; use List::Util qw(max); use Text::CSV_XS; +use Text::Iconv; use SL::Form; @@ -52,9 +53,33 @@ sub new { $self->set_options(@_) if (@_); + $self->_init_escaped_strings_map(); + return $self; } +sub _init_escaped_strings_map { + my $self = shift; + + $self->{escaped_strings_map} = + ('ä' => 'ä', + 'ö' => 'ö', + 'ü' => 'ü', + 'Ä' => 'Ä', + 'Ö' => 'Ö', + 'Ü' => 'Ü', + 'ß' => 'ß', + '>' => '>', + '<' => '<', + '"' => '"'); + + my $iconv = $main::locale->{iconv_iso8859}; + + if ($iconv) { + map { $self->{escaped_strings_map}->{$_} = $iconv->convert($self->{escaped_strings_map}->{$_}) } keys %{ $self->{escaped_strings_map} }; + } +} + sub set_columns { my $self = shift; my %columns = @_; @@ -492,6 +517,19 @@ END } } +sub unescape_string { + my $self = shift; + my $text = shift; + + foreach my $key (keys %{ $self->{escaped_strigns_map} }) { + $text =~ s/\Q$key\E/$self->{escaped_strings_map}->{$key}/g; + } + + $text =~ s/\Q&\E/&/g; + + return $text; +} + sub generate_csv_content { my $self = shift; @@ -517,7 +555,7 @@ sub generate_csv_content { my @visible_columns = $self->get_visible_columns('CSV'); if ($opts->{headers}) { - $csv->print($stdout, [ map { $self->{columns}->{$_}->{text} } @visible_columns ]); + $csv->print($stdout, [ map { $self->unescape_for_csv($self->{columns}->{$_}->{text}) } @visible_columns ]); } foreach my $row_set (@{ $self->{data} }) { diff --git a/templates/webpages/report_generator/html_report_de.html b/templates/webpages/report_generator/html_report_de.html index de330cfc4..6e1601ef8 100644 --- a/templates/webpages/report_generator/html_report_de.html +++ b/templates/webpages/report_generator/html_report_de.html @@ -40,7 +40,7 @@ [% FOREACH col = COLUMN_HEADERS %] - + [% END %] diff --git a/templates/webpages/report_generator/html_report_master.html b/templates/webpages/report_generator/html_report_master.html index d76788bbb..f414eb913 100644 --- a/templates/webpages/report_generator/html_report_master.html +++ b/templates/webpages/report_generator/html_report_master.html @@ -40,7 +40,7 @@
[% IF col.link %][% END %][% HTML.escape(col.text) %][% IF col.link %][% IF col.show_sort_indicator %][% END %][% ELSE %][% IF col.show_sort_indicator %][% END %][% END %][% IF col.link %][% END %][% col.text %][% IF col.link %][% IF col.show_sort_indicator %][% END %][% ELSE %][% IF col.show_sort_indicator %][% END %][% END %]
[% FOREACH col = COLUMN_HEADERS %] - + [% END %] diff --git a/templates/webpages/report_generator/pdf_report_de.html b/templates/webpages/report_generator/pdf_report_de.html index dac6aa3f9..d9843bf91 100644 --- a/templates/webpages/report_generator/pdf_report_de.html +++ b/templates/webpages/report_generator/pdf_report_de.html @@ -11,7 +11,7 @@
[% IF col.link %][% END %][% HTML.escape(col.text) %][% IF col.link %][% IF col.show_sort_indicator %][% END %][% ELSE %][% IF col.show_sort_indicator %][% END %][% END %][% IF col.link %][% END %][% col.text %][% IF col.link %][% IF col.show_sort_indicator %][% END %][% ELSE %][% IF col.show_sort_indicator %][% END %][% END %]
[%- FOREACH col = COLUMN_HEADERS %] - + [%- END %] diff --git a/templates/webpages/report_generator/pdf_report_master.html b/templates/webpages/report_generator/pdf_report_master.html index dac6aa3f9..d9843bf91 100644 --- a/templates/webpages/report_generator/pdf_report_master.html +++ b/templates/webpages/report_generator/pdf_report_master.html @@ -11,7 +11,7 @@
[% IF col.link %][% END %][% HTML.escape(col.text) %][% IF col.link %][% END %][% IF col.link %][% END %][% col.text %][% IF col.link %][% END %]
[%- FOREACH col = COLUMN_HEADERS %] - + [%- END %] -- 2.20.1
[% IF col.link %][% END %][% HTML.escape(col.text) %][% IF col.link %][% END %][% IF col.link %][% END %][% col.text %][% IF col.link %][% END %]