Revision 12164 trunk/libraries/libGPE-GML/src/org/gvsig/gpe/xml/GPEXmlSchemaMap.java
GPEXmlSchemaMap.java | ||
---|---|---|
5 | 5 |
import java.net.ConnectException; |
6 | 6 |
import java.net.MalformedURLException; |
7 | 7 |
import java.net.URI; |
8 |
import java.net.URISyntaxException; |
|
8 | 9 |
import java.net.URL; |
9 | 10 |
import java.net.UnknownHostException; |
10 | 11 |
import java.util.StringTokenizer; |
11 | 12 |
|
13 |
import org.gvsig.gpe.GPEErrorHandler; |
|
12 | 14 |
import org.gvsig.gpe.gml.GMLTags; |
13 |
import org.gvsig.gpe.schema.exceptions.SchemaCreationException; |
|
14 |
import org.gvsig.gpe.schema.som.impl.XSSchemaDocumentImpl; |
|
15 |
import org.gvsig.gpe.schema.utils.DownloadUtilities; |
|
15 |
import org.gvsig.xmlschema.exceptions.SchemaCreationException; |
|
16 |
import org.gvsig.xmlschema.som.impl.XSSchemaDocumentImpl; |
|
17 |
import org.gvsig.xmlschema.utils.DownloadUtilities; |
|
18 |
import org.gvsig.xmlschema.warnings.SchemaLocationWarning; |
|
16 | 19 |
import org.xmlpull.v1.XmlPullParser; |
17 | 20 |
import org.xmlpull.v1.XmlPullParserException; |
18 | 21 |
|
... | ... | |
60 | 63 |
* |
61 | 64 |
* $Id$ |
62 | 65 |
* $Log$ |
63 |
* Revision 1.2 2007-06-08 13:01:12 jorpiell |
|
66 |
* Revision 1.3 2007-06-14 13:50:05 jorpiell |
|
67 |
* The schema jar name has been changed |
|
68 |
* |
|
69 |
* Revision 1.2 2007/06/08 13:01:12 jorpiell |
|
64 | 70 |
* Add the targetNamespace to the file |
65 | 71 |
* |
66 | 72 |
* Revision 1.1 2007/06/07 14:53:30 jorpiell |
... | ... | |
74 | 80 |
public class GPEXmlSchemaMap extends XSSchemaDocumentImpl{ |
75 | 81 |
private XmlPullParser parser = null; |
76 | 82 |
private URI xmlURI = null; |
83 |
private GPEErrorHandler errorHandler = null; |
|
77 | 84 |
|
78 |
public GPEXmlSchemaMap(XmlPullParser parser, URI xmlURI){ |
|
85 |
public GPEXmlSchemaMap(XmlPullParser parser, URI xmlURI, GPEErrorHandler errorHandler){
|
|
79 | 86 |
this.parser = parser; |
80 |
this.xmlURI = xmlURI; |
|
87 |
this.xmlURI = xmlURI; |
|
88 |
this.errorHandler = errorHandler; |
|
81 | 89 |
} |
82 | 90 |
|
83 | 91 |
/** |
... | ... | |
128 | 136 |
if (!tokenizer.hasMoreTokens()){ |
129 | 137 |
//If it hasn't the name of the schemas file or dont find it, |
130 | 138 |
//it exits, and tries to parse without schema |
131 |
//warnings.setElement(new GMLWarningNotFound(null,null)); |
|
132 | 139 |
System.out.println("Error, esquema no encontrado.PARSEO SIN ESQUEMA "); |
133 |
|
|
134 | 140 |
}else{ |
135 | 141 |
String schemaLocation = tokenizer.nextToken(); |
142 |
//TODO This line must be replaced by the new downloader |
|
136 | 143 |
try { |
137 |
//TODO This line must be replaced by the new downloader |
|
138 |
File file = getSchemaFile(schemaLocation); |
|
139 |
if (file.exists()){ |
|
140 |
addSchema(file); |
|
141 |
} |
|
144 |
URI uri = getSchemaURI(schemaLocation); |
|
145 |
addSchema(uri); |
|
142 | 146 |
} catch (SchemaCreationException e) { |
143 |
// TODO Auto-generated catch block |
|
144 |
e.printStackTrace(); |
|
145 |
} |
|
146 |
} |
|
147 |
errorHandler.addError(e); |
|
148 |
} catch (SchemaLocationWarning e) { |
|
149 |
errorHandler.addWarning(e); |
|
150 |
} |
|
151 |
} |
|
147 | 152 |
} |
148 | 153 |
} |
149 | 154 |
|
... | ... | |
152 | 157 |
* It downloads the schema if it's a remote schema |
153 | 158 |
* else it tries to open a local file and return if it's succesfull |
154 | 159 |
* @param String schema location |
155 |
* @return File local (if is a remote file then first it has to download it) |
|
160 |
* @return Uri |
|
161 |
* @throws SchemaLocationWarning |
|
156 | 162 |
****************************************************************************/ |
157 |
private File getSchemaFile(String schemaLocation){
|
|
163 |
private URI getSchemaURI(String schemaLocation) throws SchemaLocationWarning{
|
|
158 | 164 |
File f = null; |
159 |
|
|
160 | 165 |
//If it is a local file, it has to construct the absolute route |
161 | 166 |
if (schemaLocation.indexOf("http://") != 0){ |
162 | 167 |
f = new File(schemaLocation); |
... | ... | |
164 | 169 |
schemaLocation = new File(xmlURI).getParentFile().getAbsolutePath() + File.separator + schemaLocation; |
165 | 170 |
f = new File(schemaLocation); |
166 | 171 |
} |
167 |
return f; |
|
172 |
try { |
|
173 |
return new URI(f.getAbsolutePath()); |
|
174 |
} catch (URISyntaxException e) { |
|
175 |
throw new SchemaLocationWarning(schemaLocation,e); |
|
176 |
} |
|
168 | 177 |
} |
169 | 178 |
//Else it is an URL direction and it has to download it. |
170 | 179 |
else { |
171 |
URL url; |
|
172 |
|
|
180 |
URL url; |
|
173 | 181 |
try { |
174 | 182 |
url = new URL(schemaLocation); |
175 | 183 |
//Download the schema without cancel option. |
176 |
f = DownloadUtilities.downloadFile(url,"gml_schmema.xsd"); |
|
177 |
} catch (MalformedURLException e) { |
|
178 |
// TODO Bloque catch generado autom?ticamente |
|
179 |
System.out.println("Error, URL del esquema mal formada: "+e.getMessage()); |
|
180 |
} catch (ConnectException e) { |
|
181 |
// TODO Bloque catch generado autom?ticamente |
|
182 |
System.out.println("Error al descargar esquema, Imposible conectar: "+e.getMessage()); |
|
183 |
} catch (UnknownHostException e) { |
|
184 |
// TODO Bloque catch generado autom?ticamente |
|
185 |
System.out.println("Error al descargar esquema, Host desconocido: "+e.getMessage()); |
|
186 |
} catch (IOException e) { |
|
187 |
// TODO Bloque catch generado autom?ticamente |
|
188 |
System.out.println("Erroral descargar esquema, Fallo de lectura/escritura: "+e.getMessage()); |
|
184 |
f = DownloadUtilities.downloadFile(url,"gml_schmema.xsd"); |
|
185 |
return new URI(f.getAbsolutePath()); |
|
186 |
} catch (Exception e) { |
|
187 |
throw new SchemaLocationWarning(schemaLocation,e); |
|
189 | 188 |
} |
190 |
return f; |
|
191 | 189 |
} |
192 | 190 |
} |
193 | 191 |
|
Also available in: Unified diff