source: ether_megapoli/trunk/service/implementation/com/medias/integration/lecture_ecriture/LectureCapteurs.java @ 482

Last change on this file since 482 was 482, checked in by vmipsl, 12 years ago

BO insertion données _ insertion code medias package insertion

  • Property svn:executable set to *
File size: 5.2 KB
Line 
1/*
2 * Created on 29 Jan. 2007
3 */
4/**
5 * @author
6 *
7 *
8 */
9package integration.lecture_ecriture;
10
11import integration.utils.Constantes;
12
13import java.io.File;
14import java.io.IOException;
15import java.util.ArrayList;
16
17import jxl.Sheet;
18import jxl.Workbook;
19import jxl.WorkbookSettings;
20import jxl.read.biff.BiffException;
21
22public class LectureCapteurs {
23        private ArrayList<String> numerosCapt;
24        private ArrayList<String> typesCapt;
25        private ArrayList<String> fabriquantsCapt;
26        private ArrayList<String> modelesCapt;
27        private ArrayList<String> numsSeriesCapt;
28        private ArrayList<String> etalonnagesCapt;
29        private ArrayList<ArrayList<String>> numsParametresCapt;
30        private ArrayList<String> nomsCaptFromFile;
31        private ArrayList<String> descriptionsCapt;
32        private ArrayList<String> descriptionsTypeCapt;
33
34        public LectureCapteurs() {
35        }
36
37        public void lireFichier() {
38                String nomFichierCapt = Constantes.cheminListes + "/" + Constantes.nomListeCapteurs;
39                File fichier = new File(nomFichierCapt);
40                if (fichier.exists()) {
41                        // Etape ou l' on crée le Workbook
42                        Workbook workbook = null;
43                        try {
44                                WorkbookSettings ws = new WorkbookSettings();
45                                ws.setEncoding(Constantes.encodageDefaut);
46                                workbook = Workbook.getWorkbook(fichier, ws);
47                        } catch (BiffException e) {
48                                e.printStackTrace();
49                        } catch (IOException e) {
50                                e.printStackTrace();
51                        }
52                        // Etape ou l'on récupére les données de la 1ére page du classeur
53                        Sheet sheet = workbook.getSheet(0);
54                        // Etape d'initialisation des listes.
55                        numerosCapt = new ArrayList<String>();
56                        typesCapt = new ArrayList<String>();
57                        fabriquantsCapt = new ArrayList<String>();
58                        modelesCapt = new ArrayList<String>();
59                        numsSeriesCapt = new ArrayList<String>();
60                        etalonnagesCapt = new ArrayList<String>();
61                        nomsCaptFromFile = new ArrayList<String>();
62//                      descriptionsCapt = new ArrayList<String>();
63//                      descriptionsTypeCapt = new ArrayList<String>();
64                        numsParametresCapt = new ArrayList<ArrayList<String>>();
65
66                        int nbCapteurs = sheet.getRows() - 1;//Constantes.nbCapteurs;
67               
68                        String numsParametres, numParametre, paramDer;
69                        int paramCourant;
70                        ArrayList<String> numsParametresLigne;
71                        // Etape de lecture des cellules
72                        for (int numCapt = 0; numCapt < nbCapteurs; numCapt++) {
73                                numerosCapt.add(sheet.getCell(0, numCapt + 1).getContents());
74                                typesCapt.add(sheet.getCell(1, numCapt + 1).getContents());
75                                fabriquantsCapt.add(sheet.getCell(2, numCapt + 1).getContents());
76                                modelesCapt.add(sheet.getCell(3, numCapt + 1).getContents());
77                                numsSeriesCapt.add(sheet.getCell(4, numCapt + 1).getContents());
78                                etalonnagesCapt.add(sheet.getCell(5, numCapt + 1).getContents());
79                                //descriptionsCapt.add(sheet.getCell(4, numCapt + 1).getContents());
80                                //descriptionsTypeCapt.add(sheet.getCell(6, numCapt + 1).getContents());
81                                numsParametres = sheet.getCell(6, numCapt + 1).getContents();
82                                numsParametresLigne = new ArrayList<String>();
83                                while (numsParametres.indexOf(Constantes.delimiteurXLS) != -1) {
84                                        // On récupére la 1ére donnée de la mesure avant le délimiteur
85                                        numParametre = numsParametres.substring(0, numsParametres.indexOf(Constantes.delimiteurXLS)).trim();
86                                        // On récupére la mesure restante aprés le délimiteur
87                                        numsParametres = numsParametres.substring(numsParametres.indexOf(Constantes.delimiteurXLS)+1).trim();
88                                        if (numParametre.equals("..")) {
89                                                if (numsParametres.indexOf(Constantes.delimiteurXLS) != -1)
90                                                        paramDer = numsParametres.substring(0, numsParametres.indexOf(Constantes.delimiteurXLS)).trim();
91                                                else
92                                                        paramDer = numsParametres.trim();
93                                                paramCourant = Integer.parseInt(numsParametresLigne.get(numsParametresLigne.size()-1));
94                                                while (paramCourant < Integer.parseInt(paramDer)-1) {
95                                                        paramCourant++;
96                                                        numsParametresLigne.add(String.valueOf(paramCourant));
97                                                }
98                                        } else {
99                                                numsParametresLigne.add(numParametre);
100                                        }
101                                }
102                                numParametre = numsParametres;
103                                numsParametresLigne.add(numParametre);
104                                numsParametresCapt.add(numsParametresLigne);
105                                nomsCaptFromFile.add(sheet.getCell(7, numCapt + 1).getContents());
106                        }
107                        // Etape de fermeture du flux
108                        workbook.close();
109                }
110        }
111
112        public ArrayList<String> getNumerosCapt() {
113                return numerosCapt;
114        }
115
116        public ArrayList<String> getDescriptionsCapt() {
117                return descriptionsCapt;
118        }
119
120        public ArrayList<String> getEtalonnagesCapt() {
121                return etalonnagesCapt;
122        }
123
124        public ArrayList<String> getFabriquantsCapt() {
125                return fabriquantsCapt;
126        }
127
128        public ArrayList<String> getModelesCapt() {
129                return modelesCapt;
130        }
131
132        public ArrayList<String> getNumsSeriesCapt() {
133                return numsSeriesCapt;
134        }
135       
136        public ArrayList<ArrayList<String>> getNumsParametresCapt() {
137                return numsParametresCapt;
138        }
139
140        public ArrayList<String> getTypesCapt() {
141                return typesCapt;
142        }
143
144        public ArrayList<String> getDescriptionsTypeCapt() {
145                return descriptionsTypeCapt;
146        }
147
148        public ArrayList<String> getNomsCaptFromFile() {
149                return nomsCaptFromFile;
150        }
151
152        public int getIndice(int numero) {
153                int indice = -1;
154                int numeroCourant;
155                for (int indiceListe = 0; indiceListe < numerosCapt.size(); indiceListe++) {
156                        numeroCourant = Integer.parseInt((String)numerosCapt.get(indiceListe));
157                        if (numeroCourant == numero) {
158                                indice = indiceListe;
159                                return indice;
160                        }
161                }
162                return indice;
163        }
164}
Note: See TracBrowser for help on using the repository browser.