1 | |
---|
2 | /* |
---|
3 | * Created on 29 Jan. 2007 |
---|
4 | */ |
---|
5 | /** |
---|
6 | * @author |
---|
7 | * |
---|
8 | * |
---|
9 | */ |
---|
10 | package com.medias.integration.lecture_ecriture; |
---|
11 | |
---|
12 | import com.medias.Constantes; |
---|
13 | import jxl.Sheet; |
---|
14 | import jxl.Workbook; |
---|
15 | import jxl.WorkbookSettings; |
---|
16 | import jxl.read.biff.BiffException; |
---|
17 | |
---|
18 | import java.io.File; |
---|
19 | import java.io.IOException; |
---|
20 | import java.util.ArrayList; |
---|
21 | |
---|
22 | public class LectureOrganismes { |
---|
23 | public LectureOrganismes() { |
---|
24 | } |
---|
25 | |
---|
26 | public void lireFichier() { |
---|
27 | String nomFichierOrg = Constantes.cheminListes + "/" + Constantes.nomListeOrganismes; |
---|
28 | File fichier = new File(nomFichierOrg); |
---|
29 | if (fichier.exists()) { |
---|
30 | // Etape ou l' on crée le Workbook |
---|
31 | Workbook workbook = null; |
---|
32 | try { |
---|
33 | WorkbookSettings ws = new WorkbookSettings(); |
---|
34 | //ws.setEncoding("OS2-850");//ISO-8859-1 |
---|
35 | ws.setEncoding(Constantes.encodageDefaut); |
---|
36 | workbook = Workbook.getWorkbook(fichier, ws); |
---|
37 | } catch (BiffException e) { |
---|
38 | e.printStackTrace(); |
---|
39 | } catch (IOException e) { |
---|
40 | e.printStackTrace(); |
---|
41 | } |
---|
42 | // Etape ou l'on récupére les données de la 1ére page du classeur |
---|
43 | Sheet sheet = workbook.getSheet(0); |
---|
44 | |
---|
45 | //initialisation des listes. |
---|
46 | numerosOrg = new ArrayList<String>(); |
---|
47 | nomsOrg = new ArrayList<String>(); |
---|
48 | descriptionsOrg = new ArrayList<String>(); |
---|
49 | mailsOrg = new ArrayList<String>(); |
---|
50 | urlsOrg = new ArrayList<String>(); |
---|
51 | ruesOrg = new ArrayList<String>(); |
---|
52 | codesPostalsOrg = new ArrayList<String>(); |
---|
53 | villesOrg = new ArrayList<String>(); |
---|
54 | paysOrg = new ArrayList<String>(); |
---|
55 | int nbOrganismes = sheet.getRows() - 1;//Constantes.nbOrganismes; |
---|
56 | // Etape de lecture des cellules |
---|
57 | for (int numOrg = 0; numOrg < nbOrganismes; numOrg++) { |
---|
58 | numerosOrg.add(sheet.getCell(0, numOrg + 1).getContents()); |
---|
59 | nomsOrg.add(sheet.getCell(1, numOrg + 1).getContents()); |
---|
60 | descriptionsOrg.add(sheet.getCell(2, numOrg + 1).getContents()); |
---|
61 | mailsOrg.add(sheet.getCell(3, numOrg + 1).getContents()); |
---|
62 | urlsOrg.add(sheet.getCell(4, numOrg + 1).getContents()); |
---|
63 | ruesOrg.add(sheet.getCell(5, numOrg + 1).getContents()); |
---|
64 | codesPostalsOrg.add(sheet.getCell(6, numOrg + 1).getContents()); |
---|
65 | villesOrg.add(sheet.getCell(7, numOrg + 1).getContents()); |
---|
66 | paysOrg.add(sheet.getCell(8, numOrg + 1).getContents()); |
---|
67 | } |
---|
68 | // Etape de fermeture du flux |
---|
69 | workbook.close(); |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | public int getIndice(int numero) { |
---|
74 | int indice = -1; |
---|
75 | int numeroCourant; |
---|
76 | for (int indiceListe = 0; indiceListe < numerosOrg.size(); indiceListe++) { |
---|
77 | numeroCourant = Integer.parseInt((String)numerosOrg.get(indiceListe)); |
---|
78 | if (numeroCourant == numero) { |
---|
79 | indice = indiceListe; |
---|
80 | return indice; |
---|
81 | } |
---|
82 | } |
---|
83 | return indice; |
---|
84 | } |
---|
85 | |
---|
86 | public ArrayList<String> getNumerosOrg() { |
---|
87 | return numerosOrg; |
---|
88 | } |
---|
89 | |
---|
90 | public ArrayList<String> getNomsOrg() { |
---|
91 | return nomsOrg; |
---|
92 | } |
---|
93 | |
---|
94 | public ArrayList<String> getMailsOrg() { |
---|
95 | return mailsOrg; |
---|
96 | } |
---|
97 | |
---|
98 | public ArrayList<String> getDescriptionsOrg() { |
---|
99 | return descriptionsOrg; |
---|
100 | } |
---|
101 | |
---|
102 | public ArrayList<String> getRuesOrg() { |
---|
103 | return ruesOrg; |
---|
104 | } |
---|
105 | |
---|
106 | public ArrayList<String> getCodesPostalsOrg() { |
---|
107 | return codesPostalsOrg; |
---|
108 | } |
---|
109 | |
---|
110 | public ArrayList<String> getVillesOrg() { |
---|
111 | return villesOrg; |
---|
112 | } |
---|
113 | |
---|
114 | public ArrayList<String> getPaysOrg() { |
---|
115 | return paysOrg; |
---|
116 | } |
---|
117 | |
---|
118 | public ArrayList<String> getUrlsOrg() { |
---|
119 | return urlsOrg; |
---|
120 | } |
---|
121 | |
---|
122 | private ArrayList<String> numerosOrg; |
---|
123 | private ArrayList<String> nomsOrg; |
---|
124 | private ArrayList<String> mailsOrg; |
---|
125 | private ArrayList<String> descriptionsOrg; |
---|
126 | private ArrayList<String> ruesOrg; |
---|
127 | private ArrayList<String> codesPostalsOrg; |
---|
128 | private ArrayList<String> villesOrg; |
---|
129 | private ArrayList<String> paysOrg; |
---|
130 | private ArrayList<String> urlsOrg; |
---|
131 | } |
---|