root / trunk / libraries / libGPE-KML / src / org / gvsig / gpe / kml / GPEKmlParser.java @ 11171
History | View | Annotate | Download (4 KB)
1 |
package org.gvsig.gpe.kml; |
---|---|
2 |
|
3 |
import java.io.BufferedInputStream; |
4 |
import java.io.File; |
5 |
import java.io.FileInputStream; |
6 |
import java.io.FileNotFoundException; |
7 |
import java.io.IOException; |
8 |
import java.io.InputStream; |
9 |
import java.util.zip.ZipEntry; |
10 |
import java.util.zip.ZipException; |
11 |
import java.util.zip.ZipFile; |
12 |
import java.util.zip.ZipInputStream; |
13 |
|
14 |
import org.gvsig.gpe.GPEContentHandler; |
15 |
import org.gvsig.gpe.GPEErrorHandler; |
16 |
import org.gvsig.gpe.kml.exceptions.KmlException; |
17 |
import org.gvsig.gpe.kml.writer.GPEKmlWriterHandler; |
18 |
import org.gvsig.gpe.writer.GPEWriterHandler; |
19 |
import org.gvsig.gpe.xml.GPEXmlParser; |
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: GPEKmlParser.java 11171 2007-04-12 17:06:44Z jorpiell $
|
64 |
* $Log$
|
65 |
* Revision 1.2 2007-04-12 17:06:43 jorpiell
|
66 |
* First GML writing tests
|
67 |
*
|
68 |
* Revision 1.1 2007/04/12 10:21:52 jorpiell
|
69 |
* Add the writers
|
70 |
*
|
71 |
*
|
72 |
*/
|
73 |
/**
|
74 |
* @author Jorge Piera LLodr? (jorge.piera@iver.es)
|
75 |
*/
|
76 |
public class GPEKmlParser extends GPEXmlParser { |
77 |
|
78 |
public GPEKmlParser(GPEContentHandler contentHandler,GPEErrorHandler errorHandler) {
|
79 |
super(contentHandler,errorHandler);
|
80 |
} |
81 |
|
82 |
/*
|
83 |
* (non-Javadoc)
|
84 |
* @see org.gvsig.gpe.GPEParser#accept(java.io.File)
|
85 |
*/
|
86 |
public boolean accept(File file) { |
87 |
if ((file.getName().toUpperCase().endsWith("KML")) || |
88 |
(file.getName().toUpperCase().endsWith("KMZ"))){
|
89 |
return true; |
90 |
} |
91 |
return false; |
92 |
} |
93 |
|
94 |
/*
|
95 |
* (non-Javadoc)
|
96 |
* @see org.gvsig.gpe.GPEParser#getFormats()
|
97 |
*/
|
98 |
public String[] getFormats() { |
99 |
String[] formats = new String[2]; |
100 |
formats[0] = "KML"; |
101 |
formats[1] = "KMZ"; |
102 |
return formats;
|
103 |
} |
104 |
|
105 |
/*
|
106 |
* (non-Javadoc)
|
107 |
* @see org.gvsig.gpe.GPEParser#getWriter(java.lang.String, java.lang.String)
|
108 |
*/
|
109 |
public GPEWriterHandler getWriter(String format, File file) throws IOException { |
110 |
return new GPEKmlWriterHandler(format,file,getErrorHandler()); |
111 |
} |
112 |
|
113 |
|
114 |
/**
|
115 |
* It creates an InputStream. The Kml file can have the
|
116 |
* KML or the KMZ extension
|
117 |
* @return
|
118 |
* @throws KmlException
|
119 |
*/
|
120 |
protected InputStream createInputStream(File file){ |
121 |
try {
|
122 |
if (file.getName().toUpperCase().endsWith("KML")){ |
123 |
return new FileInputStream(file); |
124 |
}else if(file.getName().toUpperCase().endsWith("KMZ")){ |
125 |
FileInputStream fis = new FileInputStream(file); |
126 |
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis)); |
127 |
ZipEntry entry = null; |
128 |
while((entry = zis.getNextEntry()) != null){ |
129 |
if (!entry.isDirectory()){
|
130 |
ZipFile fz = new ZipFile(file); |
131 |
return fz.getInputStream(entry);
|
132 |
} |
133 |
} |
134 |
} |
135 |
} catch (FileNotFoundException e) { |
136 |
// TODO Auto-generated catch block
|
137 |
e.printStackTrace(); |
138 |
} catch (ZipException e) { |
139 |
// TODO Auto-generated catch block
|
140 |
e.printStackTrace(); |
141 |
} catch (IOException e) { |
142 |
// TODO Auto-generated catch block
|
143 |
e.printStackTrace(); |
144 |
} |
145 |
return null; |
146 |
} |
147 |
|
148 |
/*
|
149 |
* (non-Javadoc)
|
150 |
* @see org.gvsig.gpe.xml.GPEXmlParser#initParse()
|
151 |
*/
|
152 |
protected void initParse() { |
153 |
|
154 |
} |
155 |
} |