예제 #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;
 }