source: main/trunk/greenstone2/common-src/src/jdbmedit/JdbSet.java@ 21402

Last change on this file since 21402 was 21402, checked in by davidb, 14 years ago

Refactoring of class to use API

File size: 2.5 KB
Line 
1/**********************************************************************
2 *
3 * JdbSet.java --
4 * A component of the Greenstone digital library software
5 * from the New Zealand Digital Library Project at the
6 * University of Waikato, New Zealand.
7 *
8 * Copyright (C) 2009 The New Zealand Digital Library Project
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 **********************************************************************/
25
26import java.io.BufferedInputStream;
27import java.io.InputStream;
28import java.io.IOException;
29
30import java.util.Properties;
31
32import jdbm.RecordManager;
33import jdbm.RecordManagerFactory;
34import jdbm.helper.FastIterator;
35import jdbm.htree.HTree;
36
37
38
39public class JdbSet
40{
41 public static void print_usage()
42 {
43 System.err.println("Usage: java JdbSet database-name key [value] [append]");
44 System.err.println(" - if no value is given then the lexicon indicated by the key is removed");
45 System.err.println(" - if a value is given followed by 'append' then the value is ");
46 System.err.println(" added to the existing entry rather than overwriting it");
47 System.exit(-1);
48 }
49
50
51 public static void main(String[] args)
52 {
53 int argc = args.length;
54
55 // sanity check
56 if ((argc < 2) || (argc>4)) {
57 print_usage();
58 }
59
60 try {
61 String dbname = args[0];
62 JdbmAPI jdbm_api = new JdbmAPI(dbname);
63
64 if (argc == 4) {
65
66 if (args[3].equals("append")) {
67 String key = args[1];
68 String val = args[2];
69
70 jdbm_api.append(key,val);
71 }
72 else {
73 System.err.println("Error: Unrecognised option " + args[3]);
74 print_usage();
75 }
76 }
77 else if (argc == 3) {
78 String key = args[1];
79 String val = args[2];
80 jdbm_api.set(key,val);
81 }
82 else {
83 String key = args[1];
84 jdbm_api.delete(key);
85 }
86
87 jdbm_api.close();
88 }
89
90 catch (IOException e) {
91 e.printStackTrace();
92 }
93
94 }
95
96}
97
98
Note: See TracBrowser for help on using the repository browser.