Ignore:
Timestamp:
2012-04-27T17:12:40+12:00 (12 years ago)
Author:
ak19
Message:

Dr Bainbridge modified gsprintf code to print text containing ampersand, less than and greater then with their entity values instead so that printing to STDERR from BEGIN statements (so far used only in PDFBoxConverter of the PDFBox extension) will play nicely with the XML generated for Pluginfo.pl. Pluginfo.pl has also been modified to use the correct gsprintf printing methods.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/gsprintf.pm

    r21289 r25499  
    5050# Ignore the OutputEncoding strings in the resource bundles and output all text in UTF-8
    5151my $outputstringsinUTF8 = 0;
     52my $freetext_xml_mode = 0;
     53
     54
     55sub make_freetext_xml_safe
     56{
     57    my ($text) = @_;
     58
     59    $text =~ s/\&/&/g;
     60    $text =~ s/\"/"/g;
     61    $text =~ s/\</&lt;/g;
     62    $text =~ s/\>/&gt;/g;
     63
     64    return $text;
     65}
    5266
    5367
     
    6377
    6478    # Resolve the string arguments using sprintf, then write out to the handle
    65     print $handle sprintf($text_string, @text_arguments);
     79    my $text_string_resolved = sprintf($text_string, @text_arguments);
     80
     81    if ($freetext_xml_mode) {
     82    $text_string_resolved = make_freetext_xml_safe($text_string_resolved);
     83    }
     84
     85    print $handle $text_string_resolved;
    6686}
    6787
     
    156176    if (!%defaultresourcebundle) {
    157177        # $! will still have the error value for the last failed syscall
    158         print STDERR "$! $resourcebundlename\n";
     178
     179        my $error_message = "$! $resourcebundlename\n";
     180
     181    if ($freetext_xml_mode) {
     182        $error_message = make_freetext_xml_safe($error_message);
     183    }
     184
     185        print STDERR $error_message;
     186
    159187    # set something so we don't bother trying to load it again
    160188    $defaultresourcebundle{0}=undef;
     
    292320
    293321
     322sub set_print_freetext_for_xml
     323{
     324    $freetext_xml_mode = 1;
     325}
     326
     327sub set_print_xml_tags
     328{
     329    $freetext_xml_mode = 0;
     330}
     331
    294332sub output_strings_in_UTF8
    295333{
Note: See TracChangeset for help on using the changeset viewer.