Пример #1
0
 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) {
   }
 }
Пример #2
0
 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) {
     }
   }
 }
Пример #3
0
 public void delete(String name) {
   table.remove(name);
   save();
 }
Пример #4
0
 public void add(Profile profile) {
   table.put(profile.name, profile);
   save();
 }
Пример #5
0
 public int size() {
   return table.size();
 }
Пример #6
0
 public Profile getProfile(String name) {
   Profile p = table.get(name);
   if (p == null) p = new Profile(name);
   return p;
 }
Пример #7
0
 public String[] getNames() {
   String[] names = new String[table.size()];
   names = table.keySet().toArray(names);
   Arrays.sort(names);
   return names;
 }