use IO::Wrap;
use List::Util qw(max);
use Text::CSV_XS;
+use Text::Iconv;
use SL::Form;
$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 = @_;
'data' => $self->html_format($col->{data}->[$i]),
'link' => $col->{link}->[$i],
};
- };
+ }
+
+ # Force at least a to be displayed so that browsers
+ # will format the table cell (e.g. borders etc).
+ if (!scalar @{ $col->{CELL_ROWS} }) {
+ push @{ $col->{CELL_ROWS} }, { 'data' => ' ' };
+ } elsif ((1 == scalar @{ $col->{CELL_ROWS} }) && !$col->{CELL_ROWS}->[0]->{data}) {
+ $col->{CELL_ROWS}->[0]->{data} = ' ';
+ }
}
my $row_data = {
}
}
+sub unescape_string {
+ my $self = shift;
+ my $text = shift;
+
+ foreach my $key (keys %{ $self->{escaped_strings_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;
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_string($self->{columns}->{$_}->{text}) } @visible_columns ]);
}
foreach my $row_set (@{ $self->{data} }) {