svn-gvsig-desktop / trunk / libraries / libGPE-KML / src / org / gvsig / gpe / kml / parser / GPEKmz2_1_Parser.java @ 37960
History | View | Annotate | Download (3.74 KB)
1 |
package org.gvsig.gpe.kml.parser; |
---|---|
2 |
|
3 |
import java.io.BufferedInputStream; |
4 |
import java.io.BufferedReader; |
5 |
import java.io.File; |
6 |
import java.io.FileInputStream; |
7 |
import java.io.FileNotFoundException; |
8 |
import java.io.IOException; |
9 |
import java.io.InputStream; |
10 |
import java.io.InputStreamReader; |
11 |
import java.net.URI; |
12 |
import java.util.zip.ZipEntry; |
13 |
import java.util.zip.ZipException; |
14 |
import java.util.zip.ZipFile; |
15 |
import java.util.zip.ZipInputStream; |
16 |
|
17 |
import org.gvsig.gpe.kml.exceptions.KmlException; |
18 |
import org.gvsig.gpe.kml.parser.profiles.Kml2_1_BindingProfile; |
19 |
|
20 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
21 |
*
|
22 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
23 |
*
|
24 |
* This program is free software; you can redistribute it and/or
|
25 |
* modify it under the terms of the GNU General Public License
|
26 |
* as published by the Free Software Foundation; either version 2
|
27 |
* of the License, or (at your option) any later version.
|
28 |
*
|
29 |
* This program is distributed in the hope that it will be useful,
|
30 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
31 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
32 |
* GNU General Public License for more details.
|
33 |
*
|
34 |
* You should have received a copy of the GNU General Public License
|
35 |
* along with this program; if not, write to the Free Software
|
36 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
37 |
*
|
38 |
* For more information, contact:
|
39 |
*
|
40 |
* Generalitat Valenciana
|
41 |
* Conselleria d'Infraestructures i Transport
|
42 |
* Av. Blasco Ib??ez, 50
|
43 |
* 46010 VALENCIA
|
44 |
* SPAIN
|
45 |
*
|
46 |
* +34 963862235
|
47 |
* gvsig@gva.es
|
48 |
* www.gvsig.gva.es
|
49 |
*
|
50 |
* or
|
51 |
*
|
52 |
* IVER T.I. S.A
|
53 |
* Salamanca 50
|
54 |
* 46005 Valencia
|
55 |
* Spain
|
56 |
*
|
57 |
* +34 963163400
|
58 |
* dac@iver.es
|
59 |
*/
|
60 |
/* CVS MESSAGES:
|
61 |
*
|
62 |
* $Id$
|
63 |
* $Log$
|
64 |
*
|
65 |
*/
|
66 |
/**
|
67 |
* @author Jorge Piera Llodr? (jorge.piera@iver.es)
|
68 |
*/
|
69 |
public class GPEKmz2_1_Parser extends GPEDefaultKmlParser{ |
70 |
|
71 |
public GPEKmz2_1_Parser() {
|
72 |
super();
|
73 |
setProfile(new Kml2_1_BindingProfile());
|
74 |
} |
75 |
|
76 |
/*
|
77 |
* (non-Javadoc)
|
78 |
* @see org.gvsig.gpe.parser.GPEParser#getDescription()
|
79 |
*/
|
80 |
public String getDescription() { |
81 |
return "This parser parses KML 2.1"; |
82 |
} |
83 |
|
84 |
/*
|
85 |
* (non-Javadoc)
|
86 |
* @see org.gvsig.gpe.parser.GPEParser#getName()
|
87 |
*/
|
88 |
public String getName() { |
89 |
return "KMZ v2.1"; |
90 |
} |
91 |
|
92 |
/*
|
93 |
* (non-Javadoc)
|
94 |
* @see org.gvsig.gpe.parser.GPEParser#getFormat()
|
95 |
*/
|
96 |
public String getFormat() { |
97 |
return "application/zip; subtype=kml/2.1"; |
98 |
} |
99 |
|
100 |
/**
|
101 |
* It creates an InputStream. The Kml file can have the
|
102 |
* KML or the KMZ extension
|
103 |
* @return
|
104 |
* @throws KmlException
|
105 |
*/
|
106 |
protected InputStream createInputStream(File file){ |
107 |
//KMZ
|
108 |
try {
|
109 |
FileInputStream fis = new FileInputStream(file); |
110 |
if (file.getPath().toUpperCase().endsWith("KML")) |
111 |
return fis;
|
112 |
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis)); |
113 |
ZipEntry entry = null; |
114 |
while((entry = zis.getNextEntry()) != null){ |
115 |
if (!entry.isDirectory()){
|
116 |
ZipFile fz = new ZipFile(file); |
117 |
if (entry.getName().toLowerCase().endsWith(".kml")) { |
118 |
InputStream st = fz.getInputStream(entry);
|
119 |
return fz.getInputStream(entry);
|
120 |
} |
121 |
} |
122 |
} |
123 |
} catch (FileNotFoundException e) { |
124 |
getErrorHandler().addError(e); |
125 |
} catch (ZipException e) { |
126 |
getErrorHandler().addError(e); |
127 |
} catch (IOException e) { |
128 |
getErrorHandler().addError(e); |
129 |
} |
130 |
return null; |
131 |
} |
132 |
|
133 |
/*
|
134 |
* (non-Javadoc)
|
135 |
* @see org.gvsig.gpe.GPEParser#accept(java.io.File)
|
136 |
*/
|
137 |
public boolean accept(URI uri) { |
138 |
if (uri.getPath().toUpperCase().endsWith("KMZ")){ |
139 |
return true; |
140 |
} |
141 |
if (uri.getPath().toUpperCase().endsWith("KML")){ |
142 |
return true; |
143 |
} |
144 |
return false; |
145 |
} |
146 |
|
147 |
} |