/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package Config;
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdom2.*;
import org.jdom2.input.SAXBuilder;
import org.jdom2.output.*;
/**
*
* @author phonghuynh
*/
public abstract class JDOM {
protected Document doc;
protected Element rootNode;
protected String path;
protected JDOM(String path) {
this.path = path;
SAXBuilder sxb = new SAXBuilder();
try {
doc = sxb.build(new File(path));
rootNode = doc.getRootElement();
} catch (JDOMException ex) {
doc = new Document(); // Permet lorsque le fichier vient d etre crée
//Logger.getLogger(JDOM.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
doc = new Document(); // Permet lorsque le fichier vient d etre crée
//Logger.getLogger(JDOM.class.getName()).log(Level.SEVERE, null, ex);
System.out.println("Fichier " + path + " inexistant");
}
}
public Element getRootNode() {
return rootNode;
}
public void save() {
try {
XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
sortie.output(doc, new FileOutputStream(path));
} catch (IOException ex) {
Logger.getLogger(JDOM.class.getName()).log(Level.SEVERE, null, ex);
}
}
}