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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
| package arbo;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import jaxb.Author;
import jaxb.Comment;
import jaxb.Comments;
import jaxb.File;
import jaxb.Files;
import jaxb.Folder;
import jaxb.ObjectFactory;
import jaxb.Project;
import jaxb.Replies;
//import jaxb.Reply;
public class TestJaxbv4 {
public static void main(String[] args) throws JAXBException, DatatypeConfigurationException{
ArrayList<String>listePaths = new ArrayList<String>();
listePaths.add("REVIEW/src/sonnette/Cloche.java");
listePaths.add("REVIEW/src/sonnette/common/oPair.java");
listePaths.add("REVIEW/de/fr/common/Poair.java");
listePaths.add("REVIEW/hk/fr/common/Paoir.java");
String[] path;
String cheminExiste ="";
ObjectFactory factory = new ObjectFactory();
Comments comments = factory.createComments();
ArrayList<String>listePaths1 = new ArrayList<String>();
Author auteur = factory.createAuthor();
Files files = factory.createFiles();
Project nomProjet = factory.createProject();
while(!listePaths.isEmpty()) {
path = listePaths.get(0).split("/");
Folder[]tabFolder = new Folder[path.length];
auteur.setName("brob");
for(int i=0;i<path.length;i++) {
cheminExiste=cheminExiste.concat(path[i]);
Folder folder = factory.createFolder();
folder.setName(path[i]);
tabFolder[i]=folder;
System.out.println(cheminExiste);
//Cas Projet
if(i == 0) {
if(!listePaths1.contains(cheminExiste)) {
nomProjet.setName(cheminExiste);
listePaths1.add(cheminExiste);
System.out.println("creation");
}
}
//nomProjet.getFileOrFolder().add(folder);
//Cas Fichier
else if(i == path.length-1) {
//System.out.println("ok");
File file = factory.createFile();
file.setName(path[path.length-1]);
Comment comment = factory.createComment();
String FORMATER = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX";
DateFormat format = new SimpleDateFormat(FORMATER);
Date date = new Date();
XMLGregorianCalendar gDateFormatted1 =
DatatypeFactory.newInstance().newXMLGregorianCalendar(format.format(date));
comment.setId("c0");
comment.setAuthor("brobert");
comment.setReviewID("td");
comment.setCreationDate(gDateFormatted1);
comment.setLastModified(gDateFormatted1);
comment.setPriority(0);
comment.setRecipient("");
comment.setStatus(0);
comment.setTyperemarque(0);
comment.setCriticite(0);
comment.setText("bonjour");
Replies replies = factory.createReplies();
//Reply reply = factory.createReply();
//reply.setAuthor(null);
//reply.setContent(null);
//reply.setCreationDate(null);
//replies.getReply().add(reply);
comment.setReplies(replies);
file.getComment().add(comment);
if(i == 1) {
if(!listePaths1.contains(cheminExiste)){
nomProjet.getFileOrFolder().add(file);
listePaths1.add(cheminExiste);
System.out.println("creation fichier a root");
}
}
else {
tabFolder[i-1].getFileOrFolder().add(file);
listePaths1.add(cheminExiste);
System.out.println("creation fichier ");
}
}
else {
//Cas Folder
if(i == 1) {
if(!listePaths1.contains(cheminExiste)) {
System.out.println(cheminExiste + " test");
System.out.println(tabFolder[i].getName() + " test");
nomProjet.getFileOrFolder().add(tabFolder[i]);
listePaths1.add(cheminExiste);
}
else {
//Que faire dans le cas ou le chemin est deja connu
}
}
//Cas Sous folder
else {
System.out.println(cheminExiste + " test");
System.out.println(tabFolder[i].getName() + " test");
if(!listePaths1.contains(cheminExiste)) {
tabFolder[i-1].getFileOrFolder().add(tabFolder[i]);
listePaths1.add(cheminExiste);
}
else {
//Que faire dans le cas ou le chemin est deja connu
}
}
}
}
listePaths.remove(0);
System.out.println(cheminExiste + "--------------------123456");
cheminExiste="";
}
files.getProject().add(nomProjet);
comments.setAuthor(auteur);
comments.setFiles(files);
JAXBContext context = JAXBContext.newInstance("jaxb");
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty("jaxb.formatted.output",Boolean.TRUE);
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
marshaller.marshal(comments, new java.io.File("author_brob.xml"));
marshaller.marshal(comments,System.out);
}
} |