source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/DBInfo.java@ 24393

Last change on this file since 24393 was 24393, checked in by sjm84, 13 years ago

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

  • Property svn:keywords set to Author Date Id Revision
File size: 2.4 KB
Line 
1/*
2 * DBInfo.java
3 * Copyright (C) 2008 New Zealand Digital Library, http://www.nzdl.org
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19package org.greenstone.gsdl3.util;
20
21import java.util.Vector;
22import java.util.HashMap;
23import java.util.Set;
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
29 */
30public class DBInfo
31{
32 protected HashMap info_map_;
33
34 public DBInfo()
35 {
36 info_map_ = new HashMap();
37 }
38
39 // methods for keys that can have a single value
40
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 }
48
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 }
62
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);
75 }
76
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);
85 }
86
87 /** returns a list of all the keys in the info */
88 public Set getKeys()
89 {
90 return info_map_.keySet();
91 }
92
93 /** returns the Info as a string */
94 public String toString()
95 {
96 return info_map_.toString();
97
98 }
99}
Note: See TracBrowser for help on using the repository browser.