private void xmlImportUser(List<Element> user) throws ImportDocumentException, PasswordIsTooWeakException { for (Element node : user) { String username = node.getAttributeValue("username"); User toInsert; try { this.getUserByUsername(username); } catch (UserAlreadyExistsException e) { e.getMessage(); throw new ImportDocumentException(); } catch (UserUnknownException e) { toInsert = new User(username, this); if (node.getChild("password") != null) toInsert.setPassword(node.getChild("password").getValue()); if (node.getChild("name") != null) toInsert.setName(node.getChild("name").getValue()); if (node.getChild("mask") != null) toInsert.setUmask(node.getChild("mask").getValue()); if (node.getChild("home") != null) { String[] tokens = node.getChild("home").getValue().split(PATH_DELIM); toInsert.setHomeDirectory( createDir( createPath(node.getChild("home").getValue()), tokens[tokens.length - 1], toInsert)); } else { Directory homeDirectory = new Directory( this.generateUniqueId(), username, toInsert.getUmask(), toInsert, getHomeDirectory()); toInsert.setHomeDirectory(homeDirectory); this.addDirectoryToHome(homeDirectory); } super.addUsers(toInsert); } } }
public void addUsers(String username) throws UserAlreadyExistsException, InvalidUsernameException, PasswordIsTooWeakException { try { hasUser(username); } catch (UserUnknownException e) { User toCreate = new User(username, this); Directory homeDirectory = new Directory( this.generateUniqueId(), username, toCreate.getUmask(), toCreate, getHomeDirectory()); this.addDirectoryToHome(homeDirectory); toCreate.setHomeDirectory(homeDirectory); super.addUsers(toCreate); return; } throw new UserAlreadyExistsException(username); }