Statistics
| Revision:

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

History | View | Annotate | Download (4.99 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.GPEWriterHandler;
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 11171 2007-04-12 17:06:44Z jorpiell $
52
 * $Log$
53
 * Revision 1.5  2007-04-12 17:06:42  jorpiell
54
 * First GML writing tests
55
 *
56
 * Revision 1.4  2007/04/12 10:21:29  jorpiell
57
 * Add the getWriter() method
58
 *
59
 * Revision 1.3  2007/04/11 11:18:15  csanchez
60
 * Actualizacion protoripo libGPE
61
 *
62
 * Revision 1.2  2007/04/11 08:46:21  csanchez
63
 * Actualizacion protoripo libGPE
64
 *
65
 * Revision 1.1  2007/04/11 08:19:32  csanchez
66
 * actualizacion
67
 *
68
 *
69
 */
70
/**
71
 * @author Carlos S?nchez Peri??n (sanchez_carper@gva.es)
72
 */
73

    
74

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

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

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

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

    
182

    
183
        /**
184
         * @return the errorHandler
185
         */
186
        public GPEErrorHandler getErrorHandler() {
187
                return errorHandler;
188
        }
189
        
190

    
191
}