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

Last change on this file since 14334 was 14334, checked in by qq6, 17 years ago

add users records from a text file

File size: 1.8 KB
Line 
1package org.greenstone.gsdl3.util;
2
3import java.io.BufferedReader;
4import java.io.IOException;
5import java.io.FileReader;
6import java.sql.SQLException;
7
8public class txt2usersDB {
9
10 public static void main(String[] args) throws SQLException{
11
12 if (args.length!=2){
13 System.out.println("Usage: java org.greenstone.gsdl3.txt2usersDB full_path_of_the_text_file full_path_of_the_usersDB");
14 System.exit(0);
15 }
16 try {
17 BufferedReader in = new BufferedReader(new FileReader(args[0]));
18 String str;
19 DerbyWrapper dw=new DerbyWrapper();
20 dw.connectDatabase(args[1],false);
21 String username=null;
22 String password=null;
23 String groups=null;
24 String accountstatus=null;
25 String comment=null;
26 while ((str = in.readLine()) != null) {
27 //ystem.out.println(str);
28 if (str.startsWith("<")){
29 String field=str.substring(1,str.indexOf(">"));
30 if (field.equals("comment")){
31 comment=str.substring(str.indexOf(">")+1,str.length());
32 }
33 if (field.equals("enabled")){
34 accountstatus=str.substring(str.indexOf(">")+1,str.length());
35 }
36 if (field.equals("groups")){
37 groups=str.substring(str.indexOf(">")+1,str.length());
38 }
39 if (field.equals("password")){
40 password=str.substring(str.indexOf(">")+1,str.length());
41 }
42 if (field.equals("username")){
43 username=str.substring(str.indexOf(">")+1,str.length());
44 }
45 }
46 if (str.equals("----------------------------------------------------------------------")){
47 if ((username!=null) && (password!=null) && (groups!=null) && (accountstatus!=null) && (comment!=null)){
48 dw.addUser(username, password, groups, accountstatus, comment);
49 username=null;
50 password=null;
51 groups=null;
52 accountstatus=null;
53 comment=null;
54 dw.connectDatabase(args[1],false);
55 }
56 }
57 }
58 in.close();
59 } catch (IOException e) {
60 }
61 }
62}
Note: See TracBrowser for help on using the repository browser.