134 lines
4.0 KiB
Java
134 lines
4.0 KiB
Java
package app;
|
|
|
|
import java.awt.Dimension;
|
|
import java.io.BufferedReader;
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.IOException;
|
|
import java.io.InputStreamReader;
|
|
import java.io.UnsupportedEncodingException;
|
|
|
|
import javax.swing.JFileChooser;
|
|
import javax.swing.JOptionPane;
|
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
|
|
|
import MEPTL.commandes;
|
|
import cXML.Run;
|
|
import cXML.node;
|
|
|
|
|
|
|
|
@SuppressWarnings("serial")
|
|
public class filechooser extends JFileChooser{
|
|
|
|
|
|
public filechooser() {
|
|
|
|
//addChoosableFileFilter(new FileNameExtensionFilter("ODF Writer", "odt"));
|
|
addChoosableFileFilter(new FileNameExtensionFilter("Fichier d'évaluation", "xml"));
|
|
FileNameExtensionFilter filter = new FileNameExtensionFilter("ODF Writer", "odt");
|
|
setFileFilter(filter);
|
|
setFileFilter(getAcceptAllFileFilter());
|
|
|
|
|
|
|
|
if(!commandes.filename.isEmpty()) {
|
|
File file = new File(commandes.path ); //+ "\\" + utils.filename + ".xml"
|
|
setCurrentDirectory(file);
|
|
}
|
|
|
|
setPreferredSize(new Dimension(550, 420));
|
|
|
|
int response = showOpenDialog(null);
|
|
if(response == JFileChooser.APPROVE_OPTION) {
|
|
|
|
File file = new File(getSelectedFile().getAbsolutePath());
|
|
System.out.println(file.getPath() + "\n" + file.getName());
|
|
String ext = file.getName().substring(file.getName().lastIndexOf("."));
|
|
|
|
if(ext.equals(".odt")){
|
|
openFileODF(file);
|
|
}else {
|
|
openFileXML(file);
|
|
}
|
|
|
|
System.out.println("path " + commandes.path);
|
|
System.out.println("Nom du premier node " + commandes.sujet.getNomElt());
|
|
|
|
}
|
|
}
|
|
|
|
|
|
private void openFileODF(File file) {
|
|
// Run analize = new Run();
|
|
// commandes.path = file.getPath().substring(0,file.getPath().lastIndexOf("\\"));
|
|
// commandes.filename = file.getName().substring(0,file.getName().lastIndexOf("."));
|
|
//
|
|
// commandes.sujet = analize.RunWithOneFileODT(file);
|
|
// try {
|
|
// utils.sujet = utils.LectureFichierEtudiantSousFormeDeNode(utils.sujet,analize,0,true);
|
|
// } catch (IOException e1) {
|
|
// e1.printStackTrace();
|
|
// }
|
|
// utils.sujet = utils.nodePourEcritureSujet(utils.sujet);
|
|
//
|
|
// if(!utils.fichierSujetValide()) {
|
|
// JOptionPane.showMessageDialog(null, "Le fichier n'est pas valide.");
|
|
// }else {
|
|
// utils.setTree();
|
|
// }
|
|
}
|
|
|
|
|
|
private void openFileXML(File file) {
|
|
commandes.path = file.getPath().substring(0,file.getPath().lastIndexOf("\\"));
|
|
commandes.filename = file.getName().substring(0,file.getName().lastIndexOf("."));
|
|
|
|
BufferedReader br;
|
|
try {
|
|
br = new BufferedReader(
|
|
new InputStreamReader(
|
|
new FileInputStream(file.getAbsoluteFile()), "UTF-8"));
|
|
String line;
|
|
String targetString = "";
|
|
while ((line = br.readLine()) != null) {
|
|
targetString = targetString + line;
|
|
}
|
|
|
|
//node.node2(targetString);
|
|
commandes.sujet = new node(targetString.replace("\t","").replace("\r", "").replace("\n", ""));
|
|
|
|
|
|
//Run.ecritureNodeEnXML(A, filename, path);
|
|
commandes.sujet = Run.parentAndLevel(commandes.sujet, commandes.sujet.getNomElt(), 0);
|
|
|
|
|
|
if(!fichierSujetValide()) JOptionPane.showMessageDialog(null, "Le fichier n'est pas valide.");
|
|
|
|
|
|
} catch (UnsupportedEncodingException e1) {
|
|
e1.printStackTrace();
|
|
} catch (FileNotFoundException e1) {
|
|
e1.printStackTrace();
|
|
} catch (Exception e) {
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public static boolean fichierSujetValide () {
|
|
if(commandes.sujet==null) return false;
|
|
if(!commandes.sujet.getNomElt().equals("fichier")) return false;
|
|
if(commandes.sujet.getAttributs().get("metaSujet")==null) return false;
|
|
if(!commandes.sujet.retourneEnfantsByNameExist("style:page")) return false;
|
|
if(!commandes.sujet.retourneEnfantsByNameExist("style:paragraphe")) return false;
|
|
if(!commandes.sujet.retourneEnfantsByNameExist("structurepage")) return false;
|
|
|
|
commandes.fichierValide = true;
|
|
return true;
|
|
}
|
|
|
|
|
|
}
|