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

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