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
| public class MoteurRecherche implements Serializable{
// public Vector listeNomDossier = new Vector();
private Vector listeDocumentsTrouves = new Vector();
private String champRecherche;
/** Creates a new instance of MoteurRecherche */
public MoteurRecherche() {
}
public MoteurRecherche(String champRecherche){
this.champRecherche=champRecherche;
}
public String getChampRecherche() {
return champRecherche;
}
public void setChampRecherche(String champRecherche) {
this.champRecherche = champRecherche;
}
/**
* on compare un nom de dossier avec ce qu'a entré l'utilisateur
*/
public String comparaisonDossier(String dossier, String champ){
try{
/* Ici comment tu lui dit qu'il faut prendre la première partie de la clé */
StringTokenizer cle1 = new StringTokenizer(dossier,"_");
Vector tokens1 = new Vector();
while (cle1.hasMoreTokens()) {
tokens1.add(cle1.nextToken());
}
System.out.println("///CLE1/////" + tokens1.elementAt(0));
// ici on fait le test par rapport au premier token
System.out.println ("Champ moteur de recherche " + this.getChampRecherche());
if(champ.equals(tokens1.elementAt(0))){
System.out.println("============EGALES========");
return tokens1.elementAt(0).toString();
}
else{
System.out.println("============NON EGALES========");
return null;
}
}catch(Exception e){
System.out.println("ERREUR MOteurRecherche.java" + e.getMessage());
return null;
}
}
/**
* Comparaison des procedures
*/
public String comparaisonProcedure(String procedure){
try{
StringTokenizer cle1 = new StringTokenizer(procedure,"_");
Vector tokens1 = new Vector();
while (cle1.hasMoreTokens()) {
tokens1.add(cle1.nextToken());
}
System.out.println("///CLE1PROCEDURE/////" + tokens1.elementAt(0));
// ici on fait le test par rapport au premier token
System.out.println ("Champ moteur de recherche " + this.getChampRecherche());
if(champRecherche.equals(tokens1.elementAt(0))){
System.out.println("============EGALES========");
return tokens1.elementAt(0).toString();
}
else{
System.out.println("============NON EGALES========");
return null;
}
}catch(Exception e){
System.out.println("ERREUR MoteurRecherche.java" + e.getMessage());
return null;
}
}
public Vector recuperationDossiers(Connection cnx)throws SQLException{
Statement st = cnx.createStatement();
ResultSet rs = st.executeQuery("SELECT nom FROM dossier" );
MoteurRechercheForm mrForm = new MoteurRechercheForm();
// MoteurRecherche mr = new MoteurRecherche(mrForm.getChampRecherche());
// System.out.println("===============" + mrForm.getChampRecherche()+"==============");
// On itère sur le curseur résultat
System.out.println("Recuperation du resultat pour moteur de recherche");
while( rs.next() ){
// on recupère la clé du dossier
System.out.println("valeur de rs ");
String cleRechercheDossier = comparaisonDossier((rs.getString("nom")), champRecherche);
if(cleRechercheDossier != null){
System.out.println("rajout dans la liste des documents");
getListeDocumentsTrouves().add(rs.getString("nom"));
}
}
/** Affichage du contenu du vecteur listeDocumentsTrouves */
for(int i =0; i < getListeDocumentsTrouves().size();i++){
System.out.println("ELEMENT NUMERO " + i +getListeDocumentsTrouves().elementAt(i) );
}
// ResultSet rs2 = st.executeQuery("SELECT nom FROM procedure_t");
// System.out.println("Select pour peocedure");
// System.out.println("WHILE de comparaison procedure");
// while( rs2.next()){
// String cleRechercheProcedure = mr.comparaisonProcedure(rs2.getString("nom"));
// if(cleRechercheProcedure != null){
// listeDocumentsTrouves.add(cleRechercheProcedure);
// }
// }
rs.close();
// rs2.close();
st.close();
return getListeDocumentsTrouves();
}
public Vector getListeDocumentsTrouves() {
return listeDocumentsTrouves;
}
public void setListeDocumentsTrouves(Vector listeDocumentsTrouves) {
this.listeDocumentsTrouves = listeDocumentsTrouves;
}
} |
Partager