1 | /** |
---|
2 | * Created on 26 Jan. 2007 |
---|
3 | */ |
---|
4 | |
---|
5 | /** |
---|
6 | * @author |
---|
7 | * |
---|
8 | * |
---|
9 | */ |
---|
10 | |
---|
11 | package integration.lecture_ecriture; |
---|
12 | |
---|
13 | import java.io.File; |
---|
14 | import java.io.IOException; |
---|
15 | import java.util.ArrayList; |
---|
16 | import jxl.Sheet; |
---|
17 | import jxl.Workbook; |
---|
18 | import jxl.WorkbookSettings; |
---|
19 | import jxl.read.biff.BiffException; |
---|
20 | import integration.utils.Constantes; |
---|
21 | |
---|
22 | public class LectureParametres { |
---|
23 | |
---|
24 | private ArrayList<String> numerosParam; |
---|
25 | private ArrayList<String> nomsParam; |
---|
26 | private ArrayList<String> codesMegapoliParam; |
---|
27 | private ArrayList<String> categoriesParam; |
---|
28 | private ArrayList<String> numsUnitesParam; |
---|
29 | private ArrayList<String> descriptionsParam; |
---|
30 | private ArrayList<String> nomsParamFromFile; |
---|
31 | |
---|
32 | public LectureParametres() { |
---|
33 | } |
---|
34 | |
---|
35 | public void lireFichier() { |
---|
36 | // Etape d'accés au chemin du modéle xml é amanipuler |
---|
37 | String nomFichierParam = Constantes.cheminListes + "/" + Constantes.nomListeParametres; |
---|
38 | File fichier = new File(nomFichierParam); |
---|
39 | if (fichier.exists()) { |
---|
40 | Workbook workbook = null; |
---|
41 | try { |
---|
42 | WorkbookSettings ws = new WorkbookSettings(); |
---|
43 | ws.setEncoding(Constantes.encodageDefaut); |
---|
44 | workbook = Workbook.getWorkbook(fichier, ws); |
---|
45 | } catch (BiffException e) { |
---|
46 | e.printStackTrace(); |
---|
47 | } catch (IOException e) { |
---|
48 | e.printStackTrace(); |
---|
49 | } |
---|
50 | // Etape ou l'on récupére les données de la 1ére page du classeur |
---|
51 | Sheet sheet = workbook.getSheet(0); |
---|
52 | |
---|
53 | // Initialisation des listes. |
---|
54 | numerosParam = new ArrayList<String>(); |
---|
55 | nomsParam = new ArrayList<String>(); |
---|
56 | codesMegapoliParam = new ArrayList<String>(); |
---|
57 | numsUnitesParam = new ArrayList<String>(); |
---|
58 | //descriptionsParam = new ArrayList<String>(); |
---|
59 | categoriesParam = new ArrayList<String>(); |
---|
60 | nomsParamFromFile = new ArrayList<String>(); |
---|
61 | // Etape de lecture des cellules |
---|
62 | int nbParams = sheet.getRows() - 1;//Constantes.nbParametres |
---|
63 | for (int numParam = 0; numParam < nbParams; numParam++) { |
---|
64 | numerosParam.add(sheet.getCell(0, numParam + 1).getContents()); |
---|
65 | nomsParam.add(sheet.getCell(1, numParam + 1).getContents()); |
---|
66 | codesMegapoliParam.add(sheet.getCell(2, numParam + 1).getContents()); |
---|
67 | categoriesParam.add(sheet.getCell(3, numParam + 1).getContents()); |
---|
68 | numsUnitesParam.add(sheet.getCell(4, numParam + 1).getContents()); |
---|
69 | nomsParamFromFile.add(sheet.getCell(5, numParam + 1).getContents()); |
---|
70 | //descriptionsParam.add(sheet.getCell(4, numParam + 1).getContents()); |
---|
71 | } |
---|
72 | // Etape de fermeture du flux |
---|
73 | workbook.close(); |
---|
74 | } else { |
---|
75 | EcritureLog.ecrire( |
---|
76 | "Fichier " + fichier.getName() + " non trouvé !", "err"); |
---|
77 | |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | public ArrayList<String> getNumerosParam() { |
---|
82 | return numerosParam; |
---|
83 | } |
---|
84 | public ArrayList<String> getNomsParam() { |
---|
85 | return nomsParam; |
---|
86 | } |
---|
87 | public ArrayList<String> getCodesMegapoliParam() { |
---|
88 | return codesMegapoliParam; |
---|
89 | } |
---|
90 | public ArrayList<String> getNumsUnitesParam() { |
---|
91 | return numsUnitesParam; |
---|
92 | } |
---|
93 | public ArrayList<String> getDescriptionsParam() { |
---|
94 | return descriptionsParam; |
---|
95 | } |
---|
96 | public ArrayList<String> getCategoriesParam() { |
---|
97 | return categoriesParam; |
---|
98 | } |
---|
99 | |
---|
100 | public ArrayList<String> getNomsParamFromFile() { |
---|
101 | return nomsParamFromFile; |
---|
102 | } |
---|
103 | |
---|
104 | public int getIndice(int numero) { |
---|
105 | int indice = -1; |
---|
106 | int numeroCourant; |
---|
107 | for (int indiceListe = 0; indiceListe < numerosParam.size(); indiceListe++) { |
---|
108 | numeroCourant = Integer.parseInt((String)numerosParam.get(indiceListe)); |
---|
109 | if (numeroCourant == numero) { |
---|
110 | indice = indiceListe; |
---|
111 | return indice; |
---|
112 | } |
---|
113 | } |
---|
114 | return indice; |
---|
115 | } |
---|
116 | } |
---|