analyseWriter/src/calcul/calculNombrePointEvaluation...

294 lines
10 KiB
Java

package calcul;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JOptionPane;
import MEPTL.commandes;
import cXML.node;
public class calculNombrePointEvaluation {
/**
* Ensemble des points dans les différents node principaux.
* @return
*/
public static ArrayList<String> calculPointDansToutExercice(){
ArrayList<String> ListeNodeEvaluer = new ArrayList<String>();;
for(int i = 0 ; i < commandes.sujet.getNodes().size();i++) {
if(!commandes.sujet.getNodes().get(i).getNomElt().equals("setting")) {
ListeNodeEvaluer.add(commandes.sujet.getNodes().get(i).getNomElt() + " " +
String.valueOf(calculNombreDepoint(commandes.sujet.getNodes().get(i), 0)) + " " +
String.valueOf(commandes.sujet.getNodes().get(i).getAttributs().get("poids")));
}
}
return ListeNodeEvaluer;
}
public static int calculNombreDepoint(node nod, int point) {
if(nod.getAttributs().get("evaluer")!=null) if(nod.getAttributs().get("evaluer").equals("true")){
if(nod.getAttributs().get("allContent")!=null) {
Pattern pt = Pattern.compile("[0-9]{1,}$");
Matcher match= pt.matcher(nod.getAttributs().get("allContent"));
if(match.find()) {
String s= match.group();
try {
point = point + Integer.valueOf(s);
} catch (Exception e) {
JOptionPane.showInternalMessageDialog(null, "Erreur dans la valeur de l'attribut allContent");
}
}
}
if(nod.getAttributs().get("evalNameInitialCreator")!=null) {
try {
point = point + Integer.valueOf(nod.getAttributs().get("evalNameInitialCreator"));
} catch (Exception e) {
JOptionPane.showInternalMessageDialog(null, "Erreur dans la valeur de l'attribut evalNameInitialCreator");
}
}
if(nod.getAttributs().get("evalNameCreator")!=null) {
try {
point = point + Integer.valueOf(nod.getAttributs().get("evalNameCreator"));
} catch (Exception e) {
JOptionPane.showInternalMessageDialog(null, "Erreur dans la valeur de l'attribut evalNameCreator");
}
}
if(nod.getAttributs().get("evalNameNode")!=null) {
try {
point = point + Integer.valueOf(nod.getAttributs().get("evalNameNode"));
} catch (Exception e) {
JOptionPane.showInternalMessageDialog(null, "Erreur dans la valeur de l'attribut evalNameCreator");
}
}
if(nod.getAttributs().get("evalNamePage")!=null) {
try {
point = point + Integer.valueOf(nod.getAttributs().get("evalNamePage"));
} catch (Exception e) {
JOptionPane.showInternalMessageDialog(null, "Erreur dans la valeur de l'attribut evalNamePage");
}
}
if(nod.getAttributs().get("evalNumeroPage")!=null) {
try {
point = point + Integer.valueOf(nod.getAttributs().get("evalNumeroPage"));
} catch (Exception e) {
JOptionPane.showInternalMessageDialog(null, "Erreur dans la valeur de l'attribut evalNumeroPage");
}
}
if(nod.getAttributs().get("evalNumeroAbsoluePage")!=null) {
try {
point = point + Integer.valueOf(nod.getAttributs().get("evalNumeroAbsoluePage"));
} catch (Exception e) {
JOptionPane.showInternalMessageDialog(null, "Erreur dans la valeur de l'attribut evalNumeroAbsoluePage");
}
}
if(nod.getAttributs().get("evalEntetePasActive")!=null) {
try {
point = point + Integer.valueOf(nod.getAttributs().get("evalEntetePasActive"));
} catch (Exception e) {
JOptionPane.showInternalMessageDialog(null, "Erreur dans la valeur de l'attribut evalEntetePasActive");
}
}
if(nod.getAttributs().get("evalPiedPageActive")!=null) {
try {
point = point + Integer.valueOf(nod.getAttributs().get("evalPiedPageActive"));
} catch (Exception e) {
JOptionPane.showInternalMessageDialog(null, "Erreur dans la valeur de l'attribut evalEntetePasActive");
}
}
if(nod.getAttributs().get("evalPlacement")!=null) {
try {
point = point + Integer.valueOf(nod.getAttributs().get("evalPlacement"));
} catch (Exception e) {
JOptionPane.showInternalMessageDialog(null, "Erreur dans la valeur de l'attribut evalPlacement");
}
}
if(nod.getAttributs().get("evalNameLegacyStyle")!=null) {
try {
point = point + Integer.valueOf(nod.getAttributs().get("evalNameLegacyStyle"));
} catch (Exception e) {
JOptionPane.showInternalMessageDialog(null, "Erreur dans la valeur de l'attribut evalPlacement");
}
}
if(nod.getAttributs().get("evalFirstChild")!=null) {
try {
point = point + Integer.valueOf(nod.getAttributs().get("evalFirstChild"));
} catch (Exception e) {
JOptionPane.showInternalMessageDialog(null, "Erreur dans la valeur de l'attribut evalFirstChild");
}
}
if(nod.getAttributs().get("evalLastChild")!=null) {
try {
point = point + Integer.valueOf(nod.getAttributs().get("evalLastChild"));
} catch (Exception e) {
JOptionPane.showInternalMessageDialog(null, "Erreur dans la valeur de l'attribut evalLastChild");
}
}
if(nod.getAttributs().get("evalAncrageNumeroAbsoluePage")!=null) {
try {
point = point + Integer.valueOf(nod.getAttributs().get("evalAncrageNumeroAbsoluePage"));
} catch (Exception e) {
JOptionPane.showInternalMessageDialog(null, "Erreur dans la valeur de l'attribut evalAncrageNumeroAbsoluePage");
}
}
if(nod.getAttributs().get("evalFormatageDirect")!=null) {
try {
point = point + Integer.valueOf(nod.getAttributs().get("evalFormatageDirect"));
} catch (Exception e) {
JOptionPane.showInternalMessageDialog(null, "Erreur dans la valeur de l'attribut evalFormatageDirect");
}
}
if(nod.getAttributs().get("evalSautPageColonne")!=null) {
try {
point = point + Integer.valueOf(nod.getAttributs().get("evalSautPageColonne"));
} catch (Exception e) {
JOptionPane.showInternalMessageDialog(null, "Erreur dans la valeur de l'attribut evalSautPageColonne");
}
}
if(nod.getAttributs().get("evalPasParagrapheVide")!=null) {
try {
point = point + Integer.valueOf(nod.getAttributs().get("evalPasParagrapheVide"));
} catch (Exception e) {
JOptionPane.showInternalMessageDialog(null, "Erreur dans la valeur de l'attribut evalPasParagrapheVide");
}
}
//***********************************************
//** Les points par la méthode analyseStyle *****
//***********************************************
if(nod.getAttributs().get("analyseStyle")!=null) {
if(nod.getAttributs().get("analyseStyle").equals("true")) {
String nomDuStyle = nod.getAttributs().get("text:style-name");
point = calculNombreDepointDeAnalyseStyle(commandes.sujet.retourneFirstNodeByNameAndAttributValueExactStrict("style:style", "style:name", nomDuStyle), point);
}
}
Enumeration<String> key = nod.getAttributs().keys();
while(key.hasMoreElements()) {
String k = key.nextElement();
if(nod.getAttributs().get(k).contains("")) {
Pattern pt = Pattern.compile("[0-9]{1,}$");
Matcher match= pt.matcher(nod.getAttributs().get(k));
if(match.find()) {
String s= match.group();
try {
point = point + Integer.valueOf(s);
} catch (Exception e) {
JOptionPane.showInternalMessageDialog(null, "Erreur dans la valeur de l'attribut "+ k);
}
}
}
}
for(int i = 0 ; i < nod.getNodes().size();i++) {
if(nod.getNodes().get(i)!=null) {
if(!nod.getNodes().get(i).getNomElt().equals("style:default-style")) {
point = calculNombreDepoint(nod.getNodes().get(i), point);
}
}
}
}
return point;
}
/**
* Calcul les points d'un style évalué par la méthode analyseStyle.<br>
* @param nod
* @param point
* @return
*/
private static int calculNombreDepointDeAnalyseStyle(node nod, int point) {
if(nod!=null) {
if(nod.getAttributs().get("evaluer")!=null) if(nod.getAttributs().get("evaluer").equals("true")){
Enumeration<String> key = nod.getAttributs().keys();
while(key.hasMoreElements()) {
String k = key.nextElement();
if(nod.getAttributs().get(k).contains("")) {
Pattern pt = Pattern.compile("[0-9]{1,}$");
Matcher match= pt.matcher(nod.getAttributs().get(k));
if(match.find()) {
String s= match.group();
try {
point = point + Integer.valueOf(s);
} catch (Exception e) {
JOptionPane.showInternalMessageDialog(null, "Erreur dans la valeur de l'attribut "+ k);
}
}
}
}
if(nod.getNodes().size()>0) {
for(int i = 0 ; i < nod.getNodes().size();i++) {
point = calculNombreDepointDeAnalyseStyle(nod.getNodes().get(i), point);
}
}
}
}
return point;
}
/**
* Calcul les points d'un style évalué par la méthode analyseStyle et qui hérite du node nod.<br>
* @param nod
* @param point
* @return
*/
@SuppressWarnings("unused")
private static int calculNombreDepointDepuisUnStyleDeAnalyseStyle(node nod, int point) {
Enumeration<String> key = nod.getAttributs().keys();
while(key.hasMoreElements()) {
String k = key.nextElement();
if(nod.getAttributs().get(k).contains("")||nod.getAttributs().get(k).contains("")) {
Pattern pt = Pattern.compile("[0-9]{1,}$");
Matcher match= pt.matcher(nod.getAttributs().get(k));
if(match.find()) {
String s= match.group();
try {
point = point + Integer.valueOf(s);
} catch (Exception e) {
JOptionPane.showInternalMessageDialog(null, "Erreur dans la valeur de l'attribut "+ k);
}
}
}
}
if(nod.getNodes().size()>0) {
for(int i = 0 ; i < nod.getNodes().size();i++) {
point = calculNombreDepointDepuisUnStyleDeAnalyseStyle(nod.getNodes().get(i), point);
}
}
return point;
}
}