Revision 3345
trunk/libraries/libRemoteServices/src/org/gvsig/remoteClient/wms/WMSStatus.java | ||
---|---|---|
1 | 1 |
|
2 | 2 |
package org.gvsig.remoteClient.wms; |
3 | 3 |
|
4 |
import java.awt.geom.Rectangle2D; |
|
4 | 5 |
import java.util.Vector; |
5 | 6 |
|
6 | 7 |
/** |
... | ... | |
17 | 18 |
// List of layer styles |
18 | 19 |
private Vector styles; |
19 | 20 |
// extent required by the WMS client |
20 |
private org.gvsig.remoteClient.utils.BoundaryBox bbox;
|
|
21 |
private Rectangle2D extent;
|
|
21 | 22 |
|
22 | 23 |
|
23 | 24 |
// sets the list of layers required by the WMS client |
... | ... | |
95 | 96 |
public boolean removeStyleName(String _name) { |
96 | 97 |
return styles.remove(_name); |
97 | 98 |
} |
99 |
/** |
|
100 |
* <p>Gets the extent defined by the map</p> |
|
101 |
*/ |
|
102 |
public Rectangle2D getExtent() { |
|
103 |
return extent; |
|
104 |
} |
|
105 |
/** |
|
106 |
* <p>Sets the extent defined by the map</p> |
|
107 |
*/ |
|
108 |
public void setExtent(Rectangle2D extent) { |
|
109 |
this.extent = extent; |
|
110 |
} |
|
111 |
|
|
98 | 112 |
} |
trunk/libraries/libRemoteServices/src/org/gvsig/remoteClient/wms/WMSClient.java | ||
---|---|---|
7 | 7 |
import org.gvsig.remoteClient.wms.wms_1_1_1.WMSProtocolHandler1_1_1; |
8 | 8 |
|
9 | 9 |
/** |
10 |
* <p></p> |
|
10 |
* <p>Represents the class the with the necessary logic to connect to a OGCWMS and interpretate the data </p>
|
|
11 | 11 |
* |
12 | 12 |
*/ |
13 | 13 |
public class WMSClient extends org.gvsig.remoteClient.RasterClient { |
... | ... | |
18 | 18 |
public WMSClient() |
19 | 19 |
{} |
20 | 20 |
|
21 |
/** |
|
22 |
* Constructor. |
|
23 |
* the parameter host, indicates the WMS host to connect. |
|
24 |
* */ |
|
21 | 25 |
public WMSClient(String host) |
22 | 26 |
{ |
23 | 27 |
//m_log = LogManager.getLogManager().getLogger(getClass().getName()); |
... | ... | |
30 | 34 |
handler.setHost(host); |
31 | 35 |
} |
32 | 36 |
catch(Exception e) |
33 |
{} |
|
37 |
{ |
|
38 |
//TODO: Implement logic to handle exceptions... |
|
39 |
} |
|
34 | 40 |
|
35 | 41 |
} |
36 | 42 |
|
37 | 43 |
/** |
38 |
* <p>Does ...</p> |
|
39 |
* |
|
44 |
* <p>One of the three interfaces that OGC WMS defines. Request a map.</p> |
|
40 | 45 |
*/ |
41 |
public void getMap() { |
|
42 |
handler.getMap(); |
|
46 |
public void getMap(WMSStatus status) {
|
|
47 |
handler.getMap(status);
|
|
43 | 48 |
} |
44 | 49 |
|
45 | 50 |
/** |
46 |
* <p>Does ...</p>
|
|
51 |
* <p>One of the three interfaces defined by OGC WMS, it gets the service capabilities</p>
|
|
47 | 52 |
* |
48 | 53 |
*/ |
49 | 54 |
public void getCapabilities() { |
... | ... | |
52 | 57 |
} |
53 | 58 |
|
54 | 59 |
/** |
55 |
* <p>Does ...</p> |
|
56 |
* |
|
57 |
* |
|
60 |
* <p>One of the three interfaces defined by the OGC WMS, it gets the information about a feature requested</p> |
|
58 | 61 |
* @return |
59 | 62 |
*/ |
60 | 63 |
public String getFeatureInfo() { |
... | ... | |
62 | 65 |
} |
63 | 66 |
|
64 | 67 |
/** |
65 |
* <p>Does ...</p> |
|
66 |
* |
|
67 |
* |
|
68 |
* @return |
|
68 |
* <p> Reads from the WMS Capabilities, the layers available in the service</p> |
|
69 |
* @return a TreeMap with the available layers in the WMS |
|
69 | 70 |
*/ |
70 | 71 |
public TreeMap getLayers() { |
71 | 72 |
return layers; |
72 | 73 |
} |
73 | 74 |
|
74 | 75 |
/** |
75 |
* <p>Does ...</p> |
|
76 |
* |
|
77 |
* |
|
78 |
* @return |
|
76 |
* <p>Reads from the WMS Capabilities the number if layers available in the service</p> |
|
77 |
* @return, number of layers available |
|
79 | 78 |
*/ |
80 | 79 |
public int getNumberOfLayers() { |
81 | 80 |
if (layers != null) |
... | ... | |
89 | 88 |
} |
90 | 89 |
|
91 | 90 |
/** |
92 |
* <p>Does ...</p>
|
|
91 |
* <p>Gets the WMSLayer with this name</p>
|
|
93 | 92 |
* |
94 |
* |
|
95 |
* @param _name |
|
96 |
* @return |
|
93 |
* @param _name, layer name |
|
94 |
* @return the layer with this name |
|
97 | 95 |
*/ |
98 | 96 |
public WMSLayer getLayer(String _name) { |
99 | 97 |
if (layers.get(_name) != null) |
... | ... | |
119 | 117 |
return names; |
120 | 118 |
} |
121 | 119 |
|
122 |
/** |
|
123 |
* Adds a Layer object to the vector of layers of this LayerSet |
|
124 |
*/ |
|
125 |
public void addLayer(WMSLayer layer) |
|
126 |
{ |
|
127 |
String layerName = layer.getName(); |
|
128 |
|
|
129 |
if (layerName == null) |
|
130 |
{ |
|
131 |
throw new RuntimeException("Error: attempt to add a nameless layer"); |
|
132 |
} |
|
133 |
|
|
134 |
// We use the lower case version of the name as a key for the hash map. |
|
135 |
layerName = layerName.toLowerCase(); |
|
136 |
if (layers == null) |
|
137 |
{ |
|
138 |
layers = new TreeMap(); |
|
139 |
} |
|
140 |
layers.put(layerName, layer); |
|
141 |
} |
|
120 |
// /**
|
|
121 |
// * Adds a Layer object to the vector of layers of this LayerSet
|
|
122 |
// */
|
|
123 |
// public void addLayer(WMSLayer layer)
|
|
124 |
// {
|
|
125 |
// String layerName = layer.getName();
|
|
126 |
// |
|
127 |
// if (layerName == null)
|
|
128 |
// {
|
|
129 |
// throw new RuntimeException("Error: attempt to add a nameless layer");
|
|
130 |
// }
|
|
131 |
// |
|
132 |
// // We use the lower case version of the name as a key for the hash map.
|
|
133 |
// layerName = layerName.toLowerCase();
|
|
134 |
// if (layers == null)
|
|
135 |
// {
|
|
136 |
// layers = new TreeMap();
|
|
137 |
// }
|
|
138 |
// layers.put(layerName, layer);
|
|
139 |
// }
|
|
142 | 140 |
|
143 | 141 |
/** |
144 |
* <p>Does ...</p> |
|
145 |
* |
|
146 |
* |
|
147 |
* @return |
|
142 |
* <p>Gets the image formats available in the Service to retrieve the maps</p> |
|
143 |
* @return a vector with all the available formats |
|
148 | 144 |
*/ |
149 | 145 |
public Vector getFormats() { |
150 | 146 |
return handler.getServiceInformation().formats; |
151 | 147 |
} |
152 | 148 |
|
153 | 149 |
/** |
154 |
* <p>Does ...</p> |
|
155 |
* |
|
156 |
* |
|
157 |
* @return |
|
150 |
* <p>Gets the SRS availables in the Service, all the SRS the Service can reproject to.</p> |
|
151 |
* @return vector with all the available SRS. |
|
158 | 152 |
*/ |
159 | 153 |
public Vector getSrs() { |
160 | 154 |
return handler.srs; |
161 | 155 |
} |
162 | 156 |
|
163 |
/** |
|
164 |
* <p>Does ...</p> |
|
165 |
* |
|
166 |
*/ |
|
167 | 157 |
public void close() { |
168 | 158 |
// your code here |
169 | 159 |
} |
... | ... | |
194 | 184 |
return true; |
195 | 185 |
|
196 | 186 |
} catch (Exception e) { |
197 |
//throw new DriverException(e); |
|
198 |
return true; |
|
187 |
//TODO: |
|
188 |
//Implement the logic to handle all the exceptions.... |
|
189 |
return false; |
|
199 | 190 |
} |
200 | 191 |
} |
201 | 192 |
} |
trunk/libraries/libRemoteServices/src/org/gvsig/remoteClient/wms/WMSProtocolHandler.java | ||
---|---|---|
78 | 78 |
* WMS client</p> |
79 | 79 |
*/ |
80 | 80 |
|
81 |
public void getMap() {
|
|
82 |
// your code here
|
|
81 |
public byte[] getMap(WMSStatus status) {
|
|
82 |
return null;
|
|
83 | 83 |
} |
84 | 84 |
|
85 | 85 |
/** |
... | ... | |
89 | 89 |
*/ |
90 | 90 |
public void getCapabilities() |
91 | 91 |
{ |
92 |
String ret = new String(); |
|
93 |
URL query = null; |
|
94 |
|
|
95 |
ret = ret + getHost() + "REQUEST=GetCapabilities&SERVICE=WMS&"; |
|
96 |
ret = ret + "VERSION=" + getVersion(); |
|
97 |
ret += ("&EXCEPTIONS=XML"); |
|
98 |
|
|
92 |
URL request = null; |
|
99 | 93 |
try |
100 | 94 |
{ |
101 |
query = new URL(ret);
|
|
95 |
request = new URL(buildCapabilitiesRequest());
|
|
102 | 96 |
} |
103 | 97 |
catch(Exception e) |
104 | 98 |
{ |
... | ... | |
114 | 108 |
{ |
115 | 109 |
DataOutputStream dos = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(f))); |
116 | 110 |
byte[] buffer = new byte[1024*256]; |
117 |
InputStream is = query.openStream();
|
|
111 |
InputStream is = request.openStream();
|
|
118 | 112 |
long readed = 0; |
119 | 113 |
for (int i = is.read(buffer); i>0; i = is.read(buffer)){ |
120 | 114 |
dos.write(buffer, 0, i); |
... | ... | |
138 | 132 |
return null; |
139 | 133 |
} |
140 | 134 |
|
135 |
/** |
|
136 |
* Builds the GetCapabilitiesRequest according to the OGC WMS Specifications |
|
137 |
*/ |
|
138 |
private String buildCapabilitiesRequest() |
|
139 |
{ |
|
140 |
String req = new String(); |
|
141 |
|
|
142 |
req = req + getHost() + "REQUEST=GetCapabilities&SERVICE=WMS&"; |
|
143 |
req = req + "VERSION=" + getVersion(); |
|
144 |
req += ("&EXCEPTIONS=XML"); |
|
145 |
return req; |
|
146 |
} |
|
147 |
|
|
148 |
/** |
|
149 |
* Builds the GetMapRequest according to the OGC WMS Specifications |
|
150 |
*/ |
|
151 |
private String buildMapRequest(WMSStatus status) |
|
152 |
{ |
|
153 |
String req = new String(); |
|
154 |
|
|
155 |
req = req + getHost() + "REQUEST=GetMap&SERVICE=WMS&"; |
|
156 |
req = req + "VERSION=" + getVersion() + "&"; |
|
157 |
req = req + getPartialQuery(status); |
|
158 |
if (status.getExceptionFormat() != null) { |
|
159 |
req += ("&EXCEPTIONS=" + status.getExceptionFormat()); |
|
160 |
} else { |
|
161 |
req += ("&EXCEPTIONS=XML"); |
|
162 |
} |
|
163 |
return req; |
|
164 |
} |
|
165 |
|
|
166 |
/** |
|
167 |
* Gets the part of the OGC request that share GetMap and GetFeatureInfo |
|
168 |
* @return String request |
|
169 |
*/ |
|
170 |
public String getPartialQuery(WMSStatus status) |
|
171 |
{ |
|
172 |
|
|
173 |
|
|
174 |
String req = "LAYERS=" + status.getLayerNames() + "&STYLES=" + |
|
175 |
status.getStyles() + "&SRS=" + status.getSrs() + |
|
176 |
"&BBOX=" + status.getExtent() + "&WIDTH=" + status.getWidth() + |
|
177 |
"&HEIGHT=" + status.getHeight() + "&FORMAT=" + status.getFormat(); |
|
178 |
|
|
179 |
// if (status.getTransparency()) { |
|
180 |
// req += "&TRANSPARENT=TRUE"; |
|
181 |
// } |
|
182 |
// |
|
183 |
// if (status.getBGColor() != null) { |
|
184 |
// req += ("&COLOR=" + status.getBGColor()); |
|
185 |
// } |
|
186 |
// |
|
187 |
// if (time != null) { |
|
188 |
// req += ("&TIME=" + time); |
|
189 |
// } |
|
190 |
// |
|
191 |
// if (elevation != -1) { |
|
192 |
// req += ("&ELEVATION=" + elevation); |
|
193 |
// } |
|
194 |
|
|
195 |
return req.replaceAll(" ", "%20"); |
|
196 |
} |
|
197 |
|
|
198 |
|
|
199 |
|
|
141 | 200 |
public void close() { |
142 | 201 |
// your code here |
143 | 202 |
} |
trunk/libraries/libRemoteServices/src/org/gvsig/remoteClient/utils/Utilities.java | ||
---|---|---|
45 | 45 |
import java.io.OutputStream; |
46 | 46 |
|
47 | 47 |
import java.rmi.NoSuchObjectException; |
48 |
import java.util.Vector; |
|
48 | 49 |
|
49 | 50 |
|
50 | 51 |
/** |
... | ... | |
158 | 159 |
throw new NoSuchObjectException("No se pudo parsear el xml"); |
159 | 160 |
} |
160 | 161 |
} |
162 |
|
|
161 | 163 |
/** |
164 |
* Converts the contents of a Vector to a comma separated list |
|
165 |
* |
|
166 |
* */ |
|
167 |
public static String Vector2CS(Vector v) |
|
168 |
{ |
|
169 |
String str = new String(); |
|
170 |
int i; |
|
171 |
for (i=0; i<v.size() ;i++) |
|
172 |
{ |
|
173 |
|
|
174 |
} |
|
175 |
return str; |
|
176 |
} |
|
177 |
|
|
178 |
public static boolean isValidVersion(String version) |
|
179 |
{ |
|
180 |
if(version.trim().length() == 5) |
|
181 |
{ |
|
182 |
if ( (version.charAt(1)=='.') && (version.charAt(3)=='.')) |
|
183 |
{ |
|
184 |
char x = version.charAt(0); |
|
185 |
char y = version.charAt(2); |
|
186 |
char z = version.charAt(4); |
|
187 |
|
|
188 |
if ((Character.isDigit(x)) && (Character.isDigit(y)) && (Character.isDigit(z))) |
|
189 |
{ |
|
190 |
return true; |
|
191 |
} |
|
192 |
else |
|
193 |
{ |
|
194 |
return false; |
|
195 |
} |
|
196 |
} |
|
197 |
else |
|
198 |
{ |
|
199 |
return false; |
|
200 |
} |
|
201 |
} |
|
202 |
else |
|
203 |
{ |
|
204 |
return false; |
|
205 |
} |
|
206 |
} |
|
207 |
|
|
208 |
/** |
|
162 | 209 |
* Checks if a String is a number or not |
163 | 210 |
* |
164 | 211 |
* @param String, s |
trunk/libraries/libRemoteServices/build.xml | ||
---|---|---|
6 | 6 |
<property name="src" location="src"/> |
7 | 7 |
<property name="build" location="bin"/> |
8 | 8 |
<property name="dist" location="dist"/> |
9 |
<property name="jar" value="RemoteMapClient"/>
|
|
9 |
<property name="jar" value="CqRemoteClient"/>
|
|
10 | 10 |
<!--property name="fmapdir" value="../FMAP"/--> |
11 | 11 |
<property name="targetDir" location="."/> |
12 | 12 |
|
Also available in: Unified diff