Statistics
| Revision:

root / trunk / libraries / libGPE / src / org / gvsig / gpe / GPEParser.java @ 11156

History | View | Annotate | Download (4.92 KB)

1
package org.gvsig.gpe;
2
import java.io.File;
3
import java.io.FileNotFoundException;
4
import java.io.IOException;
5

    
6
import org.gvsig.gpe.writer.IGPEWriterHandler;
7

    
8

    
9
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
10
 *
11
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
12
 *
13
 * This program is free software; you can redistribute it and/or
14
 * modify it under the terms of the GNU General Public License
15
 * as published by the Free Software Foundation; either version 2
16
 * of the License, or (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
26
 *
27
 * For more information, contact:
28
 *
29
 *  Generalitat Valenciana
30
 *   Conselleria d'Infraestructures i Transport
31
 *   Av. Blasco Ib??ez, 50
32
 *   46010 VALENCIA
33
 *   SPAIN
34
 *
35
 *      +34 963862235
36
 *   gvsig@gva.es
37
 *      www.gvsig.gva.es
38
 *
39
 *    or
40
 *
41
 *   IVER T.I. S.A
42
 *   Salamanca 50
43
 *   46005 Valencia
44
 *   Spain
45
 *
46
 *   +34 963163400
47
 *   dac@iver.es
48
 */
49
/* CVS MESSAGES:
50
 *
51
 * $Id: GPEParser.java 11156 2007-04-12 10:21:29Z jorpiell $
52
 * $Log$
53
 * Revision 1.4  2007-04-12 10:21:29  jorpiell
54
 * Add the getWriter() method
55
 *
56
 * Revision 1.3  2007/04/11 11:18:15  csanchez
57
 * Actualizacion protoripo libGPE
58
 *
59
 * Revision 1.2  2007/04/11 08:46:21  csanchez
60
 * Actualizacion protoripo libGPE
61
 *
62
 * Revision 1.1  2007/04/11 08:19:32  csanchez
63
 * actualizacion
64
 *
65
 *
66
 */
67
/**
68
 * @author Carlos S?nchez Peri??n (sanchez_carper@gva.es)
69
 */
70

    
71

    
72
public abstract class GPEParser {
73
        private GPEErrorHandler errorHandler;
74
        private GPEContentHandler contentHandler;
75
        private File parserFile = null;        
76
        private Object prueba;
77
        
78
        /** 
79
         * 
80
         * AQUI SE IMPLEMENTA LA BASE PARA PODER PARSEAR CUALQUIER FICHERO:
81
         * -COMPROBAR SI EXISTE
82
         * -COMPROBAR CODIFICACI?N DEL XML
83
         * -ABRIR EN MODO LECTURA CON LA CODIFICACI?N CORRECTA
84
         * -CREAR EL PARSER DE XML ?"XSOM"?
85
         * -DETECTAR FORMATO FICHERO Y VERSI?N ?"EST? REGISTRADO"?
86
         * -SI EXISTE, LLAMADA AL PARSER DEL FORMATO CONCRETO
87
         *
88
         **/
89
        public GPEParser(GPEContentHandler contents, GPEErrorHandler errors){
90
                this.contentHandler = contents;
91
                this.errorHandler=errors;
92
        }
93
        
94

    
95
        public void parse(File file) throws Exception{
96
                
97
//                /***** para lectura en modo texto ****/
98
//                GPEXMLReader.open();
99
//                FileReader reader = null;       
100
//                try {
101
//                        reader = new FileReader(this.parserFile);
102
//                } catch (FileNotFoundException e) {
103
//                        // TODO llamada a ??GPEErrorHandler?? para tratar la excepci?n o lanzamos desde aqu?
104
//                        // Fichero no existe.
105
//                }
106
//                BufferedReader br = new BufferedReader(reader);
107
//                char[] buffer = new char[100];
108
//                try {
109
//                        br.read(buffer);
110
//                } catch (IOException e) {
111
//                        // TODO llamada a ??GPEErrorHandler?? para tratar la excepci?n o lanzamos desde aqu?
112
//                        // Error de lectura del buffer
113
//                }
114
//                StringBuffer st = new StringBuffer(new String(buffer));
115
//                
116
//                // We find the encoding at the begining of the file
117
//                
118
//                String searchText = "encoding=\"";
119
//                int index = st.indexOf(searchText);
120
//
121
//                // If it find the encoding, it takes the new encoding, else it takes the default encoding "UTF-8"
122
//                if (index>-1) { 
123
//                        st.delete(0, index+searchText.length());
124
//                        encoding = st.substring(0, st.indexOf("\""));
125
//                }
126
//                
127
//                // make GML parser with the good enconding
128
//                XMLSchemaParser parser = new XMLSchemaParser();
129
//                
130
//                // setImput(file,encoding): it sets the encoding to read with the KXML parser                
131
//                try {
132
//                        parser.setInput(new FileInputStream(m_File), encoding);
133
//                } catch (FileNotFoundException e) {
134
//                        // TODO Auto-generated catch block
135
//                        throw new GMLException(m_File.getName(),e);
136
//                } catch (XmlPullParserException e) {
137
//                        // TODO Auto-generated catch block
138
//                        throw new GMLException(m_File.getName(),e);
139
//                }
140
//                return parser;
141

    
142
        }
143
        
144
        /**
145
         * Return if the driver can open the file
146
         * @param file
147
         * File to open
148
         * @return
149
         * True if the driver is able to open it
150
         */
151
        public abstract boolean accept(File file);
152

    
153
        /**
154
         * Return an array with all the formats that the driver
155
         * is able to read/write
156
         * @return
157
         */
158
        public abstract String[] getFormats();
159
        
160
        /**
161
         * Gets the writer that will be used for the consumer
162
         * application to create the outputformat
163
         * @param format
164
         * Format to create the file
165
         * @param file
166
         * Output file
167
         * @throws FileNotFoundException
168
         * If the file doesn't exist
169
         */
170
        public abstract IGPEWriterHandler getWriter(String format,File file) throws IOException ;
171
        
172
        /**
173
         * @return the contentHandler
174
         */
175
        public GPEContentHandler getContentHandler() {
176
                return contentHandler;
177
        }
178

    
179

    
180
        /**
181
         * @return the errorHandler
182
         */
183
        public GPEErrorHandler getErrorHandler() {
184
                return errorHandler;
185
        }
186
        
187

    
188
}