private void save() { try { Document doc = XmlUtil.getDocument(); Element root = doc.createElement("profiles"); doc.appendChild(root); Enumeration<String> keys = table.keys(); while (keys.hasMoreElements()) { table.get(keys.nextElement()).appendTo(root); } FileUtil.setText(new File(filename), FileUtil.utf8, XmlUtil.toString(doc)); } catch (Exception ignore) { } }
private void load() { File file = new File(filename); if (file.exists()) { try { Document doc = XmlUtil.getDocument(file); Element root = doc.getDocumentElement(); Node child = root.getFirstChild(); while (child != null) { if (child.getNodeType() == Node.ELEMENT_NODE) { Profile p = new Profile((Element) child); table.put(p.name, p); } child = child.getNextSibling(); } } catch (Exception ignore) { } } }
public void delete(String name) { table.remove(name); save(); }
public void add(Profile profile) { table.put(profile.name, profile); save(); }
public int size() { return table.size(); }
public Profile getProfile(String name) { Profile p = table.get(name); if (p == null) p = new Profile(name); return p; }
public String[] getNames() { String[] names = new String[table.size()]; names = table.keySet().toArray(names); Arrays.sort(names); return names; }