Ignore:
Timestamp:
2011-08-12T09:57:26+12:00 (13 years ago)
Author:
sjm84
Message:

Adding in the server-side code for the Document Maker as well as several other enhancements

File:
1 edited

Legend:

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

    r24254 r24393  
    2222import java.util.HashMap;
    2323import java.util.Set;
    24 /** class to hold info from a gdbm (or equiv) query
    25  * maps a String key to a list of Strings (values)
    26  * at the moment, the user must know if something has a single value or not
     24
     25/**
     26 * class to hold info from a gdbm (or equiv) query maps a String key to a list
     27 * of Strings (values) at the moment, the user must know if something has a
     28 * single value or not
    2729 */
    28 public class DBInfo {
     30public class DBInfo
     31{
     32    protected HashMap info_map_;
    2933
    30     protected HashMap info_map_;
     34    public DBInfo()
     35    {
     36        info_map_ = new HashMap();
     37    }
    3138
    32     public DBInfo() {
    33     info_map_ = new HashMap();
    34     }
     39    // methods for keys that can have a single value
    3540
    36     // methods for keys that can have a single value
     41    /** set the value for a key - replaces any existing value */
     42    public void setInfo(String key, String value)
     43    {
     44        Vector v = new Vector();
     45        v.add(value);
     46        info_map_.put(key, v);
     47    }
    3748
    38     /** set the value for a key - replaces any existing value */
    39     public void setInfo(String key, String value) {
    40     Vector v = new Vector();
    41     v.add(value);
    42     info_map_.put(key, v);
    43     }
     49    /**
     50     * get the value - used for keys that have one value, otherwise just returns
     51     * the first one
     52     */
     53    public String getInfo(String key)
     54    {
     55        Vector items = (Vector) info_map_.get(key);
     56        if (items == null)
     57        {
     58            return "";
     59        }
     60        return (String) items.firstElement();
     61    }
    4462
    45     /** get the value - used for keys that have one value, otherwise just
    46      * returns the first one */
    47     public String getInfo(String key) {
    48     Vector items = (Vector)info_map_.get(key);
    49     if (items==null) {
    50         return "";
     63    // methods for keys that can have multiple values
     64
     65    /** add a value to a key - for keys that can have multiple values */
     66    public void addInfo(String key, String value)
     67    {
     68        Vector v = (Vector) info_map_.get(key);
     69        if (v == null)
     70        {
     71            v = new Vector();
     72        }
     73        v.add(value);
     74        info_map_.put(key, v);
    5175    }
    52     return (String)items.firstElement();
    53     }
    5476
    55     /** get the value for the key at offset. If offset out of bounds,
    56      * just return the first one. */
    57     public String getInfoOffset(String key, int offset) {
    58     Vector items = (Vector)info_map_.get(key);
    59     if (items==null) {
    60         return "";
     77    /**
     78     * return a vector of all values associated with a key
     79     *
     80     * @return Vector of Strings
     81     */
     82    public Vector getMultiInfo(String key)
     83    {
     84        return (Vector) info_map_.get(key);
    6185    }
    62     if(offset >= 0 && offset < items.size()) {
    63         return (String)items.get(offset);
    64     } // else
    65     return (String)items.firstElement();
    66     }
    6786
     87    /** returns a list of all the keys in the info */
     88    public Set getKeys()
     89    {
     90        return info_map_.keySet();
     91    }
    6892
    69     // methods for keys that can have multiple values
    70    
    71     /** add a value to a key - for keys that can have multiple values */
    72     public void addInfo(String key, String value) {
    73     Vector v = (Vector)info_map_.get(key);
    74     if (v==null) {
    75         v = new Vector();
     93    /** returns the Info as a string */
     94    public String toString()
     95    {
     96        return info_map_.toString();
     97
    7698    }
    77     v.add(value);
    78     info_map_.put(key, v);
    79     }
    80     /** return a vector of all values associated with a key
    81      * @return Vector of Strings
    82      */
    83     public Vector getMultiInfo(String key) {
    84     return (Vector)info_map_.get(key);
    85     }
    86 
    87     /** returns a list of all the keys in the info */
    88     public Set getKeys() {
    89     return info_map_.keySet();
    90     }
    91     /** returns the Info as a string */
    92     public String toString() {
    93     return info_map_.toString();
    94 
    95     }
    9699}
Note: See TracChangeset for help on using the changeset viewer.