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 calculPointDansToutExercice(){ ArrayList ListeNodeEvaluer = new ArrayList();; 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"); } } //*********************************************** //** 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 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.
* @param nod * @param point * @return */ private static int calculNombreDepointDeAnalyseStyle(node nod, int point) { if(nod.getAttributs().get("evaluer")!=null) if(nod.getAttributs().get("evaluer").equals("true")){ Enumeration 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); } } // //**************************** // //*** Héritage d'un style **** // //**************************** // if(nod.getAttributs().get("style:parent-style-name")!=null) { // String nomDuStyleParent = nod.getAttributs().get("style:parent-style-name"); // Pattern p = Pattern.compile("^P[0-9]{1,}|^T[0-9]{1,}"); // Matcher m = p.matcher(nod.getAttributs().get("style:name")); // if(m.find()) { // point = calculNombreDepointDepuisUnStyleDeAnalyseStyle(commandes.sujet.retourneFirstNodeByNameAndAttributValueExactStrict("style:style", "style:name", nomDuStyleParent), point); // } // } } return point; } /** * Calcul les points d'un style évalué par la méthode analyseStyle et qui hérite du node nod.
* @param nod * @param point * @return */ @SuppressWarnings("unused") private static int calculNombreDepointDepuisUnStyleDeAnalyseStyle(node nod, int point) { Enumeration 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; } }