[14334] | 1 | package org.greenstone.gsdl3.util;
|
---|
| 2 |
|
---|
| 3 | import java.io.BufferedReader;
|
---|
| 4 | import java.io.IOException;
|
---|
| 5 | import java.io.FileReader;
|
---|
| 6 | import java.sql.SQLException;
|
---|
| 7 |
|
---|
| 8 | public 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);
|
---|
[14336] | 21 | boolean delete_rows = dw.deleteAllUser();
|
---|
| 22 | if (!delete_rows){
|
---|
| 23 | System.out.println("Couldn't delete rows of the users table");
|
---|
| 24 | System.exit(0);
|
---|
| 25 | }
|
---|
[14334] | 26 | String username=null;
|
---|
| 27 | String password=null;
|
---|
| 28 | String groups=null;
|
---|
| 29 | String accountstatus=null;
|
---|
| 30 | String comment=null;
|
---|
| 31 | while ((str = in.readLine()) != null) {
|
---|
| 32 | //ystem.out.println(str);
|
---|
| 33 | if (str.startsWith("<")){
|
---|
| 34 | String field=str.substring(1,str.indexOf(">"));
|
---|
| 35 | if (field.equals("comment")){
|
---|
| 36 | comment=str.substring(str.indexOf(">")+1,str.length());
|
---|
| 37 | }
|
---|
| 38 | if (field.equals("enabled")){
|
---|
| 39 | accountstatus=str.substring(str.indexOf(">")+1,str.length());
|
---|
| 40 | }
|
---|
| 41 | if (field.equals("groups")){
|
---|
| 42 | groups=str.substring(str.indexOf(">")+1,str.length());
|
---|
| 43 | }
|
---|
| 44 | if (field.equals("password")){
|
---|
| 45 | password=str.substring(str.indexOf(">")+1,str.length());
|
---|
| 46 | }
|
---|
| 47 | if (field.equals("username")){
|
---|
| 48 | username=str.substring(str.indexOf(">")+1,str.length());
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 | if (str.equals("----------------------------------------------------------------------")){
|
---|
| 52 | if ((username!=null) && (password!=null) && (groups!=null) && (accountstatus!=null) && (comment!=null)){
|
---|
[14336] | 53 | dw.connectDatabase(args[1],false);
|
---|
[14334] | 54 | dw.addUser(username, password, groups, accountstatus, comment);
|
---|
| 55 | username=null;
|
---|
| 56 | password=null;
|
---|
| 57 | groups=null;
|
---|
| 58 | accountstatus=null;
|
---|
| 59 | comment=null;
|
---|
| 60 | dw.connectDatabase(args[1],false);
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 | }
|
---|
| 64 | in.close();
|
---|
| 65 | } catch (IOException e) {
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 | }
|
---|