Revision 11239
trunk/libraries/libGPE-GML/src-test/testParserGML.java | ||
---|---|---|
1 |
import java.io.File; |
|
2 |
import java.lang.reflect.InvocationTargetException; |
|
3 |
|
|
4 |
import org.gvsig.gpe.GPEContentHandler; |
|
5 |
import org.gvsig.gpe.GPEErrorHandler; |
|
6 |
import org.gvsig.gpe.GPEParser; |
|
7 |
import org.gvsig.gpe.GPERegister; |
|
8 |
|
|
9 |
import junit.framework.TestCase; |
|
10 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
11 |
* |
|
12 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
13 |
* |
|
14 |
* This program is free software; you can redistribute it and/or |
|
15 |
* modify it under the terms of the GNU General Public License |
|
16 |
* as published by the Free Software Foundation; either version 2 |
|
17 |
* of the License, or (at your option) any later version. |
|
18 |
* |
|
19 |
* This program is distributed in the hope that it will be useful, |
|
20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
22 |
* GNU General Public License for more details. |
|
23 |
* |
|
24 |
* You should have received a copy of the GNU General Public License |
|
25 |
* along with this program; if not, write to the Free Software |
|
26 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
27 |
* |
|
28 |
* For more information, contact: |
|
29 |
* |
|
30 |
* Generalitat Valenciana |
|
31 |
* Conselleria d'Infraestructures i Transport |
|
32 |
* Av. Blasco Ib??ez, 50 |
|
33 |
* 46010 VALENCIA |
|
34 |
* SPAIN |
|
35 |
* |
|
36 |
* +34 963862235 |
|
37 |
* gvsig@gva.es |
|
38 |
* www.gvsig.gva.es |
|
39 |
* |
|
40 |
* or |
|
41 |
* |
|
42 |
* IVER T.I. S.A |
|
43 |
* Salamanca 50 |
|
44 |
* 46005 Valencia |
|
45 |
* Spain |
|
46 |
* |
|
47 |
* +34 963163400 |
|
48 |
* dac@iver.es |
|
49 |
*/ |
|
50 |
/* CVS MESSAGES: |
|
51 |
* |
|
52 |
* $Id$ |
|
53 |
* $Log$ |
|
54 |
* Revision 1.1 2007-04-18 12:54:45 csanchez |
|
55 |
* Actualizacion protoripo libGPE |
|
56 |
* |
|
57 |
* |
|
58 |
*/ |
|
59 |
/** |
|
60 |
* @author Carlos S?nchez Peri??n (sanchez_carper@gva.es) |
|
61 |
*/ |
|
62 |
public class testParserGML extends TestCase { |
|
63 |
|
|
64 |
public void setUp() throws IllegalArgumentException, SecurityException, ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException{ |
|
65 |
GPEContentHandler content=null; |
|
66 |
GPEErrorHandler errors=null; |
|
67 |
//Para registrar un driver... con los handlers de prueba de la aplicaci?n. |
|
68 |
GPERegister.addGpeDriver("GMLParser",content,errors); |
|
69 |
} |
|
70 |
public void testLineas(){ |
|
71 |
File ficherin = new File("testdata/GML-lines.gml"); |
|
72 |
GPEParser parser= null; |
|
73 |
|
|
74 |
//El accept es una utilidad para comprobar si est? registrado el parser para ese formato |
|
75 |
assertEquals(GPERegister.accept(ficherin),true); |
|
76 |
//El GPERegister devuelve el parser (del tipo GPEParser) para el formato correcto si existe. |
|
77 |
try { |
|
78 |
parser=GPERegister.getParser(ficherin); |
|
79 |
} catch (Exception e) { |
|
80 |
// TODO Bloque catch generado autom?ticamente |
|
81 |
e.printStackTrace(); |
|
82 |
} |
|
83 |
//ya podemos arrancar el parser que me devolver? eventos |
|
84 |
try { |
|
85 |
parser.parse(ficherin); |
|
86 |
} catch (Exception e) { |
|
87 |
// TODO Bloque catch generado autom?ticamente |
|
88 |
e.printStackTrace(); |
|
89 |
} |
|
90 |
} |
|
91 |
} |
|
0 | 92 |
trunk/libraries/libGPE-GML/src/org/gvsig/gpe/gml/GPEGmlParser.java | ||
---|---|---|
6 | 6 |
import java.io.IOException; |
7 | 7 |
import java.io.InputStream; |
8 | 8 |
|
9 |
import org.gvsig.gpe.GPEContentHandler; |
|
10 |
import org.gvsig.gpe.GPEErrorHandler; |
|
11 | 9 |
import org.gvsig.gpe.gml.writer.GPEGmlWriterHandler; |
12 |
import org.gvsig.gpe.writers.GPEWriterHandler; |
|
13 | 10 |
import org.gvsig.gpe.xml.GPEXmlParser; |
11 |
import org.xmlpull.v1.XmlPullParserException; |
|
14 | 12 |
|
15 | 13 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
16 | 14 |
* |
... | ... | |
56 | 54 |
* |
57 | 55 |
* $Id$ |
58 | 56 |
* $Log$ |
59 |
* Revision 1.1 2007-04-14 16:07:30 jorpiell |
|
57 |
* Revision 1.2 2007-04-18 12:54:45 csanchez |
|
58 |
* Actualizacion protoripo libGPE |
|
59 |
* |
|
60 |
* Revision 1.1 2007/04/14 16:07:30 jorpiell |
|
60 | 61 |
* The writer has been created |
61 | 62 |
* |
62 | 63 |
* |
... | ... | |
85 | 86 |
* @see org.gvsig.gpe.xml.GPEXmlParser#initParse() |
86 | 87 |
*/ |
87 | 88 |
protected void initParse() { |
88 |
// TODO Auto-generated method stub |
|
89 |
|
|
89 |
try { |
|
90 |
parser.next(); |
|
91 |
} catch (XmlPullParserException e) { |
|
92 |
// TODO Bloque catch generado autom?ticamente |
|
93 |
e.printStackTrace(); |
|
94 |
} catch (IOException e) { |
|
95 |
// TODO Bloque catch generado autom?ticamente |
|
96 |
e.printStackTrace(); |
|
97 |
} |
|
98 |
// TODO Auto-generated method stub |
|
90 | 99 |
} |
91 | 100 |
|
92 | 101 |
/* |
... | ... | |
94 | 103 |
* @see org.gvsig.gpe.GPEParser#accept(java.io.File) |
95 | 104 |
*/ |
96 | 105 |
public boolean accept(File file) { |
97 |
if (file.getName().toUpperCase().endsWith("GML")){ |
|
106 |
if ((file.getName().toUpperCase().endsWith("GML")) |
|
107 |
|| (file.getName().toUpperCase().endsWith("XML"))) { |
|
98 | 108 |
return true; |
99 | 109 |
} |
100 | 110 |
return false; |
... | ... | |
105 | 115 |
* @see org.gvsig.gpe.GPEParser#getFormats() |
106 | 116 |
*/ |
107 | 117 |
public String[] getFormats() { |
108 |
String[] formats = new String[1];
|
|
118 |
String[] formats = new String[2];
|
|
109 | 119 |
formats[0] = "GML"; |
120 |
formats[1] = "XML"; |
|
110 | 121 |
return formats; |
111 | 122 |
} |
112 | 123 |
|
trunk/libraries/libGPE-GML/src/org/gvsig/gpe/xml/GPEXmlParser.java | ||
---|---|---|
4 | 4 |
import java.io.FileNotFoundException; |
5 | 5 |
import java.io.IOException; |
6 | 6 |
import java.io.InputStream; |
7 |
import java.lang.reflect.InvocationTargetException; |
|
7 | 8 |
|
8 | 9 |
import org.gvsig.gpe.GPEContentHandler; |
9 | 10 |
import org.gvsig.gpe.GPEErrorHandler; |
10 | 11 |
import org.gvsig.gpe.GPEParser; |
11 | 12 |
import org.xmlpull.v1.XmlPullParser; |
13 |
import org.xmlpull.v1.XmlPullParserException; |
|
12 | 14 |
|
13 | 15 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
14 | 16 |
* |
... | ... | |
54 | 56 |
* |
55 | 57 |
* $Id$ |
56 | 58 |
* $Log$ |
57 |
* Revision 1.2 2007-04-12 11:47:15 jorpiell |
|
59 |
* Revision 1.3 2007-04-18 12:54:45 csanchez |
|
60 |
* Actualizacion protoripo libGPE |
|
61 |
* |
|
62 |
* Revision 1.2 2007/04/12 11:47:15 jorpiell |
|
58 | 63 |
* Add a getParser method |
59 | 64 |
* |
60 | 65 |
* Revision 1.1 2007/04/12 10:23:41 jorpiell |
... | ... | |
69 | 74 |
*/ |
70 | 75 |
public abstract class GPEXmlParser extends GPEParser { |
71 | 76 |
private InputStream inputStream = null; |
72 |
private XmlPullParser parser = null;
|
|
77 |
protected XmlPullParser parser = null;
|
|
73 | 78 |
|
74 | 79 |
public GPEXmlParser(GPEContentHandler contents, GPEErrorHandler errors) { |
75 | 80 |
super(contents, errors); |
... | ... | |
79 | 84 |
* (non-Javadoc) |
80 | 85 |
* @see org.gvsig.gpe.GPEParser#parse(java.io.File) |
81 | 86 |
*/ |
82 |
public void parse(File file) throws Exception{ |
|
83 |
inputStream = createInputStream(file); |
|
84 |
parser = GPEXmlParserFactory.getParser(); |
|
85 |
parser.setInput(getInputStream(), getEncoding()); |
|
87 |
public void parse(File file){ |
|
88 |
try { |
|
89 |
inputStream = createInputStream(file); |
|
90 |
parser = GPEXmlParserFactory.getParser(); |
|
91 |
parser.setInput(getInputStream(), getEncoding()); |
|
92 |
} // EL PARSER LANZAR? UN EVENTO AL ERRORHANDLER SEG?N EL ERROR RECOGIDO |
|
93 |
catch (FileNotFoundException e) { |
|
94 |
System.out.println("ERROR: Fichero "+ file.getName() +" no encontrado"); |
|
95 |
// TODO Bloque catch generado autom?ticamente |
|
96 |
} catch (IllegalArgumentException e) { |
|
97 |
System.out.println("ERROR: Argumento Incorrecto para KXML: "+ e.getMessage()); |
|
98 |
// TODO Bloque catch generado autom?ticamente |
|
99 |
} catch (SecurityException e) { |
|
100 |
System.out.println("ERROR: Fallo de seguridad en la clase KXML: "+ e.getMessage()); |
|
101 |
// TODO Bloque catch generado autom?ticamente |
|
102 |
} catch (InstantiationException e) { |
|
103 |
System.out.println("ERROR: Instancia de KXML incorrecta: "+ e.getMessage()); |
|
104 |
// TODO Bloque catch generado autom?ticamente |
|
105 |
} catch (IllegalAccessException e) { |
|
106 |
System.out.println("ERROR: Acceso Ilegal a memoria de KXML: "+ e.getMessage()); |
|
107 |
// TODO Bloque catch generado autom?ticamente |
|
108 |
} catch (InvocationTargetException e) { |
|
109 |
System.out.println("ERROR: Invocaci?n de KXML Incorrecta: "+ e.getMessage()); |
|
110 |
// TODO Bloque catch generado autom?ticamente |
|
111 |
} catch (NoSuchMethodException e) { |
|
112 |
System.out.println("ERROR: M?todo no implementado del parser KXML: "+ e.getMessage()); |
|
113 |
// TODO Bloque catch generado autom?ticamente |
|
114 |
} catch (ClassNotFoundException e) { |
|
115 |
System.out.println("ERROR: Clase KXML no encontrada: "+ e.getMessage()); |
|
116 |
// TODO Bloque catch generado autom?ticamente |
|
117 |
} catch (XmlPullParserException e) { |
|
118 |
System.out.println("ERROR: Excepci?n en el parser KXML: "+ e.getMessage()); |
|
119 |
// TODO Bloque catch generado autom?ticamente |
|
120 |
} catch (IOException e) { |
|
121 |
System.out.println("ERROR: No se puede leer/escribir la codificaci?n del fichero: "+ e.getMessage()); |
|
122 |
// TODO Bloque catch generado autom?ticamente |
|
123 |
} |
|
86 | 124 |
initParse(); |
87 | 125 |
} |
88 | 126 |
|
89 | 127 |
/** |
90 | 128 |
* Creates an input stream from a file. |
91 | 129 |
* @param file |
92 |
* @return |
|
130 |
* @return InputStream
|
|
93 | 131 |
* @throws FileNotFoundException |
94 | 132 |
*/ |
95 | 133 |
protected abstract InputStream createInputStream(File file) throws FileNotFoundException; |
96 | 134 |
|
97 | 135 |
/** |
98 | 136 |
* This method start the parse process. It is called |
99 |
* before the XML parser is initialized
|
|
137 |
* after the XML parser is initialized
|
|
100 | 138 |
*/ |
101 | 139 |
protected abstract void initParse(); |
102 | 140 |
|
trunk/libraries/libGPE-GML/src/GPEGmlParser.java | ||
---|---|---|
1 |
import java.io.File; |
|
2 |
import java.io.FileInputStream; |
|
3 |
import java.io.FileNotFoundException; |
|
4 |
import java.io.IOException; |
|
5 |
import java.io.InputStream; |
|
6 |
|
|
7 |
import org.gvsig.gpe.GPEContentHandler; |
|
8 |
import org.gvsig.gpe.GPEErrorHandler; |
|
9 |
import org.gvsig.gpe.gml.writer.GPEGmlWriterHandler; |
|
10 |
import org.gvsig.gpe.writers.GPEWriterHandler; |
|
11 |
import org.gvsig.gpe.xml.GPEXmlParser; |
|
12 |
import org.xmlpull.v1.XmlPullParserException; |
|
13 |
|
|
14 |
import com.sun.xml.xsom.parser.XSOMParser; |
|
15 |
|
|
16 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
17 |
* |
|
18 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
19 |
* |
|
20 |
* This program is free software; you can redistribute it and/or |
|
21 |
* modify it under the terms of the GNU General Public License |
|
22 |
* as published by the Free Software Foundation; either version 2 |
|
23 |
* of the License, or (at your option) any later version. |
|
24 |
* |
|
25 |
* This program is distributed in the hope that it will be useful, |
|
26 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
27 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
28 |
* GNU General Public License for more details. |
|
29 |
* |
|
30 |
* You should have received a copy of the GNU General Public License |
|
31 |
* along with this program; if not, write to the Free Software |
|
32 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
33 |
* |
|
34 |
* For more information, contact: |
|
35 |
* |
|
36 |
* Generalitat Valenciana |
|
37 |
* Conselleria d'Infraestructures i Transport |
|
38 |
* Av. Blasco Ib??ez, 50 |
|
39 |
* 46010 VALENCIA |
|
40 |
* SPAIN |
|
41 |
* |
|
42 |
* +34 963862235 |
|
43 |
* gvsig@gva.es |
|
44 |
* www.gvsig.gva.es |
|
45 |
* |
|
46 |
* or |
|
47 |
* |
|
48 |
* IVER T.I. S.A |
|
49 |
* Salamanca 50 |
|
50 |
* 46005 Valencia |
|
51 |
* Spain |
|
52 |
* |
|
53 |
* +34 963163400 |
|
54 |
* dac@iver.es |
|
55 |
*/ |
|
56 |
/* CVS MESSAGES: |
|
57 |
* |
|
58 |
* $Id$ |
|
59 |
* $Log$ |
|
60 |
* Revision 1.1 2007-04-18 12:54:45 csanchez |
|
61 |
* Actualizacion protoripo libGPE |
|
62 |
* |
|
63 |
* |
|
64 |
*/ |
|
65 |
/** |
|
66 |
* @author Carlos S?nchez Peri??n (sanchez_carper@gva.es) |
|
67 |
*/ |
|
68 |
public class GPEGmlParser extends GPEXmlParser{ |
|
69 |
|
|
70 |
private XSOMParser SchemaParser = null; |
|
71 |
|
|
72 |
public GPEGmlParser(GPEContentHandler contents, GPEErrorHandler errors) { |
|
73 |
super(contents, errors); |
|
74 |
// TODO Ap?ndice de constructor generado autom?ticamente |
|
75 |
} |
|
76 |
|
|
77 |
/* |
|
78 |
* (non-Javadoc) |
|
79 |
* @see org.gvsig.gpe.GPEParser#getFormats() |
|
80 |
*/ |
|
81 |
public String[] getFormats() { |
|
82 |
String[] formats = new String[2]; |
|
83 |
formats[0] = "GML"; |
|
84 |
formats[1] = "XML"; |
|
85 |
return formats; |
|
86 |
} |
|
87 |
|
|
88 |
// /* |
|
89 |
// * (non-Javadoc) |
|
90 |
// * @see org.gvsig.gpe.GPEParser#getWriter(java.lang.String, java.lang.String) |
|
91 |
// */ |
|
92 |
// public IGPEContentHandler getHandler(String format, File file) throws IOException { |
|
93 |
// return new GPEContentHandler(format,file); |
|
94 |
// } |
|
95 |
|
|
96 |
/** |
|
97 |
* |
|
98 |
* AQUI SE IMPLEMENTA LA BASE PARA PODER PARSEAR CUALQUIER FICHERO GML: |
|
99 |
* -COMPROBAR SI EXISTE |
|
100 |
* -COMPROBAR CODIFICACI?N DEL XML |
|
101 |
* -ABRIR EN MODO LECTURA CON LA CODIFICACI?N CORRECTA |
|
102 |
* -CREAR EL PARSER DE XML ?"XSOM"? |
|
103 |
* -DETECTAR FORMATO FICHERO Y VERSI?N ?"EST? REGISTRADO"? |
|
104 |
* -SI EXISTE, LLAMADA AL PARSER DEL FORMATO CONCRETO |
|
105 |
* |
|
106 |
**/ |
|
107 |
|
|
108 |
public boolean accept(File file) { |
|
109 |
if ((file.getName().toUpperCase().endsWith("GML")) |
|
110 |
|| (file.getName().toUpperCase().endsWith("XML"))) { |
|
111 |
return true; |
|
112 |
} |
|
113 |
return false; |
|
114 |
} |
|
115 |
|
|
116 |
protected InputStream createInputStream(File file) throws FileNotFoundException { |
|
117 |
// TODO Ap?ndice de m?todo generado autom?ticamente |
|
118 |
return new FileInputStream(file); |
|
119 |
} |
|
120 |
|
|
121 |
protected void initParse() { |
|
122 |
|
|
123 |
} |
|
124 |
/* |
|
125 |
* (non-Javadoc) |
|
126 |
* @see org.gvsig.gpe.GPEParser#getWriter(java.lang.String) |
|
127 |
*/ |
|
128 |
public GPEWriterHandler getWriter(String format) { |
|
129 |
return new GPEGmlWriterHandler(format, getErrorHandler()); |
|
130 |
} |
|
131 |
|
|
132 |
} |
|
0 | 133 |
trunk/libraries/libGPE-GML/.classpath | ||
---|---|---|
5 | 5 |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> |
6 | 6 |
<classpathentry kind="lib" path="/libRemoteServices/lib/gvsig-exceptions.jar"/> |
7 | 7 |
<classpathentry kind="lib" path="/libRemoteServices/lib/kxml2.jar"/> |
8 |
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3.8.1"/> |
|
9 |
<classpathentry kind="lib" path="lib/xsom14.jar" sourcepath="/windows/src/xsom/src"/> |
|
8 |
<classpathentry sourcepath="/windows/src/xsom/src" kind="lib" path="lib/xsom14.jar"/> |
|
10 | 9 |
<classpathentry kind="lib" path="lib/relaxngDatatype.jar"/> |
11 | 10 |
<classpathentry combineaccessrules="false" kind="src" path="/libGPE"/> |
11 |
<classpathentry sourcepath="ECLIPSE_HOME/plugins/org.eclipse.jdt.source_3.1.1/src/org.junit_3.8.1/junitsrc.zip" kind="var" path="JUNIT_HOME/junit.jar"/> |
|
12 | 12 |
<classpathentry kind="output" path="bin"/> |
13 | 13 |
</classpath> |
trunk/libraries/libGPE/.classpath | ||
---|---|---|
3 | 3 |
<classpathentry kind="src" path="src"/> |
4 | 4 |
<classpathentry kind="src" path="src-test"/> |
5 | 5 |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> |
6 |
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3.8.1"/>
|
|
6 |
<classpathentry sourcepath="ECLIPSE_HOME/plugins/org.eclipse.jdt.source_3.1.1/src/org.junit_3.8.1/junitsrc.zip" kind="var" path="JUNIT_HOME/junit.jar"/>
|
|
7 | 7 |
<classpathentry kind="output" path="bin"/> |
8 | 8 |
</classpath> |
trunk/libraries/libGPE/src/org/gvsig/gpe/GPERegister.java | ||
---|---|---|
50 | 50 |
* |
51 | 51 |
* $Id$ |
52 | 52 |
* $Log$ |
53 |
* Revision 1.7 2007-04-17 07:53:55 jorpiell |
|
53 |
* Revision 1.8 2007-04-18 12:54:45 csanchez |
|
54 |
* Actualizacion protoripo libGPE |
|
55 |
* |
|
56 |
* Revision 1.7 2007/04/17 07:53:55 jorpiell |
|
54 | 57 |
* Before to start a new parsing process, the initialize method of the content handlers is throwed |
55 | 58 |
* |
56 | 59 |
* Revision 1.6 2007/04/17 06:26:54 jorpiell |
... | ... | |
148 | 151 |
* @return |
149 | 152 |
* Null if the driver doesn't exist |
150 | 153 |
*/ |
154 |
|
|
155 |
|
|
151 | 156 |
public static GPEParser getParser(File file) throws Exception{ |
157 |
|
|
152 | 158 |
for (int i=0 ; i<parsers.size() ; i++){ |
153 | 159 |
GPEParser parser = (GPEParser)parsers.get(i); |
154 | 160 |
if (parser.accept(file)){ |
Also available in: Unified diff