svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / io / MapServerClient.java @ 2312
History | View | Annotate | Download (3.71 KB)
1 |
/*
|
---|---|
2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications.
|
3 |
*
|
4 |
* Copyright (C) 2004-5.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* cresques@gmail.com
|
23 |
*/
|
24 |
package org.cresques.io; |
25 |
|
26 |
import java.io.BufferedInputStream; |
27 |
import java.io.IOException; |
28 |
import java.io.InputStream; |
29 |
import java.net.MalformedURLException; |
30 |
import java.net.URL; |
31 |
|
32 |
import org.cresques.px.Extent; |
33 |
|
34 |
/**
|
35 |
* Consulta para un servidor de mapas.
|
36 |
* @author Luis W. Sevilla (sevilla_lui@gva.es)
|
37 |
*/
|
38 |
public abstract class MapServerClient implements Extent.Has { |
39 |
public static final int MAXBUFSIZE = 1024*1024; |
40 |
BufferedInputStream bufIn = null; |
41 |
byte [] buffer; |
42 |
int bufPos;
|
43 |
String serverName;
|
44 |
protected String urlBase = null; |
45 |
protected long xMin, xMax, yMin, yMax; |
46 |
protected int ancho, alto; |
47 |
public boolean echo = false; |
48 |
private Extent extent = null; |
49 |
private int maxViewWidth = 1500; |
50 |
private int maxViewHeight = 1500; |
51 |
private float minTimeBetweenQuerys = 0; |
52 |
|
53 |
public MapServerClient(String serverName) { |
54 |
this.serverName = serverName;
|
55 |
} |
56 |
|
57 |
public String getName() { return serverName; } |
58 |
|
59 |
public byte [] getBuffer() { return buffer; } |
60 |
|
61 |
public void setView(long xMin, long yMin, long xMax, long yMax) { |
62 |
this.xMin = xMin; this.xMax = xMax; |
63 |
this.yMax = yMax; this.yMin = yMin; |
64 |
} |
65 |
|
66 |
public void setViewSize( int w, int h) { |
67 |
ancho = w; alto = h; |
68 |
} |
69 |
|
70 |
/**
|
71 |
* Pone el tama?o m?ximo de la vista. Solicitando una vista m?s
|
72 |
* grande que esta al servidor dar? error (y no im?genes) :-(
|
73 |
* @param w ancho
|
74 |
* @param h alto
|
75 |
*/
|
76 |
public void setMaxViewSize( int w, int h) { |
77 |
maxViewWidth = w; maxViewHeight = h; |
78 |
} |
79 |
|
80 |
public Extent getViewExtent() {
|
81 |
return new Extent(xMin, yMax, xMax, yMin); |
82 |
} |
83 |
|
84 |
public void setExtent(Extent e) { extent = e; } |
85 |
|
86 |
public Extent getExtent() { return extent; } |
87 |
|
88 |
abstract public String getUrl(); |
89 |
|
90 |
public void get() throws Exception { |
91 |
get(getUrl()); |
92 |
} |
93 |
public void get(String address) throws Exception { |
94 |
bufPos = 0;
|
95 |
buffer = new byte[MAXBUFSIZE]; |
96 |
try {
|
97 |
// Check to see that a command parameter was entered
|
98 |
|
99 |
// Create an URL instance
|
100 |
URL url = new URL(address); |
101 |
|
102 |
// Get an input stream for reading
|
103 |
InputStream in = url.openStream();
|
104 |
|
105 |
// Create a buffered input stream for efficency
|
106 |
bufIn = new BufferedInputStream(in); |
107 |
// Repeat until end of file
|
108 |
int data;
|
109 |
for (bufPos = 0; (data = bufIn.read()) != -1; bufPos++) { |
110 |
buffer[bufPos] = (byte) data;
|
111 |
if ( echo ) System.out.println (data); |
112 |
} |
113 |
|
114 |
byte [] buf = new byte[bufPos]; |
115 |
for (int i=0; i<bufPos; i++) buf[i] = buffer[i]; |
116 |
buffer = buf; |
117 |
System.out.println(bufPos+" bytes leidos."); |
118 |
|
119 |
bufIn.close(); |
120 |
in.close(); |
121 |
} catch (MalformedURLException mue) { |
122 |
System.err.println ("Invalid URL"); |
123 |
} catch (IOException ioe) { |
124 |
System.err.println ("I/O Error - " + ioe); |
125 |
} |
126 |
} |
127 |
} |
128 |
|