Changeset 25499


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.

Location:
main/trunk/greenstone2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/bin/script/pluginfo.pl

    r25167 r25499  
    130130    }
    131131    eval "\$$strVariable = \$value";
     132    }
     133
     134    if ($xml) {
     135    &gsprintf::set_print_freetext_for_xml();
    132136    }
    133137
     
    246250        push (@plugobj_list, $plugobj);
    247251    }
     252
     253    &gsprintf::set_print_xml_tags();
    248254    print STDERR "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    249255    print STDERR "<PluginList length=\"" . scalar(@plugin_list) . "\">\n";
     
    270276    my $plugobj = &plugin::load_plugin_for_info ($plugin);
    271277    if ($xml) {
     278    &gsprintf::set_print_xml_tags();
    272279    $plugobj->print_xml_usage($header);
    273280    }
  • 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/\&/&amp;/g;
     60    $text =~ s/\"/&quot;/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.