svn-gvsig-desktop / tags / Root_CqCMSGisPlanet / libraries / libCq CMS for java.old / src / org / cresques / io / MapServerClient.java @ 1933
History | View | Annotate | Download (2.87 KB)
1 | 1717 | luisw | /*
|
---|---|---|---|
2 | * Created on 12-dic-2004
|
||
3 | */
|
||
4 | package org.cresques.io; |
||
5 | |||
6 | import java.io.BufferedInputStream; |
||
7 | import java.io.IOException; |
||
8 | import java.io.InputStream; |
||
9 | import java.net.MalformedURLException; |
||
10 | import java.net.URL; |
||
11 | |||
12 | import org.cresques.px.Extent; |
||
13 | |||
14 | /**
|
||
15 | * Consulta para un servidor de mapas.
|
||
16 | * @author Luis W. Sevilla (sevilla_lui@gva.es)
|
||
17 | */
|
||
18 | public abstract class MapServerClient implements Extent.Has { |
||
19 | public static final int MAXBUFSIZE = 1024*1024; |
||
20 | BufferedInputStream bufIn = null; |
||
21 | byte [] buffer; |
||
22 | int bufPos;
|
||
23 | String serverName;
|
||
24 | protected String urlBase = null; |
||
25 | protected long xMin, xMax, yMin, yMax; |
||
26 | protected int ancho, alto; |
||
27 | public boolean echo = false; |
||
28 | private Extent extent = null; |
||
29 | private int maxViewWidth = 1500; |
||
30 | private int maxViewHeight = 1500; |
||
31 | private float minTimeBetweenQuerys = 0; |
||
32 | |||
33 | public MapServerClient(String serverName) { |
||
34 | this.serverName = serverName;
|
||
35 | } |
||
36 | |||
37 | public String getName() { return serverName; } |
||
38 | |||
39 | public byte [] getBuffer() { return buffer; } |
||
40 | |||
41 | public void setView(long xMin, long yMin, long xMax, long yMax) { |
||
42 | this.xMin = xMin; this.xMax = xMax; |
||
43 | this.yMax = yMax; this.yMin = yMin; |
||
44 | } |
||
45 | |||
46 | public void setViewSize( int w, int h) { |
||
47 | ancho = w; alto = h; |
||
48 | } |
||
49 | |||
50 | /**
|
||
51 | * Pone el tama?o m?ximo de la vista. Solicitando una vista m?s
|
||
52 | * grande que esta al servidor dar? error (y no im?genes) :-(
|
||
53 | * @param w ancho
|
||
54 | * @param h alto
|
||
55 | */
|
||
56 | public void setMaxViewSize( int w, int h) { |
||
57 | maxViewWidth = w; maxViewHeight = h; |
||
58 | } |
||
59 | |||
60 | public Extent getViewExtent() {
|
||
61 | return new Extent(xMin, yMax, xMax, yMin); |
||
62 | } |
||
63 | |||
64 | public void setExtent(Extent e) { extent = e; } |
||
65 | |||
66 | public Extent getExtent() { return extent; } |
||
67 | |||
68 | abstract public String getUrl(); |
||
69 | |||
70 | public void get() throws Exception { |
||
71 | get(getUrl()); |
||
72 | } |
||
73 | public void get(String address) throws Exception { |
||
74 | bufPos = 0;
|
||
75 | buffer = new byte[MAXBUFSIZE]; |
||
76 | try {
|
||
77 | // Check to see that a command parameter was entered
|
||
78 | |||
79 | // Create an URL instance
|
||
80 | URL url = new URL(address); |
||
81 | |||
82 | // Get an input stream for reading
|
||
83 | InputStream in = url.openStream();
|
||
84 | |||
85 | // Create a buffered input stream for efficency
|
||
86 | bufIn = new BufferedInputStream(in); |
||
87 | // Repeat until end of file
|
||
88 | int data;
|
||
89 | for (bufPos = 0; (data = bufIn.read()) != -1; bufPos++) { |
||
90 | buffer[bufPos] = (byte) data;
|
||
91 | if ( echo ) System.out.println (data); |
||
92 | } |
||
93 | |||
94 | byte [] buf = new byte[bufPos]; |
||
95 | for (int i=0; i<bufPos; i++) buf[i] = buffer[i]; |
||
96 | buffer = buf; |
||
97 | System.out.println(bufPos+" bytes leidos."); |
||
98 | |||
99 | bufIn.close(); |
||
100 | in.close(); |
||
101 | } catch (MalformedURLException mue) { |
||
102 | System.err.println ("Invalid URL"); |
||
103 | } catch (IOException ioe) { |
||
104 | System.err.println ("I/O Error - " + ioe); |
||
105 | } |
||
106 | } |
||
107 | } |