2 Copyright (C) 2001, 2006 United States Government
3 as represented by the Administrator of the
4 National Aeronautics and Space Administration.
7 package gov
.nasa
.worldwind
.wms
;
9 import gov
.nasa
.worldwind
.util
.Logging
;
16 * @version $Id: Request.java 2471 2007-07-31 21:50:57Z tgaskins $
18 public abstract class Request
20 private URI uri
= null;
22 // Use a TreeMap to hold the query params so that they'll always be attached to the
23 // URL query string in the same order. This allows a simple string comparison to
24 // determine whether two url strings address the same document.
25 private TreeMap
<String
, String
> queryParams
= new TreeMap
<String
, String
>();
32 public Request(URI uri
) throws URISyntaxException
40 catch (URISyntaxException e
)
42 Logging
.logger().fine(Logging
.getMessage("generic.URIInvalid", uri
.toString()));
50 public Request(Request sourceRequest
) throws URISyntaxException
52 sourceRequest
.copyParamsTo(this);
53 this.setUri(sourceRequest
.getUri());
56 protected void initialize()
58 this.queryParams
.put("SERVICE", "WMS");
59 this.queryParams
.put("EXCEPTIONS", "application/vnd.ogc.se_xml");
62 private void copyParamsTo(Request destinationRequest
)
64 for (Map
.Entry
<String
, String
> entry
: this.queryParams
.entrySet())
66 destinationRequest
.setParam((String
) ((Map
.Entry
) entry
).getKey(), (String
) ((Map
.Entry
) entry
).getValue());
70 protected void setUri(URI uri
) throws URISyntaxException
74 this.uri
= new URI(uri
.getScheme(), uri
.getUserInfo(), uri
.getHost(), uri
.getPort(), uri
.getPath(),
75 this.buildQueryString(), null);
77 catch (URISyntaxException e
)
79 String message
= Logging
.getMessage("generic.URIInvalid", uri
.toString());
80 Logging
.logger().fine(message
);
85 public String
getRequestName()
87 return this.getParam("REQUEST");
90 public String
getVersion()
92 return this.getParam("VERSION");
95 public void setVersion(String version
)
97 this.setParam("VERSION", version
);
100 public void setParam(String key
, String value
)
103 this.queryParams
.put(key
, value
);
106 public String
getParam(String key
)
108 return key
!= null ?
this.queryParams
.get(key
) : null;
111 public URI
getUri() throws URISyntaxException
113 if (this.uri
== null)
118 return new URI(this.uri
.getScheme(), this.uri
.getUserInfo(), this.uri
.getHost(), this.uri
.getPort(),
119 uri
.getPath(), this.buildQueryString(), null);
121 catch (URISyntaxException e
)
123 String message
= Logging
.getMessage("generic.URIInvalid", uri
.toString());
124 Logging
.logger().fine(message
);
129 private String
buildQueryString()
131 StringBuffer queryString
= new StringBuffer();
133 for (Map
.Entry
<String
, String
> entry
: this.queryParams
.entrySet())
135 if (((Map
.Entry
) entry
).getKey() != null && ((Map
.Entry
) entry
).getValue() != null)
137 queryString
.append(((Map
.Entry
) entry
).getKey());
138 queryString
.append("=");
139 queryString
.append(((Map
.Entry
) entry
).getValue());
140 queryString
.append("&");
144 return queryString
.toString();
147 public String
toString()
149 String errorMessage
= "Error converting wms-request URI to string.";
152 java
.net
.URI fullUri
= this.getUri();
153 return fullUri
!= null ? fullUri
.toString() : errorMessage
;
155 catch (URISyntaxException e
)