Changeset 28108

Show
Ignore:
Timestamp:
21.08.2013 10:06:44 (6 years ago)
Author:
davidb
Message:

Implementation of set_infodb_entry() function for JDB database type

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/dbutil/jdbm.pm

    r23399 r28108  
    198198} 
    199199 
    200  
    201200sub set_infodb_entry 
    202201{ 
    203   my $infodb_file_path = shift(@_); 
    204   my $infodb_key = shift(@_); 
    205   my $infodb_map = shift(@_); 
    206    
    207   print STDERR "***** jdbm::set_infodb_entry() not implemented yet!\n"; 
    208 } 
     202    my $infodb_file_path = shift(@_); 
     203    my $infodb_key = shift(@_); 
     204    my $infodb_map = shift(@_); 
     205   
     206    # HTML escape anything that is not part of the "contains" metadata value 
     207    foreach my $k (keys %$infodb_map) { 
     208      my @escaped_v = (); 
     209      foreach my $v (@{$infodb_map->{$k}}) { 
     210        if ($k eq "contains") { 
     211          push(@escaped_v, $v); 
     212        } 
     213        else { 
     214          my $ev = &ghtml::unescape_html($v); 
     215          push(@escaped_v, $ev); 
     216        } 
     217      } 
     218      $infodb_map->{$k} = \@escaped_v; 
     219    } 
     220     
     221    # Generate the record string 
     222    my $serialized_infodb_map = &dbutil::convert_infodb_hash_to_string($infodb_map); 
     223###    print STDERR "**** ser dr\n$serialized_infodb_map\n\n\n"; 
     224 
     225    # Store it into JDBM using 'Txt2Jdb .... -append' which despite its name 
     226    # actually replaces the record if it already exists 
     227 
     228    my $jdbmwrap_jar = &util::filename_cat($ENV{'GSDLHOME'},"bin","java", "JDBMWrapper.jar"); 
     229    my $jdbm_jar = &util::filename_cat($ENV{'GSDLHOME'},"lib","java", "jdbm.jar"); 
     230     
     231    my $classpath = &util::pathname_cat($jdbmwrap_jar,$jdbm_jar); 
     232 
     233    # Lop off file extension, as JDBM does not expect this to be present 
     234    $infodb_file_path =~ s/\.jdb$//; 
     235 
     236    my $cmd = "java -cp \"$classpath\" Txt2Jdb -append \"$infodb_file_path\""; 
     237 
     238    my $status = undef; 
     239    if(!open(GOUT, "| $cmd")) 
     240    { 
     241    print STDERR "Error: jdbm::set_infodb_entry() failed to open pipe to: $cmd\n"; 
     242    print STDERR "       $!\n"; 
     243    $status = -1; 
     244    } 
     245    else { 
     246    binmode(GOUT,":utf8"); 
     247     
     248    print GOUT "[$infodb_key]\n"; 
     249    print GOUT "$serialized_infodb_map\n"; 
     250 
     251    close(GOUT); 
     252    $status = 0; # as in exit status of cmd OK 
     253    } 
     254 
     255    return $status;   
     256} 
     257 
     258 
    209259 
    210260