Changeset 10040


Ignore:
Timestamp:
2005-06-10T10:17:22+12:00 (19 years ago)
Author:
mdewsnip
Message:

Now writes the XML response when the command has completely finished, to prevent problems with errors happening during command processing and forming invalid XML.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/bin/script/gti.pl

    r10027 r10040  
    8989    # Process the command
    9090    if ($gti_command =~ /^get-first-n-chunks-requiring-work$/i) {
    91     &get_first_n_chunks_requiring_work(@gti_command_arguments);
     91    print &get_first_n_chunks_requiring_work(@gti_command_arguments);
    9292    }
    9393    if ($gti_command =~ /^get-language-status$/i) {
    94     &get_language_status(@gti_command_arguments);
     94    print &get_language_status(@gti_command_arguments);
    9595    }
    9696    if ($gti_command =~ /^search-chunks$/i) {
    97     &search_chunks(@gti_command_arguments);
     97    print &search_chunks(@gti_command_arguments);
    9898    }
    9999    if ($gti_command =~ /^submit-translation$/i) {
     100    # This command cannot produce any output since it reads input
    100101    &submit_translation(@gti_command_arguments);
    101102    }
     
    179180    &log_message("Number of target chunks requiring updating: " . scalar(@target_file_keys_requiring_updating));
    180181
    181     # Write an XML response to the command
    182     print "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
    183     print "<GTIResponse>\n";
    184     print "  <TranslationFile"
     182    # Form an XML response to the command
     183    my $xml_response = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
     184    $xml_response .= "<GTIResponse>\n";
     185    $xml_response .= "  <TranslationFile"
    185186    . " key=\"" . $translation_file_key . "\""
    186187    . " target_file_path=\"" . $target_file . "\""
     
    191192    # Do chunks requiring translation first
    192193    if ($num_chunks_to_return > scalar(@target_file_keys_requiring_translation)) {
    193     print "  <ChunksRequiringTranslation size=\"" . scalar(@target_file_keys_requiring_translation) . "\">\n";
     194    $xml_response .= "  <ChunksRequiringTranslation size=\"" . scalar(@target_file_keys_requiring_translation) . "\">\n";
    194195    }
    195196    else {
    196     print "  <ChunksRequiringTranslation size=\"" . $num_chunks_to_return . "\">\n";
     197    $xml_response .= "  <ChunksRequiringTranslation size=\"" . $num_chunks_to_return . "\">\n";
    197198    }
    198199
     
    203204    my $source_file_chunk_text = &make_text_xml_safe($source_file_key_to_text_mapping{$chunk_key});
    204205
    205     print "    <Chunk key=\"$chunk_key\">\n";
    206     print "      <SourceFileText date=\"$source_file_chunk_date\">$source_file_chunk_text</SourceFileText>\n";
    207     print "      <TargetFileText></TargetFileText>\n";
    208     print "    </Chunk>\n";
     206    $xml_response .= "    <Chunk key=\"$chunk_key\">\n";
     207    $xml_response .= "      <SourceFileText date=\"$source_file_chunk_date\">$source_file_chunk_text</SourceFileText>\n";
     208    $xml_response .= "      <TargetFileText></TargetFileText>\n";
     209    $xml_response .= "    </Chunk>\n";
    209210
    210211    $num_chunks_to_return--;
    211212    }
    212213
    213     print "  </ChunksRequiringTranslation>\n";
     214    $xml_response .= "  </ChunksRequiringTranslation>\n";
    214215
    215216    # Then do chunks requiring updating
    216217    if ($num_chunks_to_return > scalar(@target_file_keys_requiring_updating)) {
    217     print "  <ChunksRequiringUpdating size=\"" . scalar(@target_file_keys_requiring_updating) . "\">\n";
     218    $xml_response .= "  <ChunksRequiringUpdating size=\"" . scalar(@target_file_keys_requiring_updating) . "\">\n";
    218219    }
    219220    else {
    220     print "  <ChunksRequiringUpdating size=\"" . $num_chunks_to_return . "\">\n";
     221    $xml_response .= "  <ChunksRequiringUpdating size=\"" . $num_chunks_to_return . "\">\n";
    221222    }
    222223
     
    229230    my $target_file_chunk_text = &make_text_xml_safe($target_file_key_to_text_mapping{$chunk_key});
    230231
    231     print "    <Chunk key=\"$chunk_key\">\n";
    232     print "      <SourceFileText date=\"$source_file_chunk_date\">$source_file_chunk_text</SourceFileText>\n";
    233     print "      <TargetFileText date=\"$target_file_chunk_date\">$target_file_chunk_text</TargetFileText>\n";
    234     print "    </Chunk>\n";
     232    $xml_response .= "    <Chunk key=\"$chunk_key\">\n";
     233    $xml_response .= "      <SourceFileText date=\"$source_file_chunk_date\">$source_file_chunk_text</SourceFileText>\n";
     234    $xml_response .= "      <TargetFileText date=\"$target_file_chunk_date\">$target_file_chunk_text</TargetFileText>\n";
     235    $xml_response .= "    </Chunk>\n";
    235236
    236237    $num_chunks_to_return--;
    237238    }
    238239
    239     print "  </ChunksRequiringUpdating>\n";
    240 
    241     print "</GTIResponse>\n";
     240    $xml_response .= "  </ChunksRequiringUpdating>\n";
     241
     242    $xml_response .= "</GTIResponse>\n";
     243    return $xml_response;
    242244}
    243245
     
    253255    }
    254256
    255     # Write an XML response to the command
    256     print "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
    257     print "<GTIResponse>\n";
    258     print "  <LanguageStatus code=\"$target_language_code\">\n";
     257    # Form an XML response to the command
     258    my $xml_response = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
     259    $xml_response .= "<GTIResponse>\n";
     260    $xml_response .= "  <LanguageStatus code=\"$target_language_code\">\n";
    259261
    260262    foreach my $translation_file (@$gti_translation_files) {
     
    298300    }
    299301
    300     print "    <TranslationFile"
     302    $xml_response .= "    <TranslationFile"
    301303        . " key=\"" . $translation_file->{'key'} . "\""
    302304        . " target_file_path=\"" . $target_file . "\""
     
    306308    }
    307309
    308     print "  </LanguageStatus>\n";
    309     print "</GTIResponse>\n";
     310    $xml_response .= "  </LanguageStatus>\n";
     311
     312    $xml_response .= "</GTIResponse>\n";
     313    return $xml_response;
    310314}
    311315
     
    362366    }
    363367
    364     # Write an XML response to the command
    365     print "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
    366     print "<GTIResponse>\n";
    367 
    368     print "  <ChunksMatchingQuery size=\"" . scalar(@target_file_keys_matching_query) . "\">\n";
     368    # Form an XML response to the command
     369    my $xml_response = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n";
     370    $xml_response .= "<GTIResponse>\n";
     371
     372    $xml_response .= "  <ChunksMatchingQuery size=\"" . scalar(@target_file_keys_matching_query) . "\">\n";
    369373    foreach my $chunk_key (@target_file_keys_matching_query) {
    370374    my $target_file_chunk_text = &make_text_xml_safe($target_file_key_to_text_mapping{$chunk_key});
    371375
    372     print "    <Chunk key=\"$chunk_key\">\n";
    373     print "      <TargetFileText>$target_file_chunk_text</TargetFileText>\n";
    374     print "    </Chunk>\n";
    375     }
    376     print "  </ChunksMatchingQuery>\n";
    377 
    378     print "</GTIResponse>\n";
     376    $xml_response .= "    <Chunk key=\"$chunk_key\">\n";
     377    $xml_response .= "      <TargetFileText>$target_file_chunk_text</TargetFileText>\n";
     378    $xml_response .= "    </Chunk>\n";
     379    }
     380    $xml_response .= "  </ChunksMatchingQuery>\n";
     381
     382    $xml_response .= "</GTIResponse>\n";
     383    return $xml_response;
    379384}
    380385
     
    391396    # Check that the necessary arguments were supplied
    392397    if (!$target_language_code || !$translation_file_key) {
    393     &throw_fatal_error("Missing command argument.");  # !! This cannot be here !!
     398    &log_message("Fatal error (but cannot be thrown): Missing command argument.");
     399    die "\n";
    394400    }
    395401
Note: See TracChangeset for help on using the changeset viewer.