1 | /* |
---|
2 | * Created on 29 Jan. 2007 |
---|
3 | */ |
---|
4 | /** |
---|
5 | * @author |
---|
6 | * |
---|
7 | * |
---|
8 | */ |
---|
9 | package com.medias.integration.lecture_ecriture; |
---|
10 | |
---|
11 | import com.medias.Constantes; |
---|
12 | import jxl.Sheet; |
---|
13 | import jxl.Workbook; |
---|
14 | import jxl.WorkbookSettings; |
---|
15 | import jxl.read.biff.BiffException; |
---|
16 | |
---|
17 | import java.io.File; |
---|
18 | import java.io.IOException; |
---|
19 | import java.util.ArrayList; |
---|
20 | |
---|
21 | public class LecturePlateformes { |
---|
22 | public LecturePlateformes() { |
---|
23 | } |
---|
24 | |
---|
25 | public void lireFichier() { |
---|
26 | String nomFichierPlat = Constantes.cheminListes + "/" + Constantes.nomListePlateformes; |
---|
27 | File fichier = new File(nomFichierPlat); |
---|
28 | if (fichier.exists()) { |
---|
29 | // Etape ou l' on crée le Workbook |
---|
30 | Workbook workbook = null; |
---|
31 | try { |
---|
32 | WorkbookSettings ws = new WorkbookSettings(); |
---|
33 | ws.setEncoding(Constantes.encodageDefaut); |
---|
34 | workbook = Workbook.getWorkbook(fichier, ws); |
---|
35 | } catch (BiffException e) { |
---|
36 | e.printStackTrace(); |
---|
37 | } catch (IOException e) { |
---|
38 | e.printStackTrace(); |
---|
39 | } |
---|
40 | // Etape ou l'on récupére les données de la 1ére page du classeur |
---|
41 | Sheet sheet = workbook.getSheet(0); |
---|
42 | |
---|
43 | // initialisation des listes. |
---|
44 | numerosPlat = new ArrayList<String>(); |
---|
45 | nomsPlat = new ArrayList<String>(); |
---|
46 | typesPlat = new ArrayList<String>(); |
---|
47 | descriptionsPlat = new ArrayList<String>(); |
---|
48 | latMinsPlat = new ArrayList<String>(); |
---|
49 | latMaxsPlat = new ArrayList<String>(); |
---|
50 | longMinsPlat = new ArrayList<String>(); |
---|
51 | longMaxsPlat = new ArrayList<String>(); |
---|
52 | altMinsPlat = new ArrayList<String>(); |
---|
53 | altMaxsPlat = new ArrayList<String>(); |
---|
54 | //hautSolMinsPlat = new ArrayList<String>(); |
---|
55 | //hautSolMaxsPlat = new ArrayList<String>(); |
---|
56 | numsCaptPLat = new ArrayList<ArrayList<String>>(); |
---|
57 | |
---|
58 | |
---|
59 | nbPlateformes = sheet.getRows() - 1;//Constantes.nbPlateformes; |
---|
60 | String numsCapteurs, numCapteur, captDer; |
---|
61 | int captCourant; |
---|
62 | ArrayList<String> numsCapteursLigne; |
---|
63 | // Etape de lecture des cellules |
---|
64 | for (int numPlat = 0; numPlat < nbPlateformes; numPlat++) { |
---|
65 | numerosPlat.add(sheet.getCell(0, numPlat + 1).getContents()); |
---|
66 | nomsPlat.add(sheet.getCell(1, numPlat + 1).getContents()); |
---|
67 | descriptionsPlat.add(sheet.getCell(2, numPlat + 1).getContents()); |
---|
68 | typesPlat.add(sheet.getCell(3, numPlat + 1).getContents()); |
---|
69 | latMinsPlat.add(sheet.getCell(4, numPlat + 1).getContents().replaceAll(",", ".")); |
---|
70 | latMaxsPlat.add(sheet.getCell(5, numPlat + 1).getContents().replaceAll(",", ".")); |
---|
71 | longMinsPlat.add(sheet.getCell(6, numPlat + 1).getContents().replaceAll(",", ".")); |
---|
72 | longMaxsPlat.add(sheet.getCell(7, numPlat + 1).getContents().replaceAll(",", ".")); |
---|
73 | altMinsPlat.add(sheet.getCell(8, numPlat + 1).getContents().replaceAll(",", ".")); |
---|
74 | altMaxsPlat.add(sheet.getCell(9, numPlat + 1).getContents().replaceAll(",", ".")); |
---|
75 | //hautSolMinsPlat.add(sheet.getCell(10, numPlat + 1).getContents()); |
---|
76 | //hautSolMaxsPlat.add(sheet.getCell(11, numPlat + 1).getContents()); |
---|
77 | |
---|
78 | numsCapteurs = sheet.getCell(10, numPlat + 1).getContents(); |
---|
79 | numsCapteursLigne = new ArrayList<String>(); |
---|
80 | while (numsCapteurs.indexOf(Constantes.delimiteurXLS) != -1) { |
---|
81 | // On récupére la 1ére donnée de la mesure avant le délimiteur |
---|
82 | numCapteur = numsCapteurs.substring(0, numsCapteurs.indexOf(Constantes.delimiteurXLS)).trim(); |
---|
83 | // On récupére la mesure restante aprés le délimiteur |
---|
84 | numsCapteurs = numsCapteurs.substring(numsCapteurs.indexOf(Constantes.delimiteurXLS)+1).trim(); |
---|
85 | if (numCapteur.equals("..")) { |
---|
86 | if (numsCapteurs.indexOf(Constantes.delimiteurXLS) != -1) |
---|
87 | captDer = numsCapteurs.substring(0, numsCapteurs.indexOf(Constantes.delimiteurXLS)).trim(); |
---|
88 | else |
---|
89 | captDer = numsCapteurs.trim(); |
---|
90 | captCourant = Integer.parseInt(numsCapteursLigne.get(numsCapteursLigne.size()-1)); |
---|
91 | while (captCourant < Integer.parseInt(captDer)-1) { |
---|
92 | captCourant++; |
---|
93 | numsCapteursLigne.add(String.valueOf(captCourant)); |
---|
94 | } |
---|
95 | } else { |
---|
96 | numsCapteursLigne.add(numCapteur); |
---|
97 | } |
---|
98 | } |
---|
99 | numCapteur = numsCapteurs; |
---|
100 | numsCapteursLigne.add(numsCapteurs); |
---|
101 | numsCaptPLat.add(numsCapteursLigne); |
---|
102 | // Etape de fermeture du flux |
---|
103 | } |
---|
104 | workbook.close(); |
---|
105 | } |
---|
106 | } |
---|
107 | |
---|
108 | public int getIndice(int numero) { |
---|
109 | int indice = -1; |
---|
110 | int numeroCourant; |
---|
111 | for (int indiceListe = 0; indiceListe < numerosPlat.size(); indiceListe++) { |
---|
112 | numeroCourant = Integer.parseInt((String)numerosPlat.get(indiceListe)); |
---|
113 | if (numeroCourant == numero) { |
---|
114 | indice = indiceListe; |
---|
115 | return indice; |
---|
116 | } |
---|
117 | } |
---|
118 | return indice; |
---|
119 | } |
---|
120 | |
---|
121 | public ArrayList<String> getNumerosPlat() { |
---|
122 | return numerosPlat; |
---|
123 | } |
---|
124 | |
---|
125 | public ArrayList<String> getNomsPLat() { |
---|
126 | return nomsPlat; |
---|
127 | } |
---|
128 | |
---|
129 | public ArrayList<String> getTypesPlat() { |
---|
130 | return typesPlat; |
---|
131 | } |
---|
132 | |
---|
133 | public ArrayList<String> getDescriptionsPLat() { |
---|
134 | return descriptionsPlat; |
---|
135 | } |
---|
136 | |
---|
137 | public ArrayList<String> getLatMinsPLat() { |
---|
138 | return latMinsPlat; |
---|
139 | } |
---|
140 | |
---|
141 | public ArrayList<String> getLatMaxsPLat() { |
---|
142 | return latMaxsPlat; |
---|
143 | } |
---|
144 | |
---|
145 | public ArrayList<String> getLongMinsPLat() { |
---|
146 | return longMinsPlat; |
---|
147 | } |
---|
148 | |
---|
149 | public ArrayList<String> getLongMaxsPLat() { |
---|
150 | return longMaxsPlat; |
---|
151 | } |
---|
152 | |
---|
153 | public ArrayList<String> getAltMinsPLat() { |
---|
154 | return altMinsPlat; |
---|
155 | } |
---|
156 | |
---|
157 | public ArrayList<String> getAltMaxsPLat() { |
---|
158 | return altMaxsPlat; |
---|
159 | } |
---|
160 | |
---|
161 | public ArrayList<String> getHautSolMinsPlat() { |
---|
162 | return hautSolMinsPlat; |
---|
163 | } |
---|
164 | |
---|
165 | public ArrayList<String> getHautSolMaxsPlat() { |
---|
166 | return hautSolMaxsPlat; |
---|
167 | } |
---|
168 | |
---|
169 | public ArrayList<ArrayList<String>> getNumsCaptPlat() { |
---|
170 | return numsCaptPLat; |
---|
171 | } |
---|
172 | |
---|
173 | ArrayList<ArrayList<String>> numsCaptPLat; |
---|
174 | private ArrayList<String> numerosPlat; |
---|
175 | |
---|
176 | private ArrayList<String> nomsPlat; |
---|
177 | |
---|
178 | private ArrayList<String> typesPlat; |
---|
179 | |
---|
180 | private ArrayList<String> descriptionsPlat; |
---|
181 | |
---|
182 | private ArrayList<String> latMinsPlat; |
---|
183 | |
---|
184 | private ArrayList<String> latMaxsPlat; |
---|
185 | |
---|
186 | private ArrayList<String> longMinsPlat; |
---|
187 | |
---|
188 | private ArrayList<String> longMaxsPlat; |
---|
189 | |
---|
190 | private ArrayList<String> altMinsPlat; |
---|
191 | |
---|
192 | private ArrayList<String> altMaxsPlat; |
---|
193 | |
---|
194 | private ArrayList<String> hautSolMinsPlat; |
---|
195 | |
---|
196 | private ArrayList<String> hautSolMaxsPlat; |
---|
197 | |
---|
198 | private int nbPlateformes; |
---|
199 | } |
---|