Changeset 16809

Show
Ignore:
Timestamp:
15.08.2008 13:49:47 (11 years ago)
Author:
ak19
Message:

GDBMWrapper converts the key string to UTF8 now before doing the lookup. The href_url key is no longer URLencoded by HTMLPlugin, which means it is in UTF8.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • greenstone3/trunk/src/java/org/greenstone/gsdl3/util/GDBMWrapper.java

    r16797 r16809  
    66 
    77import org.apache.log4j.Logger; 
     8 
     9import java.io.UnsupportedEncodingException; 
    810 
    911/** java wrapper class for gdbm - uses Java-GDBM written by Martin Pool 
     
    7274    String s_info; 
    7375    try { 
    74       s_info = (String)db_.fetch(key); 
     76    try { 
     77        // The key is UTF8: do db lookup using the UTF8 version of key 
     78        s_info = (String)db_.fetch(key.getBytes("UTF-8")); 
     79    } catch(UnsupportedEncodingException e) { 
     80        logger.warn("utf8 key for " + key  
     81             + " unrecognised. Retrying with default encoding."); 
     82        // retry db lookup using default encoding of key instead of UTF8 
     83        s_info = (String)db_.fetch(key); 
     84    } 
    7585    } catch (GdbmException e) { 
    7686      logger.error("couldn't get record"); 
     
    102112  } 
    103113 
    104     /** returns a string of key-value entries that  
    105      *  can be printed for debugging purposes. */ 
     114    /** returns a string of key-value entries that 
     115     *  can be printed for debugging purposes. */ 
    106116    public String displayAllEntries() { 
    107117    StringBuffer output = new StringBuffer(); 
     
    118128        output.append("\n"); 
    119129        //logger.warn("key: " + key + "\tvalue: " + value); 
     130 
     131        String urlkey = java.net.URLEncoder.encode((String)key, "UTF8"); 
     132        output.append("URL encoded key: " + urlkey); 
     133        //logger.warn("URL encoded key: " + urlkey); 
    120134        } 
     135    } catch(UnsupportedEncodingException e) { 
     136        logger.warn("Trouble converting key " + key + " to UTF-8."); 
    121137    } catch(Exception e) { 
    122138        logger.warn("Exception encountered when trying to displayAllEntries():" + e);