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

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

BO insertion données _ ajout code medias
clean

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