/** * Delete an user. Removes all this user entries from the properties. After removing the * corresponding from the properties, save the data. */ public synchronized void delete(String usrName) throws FtpException { lazyInit(); // remove entries from properties String thisPrefix = PREFIX + usrName + '.'; Enumeration<?> propNames = userDataProp.propertyNames(); ArrayList<String> remKeys = new ArrayList<String>(); while (propNames.hasMoreElements()) { String thisKey = propNames.nextElement().toString(); if (thisKey.startsWith(thisPrefix)) { remKeys.add(thisKey); } } Iterator<String> remKeysIt = remKeys.iterator(); while (remKeysIt.hasNext()) { userDataProp.remove(remKeysIt.next()); } saveUserData(); }
/** Get all user names. */ public synchronized String[] getAllUserNames() { lazyInit(); // get all user names String suffix = '.' + ATTR_HOME; ArrayList<String> ulst = new ArrayList<String>(); Enumeration<?> allKeys = userDataProp.propertyNames(); int prefixlen = PREFIX.length(); int suffixlen = suffix.length(); while (allKeys.hasMoreElements()) { String key = (String) allKeys.nextElement(); if (key.endsWith(suffix)) { String name = key.substring(prefixlen); int endIndex = name.length() - suffixlen; name = name.substring(0, endIndex); ulst.add(name); } } Collections.sort(ulst); return ulst.toArray(new String[0]); }