Revision 11205
trunk/libraries/libGPE-KML/src-test/org/gvsig/gpe/kml/KmlReaderTest.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml; |
|
2 |
|
|
3 |
|
|
4 |
import java.io.File; |
|
5 |
import java.io.FileInputStream; |
|
6 |
import java.io.FileNotFoundException; |
|
7 |
import java.io.InputStream; |
|
8 |
import java.util.Iterator; |
|
9 |
import java.util.Map; |
|
10 |
import java.util.Set; |
|
11 |
|
|
12 |
import junit.framework.TestCase; |
|
13 |
|
|
14 |
import org.gvsig.gpe.gml.factories.GeometriesFactory; |
|
15 |
import org.gvsig.gpe.gml.factories.IGeometriesFactory; |
|
16 |
import org.gvsig.gpe.gml.v2.GMLSimpleFeature_v2; |
|
17 |
import org.gvsig.gpe.kml.engine.IFeaturesIterator; |
|
18 |
import org.gvsig.gpe.kml.exceptions.KmlException; |
|
19 |
|
|
20 |
|
|
21 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
22 |
* |
|
23 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
24 |
* |
|
25 |
* This program is free software; you can redistribute it and/or |
|
26 |
* modify it under the terms of the GNU General Public License |
|
27 |
* as published by the Free Software Foundation; either version 2 |
|
28 |
* of the License, or (at your option) any later version. |
|
29 |
* |
|
30 |
* This program is distributed in the hope that it will be useful, |
|
31 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
32 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
33 |
* GNU General Public License for more details. |
|
34 |
* |
|
35 |
* You should have received a copy of the GNU General Public License |
|
36 |
* along with this program; if not, write to the Free Software |
|
37 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
38 |
* |
|
39 |
* For more information, contact: |
|
40 |
* |
|
41 |
* Generalitat Valenciana |
|
42 |
* Conselleria d'Infraestructures i Transport |
|
43 |
* Av. Blasco Ib??ez, 50 |
|
44 |
* 46010 VALENCIA |
|
45 |
* SPAIN |
|
46 |
* |
|
47 |
* +34 963862235 |
|
48 |
* gvsig@gva.es |
|
49 |
* www.gvsig.gva.es |
|
50 |
* |
|
51 |
* or |
|
52 |
* |
|
53 |
* IVER T.I. S.A |
|
54 |
* Salamanca 50 |
|
55 |
* 46005 Valencia |
|
56 |
* Spain |
|
57 |
* |
|
58 |
* +34 963163400 |
|
59 |
* dac@iver.es |
|
60 |
*/ |
|
61 |
/* CVS MESSAGES: |
|
62 |
* |
|
63 |
* $Id$ |
|
64 |
* $Log$ |
|
65 |
* Revision 1.1 2007-03-07 11:51:53 jorpiell |
|
66 |
* Añadidos los tests |
|
67 |
* |
|
68 |
* Revision 1.1 2007/02/12 13:49:18 jorpiell |
|
69 |
* A?adido el driver de KML |
|
70 |
* |
|
71 |
* |
|
72 |
*/ |
|
73 |
/** |
|
74 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
|
75 |
*/ |
|
76 |
public class KmlReaderTest extends TestCase { |
|
77 |
private static String kmlGoogleExample = "testdata/kml/KML_Samples.kml"; |
|
78 |
private static String kmlPlaceMarket = "testdata/kml/KML_PlaceMarket.kml"; |
|
79 |
private static String kmlGorliz = "testdata/kml/gorliz.kml"; |
|
80 |
private IGeometriesFactory factory = new GeometriesFactory(); |
|
81 |
|
|
82 |
public void testGoogleExample() throws Exception{ |
|
83 |
assertEquals(parseFile(kmlGoogleExample),20); |
|
84 |
} |
|
85 |
|
|
86 |
public void testPlaceMarket() throws Exception{ |
|
87 |
assertEquals(parseFile(kmlPlaceMarket),1); |
|
88 |
} |
|
89 |
|
|
90 |
public void testGorliz() throws Exception{ |
|
91 |
assertEquals(parseFile(kmlGorliz),51); |
|
92 |
} |
|
93 |
|
|
94 |
public int parseFile(String file) throws Exception{ |
|
95 |
KmlDriver driver = new KmlDriver(createInputStream(new File(file)),factory); |
|
96 |
|
|
97 |
System.out.println("********* FILE START: " + file + "***********"); |
|
98 |
|
|
99 |
IFeaturesIterator iterator = driver.getFeaturesIterator(); |
|
100 |
int i=0; |
|
101 |
while (iterator.hasNext()){ |
|
102 |
//Object feature = iterator.next(); |
|
103 |
System.out.println("********* FEATURE NUMBER " + i + " ***********"); |
|
104 |
GMLSimpleFeature_v2 feature = (GMLSimpleFeature_v2) iterator.next(); |
|
105 |
if (feature != null){ |
|
106 |
System.out.println("Geometria: " + feature.getGeom()); |
|
107 |
Map values = feature.getValues(); |
|
108 |
Set keys = values.keySet(); |
|
109 |
Iterator it = keys.iterator(); |
|
110 |
while (it.hasNext()){ |
|
111 |
String key = (String)it.next(); |
|
112 |
System.out.print(key + ": "); |
|
113 |
System.out.println(values.get(key)); |
|
114 |
}} |
|
115 |
i++; |
|
116 |
} |
|
117 |
System.out.println("NUM FEATURES: " + i); |
|
118 |
return i; |
|
119 |
} |
|
120 |
|
|
121 |
/** |
|
122 |
* It creates an InputStream. The Kml file can have the |
|
123 |
* KML or the KMZ extension |
|
124 |
* @return |
|
125 |
* @throws KmlException |
|
126 |
*/ |
|
127 |
private InputStream createInputStream(File file) throws KmlException{ |
|
128 |
try { |
|
129 |
if (file.getName().toUpperCase().endsWith("KML")){ |
|
130 |
return new FileInputStream(file); |
|
131 |
}else if(file.getName().toUpperCase().endsWith("KMZ")){ |
|
132 |
return null; |
|
133 |
}else{ |
|
134 |
throw new KmlException(file); |
|
135 |
} |
|
136 |
} catch (FileNotFoundException e) { |
|
137 |
throw new KmlException(file,e); |
|
138 |
} |
|
139 |
} |
|
140 |
|
|
141 |
|
|
142 |
} |
|
143 |
|
trunk/libraries/libGPE-KML/src-test/org/gvsig/gpe/kml/readers/KMLSampleTest.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml.readers; |
|
2 |
|
|
3 |
import org.gvsig.gpe.readers.GPEReaderBaseTest; |
|
4 |
|
|
5 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
6 |
* |
|
7 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
8 |
* |
|
9 |
* This program is free software; you can redistribute it and/or |
|
10 |
* modify it under the terms of the GNU General Public License |
|
11 |
* as published by the Free Software Foundation; either version 2 |
|
12 |
* of the License, or (at your option) any later version. |
|
13 |
* |
|
14 |
* This program is distributed in the hope that it will be useful, |
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 |
* GNU General Public License for more details. |
|
18 |
* |
|
19 |
* You should have received a copy of the GNU General Public License |
|
20 |
* along with this program; if not, write to the Free Software |
|
21 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
22 |
* |
|
23 |
* For more information, contact: |
|
24 |
* |
|
25 |
* Generalitat Valenciana |
|
26 |
* Conselleria d'Infraestructures i Transport |
|
27 |
* Av. Blasco Ib??ez, 50 |
|
28 |
* 46010 VALENCIA |
|
29 |
* SPAIN |
|
30 |
* |
|
31 |
* +34 963862235 |
|
32 |
* gvsig@gva.es |
|
33 |
* www.gvsig.gva.es |
|
34 |
* |
|
35 |
* or |
|
36 |
* |
|
37 |
* IVER T.I. S.A |
|
38 |
* Salamanca 50 |
|
39 |
* 46005 Valencia |
|
40 |
* Spain |
|
41 |
* |
|
42 |
* +34 963163400 |
|
43 |
* dac@iver.es |
|
44 |
*/ |
|
45 |
/* CVS MESSAGES: |
|
46 |
* |
|
47 |
* $Id$ |
|
48 |
* $Log$ |
|
49 |
* Revision 1.1 2007-04-13 13:16:21 jorpiell |
|
50 |
* Add KML reading support |
|
51 |
* |
|
52 |
* |
|
53 |
*/ |
|
54 |
/** |
|
55 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es) |
|
56 |
*/ |
|
57 |
public class KMLSampleTest extends KMLBaseTest{ |
|
58 |
|
|
59 |
/* |
|
60 |
* (non-Javadoc) |
|
61 |
* @see org.gvsig.gpe.readers.GPEReaderBaseTest#getFile() |
|
62 |
*/ |
|
63 |
public String getFile() { |
|
64 |
return "testdata/KML_Samples.kml"; |
|
65 |
} |
|
66 |
|
|
67 |
} |
|
0 | 68 |
trunk/libraries/libGPE-KML/src-test/org/gvsig/gpe/kml/readers/KMLBaseTest.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml.readers; |
|
2 |
|
|
3 |
import org.gvsig.gpe.readers.GPEReaderBaseTest; |
|
4 |
|
|
5 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
6 |
* |
|
7 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
8 |
* |
|
9 |
* This program is free software; you can redistribute it and/or |
|
10 |
* modify it under the terms of the GNU General Public License |
|
11 |
* as published by the Free Software Foundation; either version 2 |
|
12 |
* of the License, or (at your option) any later version. |
|
13 |
* |
|
14 |
* This program is distributed in the hope that it will be useful, |
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 |
* GNU General Public License for more details. |
|
18 |
* |
|
19 |
* You should have received a copy of the GNU General Public License |
|
20 |
* along with this program; if not, write to the Free Software |
|
21 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
22 |
* |
|
23 |
* For more information, contact: |
|
24 |
* |
|
25 |
* Generalitat Valenciana |
|
26 |
* Conselleria d'Infraestructures i Transport |
|
27 |
* Av. Blasco Ib??ez, 50 |
|
28 |
* 46010 VALENCIA |
|
29 |
* SPAIN |
|
30 |
* |
|
31 |
* +34 963862235 |
|
32 |
* gvsig@gva.es |
|
33 |
* www.gvsig.gva.es |
|
34 |
* |
|
35 |
* or |
|
36 |
* |
|
37 |
* IVER T.I. S.A |
|
38 |
* Salamanca 50 |
|
39 |
* 46005 Valencia |
|
40 |
* Spain |
|
41 |
* |
|
42 |
* +34 963163400 |
|
43 |
* dac@iver.es |
|
44 |
*/ |
|
45 |
/* CVS MESSAGES: |
|
46 |
* |
|
47 |
* $Id$ |
|
48 |
* $Log$ |
|
49 |
* Revision 1.1 2007-04-13 13:16:21 jorpiell |
|
50 |
* Add KML reading support |
|
51 |
* |
|
52 |
* |
|
53 |
*/ |
|
54 |
/** |
|
55 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es) |
|
56 |
*/ |
|
57 |
public abstract class KMLBaseTest extends GPEReaderBaseTest{ |
|
58 |
|
|
59 |
/* |
|
60 |
* (non-Javadoc) |
|
61 |
* @see org.gvsig.gpe.readers.GPEReaderBaseTest#getGPEDriverName() |
|
62 |
*/ |
|
63 |
public String getGPEParserName() { |
|
64 |
return "org.gvsig.gpe.kml.GPEKmlParser"; |
|
65 |
} |
|
66 |
|
|
67 |
} |
|
0 | 68 |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/KmlAttributesMap.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml; |
|
2 |
|
|
3 |
import java.util.LinkedHashMap; |
|
4 |
|
|
5 |
|
|
6 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
7 |
* |
|
8 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
9 |
* |
|
10 |
* This program is free software; you can redistribute it and/or |
|
11 |
* modify it under the terms of the GNU General Public License |
|
12 |
* as published by the Free Software Foundation; either version 2 |
|
13 |
* of the License, or (at your option) any later version. |
|
14 |
* |
|
15 |
* This program is distributed in the hope that it will be useful, |
|
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18 |
* GNU General Public License for more details. |
|
19 |
* |
|
20 |
* You should have received a copy of the GNU General Public License |
|
21 |
* along with this program; if not, write to the Free Software |
|
22 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
23 |
* |
|
24 |
* For more information, contact: |
|
25 |
* |
|
26 |
* Generalitat Valenciana |
|
27 |
* Conselleria d'Infraestructures i Transport |
|
28 |
* Av. Blasco Ib??ez, 50 |
|
29 |
* 46010 VALENCIA |
|
30 |
* SPAIN |
|
31 |
* |
|
32 |
* +34 963862235 |
|
33 |
* gvsig@gva.es |
|
34 |
* www.gvsig.gva.es |
|
35 |
* |
|
36 |
* or |
|
37 |
* |
|
38 |
* IVER T.I. S.A |
|
39 |
* Salamanca 50 |
|
40 |
* 46005 Valencia |
|
41 |
* Spain |
|
42 |
* |
|
43 |
* +34 963163400 |
|
44 |
* dac@iver.es |
|
45 |
*/ |
|
46 |
/* CVS MESSAGES: |
|
47 |
* |
|
48 |
* $Id$ |
|
49 |
* $Log$ |
|
50 |
* Revision 1.1 2007-03-07 08:19:10 jorpiell |
|
51 |
* Pasadas las clases de KML de libGPE-GML a libGPE-KML |
|
52 |
* |
|
53 |
* Revision 1.1 2007/02/28 11:48:31 csanchez |
|
54 |
* *** empty log message *** |
|
55 |
* |
|
56 |
* Revision 1.1 2007/02/20 10:53:20 jorpiell |
|
57 |
* Añadidos los proyectos de kml y gml antiguos |
|
58 |
* |
|
59 |
* Revision 1.1 2007/02/12 13:49:18 jorpiell |
|
60 |
* A?adido el driver de KML |
|
61 |
* |
|
62 |
* |
|
63 |
*/ |
|
64 |
/** |
|
65 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
|
66 |
*/ |
|
67 |
public class KmlAttributesMap extends LinkedHashMap{ |
|
68 |
|
|
69 |
public KmlAttributesMap(){ |
|
70 |
super(); |
|
71 |
put(KmlTags.FOLDER_NAME,KmlFeaturesIterator.getCurrentFolder()); |
|
72 |
put(KmlTags.NAME,""); |
|
73 |
put(KmlTags.DESCRIPTION,""); |
|
74 |
put(KmlTags.VISIBILITY,""); |
|
75 |
put(KmlTags.LOOKAT,new LinkedHashMap()); |
|
76 |
} |
|
77 |
|
|
78 |
public Object put(Object key, Object value) { |
|
79 |
if (value == null){ |
|
80 |
value = ""; |
|
81 |
} |
|
82 |
return super.put(key,value); |
|
83 |
} |
|
84 |
} |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/KmlHeaderParser.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml; |
|
2 |
|
|
3 |
import org.gvsig.gpe.kml.engine.IReaderFile; |
|
4 |
import org.gvsig.gpe.kml.exceptions.KmlHeaderParseException; |
|
5 |
import org.gvsig.gpe.kml.exceptions.KmlNotRootTagException; |
|
6 |
|
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
8 |
* |
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
10 |
* |
|
11 |
* This program is free software; you can redistribute it and/or |
|
12 |
* modify it under the terms of the GNU General Public License |
|
13 |
* as published by the Free Software Foundation; either version 2 |
|
14 |
* of the License, or (at your option) any later version. |
|
15 |
* |
|
16 |
* This program is distributed in the hope that it will be useful, |
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19 |
* GNU General Public License for more details. |
|
20 |
* |
|
21 |
* You should have received a copy of the GNU General Public License |
|
22 |
* along with this program; if not, write to the Free Software |
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
24 |
* |
|
25 |
* For more information, contact: |
|
26 |
* |
|
27 |
* Generalitat Valenciana |
|
28 |
* Conselleria d'Infraestructures i Transport |
|
29 |
* Av. Blasco Ib??ez, 50 |
|
30 |
* 46010 VALENCIA |
|
31 |
* SPAIN |
|
32 |
* |
|
33 |
* +34 963862235 |
|
34 |
* gvsig@gva.es |
|
35 |
* www.gvsig.gva.es |
|
36 |
* |
|
37 |
* or |
|
38 |
* |
|
39 |
* IVER T.I. S.A |
|
40 |
* Salamanca 50 |
|
41 |
* 46005 Valencia |
|
42 |
* Spain |
|
43 |
* |
|
44 |
* +34 963163400 |
|
45 |
* dac@iver.es |
|
46 |
*/ |
|
47 |
/* CVS MESSAGES: |
|
48 |
* |
|
49 |
* $Id$ |
|
50 |
* $Log$ |
|
51 |
* Revision 1.1 2007-03-07 08:19:10 jorpiell |
|
52 |
* Pasadas las clases de KML de libGPE-GML a libGPE-KML |
|
53 |
* |
|
54 |
* Revision 1.1 2007/02/28 11:48:31 csanchez |
|
55 |
* *** empty log message *** |
|
56 |
* |
|
57 |
* Revision 1.1 2007/02/20 10:53:20 jorpiell |
|
58 |
* Añadidos los proyectos de kml y gml antiguos |
|
59 |
* |
|
60 |
* Revision 1.1 2007/02/12 13:49:18 jorpiell |
|
61 |
* A?adido el driver de KML |
|
62 |
* |
|
63 |
* |
|
64 |
*/ |
|
65 |
/** |
|
66 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
|
67 |
*/ |
|
68 |
public class KmlHeaderParser { |
|
69 |
private IReaderFile reader = null; |
|
70 |
private String nameSpace = null; |
|
71 |
|
|
72 |
public KmlHeaderParser(IReaderFile reader) throws KmlHeaderParseException{ |
|
73 |
this.reader = reader; |
|
74 |
parseHeader(); |
|
75 |
} |
|
76 |
|
|
77 |
/** |
|
78 |
* This method parses the kml header file |
|
79 |
* @throws KmlHeaderParseException |
|
80 |
*/ |
|
81 |
private void parseHeader() throws KmlHeaderParseException{ |
|
82 |
try { |
|
83 |
reader.nextTag(); |
|
84 |
String name = reader.getName(); |
|
85 |
if (name.compareTo(KmlTags.ROOT) != 0){ |
|
86 |
throw new KmlNotRootTagException(name); |
|
87 |
} |
|
88 |
for (int i=0 ; i<reader.getAttributeCount() ; i++){ |
|
89 |
nameSpace = reader.getAttributeValue(i); |
|
90 |
} |
|
91 |
} catch (Exception e) { |
|
92 |
throw new KmlHeaderParseException(e); |
|
93 |
} |
|
94 |
} |
|
95 |
|
|
96 |
/** |
|
97 |
* @return Returns the nameSpace. |
|
98 |
*/ |
|
99 |
public String getNameSpace() { |
|
100 |
return nameSpace; |
|
101 |
} |
|
102 |
} |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/KmlParsersFactory.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml; |
|
2 |
|
|
3 |
import java.util.Hashtable; |
|
4 |
|
|
5 |
import org.gvsig.exceptions.BaseException; |
|
6 |
import org.gvsig.gpe.gml.factories.IGeometriesFactory; |
|
7 |
import org.gvsig.gpe.kml.engine.AbstractFeaturesParser; |
|
8 |
import org.gvsig.gpe.kml.engine.IFeaturesParser; |
|
9 |
import org.gvsig.gpe.kml.engine.IReaderFile; |
|
10 |
import org.gvsig.gpe.kml.exceptions.KmlImpossibleCreateParser; |
|
11 |
import org.gvsig.gpe.kml.warnings.NotNamespaceParserWarning; |
|
12 |
import org.gvsig.gpe.kml.warnings.WarningsContainer; |
|
13 |
|
|
14 |
|
|
15 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
16 |
* |
|
17 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
18 |
* |
|
19 |
* This program is free software; you can redistribute it and/or |
|
20 |
* modify it under the terms of the GNU General Public License |
|
21 |
* as published by the Free Software Foundation; either version 2 |
|
22 |
* of the License, or (at your option) any later version. |
|
23 |
* |
|
24 |
* This program is distributed in the hope that it will be useful, |
|
25 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
26 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
27 |
* GNU General Public License for more details. |
|
28 |
* |
|
29 |
* You should have received a copy of the GNU General Public License |
|
30 |
* along with this program; if not, write to the Free Software |
|
31 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
32 |
* |
|
33 |
* For more information, contact: |
|
34 |
* |
|
35 |
* Generalitat Valenciana |
|
36 |
* Conselleria d'Infraestructures i Transport |
|
37 |
* Av. Blasco Ib??ez, 50 |
|
38 |
* 46010 VALENCIA |
|
39 |
* SPAIN |
|
40 |
* |
|
41 |
* +34 963862235 |
|
42 |
* gvsig@gva.es |
|
43 |
* www.gvsig.gva.es |
|
44 |
* |
|
45 |
* or |
|
46 |
* |
|
47 |
* IVER T.I. S.A |
|
48 |
* Salamanca 50 |
|
49 |
* 46005 Valencia |
|
50 |
* Spain |
|
51 |
* |
|
52 |
* +34 963163400 |
|
53 |
* dac@iver.es |
|
54 |
*/ |
|
55 |
/* CVS MESSAGES: |
|
56 |
* |
|
57 |
* $Id$ |
|
58 |
* $Log$ |
|
59 |
* Revision 1.2 2007-04-12 10:21:52 jorpiell |
|
60 |
* Add the writers |
|
61 |
* |
|
62 |
* Revision 1.1 2007/03/07 08:19:10 jorpiell |
|
63 |
* Pasadas las clases de KML de libGPE-GML a libGPE-KML |
|
64 |
* |
|
65 |
* Revision 1.1 2007/02/28 11:48:31 csanchez |
|
66 |
* *** empty log message *** |
|
67 |
* |
|
68 |
* Revision 1.1 2007/02/20 10:53:20 jorpiell |
|
69 |
* Añadidos los proyectos de kml y gml antiguos |
|
70 |
* |
|
71 |
* Revision 1.1 2007/02/12 13:49:18 jorpiell |
|
72 |
* A?adido el driver de KML |
|
73 |
* |
|
74 |
* |
|
75 |
*/ |
|
76 |
/** |
|
77 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
|
78 |
*/ |
|
79 |
public class KmlParsersFactory { |
|
80 |
private WarningsContainer warnings = null; |
|
81 |
private static Hashtable supportedVersions = new Hashtable(); |
|
82 |
private static Hashtable parserVersions = new Hashtable(); |
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
static { |
|
87 |
supportedVersions.put("http://earth.google.com/kml/2.1",KmlFeaturesParser.class); |
|
88 |
supportedVersions.put("http://earth.google.com/kml/2.0",KmlFeaturesParser.class); |
|
89 |
supportedVersions.put("unknown",KmlFeaturesParser.class); |
|
90 |
} |
|
91 |
|
|
92 |
public IFeaturesParser createParser(String nameSpace, IGeometriesFactory factory, IReaderFile reader) throws BaseException{ |
|
93 |
Class clazz = (Class) supportedVersions.get(nameSpace); |
|
94 |
if (clazz == null){ |
|
95 |
clazz = (Class) supportedVersions.get("unknown"); |
|
96 |
//WARNING VERSION NOT SUPPORTED OR NOT SPECIFIED |
|
97 |
warnings.setElement(new NotNamespaceParserWarning(nameSpace)); |
|
98 |
} |
|
99 |
if (clazz != null){ |
|
100 |
//Utilizamos un interfaz con los tipos y las geometrias b?sicas de GML |
|
101 |
//?Otra opcion seria parsear el schemas de opengis, para obtener los tipos b?sicos? |
|
102 |
Class [] args = {IReaderFile.class,IGeometriesFactory.class}; |
|
103 |
Object [] params = {reader,factory}; |
|
104 |
//pasamos el parser con el que estamos leyendo el gml y el interfaz de geometrias |
|
105 |
//para continuar con la comprobaci?n del fichero GML |
|
106 |
try { |
|
107 |
return (AbstractFeaturesParser)clazz.getConstructor(args).newInstance(params); |
|
108 |
} catch (Exception e) { |
|
109 |
throw new KmlImpossibleCreateParser(nameSpace,e); |
|
110 |
} |
|
111 |
} |
|
112 |
return null ; |
|
113 |
} |
|
114 |
|
|
115 |
|
|
116 |
} |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/KmlFeaturesIterator.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import org.gvsig.exceptions.BaseException; |
|
6 |
import org.gvsig.gpe.gml.factories.IGeometriesFactory; |
|
7 |
import org.gvsig.gpe.kml.bindings.FolderBinding; |
|
8 |
import org.gvsig.gpe.kml.bindings.PlaceMarketBinding; |
|
9 |
import org.gvsig.gpe.kml.engine.AbstractFeaturesIterator; |
|
10 |
import org.gvsig.gpe.kml.engine.IReaderFile; |
|
11 |
import org.gvsig.gpe.kml.exceptions.KmlBodyParseException; |
|
12 |
import org.kxml2.io.KXmlParser; |
|
13 |
import org.xmlpull.v1.XmlPullParserException; |
|
14 |
|
|
15 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
16 |
* |
|
17 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
18 |
* |
|
19 |
* This program is free software; you can redistribute it and/or |
|
20 |
* modify it under the terms of the GNU General Public License |
|
21 |
* as published by the Free Software Foundation; either version 2 |
|
22 |
* of the License, or (at your option) any later version. |
|
23 |
* |
|
24 |
* This program is distributed in the hope that it will be useful, |
|
25 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
26 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
27 |
* GNU General Public License for more details. |
|
28 |
* |
|
29 |
* You should have received a copy of the GNU General Public License |
|
30 |
* along with this program; if not, write to the Free Software |
|
31 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
32 |
* |
|
33 |
* For more information, contact: |
|
34 |
* |
|
35 |
* Generalitat Valenciana |
|
36 |
* Conselleria d'Infraestructures i Transport |
|
37 |
* Av. Blasco Ib??ez, 50 |
|
38 |
* 46010 VALENCIA |
|
39 |
* SPAIN |
|
40 |
* |
|
41 |
* +34 963862235 |
|
42 |
* gvsig@gva.es |
|
43 |
* www.gvsig.gva.es |
|
44 |
* |
|
45 |
* or |
|
46 |
* |
|
47 |
* IVER T.I. S.A |
|
48 |
* Salamanca 50 |
|
49 |
* 46005 Valencia |
|
50 |
* Spain |
|
51 |
* |
|
52 |
* +34 963163400 |
|
53 |
* dac@iver.es |
|
54 |
*/ |
|
55 |
/* CVS MESSAGES: |
|
56 |
* |
|
57 |
* $Id$ |
|
58 |
* $Log$ |
|
59 |
* Revision 1.1 2007-03-07 08:19:10 jorpiell |
|
60 |
* Pasadas las clases de KML de libGPE-GML a libGPE-KML |
|
61 |
* |
|
62 |
* Revision 1.1 2007/02/28 11:48:31 csanchez |
|
63 |
* *** empty log message *** |
|
64 |
* |
|
65 |
* Revision 1.1 2007/02/20 10:53:20 jorpiell |
|
66 |
* Añadidos los proyectos de kml y gml antiguos |
|
67 |
* |
|
68 |
* Revision 1.1 2007/02/12 13:49:18 jorpiell |
|
69 |
* A?adido el driver de KML |
|
70 |
* |
|
71 |
* |
|
72 |
*/ |
|
73 |
/** |
|
74 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
|
75 |
*/ |
|
76 |
public class KmlFeaturesIterator extends AbstractFeaturesIterator{ |
|
77 |
private static String currentFolder = null; |
|
78 |
|
|
79 |
public KmlFeaturesIterator(IReaderFile reader, IGeometriesFactory factory) { |
|
80 |
super(reader, factory); |
|
81 |
} |
|
82 |
|
|
83 |
/* |
|
84 |
* (non-Javadoc) |
|
85 |
* @see org.gvsig.remoteClient.gmlEngine.IFeaturesIterator#hasNext() |
|
86 |
*/ |
|
87 |
public boolean hasNext() throws BaseException { |
|
88 |
boolean endFile = false; |
|
89 |
int currentTag; |
|
90 |
boolean isFolder = false; |
|
91 |
|
|
92 |
try { |
|
93 |
String tag = reader.getName(); |
|
94 |
currentTag = reader.getEventType(); |
|
95 |
|
|
96 |
while (!endFile){ |
|
97 |
switch(currentTag){ |
|
98 |
case KXmlParser.START_TAG: |
|
99 |
if (tag.compareTo(KmlTags.PLACEMARK) == 0){ |
|
100 |
return true; |
|
101 |
}else if(tag.compareTo(KmlTags.FOLDER) == 0){ |
|
102 |
currentFolder = (String)new FolderBinding(getGFactory()).parse(reader); |
|
103 |
tag = reader.getName(); |
|
104 |
} |
|
105 |
break; |
|
106 |
case KXmlParser.END_TAG: |
|
107 |
if (tag.compareTo(KmlTags.ROOT) == 0){ |
|
108 |
endFile = true; |
|
109 |
} |
|
110 |
break; |
|
111 |
case KXmlParser.TEXT: |
|
112 |
break; |
|
113 |
} |
|
114 |
if (!endFile){ |
|
115 |
if (!isFolder){ |
|
116 |
currentTag = reader.next(); |
|
117 |
tag = reader.getName(); |
|
118 |
}else{ |
|
119 |
isFolder = false; |
|
120 |
} |
|
121 |
} |
|
122 |
} |
|
123 |
} catch (XmlPullParserException e) { |
|
124 |
throw new KmlBodyParseException(e); |
|
125 |
} catch (IOException e) { |
|
126 |
throw new KmlBodyParseException(e); |
|
127 |
} |
|
128 |
return false; |
|
129 |
} |
|
130 |
|
|
131 |
/* |
|
132 |
* (non-Javadoc) |
|
133 |
* @see org.gvsig.remoteClient.gmlEngine.IFeaturesIterator#next() |
|
134 |
*/ |
|
135 |
public Object next() throws BaseException { |
|
136 |
String tag = reader.getName(); |
|
137 |
|
|
138 |
if (tag.compareTo(KmlTags.PLACEMARK) == 0){ |
|
139 |
return new PlaceMarketBinding(gFactory).parse(reader); |
|
140 |
} |
|
141 |
return null; |
|
142 |
} |
|
143 |
|
|
144 |
/** |
|
145 |
* @return Returns the currentFolder. |
|
146 |
*/ |
|
147 |
public static String getCurrentFolder() { |
|
148 |
if (currentFolder == null){ |
|
149 |
return KmlTags.DEFAULT_LEGEND; |
|
150 |
} |
|
151 |
return currentFolder; |
|
152 |
} |
|
153 |
} |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/KmlDriver.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml; |
|
2 |
|
|
3 |
import java.awt.geom.Rectangle2D; |
|
4 |
import java.io.InputStream; |
|
5 |
|
|
6 |
import org.gvsig.exceptions.BaseException; |
|
7 |
import org.gvsig.exceptions.ListBaseException; |
|
8 |
import org.gvsig.gpe.gml.factories.IGeometriesFactory; |
|
9 |
import org.gvsig.gpe.kml.engine.AbstractDriver; |
|
10 |
import org.gvsig.gpe.kml.engine.IFeaturesIterator; |
|
11 |
import org.gvsig.gpe.kml.engine.XmlReaderFile; |
|
12 |
import org.gvsig.gpe.kml.exceptions.KmlException; |
|
13 |
import org.xmlpull.v1.XmlPullParserException; |
|
14 |
|
|
15 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
16 |
* |
|
17 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
18 |
* |
|
19 |
* This program is free software; you can redistribute it and/or |
|
20 |
* modify it under the terms of the GNU General Public License |
|
21 |
* as published by the Free Software Foundation; either version 2 |
|
22 |
* of the License, or (at your option) any later version. |
|
23 |
* |
|
24 |
* This program is distributed in the hope that it will be useful, |
|
25 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
26 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
27 |
* GNU General Public License for more details. |
|
28 |
* |
|
29 |
* You should have received a copy of the GNU General Public License |
|
30 |
* along with this program; if not, write to the Free Software |
|
31 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
32 |
* |
|
33 |
* For more information, contact: |
|
34 |
* |
|
35 |
* Generalitat Valenciana |
|
36 |
* Conselleria d'Infraestructures i Transport |
|
37 |
* Av. Blasco Ib??ez, 50 |
|
38 |
* 46010 VALENCIA |
|
39 |
* SPAIN |
|
40 |
* |
|
41 |
* +34 963862235 |
|
42 |
* gvsig@gva.es |
|
43 |
* www.gvsig.gva.es |
|
44 |
* |
|
45 |
* or |
|
46 |
* |
|
47 |
* IVER T.I. S.A |
|
48 |
* Salamanca 50 |
|
49 |
* 46005 Valencia |
|
50 |
* Spain |
|
51 |
* |
|
52 |
* +34 963163400 |
|
53 |
* dac@iver.es |
|
54 |
*/ |
|
55 |
/* CVS MESSAGES: |
|
56 |
* |
|
57 |
* $Id$ |
|
58 |
* $Log$ |
|
59 |
* Revision 1.1 2007-03-07 08:19:10 jorpiell |
|
60 |
* Pasadas las clases de KML de libGPE-GML a libGPE-KML |
|
61 |
* |
|
62 |
* Revision 1.1 2007/02/28 11:48:31 csanchez |
|
63 |
* *** empty log message *** |
|
64 |
* |
|
65 |
* Revision 1.1 2007/02/20 10:53:20 jorpiell |
|
66 |
* Añadidos los proyectos de kml y gml antiguos |
|
67 |
* |
|
68 |
* Revision 1.1 2007/02/12 13:49:18 jorpiell |
|
69 |
* A?adido el driver de KML |
|
70 |
* |
|
71 |
* |
|
72 |
*/ |
|
73 |
/** |
|
74 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
|
75 |
*/ |
|
76 |
public class KmlDriver extends AbstractDriver{ |
|
77 |
private KmlHeaderParser headerParser = null; |
|
78 |
|
|
79 |
public KmlDriver(InputStream file,IGeometriesFactory factory) throws BaseException { |
|
80 |
super(file, factory); |
|
81 |
} |
|
82 |
|
|
83 |
/* |
|
84 |
* (non-Javadoc) |
|
85 |
* @see org.gvsig.remoteClient.gmlEngine.IDriver#getFeaturesIterator() |
|
86 |
*/ |
|
87 |
public IFeaturesIterator getFeaturesIterator() throws BaseException { |
|
88 |
return featuresParser.getFeaturesIterator(); |
|
89 |
} |
|
90 |
|
|
91 |
/* |
|
92 |
* (non-Javadoc) |
|
93 |
* @see org.gvsig.remoteClient.gmlEngine.IDriver#getExtent() |
|
94 |
*/ |
|
95 |
public Rectangle2D getExtent() { |
|
96 |
// TODO Auto-generated method stub |
|
97 |
return null; |
|
98 |
} |
|
99 |
|
|
100 |
/* |
|
101 |
* (non-Javadoc) |
|
102 |
* @see org.gvsig.remoteClient.gmlEngine.IDriver#getSRS() |
|
103 |
*/ |
|
104 |
public String getSRS() { |
|
105 |
// TODO Auto-generated method stub |
|
106 |
return null; |
|
107 |
} |
|
108 |
|
|
109 |
/* |
|
110 |
* (non-Javadoc) |
|
111 |
* @see org.gvsig.remoteClient.gmlEngine.IDriver#getVersion() |
|
112 |
*/ |
|
113 |
public String getVersion() { |
|
114 |
// TODO Auto-generated method stub |
|
115 |
return null; |
|
116 |
} |
|
117 |
|
|
118 |
/* |
|
119 |
* (non-Javadoc) |
|
120 |
* @see org.gvsig.remoteClient.gmlEngine.IDriver#getWarnings() |
|
121 |
*/ |
|
122 |
public ListBaseException getWarnings() { |
|
123 |
// TODO Auto-generated method stub |
|
124 |
return null; |
|
125 |
} |
|
126 |
|
|
127 |
/* |
|
128 |
* (non-Javadoc) |
|
129 |
* @see org.gvsig.remoteClient.gmlEngine.AbstractDriver#initialize(org.gvsig.remoteClient.gml.factories.IGeometriesFactory) |
|
130 |
*/ |
|
131 |
protected void initialize(IGeometriesFactory factory) throws BaseException { |
|
132 |
headerParser = new KmlHeaderParser(getReader()); |
|
133 |
|
|
134 |
KmlParsersFactory parsersFactory = new KmlParsersFactory(); |
|
135 |
featuresParser = (KmlFeaturesParser)parsersFactory.createParser(headerParser.getNameSpace(),factory,getReader()); |
|
136 |
} |
|
137 |
|
|
138 |
/* |
|
139 |
* (non-Javadoc) |
|
140 |
* @see org.gvsig.remoteClient.gmlEngine.AbstractDriver#initializeReader() |
|
141 |
*/ |
|
142 |
protected void initializeReader() throws BaseException { |
|
143 |
// make GML parser with the good enconding |
|
144 |
XmlReaderFile xmlReader = new XmlReaderFile(); |
|
145 |
|
|
146 |
// setInput(file,encoding): it sets the encoding to read with the KXML parser |
|
147 |
//It is necessary to close the file before |
|
148 |
try { |
|
149 |
xmlReader.setInput(getInputStream(), getEncoding()); |
|
150 |
} catch (XmlPullParserException e) { |
|
151 |
// TODO Auto-generated catch block |
|
152 |
throw new KmlException(getInputStream(),e); |
|
153 |
} |
|
154 |
setReader(xmlReader); |
|
155 |
} |
|
156 |
|
|
157 |
|
|
158 |
|
|
159 |
} |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/KmlFeaturesParser.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import org.gvsig.exceptions.BaseException; |
|
6 |
import org.gvsig.gpe.gml.factories.IGeometriesFactory; |
|
7 |
import org.gvsig.gpe.kml.engine.AbstractFeaturesParser; |
|
8 |
import org.gvsig.gpe.kml.engine.IFeaturesIterator; |
|
9 |
import org.gvsig.gpe.kml.engine.IReaderFile; |
|
10 |
import org.gvsig.gpe.kml.exceptions.KmlBodyParseException; |
|
11 |
import org.xmlpull.v1.XmlPullParserException; |
|
12 |
|
|
13 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
14 |
* |
|
15 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
16 |
* |
|
17 |
* This program is free software; you can redistribute it and/or |
|
18 |
* modify it under the terms of the GNU General Public License |
|
19 |
* as published by the Free Software Foundation; either version 2 |
|
20 |
* of the License, or (at your option) any later version. |
|
21 |
* |
|
22 |
* This program is distributed in the hope that it will be useful, |
|
23 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
24 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
25 |
* GNU General Public License for more details. |
|
26 |
* |
|
27 |
* You should have received a copy of the GNU General Public License |
|
28 |
* along with this program; if not, write to the Free Software |
|
29 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
30 |
* |
|
31 |
* For more information, contact: |
|
32 |
* |
|
33 |
* Generalitat Valenciana |
|
34 |
* Conselleria d'Infraestructures i Transport |
|
35 |
* Av. Blasco Ib??ez, 50 |
|
36 |
* 46010 VALENCIA |
|
37 |
* SPAIN |
|
38 |
* |
|
39 |
* +34 963862235 |
|
40 |
* gvsig@gva.es |
|
41 |
* www.gvsig.gva.es |
|
42 |
* |
|
43 |
* or |
|
44 |
* |
|
45 |
* IVER T.I. S.A |
|
46 |
* Salamanca 50 |
|
47 |
* 46005 Valencia |
|
48 |
* Spain |
|
49 |
* |
|
50 |
* +34 963163400 |
|
51 |
* dac@iver.es |
|
52 |
*/ |
|
53 |
/* CVS MESSAGES: |
|
54 |
* |
|
55 |
* $Id$ |
|
56 |
* $Log$ |
|
57 |
* Revision 1.1 2007-03-07 08:19:10 jorpiell |
|
58 |
* Pasadas las clases de KML de libGPE-GML a libGPE-KML |
|
59 |
* |
|
60 |
* Revision 1.1 2007/02/28 11:48:31 csanchez |
|
61 |
* *** empty log message *** |
|
62 |
* |
|
63 |
* Revision 1.1 2007/02/20 10:53:20 jorpiell |
|
64 |
* Añadidos los proyectos de kml y gml antiguos |
|
65 |
* |
|
66 |
* Revision 1.1 2007/02/12 13:49:18 jorpiell |
|
67 |
* A?adido el driver de KML |
|
68 |
* |
|
69 |
* |
|
70 |
*/ |
|
71 |
/** |
|
72 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
|
73 |
*/ |
|
74 |
public class KmlFeaturesParser extends AbstractFeaturesParser{ |
|
75 |
|
|
76 |
public KmlFeaturesParser(IReaderFile reader, IGeometriesFactory gFactory)throws BaseException { |
|
77 |
super(reader, gFactory); |
|
78 |
parseHeader(); |
|
79 |
} |
|
80 |
|
|
81 |
private void parseHeader()throws BaseException{ |
|
82 |
try { |
|
83 |
reader.nextTag(); |
|
84 |
String tag = reader.getName(); |
|
85 |
|
|
86 |
} catch (XmlPullParserException e) { |
|
87 |
throw new KmlBodyParseException(e); |
|
88 |
} catch (IOException e) { |
|
89 |
throw new KmlBodyParseException(e); |
|
90 |
} |
|
91 |
} |
|
92 |
|
|
93 |
/* |
|
94 |
* (non-Javadoc) |
|
95 |
* @see org.gvsig.remoteClient.gmlEngine.IFeaturesParser#getFeaturesIterator() |
|
96 |
*/ |
|
97 |
public IFeaturesIterator getFeaturesIterator() throws BaseException { |
|
98 |
return new KmlFeaturesIterator(getReader(),getGFactory()); |
|
99 |
} |
|
100 |
|
|
101 |
/* |
|
102 |
* (non-Javadoc) |
|
103 |
* @see org.gvsig.remoteClient.gmlEngine.IFeaturesParser#getVersion() |
|
104 |
*/ |
|
105 |
public String getVersion() { |
|
106 |
return "2.1"; |
|
107 |
} |
|
108 |
|
|
109 |
} |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/versions/KmlParsersFactory.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml.versions; |
|
2 |
|
|
3 |
import java.util.Hashtable; |
|
4 |
|
|
5 |
import org.gvsig.exceptions.BaseException; |
|
6 |
import org.gvsig.gpe.kml.GPEKmlParser; |
|
7 |
import org.gvsig.gpe.kml.KmlTags; |
|
8 |
import org.gvsig.gpe.kml.exceptions.KmlImpossibleCreateParser; |
|
9 |
import org.xmlpull.v1.XmlPullParser; |
|
10 |
|
|
11 |
|
|
12 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
13 |
* |
|
14 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
15 |
* |
|
16 |
* This program is free software; you can redistribute it and/or |
|
17 |
* modify it under the terms of the GNU General Public License |
|
18 |
* as published by the Free Software Foundation; either version 2 |
|
19 |
* of the License, or (at your option) any later version. |
|
20 |
* |
|
21 |
* This program is distributed in the hope that it will be useful, |
|
22 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
23 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
24 |
* GNU General Public License for more details. |
|
25 |
* |
|
26 |
* You should have received a copy of the GNU General Public License |
|
27 |
* along with this program; if not, write to the Free Software |
|
28 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
29 |
* |
|
30 |
* For more information, contact: |
|
31 |
* |
|
32 |
* Generalitat Valenciana |
|
33 |
* Conselleria d'Infraestructures i Transport |
|
34 |
* Av. Blasco Ib??ez, 50 |
|
35 |
* 46010 VALENCIA |
|
36 |
* SPAIN |
|
37 |
* |
|
38 |
* +34 963862235 |
|
39 |
* gvsig@gva.es |
|
40 |
* www.gvsig.gva.es |
|
41 |
* |
|
42 |
* or |
|
43 |
* |
|
44 |
* IVER T.I. S.A |
|
45 |
* Salamanca 50 |
|
46 |
* 46005 Valencia |
|
47 |
* Spain |
|
48 |
* |
|
49 |
* +34 963163400 |
|
50 |
* dac@iver.es |
|
51 |
*/ |
|
52 |
/* CVS MESSAGES: |
|
53 |
* |
|
54 |
* $Id$ |
|
55 |
* $Log$ |
|
56 |
* Revision 1.1 2007-04-13 13:16:21 jorpiell |
|
57 |
* Add KML reading support |
|
58 |
* |
|
59 |
* Revision 1.2 2007/04/12 10:21:52 jorpiell |
|
60 |
* Add the writers |
|
61 |
* |
|
62 |
* Revision 1.1 2007/03/07 08:19:10 jorpiell |
|
63 |
* Pasadas las clases de KML de libGPE-GML a libGPE-KML |
|
64 |
* |
|
65 |
* Revision 1.1 2007/02/28 11:48:31 csanchez |
|
66 |
* *** empty log message *** |
|
67 |
* |
|
68 |
* Revision 1.1 2007/02/20 10:53:20 jorpiell |
|
69 |
* Añadidos los proyectos de kml y gml antiguos |
|
70 |
* |
|
71 |
* Revision 1.1 2007/02/12 13:49:18 jorpiell |
|
72 |
* A?adido el driver de KML |
|
73 |
* |
|
74 |
* |
|
75 |
*/ |
|
76 |
/** |
|
77 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
|
78 |
*/ |
|
79 |
public class KmlParsersFactory { |
|
80 |
private static Hashtable supportedVersions = new Hashtable(); |
|
81 |
|
|
82 |
static { |
|
83 |
supportedVersions.put("http://earth.google.com/kml/2.1",KmlParserV2_0.class); |
|
84 |
supportedVersions.put("http://earth.google.com/kml/2.0",KmlParserV2_0.class); |
|
85 |
supportedVersions.put(KmlTags.UNKNOWN_VERSION,KmlParserV2_1.class); |
|
86 |
} |
|
87 |
|
|
88 |
public AbstractKmlParser createParser(String nameSpace,XmlPullParser parser, GPEKmlParser handler) throws BaseException{ |
|
89 |
Class clazz = (Class) supportedVersions.get(nameSpace); |
|
90 |
if (clazz == null){ |
|
91 |
clazz = (Class) supportedVersions.get(KmlTags.UNKNOWN_VERSION); |
|
92 |
} |
|
93 |
if (clazz != null){ |
|
94 |
Class [] args = {XmlPullParser.class,GPEKmlParser.class}; |
|
95 |
Object [] params = {parser,handler}; |
|
96 |
try { |
|
97 |
return (AbstractKmlParser)clazz.getConstructor(args).newInstance(params); |
|
98 |
} catch (Exception e) { |
|
99 |
throw new KmlImpossibleCreateParser(nameSpace,e); |
|
100 |
} |
|
101 |
} |
|
102 |
return null ; |
|
103 |
} |
|
104 |
|
|
105 |
|
|
106 |
} |
|
0 | 107 |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/versions/AbstractKmlParser.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml.versions; |
|
2 |
|
|
3 |
import org.gvsig.gpe.kml.GPEKmlParser; |
|
4 |
import org.gvsig.gpe.kml.exceptions.KmlBodyParseException; |
|
5 |
import org.xmlpull.v1.XmlPullParser; |
|
6 |
|
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
8 |
* |
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
10 |
* |
|
11 |
* This program is free software; you can redistribute it and/or |
|
12 |
* modify it under the terms of the GNU General Public License |
|
13 |
* as published by the Free Software Foundation; either version 2 |
|
14 |
* of the License, or (at your option) any later version. |
|
15 |
* |
|
16 |
* This program is distributed in the hope that it will be useful, |
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19 |
* GNU General Public License for more details. |
|
20 |
* |
|
21 |
* You should have received a copy of the GNU General Public License |
|
22 |
* along with this program; if not, write to the Free Software |
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
24 |
* |
|
25 |
* For more information, contact: |
|
26 |
* |
|
27 |
* Generalitat Valenciana |
|
28 |
* Conselleria d'Infraestructures i Transport |
|
29 |
* Av. Blasco Ib??ez, 50 |
|
30 |
* 46010 VALENCIA |
|
31 |
* SPAIN |
|
32 |
* |
|
33 |
* +34 963862235 |
|
34 |
* gvsig@gva.es |
|
35 |
* www.gvsig.gva.es |
|
36 |
* |
|
37 |
* or |
|
38 |
* |
|
39 |
* IVER T.I. S.A |
|
40 |
* Salamanca 50 |
|
41 |
* 46005 Valencia |
|
42 |
* Spain |
|
43 |
* |
|
44 |
* +34 963163400 |
|
45 |
* dac@iver.es |
|
46 |
*/ |
|
47 |
/* CVS MESSAGES: |
|
48 |
* |
|
49 |
* $Id$ |
|
50 |
* $Log$ |
|
51 |
* Revision 1.1 2007-04-13 13:16:21 jorpiell |
|
52 |
* Add KML reading support |
|
53 |
* |
|
54 |
* |
|
55 |
*/ |
|
56 |
/** |
|
57 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es) |
|
58 |
*/ |
|
59 |
public abstract class AbstractKmlParser { |
|
60 |
private XmlPullParser parser = null; |
|
61 |
private GPEKmlParser handler = null; |
|
62 |
|
|
63 |
public AbstractKmlParser(XmlPullParser parser, GPEKmlParser handler) { |
|
64 |
super(); |
|
65 |
this.parser = parser; |
|
66 |
this.handler = handler; |
|
67 |
} |
|
68 |
|
|
69 |
/** |
|
70 |
* Return the version |
|
71 |
* @return |
|
72 |
*/ |
|
73 |
public abstract String getVersion(); |
|
74 |
|
|
75 |
/** |
|
76 |
* Initialize the parsing process |
|
77 |
* @return |
|
78 |
*/ |
|
79 |
public abstract void initParse() throws KmlBodyParseException; |
|
80 |
|
|
81 |
/** |
|
82 |
* @return the handler |
|
83 |
*/ |
|
84 |
public GPEKmlParser getHandler() { |
|
85 |
return handler; |
|
86 |
} |
|
87 |
|
|
88 |
/** |
|
89 |
* @return the parser |
|
90 |
*/ |
|
91 |
public XmlPullParser getParser() { |
|
92 |
return parser; |
|
93 |
} |
|
94 |
} |
|
0 | 95 |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/versions/KmlParserV2_0.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml.versions; |
|
2 |
|
|
3 |
import java.io.IOException; |
|
4 |
|
|
5 |
import org.gvsig.gpe.kml.GPEKmlParser; |
|
6 |
import org.gvsig.gpe.kml.KmlTags; |
|
7 |
import org.gvsig.gpe.kml.bindings.DocumentBinding; |
|
8 |
import org.gvsig.gpe.kml.bindings.LookAtBinding; |
|
9 |
import org.gvsig.gpe.kml.bindings.PlaceMarketBinding; |
|
10 |
import org.gvsig.gpe.kml.exceptions.KmlBodyParseException; |
|
11 |
import org.kxml2.io.KXmlParser; |
|
12 |
import org.xmlpull.v1.XmlPullParser; |
|
13 |
import org.xmlpull.v1.XmlPullParserException; |
|
14 |
|
|
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-13 13:16:21 jorpiell |
|
61 |
* Add KML reading support |
|
62 |
* |
|
63 |
* Revision 1.1 2007/03/07 08:19:10 jorpiell |
|
64 |
* Pasadas las clases de KML de libGPE-GML a libGPE-KML |
|
65 |
* |
|
66 |
* Revision 1.1 2007/02/28 11:48:31 csanchez |
|
67 |
* *** empty log message *** |
|
68 |
* |
|
69 |
* Revision 1.1 2007/02/20 10:53:20 jorpiell |
|
70 |
* Añadidos los proyectos de kml y gml antiguos |
|
71 |
* |
|
72 |
* Revision 1.1 2007/02/12 13:49:18 jorpiell |
|
73 |
* A?adido el driver de KML |
|
74 |
* |
|
75 |
* |
|
76 |
*/ |
|
77 |
/** |
|
78 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
|
79 |
*/ |
|
80 |
public class KmlParserV2_0 extends AbstractKmlParser{ |
|
81 |
|
|
82 |
public KmlParserV2_0(XmlPullParser parser, GPEKmlParser handler) { |
|
83 |
super(parser, handler); |
|
84 |
} |
|
85 |
|
|
86 |
/* |
|
87 |
* (non-Javadoc) |
|
88 |
* @see org.gvsig.remoteClient.gmlEngine.IFeaturesParser#getVersion() |
|
89 |
*/ |
|
90 |
public String getVersion() { |
|
91 |
return "2.0"; |
|
92 |
} |
|
93 |
|
|
94 |
/* |
|
95 |
* (non-Javadoc) |
|
96 |
* @see org.gvsig.gpe.kml.versions.AbstractKmlParser#initParse() |
|
97 |
*/ |
|
98 |
public void initParse() throws KmlBodyParseException { |
|
99 |
boolean endFeature = false; |
|
100 |
int currentTag; |
|
101 |
|
|
102 |
try { |
|
103 |
String tag = getParser().getName(); |
|
104 |
currentTag = getParser().getEventType(); |
|
105 |
|
|
106 |
while (!endFeature){ |
|
107 |
switch(currentTag){ |
|
108 |
case XmlPullParser.START_TAG: |
|
109 |
if (tag.compareTo(KmlTags.DOCUMENT) == 0){ |
|
110 |
DocumentBinding.parse(getParser(), getHandler()); |
|
111 |
} |
|
112 |
break; |
|
113 |
case XmlPullParser.END_DOCUMENT: |
|
114 |
endFeature = true; |
|
115 |
|
|
116 |
break; |
|
117 |
} |
|
118 |
if (!endFeature){ |
|
119 |
currentTag = getParser().next(); |
|
120 |
tag = getParser().getName(); |
|
121 |
} |
|
122 |
} |
|
123 |
|
|
124 |
} catch (XmlPullParserException e) { |
|
125 |
throw new KmlBodyParseException (e); |
|
126 |
} catch (IOException e) { |
|
127 |
throw new KmlBodyParseException (e); |
|
128 |
} |
|
129 |
} |
|
130 |
|
|
131 |
} |
|
0 | 132 |
trunk/libraries/libGPE-KML/src/org/gvsig/gpe/kml/versions/KmlParserV2_1.java | ||
---|---|---|
1 |
package org.gvsig.gpe.kml.versions; |
|
2 |
|
|
3 |
import org.gvsig.gpe.kml.GPEKmlParser; |
|
4 |
import org.xmlpull.v1.XmlPullParser; |
|
5 |
|
|
6 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
7 |
* |
|
8 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
9 |
* |
|
10 |
* This program is free software; you can redistribute it and/or |
|
11 |
* modify it under the terms of the GNU General Public License |
|
12 |
* as published by the Free Software Foundation; either version 2 |
|
13 |
* of the License, or (at your option) any later version. |
|
14 |
* |
|
15 |
* This program is distributed in the hope that it will be useful, |
|
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18 |
* GNU General Public License for more details. |
|
19 |
* |
|
20 |
* You should have received a copy of the GNU General Public License |
|
21 |
* along with this program; if not, write to the Free Software |
|
22 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
23 |
* |
|
24 |
* For more information, contact: |
|
25 |
* |
|
26 |
* Generalitat Valenciana |
|
27 |
* Conselleria d'Infraestructures i Transport |
|
28 |
* Av. Blasco Ib??ez, 50 |
|
29 |
* 46010 VALENCIA |
|
30 |
* SPAIN |
|
31 |
* |
|
32 |
* +34 963862235 |
|
33 |
* gvsig@gva.es |
|
34 |
* www.gvsig.gva.es |
|
35 |
* |
|
36 |
* or |
|
37 |
* |
|
38 |
* IVER T.I. S.A |
|
39 |
* Salamanca 50 |
|
40 |
* 46005 Valencia |
|
41 |
* Spain |
|
42 |
* |
|
43 |
* +34 963163400 |
|
44 |
* dac@iver.es |
|
45 |
*/ |
|
46 |
/* CVS MESSAGES: |
|
47 |
* |
|
48 |
* $Id$ |
|
49 |
* $Log$ |
|
50 |
* Revision 1.1 2007-04-13 13:16:21 jorpiell |
|
51 |
* Add KML reading support |
|
52 |
* |
|
53 |
* |
|
54 |
*/ |
|
55 |
/** |
|
56 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es) |
|
57 |
*/ |
|
58 |
public class KmlParserV2_1 extends KmlParserV2_0{ |
|
59 |
|
|
60 |
public KmlParserV2_1(XmlPullParser parser, GPEKmlParser handler) { |
|
61 |
super(parser, handler); |
|
62 |
} |
|
63 |
|
|
64 |
/* |
|
65 |
* (non-Javadoc) |
Also available in: Unified diff