source: greenstone3/trunk/src/java/org/greenstone/gsdl3/util/txt2usersDB.java@ 16869

Last change on this file since 16869 was 16869, checked in by kjdon, 16 years ago

added license message

File size: 2.9 KB
Line 
1/*
2 * txt2usersDB.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.io.BufferedReader;
22import java.io.IOException;
23import java.io.FileReader;
24import java.sql.SQLException;
25
26public class txt2usersDB {
27
28 public static void main(String[] args) throws SQLException{
29
30 if (args.length!=2){
31 System.out.println("Usage: java org.greenstone.gsdl3.txt2usersDB full_path_of_the_text_file full_path_of_the_usersDB");
32 System.exit(0);
33 }
34 try {
35 BufferedReader in = new BufferedReader(new FileReader(args[0]));
36 String str;
37 DerbyWrapper dw=new DerbyWrapper();
38 dw.connectDatabase(args[1],false);
39 boolean delete_rows = dw.deleteAllUser();
40 if (!delete_rows){
41 System.out.println("Couldn't delete rows of the users table");
42 System.exit(0);
43 }
44 String username=null;
45 String password=null;
46 String groups=null;
47 String accountstatus=null;
48 String comment=null;
49 while ((str = in.readLine()) != null) {
50 //ystem.out.println(str);
51 if (str.startsWith("<")){
52 String field=str.substring(1,str.indexOf(">"));
53 if (field.equals("comment")){
54 comment=str.substring(str.indexOf(">")+1,str.length());
55 }
56 if (field.equals("enabled")){
57 accountstatus=str.substring(str.indexOf(">")+1,str.length());
58 }
59 if (field.equals("groups")){
60 groups=str.substring(str.indexOf(">")+1,str.length());
61 }
62 if (field.equals("password")){
63 password=dw.rot13(str.substring(str.indexOf(">")+1,str.length()));
64 }
65 if (field.equals("username")){
66 username=str.substring(str.indexOf(">")+1,str.length());
67 }
68 }
69 if (str.equals("----------------------------------------------------------------------")){
70 if ((username!=null) && (password!=null) && (groups!=null) && (accountstatus!=null) && (comment!=null)){
71 dw.connectDatabase(args[1],false);
72 dw.addUser(username, password, groups, accountstatus, comment);
73 username=null;
74 password=null;
75 groups=null;
76 accountstatus=null;
77 comment=null;
78 dw.connectDatabase(args[1],false);
79 }
80 }
81 }
82 in.close();
83 } catch (IOException e) {
84 }
85 }
86}
Note: See TracBrowser for help on using the repository browser.