1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
package beanAction;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import org.jdom2.Attribute;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;
import com.opensymphony.xwork2.ActionSupport;
public class AjoutDocumentAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private String titre;
private String createur;
private String sujet;
private String description;
private String date;
private int id;
static Element racine = new Element("documents");
static Document doc = new Document(racine);
public String execute() throws Exception {
Element document = new Element("document");
racine.addContent(document);
Attribute id = new Attribute("id","ici l'attribut id qui doit s'incrementer");
document.setAttribute(id);
Element titre = new Element("titre");
document.addContent(titre.setText(getTitre()));
// Element id = new Element("id");
// document.setAttribute("id",for(i=0;i<10;i++){});
Element creator = new Element("createur");
document.addContent(creator.setText(getCreator()));
Element subject = new Element("sujet");
document.addContent(subject.setText(getSubject()));
Element description = new Element("description");
document.addContent(description.setText(getDescription()));
Element date = new Element("date");
document.addContent(date.setText(getDate()));
XMLOutputter sortie = new XMLOutputter(Format.getPrettyFormat());
// sortie.output(document, System.out);
sortie.output(doc, new FileOutputStream("C:/workspace/GED-1.1/ressources/documents.xml"));
return null;}
// getters and setters
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitre() {
return titre;
}
public void setTitre(String titre) {
this.titre = titre;
}
public String getCreator() {
return createur;
}
public void setCreator(String creator) {
this.createur = creator;
}
public String getSubject() {
return sujet;
}
public void setSubject(String subject) {
this.sujet = subject;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
} |
Partager