Revision 5536
trunk/libraries/libRemoteServices/src/org/gvsig/remoteClient/wms/WMSProtocolHandler.java | ||
---|---|---|
24 | 24 |
import org.kxml2.io.KXmlParser; |
25 | 25 |
import org.xmlpull.v1.XmlPullParserException; |
26 | 26 |
|
27 |
import com.iver.andami.PluginServices; |
|
28 |
|
|
29 | 27 |
/** |
30 | 28 |
* <p> Abstract class that represents handlers to comunicate via WMS protocol. |
31 | 29 |
* </p> |
... | ... | |
235 | 233 |
} |
236 | 234 |
else |
237 | 235 |
{ |
238 |
sb.append("<INFO>").append(PluginServices.getText(this, "info_format_not_supported")).append("</INFO>");
|
|
236 |
sb.append("<INFO>").append("Info format not supported").append("</INFO>");
|
|
239 | 237 |
return sb.toString(); |
240 | 238 |
//Para que funcione con el GetFeatureInfo Viewer generico hay que devolver: |
241 | 239 |
// return output.toString(); |
... | ... | |
249 | 247 |
} |
250 | 248 |
else |
251 | 249 |
{ |
252 |
sb.append("<INFO>").append(PluginServices.getText(this, "info_format_not_supported")).append("</INFO>");
|
|
250 |
sb.append("<INFO>").append("Info format not supported").append("</INFO>");
|
|
253 | 251 |
return sb.toString(); |
254 | 252 |
} |
255 | 253 |
} |
256 | 254 |
catch(Exception e) |
257 | 255 |
{ |
258 | 256 |
e.printStackTrace(); |
259 |
sb.append("<INFO>").append(PluginServices.getText(this, "info_format_not_supported")).append("</INFO>");
|
|
257 |
sb.append("<INFO>").append("Info format not supported").append("</INFO>");
|
|
260 | 258 |
return sb.toString(); |
261 | 259 |
|
262 | 260 |
} |
trunk/libraries/libRemoteServices/src/org/gvsig/remoteClient/wfs/WFSProtocolHandler.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.io.File; |
4 | 4 |
import java.net.URL; |
5 |
import java.util.Enumeration; |
|
6 | 5 |
import java.util.HashMap; |
7 | 6 |
import java.util.Hashtable; |
8 | 7 |
import java.util.Set; |
9 | 8 |
import java.util.Vector; |
10 | 9 |
|
11 | 10 |
import org.gvsig.remoteClient.OGCProtocolHandler; |
11 |
import org.gvsig.remoteClient.utils.Utilities; |
|
12 | 12 |
|
13 | 13 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
14 | 14 |
* |
... | ... | |
54 | 54 |
* |
55 | 55 |
* $Id$ |
56 | 56 |
* $Log$ |
57 |
* Revision 1.3 2006-05-23 13:23:13 jorpiell |
|
57 |
* Revision 1.4 2006-05-30 13:58:03 jaume |
|
58 |
* cancelable downloads |
|
59 |
* |
|
60 |
* Revision 1.3 2006/05/23 13:23:13 jorpiell |
|
58 | 61 |
* Se ha cambiado el final del bucle de parseado y se tiene en cuenta el online resource |
59 | 62 |
* |
60 | 63 |
* Revision 1.2 2006/04/20 16:39:16 jorpiell |
... | ... | |
94 | 97 |
e.printStackTrace(); |
95 | 98 |
} |
96 | 99 |
try { |
97 |
File f = com.iver.andami.Utilities.downloadFile(request,"wfs_capabilities.xml");
|
|
100 |
File f = Utilities.downloadFile(request,"wfs_capabilities.xml", null);
|
|
98 | 101 |
parseCapabilities(f); |
99 | 102 |
} catch(Exception e) { |
100 | 103 |
e.printStackTrace(); |
... | ... | |
156 | 159 |
e.printStackTrace(); |
157 | 160 |
} |
158 | 161 |
try { |
159 |
File f = com.iver.andami.Utilities.downloadFile(request, "wfs_describeFeatureType.xml");
|
|
162 |
File f = Utilities.downloadFile(request, "wfs_describeFeatureType.xml", null);
|
|
160 | 163 |
parseDescribeFeatureType(f); |
161 | 164 |
|
162 | 165 |
} catch(Exception e) { |
... | ... | |
205 | 208 |
e.printStackTrace(); |
206 | 209 |
} |
207 | 210 |
try { |
208 |
File f = com.iver.andami.Utilities.downloadFile(request, "wfs_getFeature.xml");
|
|
211 |
File f = Utilities.downloadFile(request, "wfs_getFeature.xml", null);
|
|
209 | 212 |
return f; |
210 | 213 |
|
211 | 214 |
} catch(Exception e) { |
trunk/libraries/libRemoteServices/src/org/gvsig/remoteClient/utils/Utilities.java | ||
---|---|---|
68 | 68 |
*/ |
69 | 69 |
public class Utilities { |
70 | 70 |
private static String characters; |
71 |
static boolean canceled; |
|
72 |
static final long latency = 500; |
|
71 | 73 |
/** |
72 | 74 |
* <b>key</b>: URL, <b>value</b>: path to the downloaded file. |
73 | 75 |
*/ |
74 | 76 |
private static Hashtable downloadedFiles; |
77 |
static Exception downloadException; |
|
75 | 78 |
private static final String tempDirectoryPath = System.getProperty("java.io.tmpdir")+"/tmp-andami"; |
76 | 79 |
|
77 | 80 |
|
... | ... | |
431 | 434 |
* @param url |
432 | 435 |
* @param filePath |
433 | 436 |
*/ |
434 |
private static void addDownloadedURL(URL url, String filePath){
|
|
437 |
static void addDownloadedURL(URL url, String filePath){ |
|
435 | 438 |
if (downloadedFiles==null) |
436 | 439 |
downloadedFiles = new Hashtable(); |
437 | 440 |
String fileName = (String) downloadedFiles.put(url, filePath); |
... | ... | |
458 | 461 |
* @throws ConnectException |
459 | 462 |
* @throws UnknownHostException |
460 | 463 |
*/ |
461 |
public static File downloadFile(URL url, String name, ICancellable cancel) throws IOException,ConnectException, UnknownHostException{ |
|
464 |
public static synchronized File downloadFile(URL url, String name, ICancellable cancel) throws IOException,ConnectException, UnknownHostException{
|
|
462 | 465 |
File f = null; |
463 |
|
|
464 |
try{
|
|
465 |
if ((f=getPreviousDownloadedURL(url))==null){
|
|
466 |
File tempDirectory = new File(tempDirectoryPath);
|
|
467 |
if (!tempDirectory.exists())
|
|
468 |
tempDirectory.mkdir(); |
|
469 |
|
|
470 |
f = new File(tempDirectoryPath+"/"+name+System.currentTimeMillis()); |
|
471 |
|
|
472 |
System.out.println("downloading '"+url.toString()+"' to: "+f.getAbsolutePath());
|
|
473 |
|
|
474 |
f.deleteOnExit();
|
|
475 |
DataOutputStream dos = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(f)));
|
|
476 |
byte[] buffer = new byte[1024*4];
|
|
477 |
DataInputStream is = new DataInputStream(url.openStream());
|
|
478 |
long readed = 0;
|
|
479 |
boolean canceled = (cancel!=null) ? cancel.isCanceled() : false;
|
|
480 |
for (int i = is.read(buffer); !canceled && i>0; i = is.read(buffer)){
|
|
481 |
dos.write(buffer, 0, i);
|
|
482 |
readed += i;
|
|
483 |
if (cancel!=null)
|
|
484 |
canceled = cancel.isCanceled();
|
|
485 |
|
|
486 |
}
|
|
487 |
dos.close();
|
|
488 |
is.close();
|
|
489 |
is = null;
|
|
490 |
dos = null;
|
|
491 |
if (canceled) {
|
|
492 |
System.err.println("[RemoteClients] '"+url+"' CANCELED.");
|
|
493 |
f.delete();
|
|
494 |
f= null;
|
|
495 |
} else {
|
|
496 |
addDownloadedURL(url, f.getAbsolutePath());
|
|
497 |
}
|
|
498 |
}
|
|
499 |
} catch (IOException io) {
|
|
500 |
io.printStackTrace();
|
|
501 |
}
|
|
502 |
|
|
503 |
return f;
|
|
466 |
|
|
467 |
if ((f=getPreviousDownloadedURL(url))==null){
|
|
468 |
File tempDirectory = new File(tempDirectoryPath);
|
|
469 |
if (!tempDirectory.exists())
|
|
470 |
tempDirectory.mkdir();
|
|
471 |
|
|
472 |
f = new File(tempDirectoryPath+"/"+name+System.currentTimeMillis()); |
|
473 |
|
|
474 |
if (cancel == null) { |
|
475 |
cancel = new ICancellable() {
|
|
476 |
public boolean isCanceled() { |
|
477 |
return false;
|
|
478 |
}
|
|
479 |
};
|
|
480 |
}
|
|
481 |
Thread downloader = new Thread(new Downloader(url, f));
|
|
482 |
Thread monitor = new Thread(new Monitor(cancel));
|
|
483 |
monitor.start();
|
|
484 |
downloader.start();
|
|
485 |
while(!canceled && downloader.isAlive()) {
|
|
486 |
try {
|
|
487 |
Thread.sleep(latency);
|
|
488 |
} catch (InterruptedException e) { |
|
489 |
// TODO Auto-generated catch block
|
|
490 |
e.printStackTrace();
|
|
491 |
}
|
|
492 |
}
|
|
493 |
downloader = null;
|
|
494 |
monitor = null;
|
|
495 |
if (Utilities.downloadException!=null) {
|
|
496 |
Exception e = Utilities.downloadException;
|
|
497 |
if (e instanceof IOException)
|
|
498 |
throw (IOException) e;
|
|
499 |
else if (e instanceof ConnectException)
|
|
500 |
throw (ConnectException) e;
|
|
501 |
else if (e instanceof UnknownHostException)
|
|
502 |
throw (UnknownHostException) e;
|
|
503 |
}
|
|
504 |
}
|
|
505 |
|
|
506 |
return f;
|
|
504 | 507 |
} |
505 | 508 |
|
506 | 509 |
/** |
... | ... | |
545 | 548 |
if (downloadedFiles != null && downloadedFiles.containsKey(url)) |
546 | 549 |
downloadedFiles.remove(url); |
547 | 550 |
} |
551 |
|
|
552 |
|
|
548 | 553 |
} |
554 |
|
|
555 |
final class Monitor implements Runnable { |
|
556 |
ICancellable c; |
|
557 |
public Monitor(ICancellable cancel) { |
|
558 |
Utilities.canceled = false; |
|
559 |
this.c = cancel; |
|
560 |
} |
|
561 |
public void run() { |
|
562 |
while (!c.isCanceled()) { |
|
563 |
try { |
|
564 |
Thread.sleep(Utilities.latency); |
|
565 |
} catch (InterruptedException e) { |
|
566 |
// TODO Auto-generated catch block |
|
567 |
e.printStackTrace(); |
|
568 |
} |
|
569 |
} |
|
570 |
Utilities.canceled = true; |
|
571 |
} |
|
572 |
} |
|
573 |
|
|
574 |
final class Downloader implements Runnable { |
|
575 |
private URL url; |
|
576 |
private File dstFile; |
|
577 |
|
|
578 |
public Downloader(URL url, File dstFile) { |
|
579 |
this.url = url; |
|
580 |
this.dstFile = dstFile; |
|
581 |
Utilities.downloadException = null; |
|
582 |
} |
|
583 |
|
|
584 |
public void run() { |
|
585 |
System.out.println("downloading '"+url.toString()+"' to: "+dstFile.getAbsolutePath()); |
|
586 |
|
|
587 |
DataOutputStream dos; |
|
588 |
try { |
|
589 |
dos = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(dstFile))); |
|
590 |
byte[] buffer = new byte[1024*4]; |
|
591 |
DataInputStream is = new DataInputStream(url.openStream()); |
|
592 |
long readed = 0; |
|
593 |
for (int i = is.read(buffer); !Utilities.canceled && i>0; i = is.read(buffer)){ |
|
594 |
dos.write(buffer, 0, i); |
|
595 |
readed += i; |
|
596 |
|
|
597 |
} |
|
598 |
dos.close(); |
|
599 |
is.close(); |
|
600 |
is = null; |
|
601 |
dos = null; |
|
602 |
if (Utilities.canceled) { |
|
603 |
System.err.println("[RemoteClients] '"+url+"' CANCELED."); |
|
604 |
dstFile.delete(); |
|
605 |
dstFile= null; |
|
606 |
} else { |
|
607 |
Utilities.addDownloadedURL(url, dstFile.getAbsolutePath()); |
|
608 |
} |
|
609 |
} catch (Exception e) { |
|
610 |
Utilities.downloadException = e; |
|
611 |
} |
|
612 |
|
|
613 |
} |
|
614 |
} |
Also available in: Unified diff