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
|
package packageTreatment;
import java.io.*;
import org.jdom2.*;
import org.jdom2.input.*;
import java.util.List;
import java.util.Iterator;
import java.util.StringTokenizer;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspWriter;
public class Rechercher
{
static org.jdom2.Document document;
static Element racine;
static String name;
public static void cherche(String parNom, String parPrenom, HttpServletRequest request,JspWriter out) throws ServletException, IOException
{
Document document = null ;
String file = "annuaire.xml" ;
SAXBuilder builder = new SAXBuilder();
try {
document = builder.build(new File(request.getServletContext().getRealPath(file)));
} catch (JDOMException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
racine = document.getRootElement();
List<Element> personne = racine.getChildren("personne");
Iterator<Element> i = personne.iterator();
out.write("<table border=\"1\">") ;
out.write("<caption> CONTACTS </caption>") ;
out.write("<tr>");
out.write("<th> prenom </th>");
out.write("<th> nom </th>");
out.write("<th> adresse </th>");
out.write("<th> email </th>");
out.write("<th> numFixe </th>");
out.write("<th> numPortable </th>");
out.write("<th> commentaire </th>");
out.write("</tr>");
while(i.hasNext())
{
Element courant = (Element)i.next();
String id = courant.getAttributeValue("id");
if(teste(parNom,parPrenom,id))
{
//string(courant.getChild("prenom").getText(),courant.getChild("nom").getText(),courant.getChild("adresse").getText(),courant.getChild("email").getText(),courant.getChild("numFixe").getText(),courant.getChild("numPortable").getText(),courant.getChild("commentaire").getText(),response);
out.write("<tr>");
out.write("<td>"+ courant.getChild("prenom").getText()+"</td>");
out.write("<td>"+ courant.getChild("nom").getText()+"</td>");
out.write("<td>"+ courant.getChild("adresse").getText()+"</td>");
out.write("<td>"+ courant.getChild("email").getText()+"</td>");
out.write("<td>"+ courant.getChild("numFixe").getText()+"</td>");
out.write("<td>"+ courant.getChild("numPortable").getText()+"</td>");
out.write("<td>"+ courant.getChild("commentaire").getText()+"</td>");
out.write("<tr>");
out.write("</table>");
}
}
}
static boolean teste (String nom, String prenom, String id)
{
String[] nomPrenom = new String[2];
int i=0;
boolean bool = false ;
StringTokenizer st = new StringTokenizer(id,"||");
while (st.hasMoreTokens())
{
nomPrenom[i] = st.nextToken();
i++;
}
if ( (nomPrenom[0].equals(prenom)) || (nomPrenom[1].equals(nom)) )
{
bool = true ;
}
return bool;
}
} |
Partager