*/
public void generateApacheUserTable() throws HtpasswdException {
// Check if a db-connection is ready to use
if (db == null)
throw new HtpasswdException("No DbHandler bound to " + "htpasswdhandler");
// Check that the AuthUserFile exists
try {
FileWriter file = new FileWriter(authUserFileName);
// Query db
try {
ResultSet rs = db.executeQuery("SELECT ANVID, LOSENORD FROM anvandare");
// Loop through resultset and write to file
String anvid = "";
String losenord = "";
while (rs.next()) {
anvid = rs.getString("ANVID");
losenord = rs.getString("LOSENORD");
if (anvid == null) {
anvid = "";
}
if (losenord == null) {
losenord = "";
}
file.write(anvid.trim() + ":" + losenord.trim() + "\r\n");
}
} catch (DbHandlerException e) {
throw new HtpasswdException("Can't read from db because: "
+ e.getMessage());
} catch (SQLException e) {
throw new HtpasswdException("Can't read from db because: "
+ e.getMessage());
} finally {
try {
db.close();
} catch (DbHandlerException e) {
throw new HtpasswdException("Can't close the db: " + e.getMessage());
}
}
file.close();
} catch (IOException e) {
throw new HtpasswdException("Could not write to AuthUser file because: "
+ e.getMessage());
}
}