package org.greenstone.gsdl3.util; import java.io.BufferedReader; import java.io.IOException; import java.io.FileReader; import java.sql.SQLException; public class txt2usersDB { public static void main(String[] args) throws SQLException{ if (args.length!=2){ System.out.println("Usage: java org.greenstone.gsdl3.txt2usersDB full_path_of_the_text_file full_path_of_the_usersDB"); System.exit(0); } try { BufferedReader in = new BufferedReader(new FileReader(args[0])); String str; DerbyWrapper dw=new DerbyWrapper(); dw.connectDatabase(args[1],false); boolean delete_rows = dw.deleteAllUser(); if (!delete_rows){ System.out.println("Couldn't delete rows of the users table"); System.exit(0); } String username=null; String password=null; String groups=null; String accountstatus=null; String comment=null; while ((str = in.readLine()) != null) { //ystem.out.println(str); if (str.startsWith("<")){ String field=str.substring(1,str.indexOf(">")); if (field.equals("comment")){ comment=str.substring(str.indexOf(">")+1,str.length()); } if (field.equals("enabled")){ accountstatus=str.substring(str.indexOf(">")+1,str.length()); } if (field.equals("groups")){ groups=str.substring(str.indexOf(">")+1,str.length()); } if (field.equals("password")){ password=str.substring(str.indexOf(">")+1,str.length()); } if (field.equals("username")){ username=str.substring(str.indexOf(">")+1,str.length()); } } if (str.equals("----------------------------------------------------------------------")){ if ((username!=null) && (password!=null) && (groups!=null) && (accountstatus!=null) && (comment!=null)){ dw.connectDatabase(args[1],false); dw.addUser(username, password, groups, accountstatus, comment); username=null; password=null; groups=null; accountstatus=null; comment=null; dw.connectDatabase(args[1],false); } } } in.close(); } catch (IOException e) { } } }