root / trunk / extensions / extWMS / src / com / iver / cit / gvsig / webmapcontext / WebMapContext.java @ 4920
History | View | Annotate | Download (29.7 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. 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 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
|
42 |
/* CVS MESSAGES:
|
43 |
*
|
44 |
* $Id: WebMapContext.java 4920 2006-04-21 11:53:50Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.6 2006-04-21 11:53:50 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.5 2006/04/21 11:02:25 jaume
|
50 |
* few translations
|
51 |
*
|
52 |
* Revision 1.4 2006/04/21 10:27:32 jaume
|
53 |
* exporting now supported
|
54 |
*
|
55 |
* Revision 1.3 2006/04/20 17:11:54 jaume
|
56 |
* Attempting to export
|
57 |
*
|
58 |
* Revision 1.2 2006/04/19 16:34:29 jaume
|
59 |
* *** empty log message ***
|
60 |
*
|
61 |
* Revision 1.1 2006/04/19 07:57:29 jaume
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
* Revision 1.1 2006/04/12 17:10:53 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
*
|
68 |
*/
|
69 |
package com.iver.cit.gvsig.webmapcontext; |
70 |
|
71 |
import java.awt.Dimension; |
72 |
import java.awt.geom.Rectangle2D; |
73 |
import java.io.BufferedReader; |
74 |
import java.io.File; |
75 |
import java.io.FileInputStream; |
76 |
import java.io.FileNotFoundException; |
77 |
import java.io.FileReader; |
78 |
import java.io.IOException; |
79 |
import java.net.URL; |
80 |
import java.util.ArrayList; |
81 |
import java.util.HashMap; |
82 |
import java.util.Hashtable; |
83 |
import java.util.Vector; |
84 |
|
85 |
import org.kxml2.io.KXmlParser; |
86 |
import org.xmlpull.v1.XmlPullParserException; |
87 |
|
88 |
import com.iver.andami.PluginServices; |
89 |
import com.iver.andami.messages.NotificationManager; |
90 |
import com.iver.cit.gvsig.fmap.MapControl; |
91 |
import com.iver.cit.gvsig.fmap.drivers.UnsupportedVersionException; |
92 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
93 |
import com.iver.cit.gvsig.fmap.layers.FLyrWMS; |
94 |
import com.iver.cit.gvsig.fmap.layers.WMSLayerNode; |
95 |
import com.iver.cit.gvsig.fmap.layers.WMSLayerNode.FMapWMSStyle; |
96 |
import com.iver.cit.gvsig.fmap.rendering.XmlBuilder; |
97 |
import com.iver.cit.gvsig.gui.View; |
98 |
import com.iver.cit.gvsig.project.ProjectView; |
99 |
|
100 |
/**
|
101 |
*
|
102 |
*
|
103 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
104 |
* @author laura d?az s?nchez - laura.diaz@iver.es
|
105 |
*
|
106 |
*/
|
107 |
public class WebMapContext { |
108 |
public final static String FILE_EXTENSION = ".cml"; |
109 |
|
110 |
static final ArrayList supportedVersions = new ArrayList(); |
111 |
static public final ArrayList exportVersions = new ArrayList(); |
112 |
private File mapContextFile; |
113 |
private String encoding = "UTF-8"; |
114 |
private String WMC_START_TAG; |
115 |
|
116 |
// MapContext stuff
|
117 |
public String fileVersion = null; |
118 |
public Dimension windowSize = null; |
119 |
public String srs = null; |
120 |
public Rectangle2D bBox = null; |
121 |
public String title = null; |
122 |
public String id = null; |
123 |
public String xmlns = null; |
124 |
public String xmlns_xlink = null; |
125 |
public String xmlns_xsi = null;; |
126 |
public String xsi_schemaLocation = null; |
127 |
public String _abstract = null; |
128 |
public ArrayList keywordList = null; |
129 |
public Dimension logoURLSize = null; |
130 |
public String logoURLFormat = null; |
131 |
public String logoURL = null; |
132 |
public String descriptionURLFormat = null; |
133 |
public String descriptionURL = null; |
134 |
public boolean contactInfo = false; |
135 |
public String contactPerson = null; |
136 |
public String contactOrganization = null; |
137 |
public String contactPosition = null; |
138 |
public String address = null; |
139 |
public String city = null; |
140 |
public String stateOrProvince = null; |
141 |
public String postCode = null; |
142 |
public String country = null; |
143 |
public String telephone = null; |
144 |
public String fax = null; |
145 |
public String email = null;; |
146 |
/**
|
147 |
* list of FLyrWMS.
|
148 |
*/
|
149 |
ArrayList layerList = null; |
150 |
/**
|
151 |
* key: server URL (URL)
|
152 |
* value: server title (String)
|
153 |
*/
|
154 |
Hashtable serverTitles = null; |
155 |
/**
|
156 |
* key: layer FLyrWMS
|
157 |
* value: layer abstract (String)
|
158 |
*/
|
159 |
Hashtable layerAbstracts = null; |
160 |
/**
|
161 |
* key: layer FLyrWMS
|
162 |
* value: layer formats (String[])
|
163 |
*/
|
164 |
Hashtable layerFormats = null; |
165 |
/**
|
166 |
* key: layer FLyrWMS
|
167 |
* value: styles (FMapWMSStyle[])
|
168 |
*/
|
169 |
Hashtable layerStyles = null; |
170 |
|
171 |
|
172 |
static {
|
173 |
supportedVersions.add("1.1.0");
|
174 |
supportedVersions.add("1.0.0");
|
175 |
supportedVersions.add("0.1.4");
|
176 |
} |
177 |
|
178 |
static {
|
179 |
exportVersions.add("1.1.0");
|
180 |
} |
181 |
|
182 |
public WebMapContext(File file) throws UnsupportedVersionException { |
183 |
this.mapContextFile = file;
|
184 |
if (getVersion()!=null) { |
185 |
if (supportedVersions.contains(getVersion()))
|
186 |
WMC_START_TAG = WebMapContextTags.VIEW_CONTEXT; |
187 |
if (getVersion().equals("0.1.4")) { |
188 |
WMC_START_TAG = WebMapContextTags.VIEW_CONTEXT_0_1_4; |
189 |
parse1_1_0(file); |
190 |
} else if (getVersion().equals("1.1.0")) { |
191 |
parse1_1_0(file); |
192 |
} else if (getVersion().equals("1.0.0")) { |
193 |
parse1_1_0(file); |
194 |
} else {
|
195 |
parseDefaultVersion(file); |
196 |
} |
197 |
} else throw new UnsupportedVersionException(PluginServices.getText(this, "file_version")+": "+getVersion()); |
198 |
} |
199 |
|
200 |
public WebMapContext() { }
|
201 |
|
202 |
private void parseDefaultVersion(File file) { |
203 |
parse1_1_0(file); |
204 |
} |
205 |
|
206 |
/**
|
207 |
* Reads the header of the Weg Map Context file and determines which version
|
208 |
* it belongs to.
|
209 |
* @return String.
|
210 |
*/
|
211 |
private String getVersion() { |
212 |
if (fileVersion == null) { |
213 |
String v = null; |
214 |
try {
|
215 |
FileReader fr = new FileReader(mapContextFile); |
216 |
KXmlParser parser = new KXmlParser();
|
217 |
parser.setInput(fr); |
218 |
parser.nextTag(); |
219 |
if ( parser.getEventType() != KXmlParser.END_DOCUMENT ) {
|
220 |
if ((parser.getName().compareTo(WebMapContextTags.VIEW_CONTEXT) == 0) || |
221 |
parser.getName().compareTo(WebMapContextTags.VIEW_CONTEXT_0_1_4) == 0) {
|
222 |
v = parser.getAttributeValue("", WebMapContextTags.VERSION);
|
223 |
} |
224 |
} |
225 |
} catch (FileNotFoundException fnfEx) { |
226 |
} catch (XmlPullParserException xmlEx) {
|
227 |
xmlEx.printStackTrace(); |
228 |
} catch (IOException e) { |
229 |
} |
230 |
fileVersion = v; |
231 |
} |
232 |
return fileVersion;
|
233 |
} |
234 |
|
235 |
/**
|
236 |
* Reads a Web Map Context version 1.1.0. As far as v1.0.0 is a subset of
|
237 |
* v1.1.0 it can be used to read files belonging to 1.0.0 as well.
|
238 |
* @param file, the web map context file.
|
239 |
*/
|
240 |
private void parse1_1_0(File file) { |
241 |
try {
|
242 |
FileReader fr;
|
243 |
try
|
244 |
{ |
245 |
fr = new FileReader(file); |
246 |
BufferedReader br = new BufferedReader(fr); |
247 |
char[] buffer = new char[100]; |
248 |
br.read(buffer); |
249 |
StringBuffer st = new StringBuffer(new String(buffer)); |
250 |
String searchText = "encoding=\""; |
251 |
int index = st.indexOf(searchText);
|
252 |
if (index>-1) { |
253 |
st.delete(0, index+searchText.length());
|
254 |
encoding = st.substring(0, st.indexOf("\"")); |
255 |
} |
256 |
} catch(FileNotFoundException ex) { |
257 |
ex.printStackTrace(); |
258 |
} catch (IOException e) { |
259 |
e.printStackTrace(); |
260 |
} |
261 |
|
262 |
fr = new FileReader(file); |
263 |
KXmlParser parser = new KXmlParser();
|
264 |
parser.setInput(new FileInputStream(file), encoding); |
265 |
int tag = parser.nextTag();
|
266 |
if ( parser.getEventType() != KXmlParser.END_DOCUMENT )
|
267 |
{ |
268 |
parser.require(KXmlParser.START_TAG, null, WMC_START_TAG);
|
269 |
while(tag != KXmlParser.END_DOCUMENT) {
|
270 |
switch(tag) {
|
271 |
case KXmlParser.START_TAG:
|
272 |
if (parser.getName().compareTo(WMC_START_TAG) == 0) { |
273 |
id = parser.getAttributeValue("", WebMapContextTags.ID);
|
274 |
xmlns = parser.getAttributeValue("", WebMapContextTags.XMLNS);
|
275 |
xmlns_xlink = parser.getAttributeValue("", WebMapContextTags.XMLNS_XLINK);
|
276 |
xmlns_xsi = parser.getAttributeValue("", WebMapContextTags.XMLNS_XSI);
|
277 |
xsi_schemaLocation = parser.getAttributeValue("", WebMapContextTags.XSI_SCHEMA_LOCATION) ;
|
278 |
} else if (parser.getName().compareTo(WebMapContextTags.GENERAL) == 0) { |
279 |
parseGeneral1_1_0(parser); |
280 |
} else if (parser.getName().compareTo(WebMapContextTags.LAYER_LIST) == 0) { |
281 |
int layerListTag = parser.nextTag();
|
282 |
boolean bLayerListEnd = false; |
283 |
layerList = new ArrayList(); |
284 |
while (!bLayerListEnd) {
|
285 |
switch(layerListTag) {
|
286 |
case KXmlParser.START_TAG:
|
287 |
if (parser.getName().compareTo(WebMapContextTags.LAYER) == 0) { |
288 |
FLyrWMS layer = parseLayer1_1_0(parser); |
289 |
// will use the mapcontext's bounding box as layer's fullextent
|
290 |
layer.setFullExtent(bBox); |
291 |
// and mapcontext's srs
|
292 |
layer.setSRS(srs); |
293 |
layer.setWmsTransparency(true);
|
294 |
layerList.add(layer); |
295 |
} else {
|
296 |
System.out.println("Unrecognized "+parser.getName()); |
297 |
} |
298 |
break;
|
299 |
case KXmlParser.END_TAG:
|
300 |
if (parser.getName().compareTo(WebMapContextTags.LAYER_LIST) == 0) |
301 |
bLayerListEnd = true;
|
302 |
break;
|
303 |
case KXmlParser.TEXT:
|
304 |
//System.out.println("[TEXT]["+kxmlParser.getText()+"]");
|
305 |
break;
|
306 |
} |
307 |
layerListTag = parser.next(); |
308 |
} |
309 |
} else if (parser.getName().compareTo(WebMapContextTags.DIMENSION_LIST) == 0) { |
310 |
// TODO
|
311 |
System.out.println("WebMapContext's Dimension not yet implemented"); |
312 |
} else {
|
313 |
System.out.println("Unrecognized "+parser.getName()); |
314 |
} |
315 |
break;
|
316 |
case KXmlParser.END_TAG:
|
317 |
break;
|
318 |
case KXmlParser.TEXT:
|
319 |
//System.out.println("[TEXT]["+kxmlParser.getText()+"]");
|
320 |
break;
|
321 |
} |
322 |
tag = parser.next(); |
323 |
} |
324 |
parser.require(KXmlParser.END_DOCUMENT, null, null); |
325 |
} |
326 |
} catch (Exception e) { |
327 |
NotificationManager.addError(PluginServices.getText(this, "map_context_file_error"),e); |
328 |
e.printStackTrace(); |
329 |
} |
330 |
} |
331 |
|
332 |
|
333 |
/**
|
334 |
* Parses the General tag of a web map context 1.1.0 (and 1.0.0) file
|
335 |
* @param parser
|
336 |
* @throws XmlPullParserException
|
337 |
* @throws IOException
|
338 |
*/
|
339 |
private void parseGeneral1_1_0(KXmlParser parser) throws XmlPullParserException, IOException { |
340 |
boolean end = false; |
341 |
int tag = parser.next();
|
342 |
while (!end) {
|
343 |
switch(tag) {
|
344 |
case KXmlParser.START_TAG:
|
345 |
if (parser.getName().compareTo(WebMapContextTags.WINDOW) == 0) { |
346 |
if (windowSize == null) windowSize = new Dimension(); |
347 |
windowSize.setSize(Integer.parseInt(parser.getAttributeValue("", WebMapContextTags.WIDTH)), |
348 |
Integer.parseInt(parser.getAttributeValue("", WebMapContextTags.HEIGHT))); |
349 |
} else if (parser.getName().compareTo(WebMapContextTags.BOUNDING_BOX) == 0) { |
350 |
srs = parser.getAttributeValue("", WebMapContextTags.SRS);
|
351 |
double minx = Double.parseDouble(parser.getAttributeValue("", WebMapContextTags.X_MIN)); |
352 |
double miny = Double.parseDouble(parser.getAttributeValue("", WebMapContextTags.Y_MIN)); |
353 |
double maxx = Double.parseDouble(parser.getAttributeValue("", WebMapContextTags.X_MAX)); |
354 |
double maxy = Double.parseDouble(parser.getAttributeValue("", WebMapContextTags.Y_MAX)); |
355 |
bBox = new Rectangle2D.Double(minx, miny, maxx-minx, maxy-maxx); |
356 |
} else if (parser.getName().compareTo(WebMapContextTags.TITLE) == 0) { |
357 |
title = parser.nextText(); |
358 |
} else if (parser.getName().compareTo(WebMapContextTags.ABSTRACT) == 0) { |
359 |
_abstract = parser.nextText(); |
360 |
} else if (parser.getName().compareTo(WebMapContextTags.KEYWORD_LIST) == 0) { |
361 |
keywordList = new ArrayList(); |
362 |
boolean keywordEnd = false; |
363 |
int keywordTag = parser.next();
|
364 |
while (!keywordEnd) {
|
365 |
switch(keywordTag) {
|
366 |
case KXmlParser.START_TAG:
|
367 |
if (parser.getName().compareTo(WebMapContextTags.KEYWORD) == 0) { |
368 |
keywordList.add(parser.nextText()); |
369 |
} else {
|
370 |
System.out.println("Unrecognized "+parser.getName()); |
371 |
} |
372 |
break;
|
373 |
case KXmlParser.END_TAG:
|
374 |
if (parser.getName().compareTo(WebMapContextTags.KEYWORD_LIST) == 0) |
375 |
keywordEnd = true;
|
376 |
break;
|
377 |
case KXmlParser.TEXT:
|
378 |
if (parser.getName()!=null) |
379 |
System.out.println("[TAG]["+parser.getName()+"]\n[TEXT]["+parser.getText().trim()+"]"); |
380 |
break;
|
381 |
} |
382 |
keywordTag = parser.next(); |
383 |
} |
384 |
} else if (parser.getName().compareTo(WebMapContextTags.LOGO_URL) == 0) { |
385 |
logoURLSize = new Dimension(Integer.parseInt(parser.getAttributeValue("", WebMapContextTags.WIDTH)), |
386 |
Integer.parseInt(parser.getAttributeValue("", WebMapContextTags.HEIGHT))); |
387 |
logoURLFormat = parser.getAttributeValue("", WebMapContextTags.FORMAT.toLowerCase());
|
388 |
parser.nextTag(); |
389 |
if (parser.getName().compareTo(WebMapContextTags.ONLINE_RESOURCE) == 0) { |
390 |
logoURL = parser.getAttributeValue("", WebMapContextTags.XLINK_HREF);
|
391 |
} else {
|
392 |
System.out.println("Unrecognized "+parser.getName()); |
393 |
} |
394 |
} else if (parser.getName().compareTo(WebMapContextTags.DESCRIPTION_URL) == 0) { |
395 |
descriptionURLFormat = parser.getAttributeValue("", WebMapContextTags.FORMAT.toLowerCase());
|
396 |
parser.nextTag(); |
397 |
if (parser.getName().compareTo(WebMapContextTags.ONLINE_RESOURCE) == 0) { |
398 |
descriptionURL = parser.getAttributeValue("", WebMapContextTags.XLINK_HREF);
|
399 |
} else {
|
400 |
System.out.println("Unrecognized "+parser.getName()); |
401 |
} |
402 |
} else if (parser.getName().compareTo(WebMapContextTags.CONTACT_INFORMATION) == 0) { |
403 |
boolean contactInfoEnd = false; |
404 |
int contactInfoTag = parser.next();
|
405 |
while (!contactInfoEnd) {
|
406 |
switch(contactInfoTag) {
|
407 |
case KXmlParser.START_TAG:
|
408 |
if (parser.getName().compareTo(WebMapContextTags.CONTACT_PERSON) == 0) { |
409 |
contactPerson = parser.nextText(); |
410 |
} else if (parser.getName().compareTo(WebMapContextTags.CONTACT_ORGANIZATION) == 0) { |
411 |
contactOrganization = parser.nextText(); |
412 |
} else if (parser.getName().compareTo(WebMapContextTags.CONTACT_POSITION) == 0) { |
413 |
contactPosition = parser.nextText(); |
414 |
} else if (parser.getName().compareTo(WebMapContextTags.ADDRESS) == 0) { |
415 |
address = parser.nextText(); |
416 |
} else if (parser.getName().compareTo(WebMapContextTags.CITY) == 0) { |
417 |
city = parser.nextText(); |
418 |
} else if (parser.getName().compareTo(WebMapContextTags.STATE_OR_PROVINCE) == 0) { |
419 |
stateOrProvince = parser.nextText(); |
420 |
} else if (parser.getName().compareTo(WebMapContextTags.POSTCODE) == 0) { |
421 |
postCode = parser.nextText(); |
422 |
} else if (parser.getName().compareTo(WebMapContextTags.COUNTRY) == 0) { |
423 |
country = parser.nextText(); |
424 |
} else if (parser.getName().compareTo(WebMapContextTags.CONTACT_VOICE_TELEPHONE) == 0) { |
425 |
telephone = parser.nextText(); |
426 |
} else if (parser.getName().compareTo(WebMapContextTags.CONTACT_FACSIMILE_TELEPHONE) == 0) { |
427 |
fax = parser.nextText(); |
428 |
} else if (parser.getName().compareTo(WebMapContextTags.CONTACT_ELECTRONIC_MAIL_ADDRESS) == 0) { |
429 |
email = parser.nextText(); |
430 |
} else if (parser.getName().compareTo(WebMapContextTags.CONTACT_PERSON_PRIMARY) == 0) { |
431 |
// DO NOTHING
|
432 |
} else if (parser.getName().compareTo(WebMapContextTags.CONTACT_ADDRESS) == 0) { |
433 |
// DO NOTHING
|
434 |
} else {
|
435 |
System.out.println("Unrecognized "+parser.getName()); |
436 |
} |
437 |
break;
|
438 |
case KXmlParser.END_TAG:
|
439 |
if (parser.getName().compareTo(WebMapContextTags.CONTACT_INFORMATION) == 0) |
440 |
contactInfoEnd = true;
|
441 |
break;
|
442 |
case KXmlParser.TEXT:
|
443 |
if (parser.getName()!=null) |
444 |
System.out.println("[TAG]["+parser.getName()+"]\n[TEXT]["+parser.getText().trim()+"]"); |
445 |
break;
|
446 |
} |
447 |
contactInfoTag = parser.next(); |
448 |
} |
449 |
} else {
|
450 |
System.out.println("Unrecognized "+parser.getName()); |
451 |
} |
452 |
break;
|
453 |
case KXmlParser.END_TAG:
|
454 |
if (parser.getName().compareTo(WebMapContextTags.GENERAL) == 0) |
455 |
end = true;
|
456 |
break;
|
457 |
case KXmlParser.TEXT:
|
458 |
if (parser.getName()!=null) |
459 |
System.out.println("[TAG]["+parser.getName()+"]\n[TEXT]["+parser.getText().trim()+"]"); |
460 |
break;
|
461 |
} |
462 |
tag = parser.next(); |
463 |
} |
464 |
} |
465 |
|
466 |
private FLyrWMS parseLayer1_1_0(KXmlParser parser) throws XmlPullParserException, IOException { |
467 |
boolean end = false; |
468 |
FLyrWMS layer = new FLyrWMS();
|
469 |
|
470 |
String queryable = parser.getAttributeValue("", WebMapContextTags.QUERYABLE); |
471 |
layer.setQueryable(queryable!=null && queryable.equals("1")); |
472 |
|
473 |
String hidden = parser.getAttributeValue("", WebMapContextTags.HIDDEN); |
474 |
layer.setVisible(hidden==null || hidden.equals("1") || hidden.toLowerCase().equals("true")); |
475 |
int tag = parser.next();
|
476 |
while (!end) {
|
477 |
switch(tag) {
|
478 |
case KXmlParser.START_TAG:
|
479 |
if (parser.getName().compareTo(WebMapContextTags.SERVER) == 0) { |
480 |
String serverTitle = parser.getAttributeValue("", WebMapContextTags.TITLE.toLowerCase()); |
481 |
parser.nextTag(); |
482 |
if (parser.getName().compareTo(WebMapContextTags.ONLINE_RESOURCE) == 0) { |
483 |
layer.setHost(new URL(parser.getAttributeValue("", WebMapContextTags.XLINK_HREF))); |
484 |
if (serverTitles == null) |
485 |
serverTitles = new Hashtable(); |
486 |
serverTitles.put(parser.getAttributeValue("", WebMapContextTags.XLINK_HREF), serverTitle);
|
487 |
} |
488 |
} else if (parser.getName().compareTo(WebMapContextTags.TITLE) == 0) { |
489 |
layer.setName(parser.nextText()); |
490 |
} else if (parser.getName().compareTo(WebMapContextTags.NAME) == 0) { |
491 |
layer.setLayerQuery(parser.nextText()); |
492 |
/*} else if (parser.getName().compareTo(WebMapContextTags.LAYER) == 0) {
|
493 |
FLyrWMS sonLayer = parseLayer1_1_0(parser);
|
494 |
String q = layer.getLayerQuery();
|
495 |
if (q == null) q = "";
|
496 |
else q += ",";
|
497 |
layer.setLayerQuery( q + sonLayer.getLayerQuery());*/
|
498 |
} else if (parser.getName().compareTo(WebMapContextTags.ABSTRACT) == 0) { |
499 |
if (layerAbstracts == null) |
500 |
layerAbstracts = new Hashtable(); |
501 |
layerAbstracts.put(layer, parser.nextText()); |
502 |
} else if (parser.getName().compareTo(WebMapContextTags.SRS) == 0) { |
503 |
layer.setSRS(parser.nextText()); |
504 |
} else if (parser.getName().compareTo(WebMapContextTags.FORMAT_LIST) == 0) { |
505 |
int formatsTag = parser.nextTag();
|
506 |
boolean bFormatsEnd = false; |
507 |
ArrayList formats = new ArrayList(); |
508 |
while (!bFormatsEnd) {
|
509 |
switch (formatsTag) {
|
510 |
case KXmlParser.START_TAG:
|
511 |
if (parser.getName().compareTo(WebMapContextTags.FORMAT) == 0) { |
512 |
String current = parser.getAttributeValue("", WebMapContextTags.CURRENT); |
513 |
String format = parser.nextText();
|
514 |
if (current!=null && current.equals("1")) |
515 |
layer.setFormat(format); |
516 |
formats.add(format); |
517 |
} else {
|
518 |
System.out.println("Unrecognized "+parser.getName()); |
519 |
} |
520 |
break;
|
521 |
case KXmlParser.END_TAG:
|
522 |
if (parser.getName().compareTo(WebMapContextTags.FORMAT_LIST) == 0) |
523 |
bFormatsEnd = true;
|
524 |
break;
|
525 |
case KXmlParser.TEXT:
|
526 |
if (parser.getName()!=null) |
527 |
System.out.println("[TAG]["+parser.getName()+"]\n[TEXT]["+parser.getText().trim()+"]"); |
528 |
break;
|
529 |
} |
530 |
formatsTag = parser.next(); |
531 |
} |
532 |
if (layerFormats == null) |
533 |
layerFormats = new Hashtable(); |
534 |
layerFormats.put(layer, formats.toArray(new String[0])); |
535 |
|
536 |
} else if (parser.getName().compareTo(WebMapContextTags.STYLE_LIST) == 0) { |
537 |
int stylesTag = parser.nextTag();
|
538 |
boolean bStylesEnd = false; |
539 |
ArrayList styles = new ArrayList(); |
540 |
while (!bStylesEnd) {
|
541 |
switch (stylesTag) {
|
542 |
case KXmlParser.START_TAG:
|
543 |
if (parser.getName().compareTo(WebMapContextTags.STYLE) == 0) { |
544 |
String current = parser.getAttributeValue("", WebMapContextTags.CURRENT); |
545 |
FMapWMSStyle style = parseStyle1_1_0(parser); |
546 |
if (current!=null && current.equals("1")) { |
547 |
Vector v = new Vector(); |
548 |
v.add(style.name); |
549 |
layer.setStyles(v); |
550 |
} |
551 |
styles.add(style); |
552 |
} else {
|
553 |
System.out.println("Unrecognized "+parser.getName()); |
554 |
} |
555 |
break;
|
556 |
case KXmlParser.END_TAG:
|
557 |
if (parser.getName().compareTo(WebMapContextTags.STYLE_LIST) == 0) |
558 |
bStylesEnd = true;
|
559 |
break;
|
560 |
case KXmlParser.TEXT:
|
561 |
if (parser.getName()!=null) |
562 |
System.out.println("[TAG]["+parser.getName()+"]\n[TEXT]["+parser.getText().trim()+"]"); |
563 |
break;
|
564 |
} |
565 |
stylesTag = parser.next(); |
566 |
} |
567 |
if (layerStyles == null) |
568 |
layerStyles = new Hashtable(); |
569 |
|
570 |
layerStyles.put(layer, styles.toArray(new FMapWMSStyle[0])); |
571 |
} else {
|
572 |
System.out.println("Unrecognized "+parser.getName()); |
573 |
} |
574 |
break;
|
575 |
case KXmlParser.END_TAG:
|
576 |
if (parser.getName().compareTo(WebMapContextTags.LAYER) == 0) |
577 |
end = true;
|
578 |
break;
|
579 |
case KXmlParser.TEXT:
|
580 |
if (parser.getName()!=null) |
581 |
System.out.println("[TAG]["+parser.getName()+"]\n[TEXT]["+parser.getText().trim()+"]"); |
582 |
break;
|
583 |
} |
584 |
tag = parser.next(); |
585 |
} |
586 |
return layer;
|
587 |
} |
588 |
|
589 |
private FMapWMSStyle parseStyle1_1_0(KXmlParser parser) throws XmlPullParserException, IOException { |
590 |
boolean end = false; |
591 |
String styleName = null; |
592 |
String styleAbstract = null; |
593 |
String styleTitle = null; |
594 |
int tag = parser.next();
|
595 |
while (!end) {
|
596 |
switch(tag) {
|
597 |
case KXmlParser.START_TAG:
|
598 |
if (parser.getName().compareTo(WebMapContextTags.NAME) == 0) { |
599 |
styleName = parser.nextText(); |
600 |
} else if (parser.getName().compareTo(WebMapContextTags.ABSTRACT) == 0) { |
601 |
styleAbstract = parser.nextText(); |
602 |
} else if (parser.getName().compareTo(WebMapContextTags.TITLE) == 0) { |
603 |
styleTitle = parser.nextText(); |
604 |
} else {
|
605 |
System.out.println("Unrecognized "+parser.getName()); |
606 |
} |
607 |
break;
|
608 |
case KXmlParser.END_TAG:
|
609 |
if (parser.getName().compareTo(WebMapContextTags.STYLE) == 0) |
610 |
end = true;
|
611 |
break;
|
612 |
case KXmlParser.TEXT:
|
613 |
if (parser.getName()!=null) |
614 |
System.out.println("[TAG]["+parser.getName()+"]\n[TEXT]["+parser.getText().trim()+"]"); |
615 |
break;
|
616 |
} |
617 |
tag = parser.next(); |
618 |
} |
619 |
WMSLayerNode n = new WMSLayerNode();
|
620 |
FMapWMSStyle sty = n.new FMapWMSStyle(styleName, styleTitle, styleAbstract, null);
|
621 |
return sty;
|
622 |
} |
623 |
|
624 |
public String createMapContext1_1_0(ProjectView v) { |
625 |
ArrayList layersToExport = new ArrayList(); |
626 |
FLayers lyrs = v.getMapContext().getLayers(); |
627 |
int count = lyrs.getLayersCount();
|
628 |
for (int i = 0; i < count; i++) { |
629 |
if (lyrs.getLayer(i) instanceof FLyrWMS) { |
630 |
layersToExport.add((FLyrWMS) lyrs.getLayer(i)); |
631 |
} |
632 |
} |
633 |
|
634 |
XmlBuilder xml = new XmlBuilder();
|
635 |
HashMap xmlAttrs = new HashMap(); |
636 |
xml.writeHeader(); |
637 |
|
638 |
// <ViewContext>
|
639 |
xmlAttrs.put(WebMapContextTags.VERSION, fileVersion); |
640 |
xmlAttrs.put(WebMapContextTags.ID, id); |
641 |
xmlAttrs.put(WebMapContextTags.XMLNS, WebMapContextTags.XMLNS_VALUE); |
642 |
xmlAttrs.put(WebMapContextTags.XMLNS_XLINK, WebMapContextTags.XMLNS_XLINK_VALUE); |
643 |
xmlAttrs.put(WebMapContextTags.XMLNS_XSI, WebMapContextTags.XMLNS_XSI_VALUE); |
644 |
xmlAttrs.put(WebMapContextTags.XSI_SCHEMA_LOCATION, WebMapContextTags.XSI_SCHEMA_LOCATION_VALUE); |
645 |
xml.openTag(WebMapContextTags.VIEW_CONTEXT, xmlAttrs); |
646 |
xmlAttrs.clear(); |
647 |
|
648 |
// <General>
|
649 |
xml.openTag(WebMapContextTags.GENERAL); |
650 |
|
651 |
// <Window>
|
652 |
if (windowSize!=null) { |
653 |
xmlAttrs.put(WebMapContextTags.WIDTH, ((int) windowSize.getWidth())+""); |
654 |
xmlAttrs.put(WebMapContextTags.HEIGHT, ((int) windowSize.getHeight())+""); |
655 |
xml.writeTag(WebMapContextTags.WINDOW, xmlAttrs); |
656 |
xmlAttrs.clear(); |
657 |
} |
658 |
// </Window>
|
659 |
|
660 |
// <BoundingBox>
|
661 |
xmlAttrs.put(WebMapContextTags.SRS, v.getProjection().getAbrev()); |
662 |
Rectangle2D rect = v.getMapContext().getViewPort().getAdjustedExtent();
|
663 |
xmlAttrs.put(WebMapContextTags.X_MIN, rect.getMinX()+"");
|
664 |
xmlAttrs.put(WebMapContextTags.Y_MIN, rect.getMinY()+"");
|
665 |
xmlAttrs.put(WebMapContextTags.X_MAX, rect.getMaxX()+"");
|
666 |
xmlAttrs.put(WebMapContextTags.Y_MAX, rect.getMaxY()+"");
|
667 |
xml.writeTag(WebMapContextTags.BOUNDING_BOX, xmlAttrs); |
668 |
xmlAttrs.clear(); |
669 |
// </BoundingBox>
|
670 |
|
671 |
// <Title>
|
672 |
xml.writeTag(WebMapContextTags.TITLE, title.trim()); |
673 |
// </Title>
|
674 |
|
675 |
// <Abstract>
|
676 |
if (_abstract != null) |
677 |
xml.writeTag(WebMapContextTags.ABSTRACT, _abstract.trim()); |
678 |
// </Abstract>
|
679 |
|
680 |
// <LogoURL>
|
681 |
if (logoURL != null) |
682 |
xml.writeTag(WebMapContextTags.LOGO_URL, logoURL.trim()); |
683 |
// </LogoURL>
|
684 |
|
685 |
// <DescriptionURL>
|
686 |
if (descriptionURL != null) |
687 |
xml.writeTag(WebMapContextTags.DESCRIPTION_URL, descriptionURL.trim()); |
688 |
// </DescriptionURL>
|
689 |
|
690 |
// <KeywordList>
|
691 |
if (contactInfo) {
|
692 |
|
693 |
// <ContactInformation>
|
694 |
xml.openTag(WebMapContextTags.CONTACT_INFORMATION); |
695 |
if (contactPerson != null || contactOrganization != null) { |
696 |
|
697 |
// <ContactPersonPrimary>
|
698 |
xml.openTag(WebMapContextTags.CONTACT_PERSON_PRIMARY); |
699 |
|
700 |
// <ContactPerson>
|
701 |
if (contactPerson != null) |
702 |
xml.writeTag(WebMapContextTags.CONTACT_PERSON, contactPerson.trim()); |
703 |
// </ContactPerson>
|
704 |
|
705 |
// <ContactOrganization>
|
706 |
if (contactOrganization != null) |
707 |
xml.writeTag(WebMapContextTags.CONTACT_ORGANIZATION, contactOrganization.trim()); |
708 |
// </ContactOrganization>
|
709 |
|
710 |
xml.closeTag(); |
711 |
// </ContactPersonPrimary>
|
712 |
} |
713 |
xml.closeTag(); |
714 |
// </ContactInformation>
|
715 |
|
716 |
// <ContactPosition>
|
717 |
if (contactPosition != null) |
718 |
xml.writeTag(WebMapContextTags.CONTACT_POSITION, contactPosition.trim()); |
719 |
// </ContactPosition>
|
720 |
|
721 |
// <ContactAddress>
|
722 |
if (address != null || city != null || stateOrProvince != null || postCode != null || country != null) { |
723 |
xml.openTag(WebMapContextTags.CONTACT_ADDRESS); |
724 |
|
725 |
// <AddressType>
|
726 |
xml.writeTag(WebMapContextTags.ADDRESS_TYPE, "Postal");
|
727 |
// </AddressType>
|
728 |
|
729 |
// <Address>
|
730 |
if (address != null) |
731 |
xml.writeTag(WebMapContextTags.ADDRESS, address.trim()); |
732 |
// </Address>
|
733 |
|
734 |
// <City>
|
735 |
if (city != null) |
736 |
xml.writeTag(WebMapContextTags.CITY, city.trim()); |
737 |
// </City>
|
738 |
|
739 |
// <StateOrProvince>
|
740 |
if (stateOrProvince != null) |
741 |
xml.writeTag(WebMapContextTags.STATE_OR_PROVINCE, stateOrProvince.trim()); |
742 |
// </StateOrProvince>
|
743 |
|
744 |
// <PostCode>
|
745 |
if (postCode != null) |
746 |
xml.writeTag(WebMapContextTags.POSTCODE, postCode.trim()); |
747 |
// </PostCode>
|
748 |
|
749 |
// <Country>
|
750 |
if (country != null) |
751 |
xml.writeTag(WebMapContextTags.COUNTRY, country.trim()); |
752 |
// </Country>
|
753 |
xml.closeTag(); |
754 |
} |
755 |
// </ContactAddress>
|
756 |
|
757 |
// <ContactVoiceTelephone>
|
758 |
if (telephone != null) |
759 |
xml.writeTag(WebMapContextTags.CONTACT_VOICE_TELEPHONE, telephone.trim()); |
760 |
// </ContactVoiceTelephone>
|
761 |
|
762 |
// <ContactFacsimileTelephone>
|
763 |
if (fax != null) |
764 |
xml.writeTag(WebMapContextTags.CONTACT_FACSIMILE_TELEPHONE, fax.trim()); |
765 |
// </ContactFacsimileTelephone>
|
766 |
|
767 |
// <ContactElectronicMailAddress>
|
768 |
if (email != null) |
769 |
xml.writeTag(WebMapContextTags.CONTACT_ELECTRONIC_MAIL_ADDRESS, email.trim()); |
770 |
// </ContactElectronicMailAddress>
|
771 |
} |
772 |
if (keywordList != null) { |
773 |
xml.openTag(WebMapContextTags.KEYWORD_LIST); |
774 |
for (int i = 0; i < keywordList.size(); i++) { |
775 |
xml.writeTag(WebMapContextTags.KEYWORD, ((String) keywordList.get(i)).trim());
|
776 |
} |
777 |
xml.closeTag(); |
778 |
} |
779 |
// </KeywordList>
|
780 |
xml.closeTag(); |
781 |
// </General>
|
782 |
|
783 |
// <LayerList>
|
784 |
xml.openTag(WebMapContextTags.LAYER_LIST); |
785 |
for (int i = 0; i < layersToExport.size(); i++) { |
786 |
xml.writeRaw(((FLyrWMS) layersToExport.get(i)).toMapContext("1.1.0"));
|
787 |
} |
788 |
xml.closeTag(); |
789 |
// </LayerList>
|
790 |
xml.closeTag(); |
791 |
// </ViewContext>
|
792 |
|
793 |
return xml.getXML();
|
794 |
} |
795 |
|
796 |
public String toXML(ProjectView v) { |
797 |
if (fileVersion.equals("1.1.0")) { |
798 |
return createMapContext1_1_0(v);
|
799 |
} |
800 |
return null; |
801 |
} |
802 |
} |