svn-gvsig-desktop / branches / v10 / libraries / libArcIMS_old / src / org / gvsig / remoteClient / arcims / ArcXML.java @ 12255
History | View | Annotate | Download (7.62 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Prodevelop and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Prodevelop Integraci?n de Tecnolog?as SL
|
34 |
* Conde Salvatierra de ?lava , 34-10
|
35 |
* 46004 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963 510 612
|
39 |
* +34 963 510 968
|
40 |
* gis@prodevelop.es
|
41 |
* http://www.prodevelop.es
|
42 |
*/
|
43 |
|
44 |
package org.gvsig.remoteClient.arcims; |
45 |
|
46 |
import org.gvsig.remoteClient.arcims.utils.ServiceInformation; |
47 |
import org.gvsig.remoteClient.arcims.utils.ServiceInformationLayer; |
48 |
|
49 |
import java.awt.Color; |
50 |
import java.awt.Dimension; |
51 |
import java.awt.geom.Rectangle2D; |
52 |
|
53 |
import java.text.DecimalFormat; |
54 |
import java.text.DecimalFormatSymbols; |
55 |
|
56 |
import java.util.Vector; |
57 |
|
58 |
|
59 |
/**
|
60 |
* Class that provides static methods to generate general ArcXML requests
|
61 |
* @author jsanz
|
62 |
* @author jcarrasco
|
63 |
*/
|
64 |
public class ArcXML { |
65 |
public static final String PATRON = new String("0.0########"); |
66 |
|
67 |
/**
|
68 |
* Starting string for an ArcXML request
|
69 |
* @param version
|
70 |
* @return String
|
71 |
*/
|
72 |
protected static String startRequest(String version) { |
73 |
return "<ARCXML version=\"" + version + "\">\r\n" + "\t<REQUEST>\r\n"; |
74 |
} |
75 |
|
76 |
/**
|
77 |
* Ending string for an ArcXML request
|
78 |
* @return string
|
79 |
*/
|
80 |
protected static String endRequest() { |
81 |
return "\t</REQUEST>\r\n" + "</ARCXML>\r\n"; |
82 |
} |
83 |
|
84 |
/**
|
85 |
* Creates the ArcXML request for a Service_Info
|
86 |
* @param version
|
87 |
* @return String
|
88 |
*/
|
89 |
public static String getServiceInfoRequest(String version) { |
90 |
/**
|
91 |
* We will request all the information the server can expose of
|
92 |
* its services
|
93 |
*/
|
94 |
String envelope = "true"; |
95 |
String fields = "true"; |
96 |
String renderer = "true"; |
97 |
String extensions = "true"; |
98 |
|
99 |
return startRequest(version) + "\t\t<GET_SERVICE_INFO envelope=\"" + |
100 |
envelope + "\" fields=\"" + fields + "\" renderer=\"" + renderer + |
101 |
"\"\r\n" + "\t\t\textensions=\"" + extensions + "\" />\r\n" + |
102 |
endRequest(); |
103 |
} |
104 |
|
105 |
/**
|
106 |
* Builds a start LAYER element for a XML response of a GetElementInfo
|
107 |
* @see ArcImsProtocolHandler#getElementInfo(ArcImsStatus, int, int, int)
|
108 |
* @param id
|
109 |
* @param si
|
110 |
* @return String, the start tag for the LAYER element
|
111 |
*/
|
112 |
public static String getLayerHeaderInfoResponse(String id, |
113 |
ServiceInformation si) { |
114 |
String name = null; |
115 |
Vector layers = si.getLayers();
|
116 |
|
117 |
int i = 0; |
118 |
ServiceInformationLayer sil; |
119 |
|
120 |
for (i = 0; i < layers.size(); i++) { |
121 |
sil = (ServiceInformationLayer) layers.get(i); |
122 |
|
123 |
if (sil.getId().equals(id)) {
|
124 |
name = sil.getName(); |
125 |
|
126 |
break;
|
127 |
} |
128 |
} |
129 |
|
130 |
return "<LAYER ID=\"" + id + "\" NAME=\"" + name + "\">"; |
131 |
} |
132 |
|
133 |
/**
|
134 |
* Builds a end LAYER element for a XML response of a GetElementInfo
|
135 |
* @see ArcImsProtocolHandler#getElementInfo(ArcImsStatus, int, int, int)
|
136 |
* @return String, the end tag for the LAYER element
|
137 |
*/
|
138 |
protected static String getLayerFooterInfoResponse() { |
139 |
return "\t</LAYER>\r\n"; |
140 |
} |
141 |
|
142 |
/**
|
143 |
* Creates a ENVELOPE element from a Rectangle2D
|
144 |
* @param r Rectangle2D to parse
|
145 |
* @param ds with the Decimal separator
|
146 |
* @return String with proper ArcXML tags
|
147 |
* @see java.awt.geom.Rectangle2D
|
148 |
*/
|
149 |
protected static String getEnvelope(Rectangle2D r, char ds) { |
150 |
if (r == null) { |
151 |
return ""; |
152 |
} else {
|
153 |
DecimalFormatSymbols dfs = new DecimalFormatSymbols(); |
154 |
dfs.setDecimalSeparator(ds); |
155 |
|
156 |
DecimalFormat formatter = new DecimalFormat(PATRON, dfs); |
157 |
|
158 |
String envelope = new String(); |
159 |
envelope = "<ENVELOPE " + "minx=\"" + |
160 |
formatter.format(r.getMinX()) + "\" miny=\"" +
|
161 |
formatter.format(r.getMinY()) + "\" maxx=\"" +
|
162 |
formatter.format(r.getMaxX()) + "\" maxy=\"" +
|
163 |
formatter.format(r.getMaxY()) + "\"/>";
|
164 |
|
165 |
return envelope;
|
166 |
} |
167 |
} |
168 |
|
169 |
/**
|
170 |
* Creates a IMAGESIZE element from a Dimension object
|
171 |
* @param sz Dimension to parse
|
172 |
* @return String with proper ArcXML tags
|
173 |
* @see java.awt.Dimension
|
174 |
*/
|
175 |
protected static String getImageSize(Dimension sz) { |
176 |
return "<IMAGESIZE width=\"" + sz.width + "\" height=\"" + sz.height + |
177 |
"\" />";
|
178 |
} |
179 |
|
180 |
/**
|
181 |
* Creates the FILTERCOORDSYS element
|
182 |
* @param srs The EPSG code
|
183 |
* @return String with proper ArcXML tags
|
184 |
*/
|
185 |
protected static String getFilterCoordsys(String srs) { |
186 |
if (!srs.equals("")) { |
187 |
return "<FILTERCOORDSYS id=\"" + srs + "\" />"; |
188 |
} else {
|
189 |
return ""; |
190 |
} |
191 |
} |
192 |
|
193 |
/**
|
194 |
* Creates the FEATURECOORDSYS element based on a EPSG code
|
195 |
* @param srs The EPSG code
|
196 |
* @return String with proper ArcXML tags
|
197 |
*/
|
198 |
protected static String getFeatureCoordsys(String srs) { |
199 |
if (!srs.equals("")) { |
200 |
return "<FEATURECOORDSYS id=\"" + srs + "\" />"; |
201 |
} else {
|
202 |
return ""; |
203 |
} |
204 |
} |
205 |
|
206 |
/**
|
207 |
* Creates a BACKGROUND color for the ArcIMS service based
|
208 |
* on two colors
|
209 |
* @param backColor Color for the background
|
210 |
* @param transColor Transparent color in the output image
|
211 |
* @return String with proper ArcXML tags
|
212 |
*/
|
213 |
protected static String getBackground(java.awt.Color backColor, |
214 |
Color transColor) {
|
215 |
String strBackColor = new String(backColor.getRed() + "," + |
216 |
backColor.getGreen() + "," + backColor.getBlue());
|
217 |
String strTransColor = new String(transColor.getRed() + "," + |
218 |
transColor.getGreen() + "," + transColor.getBlue());
|
219 |
|
220 |
return "<BACKGROUND color=\"" + strBackColor + "\" transcolor=\"" + |
221 |
strTransColor + "\"/>";
|
222 |
} |
223 |
|
224 |
/**
|
225 |
* Method that creates a GETCLIENTSERVICES ArcXML to request a complete
|
226 |
* list of Services available in an ArcIMS Server
|
227 |
* @return String with proper ArcXML tags
|
228 |
*/
|
229 |
public static String getClientServices() { |
230 |
return "<GETCLIENTSERVICES/>"; |
231 |
} |
232 |
|
233 |
/**
|
234 |
* Simple method to get string representations of double numbers
|
235 |
* according to a decimal separator
|
236 |
* @param number
|
237 |
* @param ds
|
238 |
* @return
|
239 |
*/
|
240 |
public static String parseNumber(double number, char ds) { |
241 |
DecimalFormatSymbols dfs = new DecimalFormatSymbols(); |
242 |
dfs.setDecimalSeparator(ds); |
243 |
|
244 |
DecimalFormat formatter = new DecimalFormat(PATRON, dfs); |
245 |
|
246 |
return formatter.format(number);
|
247 |
} |
248 |
|
249 |
public static String replaceUnwantedCharacters(String str) { |
250 |
String resp = str;
|
251 |
resp = resp.replace('.', '_'); |
252 |
resp = resp.replace('#', 'z'); |
253 |
|
254 |
return resp;
|
255 |
} |
256 |
} |