| 12
 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
 
 |  
package mkrss;
 
import java.io.* ;
import org.w3c.dom.*;
 
 
public class Main {
 
 
    public Main() {
    }
 
    /**
     * @param args the command line arguments
     */
       public static void main(String[] args) throws Exception {
 
       String saisie;                     //variable de saisie contenant l'url du flux rss.
       String rep="OK";
       int [] lus;                        //tableau contenant les indices d'articles consultés.
       MkTree rssvct = new MkTree();     //Déclaration d'un tableau.
       MkItem  anode = new MkItem();     //Déclaration d'un élement contenant toutes les infos concernant un titre.
       String atitre = "";                //variablede travail.
       String adescription = "";        //variable de travail.
       String alink ="";                //variable de travail.
 
       OutilsIO  monoutilIO = new OutilsIO();
       OutilsDOM monoutil = new OutilsDOM();
 
       //gestion d'un fichier.
       DataOutputStream outlistesites = monoutilIO.OpenFile("listesites.log");
       //regarder si le site a déjà était visité.
       outlistesites.close ();
 
 
       BufferedReader entreeClavier = new BufferedReader(
               new InputStreamReader(System.in));
 
 
       while (! rep.equals ("fin")){
 
           System.out.println ("Saisissez une url :");
           saisie = entreeClavier.readLine();
           System.out.println ("Merci !");
           //System.out.println ("Vous avez demandé à récupérer le flux rss: ");
           //System.out.println (saisie);
 
 
 
           InputStream ismain = monoutil.OuvrirConnexion(saisie);
 
           Document envfabricdoc = monoutil.CreerFabriqueDocument (ismain);
 
           /* Parcours de l'arbre et extraction des informations */;
 
               NodeList nlitem = envfabricdoc.getElementsByTagName("item");
 
               for (int i=0 ; i<nlitem.getLength(); i++)
               {
 
                   Element item = (Element)nlitem.item(i);
 
 
                   /* Affichage des titres et des articles        */
                   /* et remplissage au fur et à mesure du vector */
 
                   for (Node child = item.getFirstChild(); child!=null ; child = child.getNextSibling())  
                   {
                       if (child.getNodeType() == Node.ELEMENT_NODE && ((Element)child).getTagName().equals("title"))
                       {
                           atitre = child.getTextContent ();
                           System.out.println(i+1 + "\t" + atitre);
                       }
                       else if  (child.getNodeType() == Node.ELEMENT_NODE && ((Element)child).getTagName().equals("description"))
                       { 
                           adescription = child.getTextContent();   
                           //System.out.println("\t\t" + adescription);
                       }
                       else if ( child.getNodeType() == Node.ELEMENT_NODE && ((Element)child).getTagName().equals("link"))  
                           { 
                               alink = child.getTextContent();
                               //System.out.println("\t\t" + alink);
                           }
 
               } //fin de for
 
               //initialisation d'un élément à ajouter au vecteur.   
               anode.MkItem(saisie, atitre, adescription,alink);
 
 
          -->  rssvct.unoeud.add(anode);
 
           }//fin de for
 
 
           System.out.println ("Voulez-vous continuer? Si non, taper fin. ");
           rep = entreeClavier.readLine();
           System.out.println (rep);
 
       }//Fin de while
 
 
       //affichage de la taille de la liste
       //System.out.println( rssvct.unoeud.size());
 
 
 
       System.out.println ("FIN DU PROGRAMME");
 
 
    }//fin de méthode Main
 
}//fin de la classe Main | 
Partager