Revision 12673

View differences:

org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.122/org.gvsig.raster.wms.app.wmsclient/buildNumber.properties
1
#Sun Oct 04 02:21:08 CEST 2020
2
buildNumber=177
0 3

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.122/org.gvsig.raster.wms.app.wmsclient/src/main/assembly/gvsig-plugin-package.xml
1
<assembly>
2
    <id>gvsig-plugin-package</id>
3
    <formats>
4
        <format>zip</format>
5
    </formats>
6
    <baseDirectory>${project.artifactId}</baseDirectory>
7
    <includeBaseDirectory>true</includeBaseDirectory>
8
    <files>
9
        <file>
10
            <source>target/${project.artifactId}-${project.version}.jar</source>
11
            <outputDirectory>lib</outputDirectory>
12
        </file>
13
        <file>
14
            <source>target/package.info</source>
15
        </file>
16
    </files>
17

  
18
    <fileSets>
19
        <fileSet>
20
            <directory>src/main/resources-plugin</directory>
21
            <outputDirectory>.</outputDirectory>
22
        </fileSet>
23
    </fileSets>
24

  
25

  
26
    <dependencySets>
27
        <dependencySet>
28
            <useProjectArtifact>false</useProjectArtifact>
29
            <useTransitiveDependencies>false</useTransitiveDependencies>
30
            <outputDirectory>lib</outputDirectory>
31
            <includes> 
32
                <include>org.gvsig:org.gvsig.raster.wms.remoteclient:jar</include>
33
                <include>org.gvsig:org.gvsig.raster.wms.io:jar</include>
34
            </includes>
35
        </dependencySet>
36
    </dependencySets>
37
</assembly>
0 38

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.122/org.gvsig.raster.wms.app.wmsclient/src/main/java/org/gvsig/raster/wms/app/wmsclient/wmc/XmlBuilder.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
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., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
 
23
package org.gvsig.raster.wms.app.wmsclient.wmc;
24

  
25
import java.util.HashMap;
26
import java.util.Stack;
27

  
28
/**
29
 * Title:         XmlBuilder
30
 * Description:   Util class to build xml
31
 * @author laura
32
 */
33
public class XmlBuilder
34
{
35
  // Default size of the XML document to be generated. Used to set the initial
36
  // capacity of m_xml.
37
  private static final int DEF_XMLDOC_SIZE = 256;
38

  
39
  // Pad unit.
40
  private static final String PAD = "  ";
41

  
42
  
43
  // Number of pre-defined pad strings, one for each pad
44
  // level (0..NUM_PADSTRINGS-1). Should at least be set to 10 for performance.
45
  private static final int NUM_PADSTRINGS = 20;
46

  
47
  // Byte representation of '\n'.
48
  private static final byte[] NEWLINE_BYTES = "\n".getBytes();
49

  
50

  
51
  // Array of pad strings, each preceded by a '\n' character.
52
  private static String s_padStrings[];
53

  
54
  // XML-encoded newline character.
55
  private static String s_newlineXmlEnc;
56

  
57

  
58
  // XML document being built.
59
  private StringBuffer m_xml = new StringBuffer(DEF_XMLDOC_SIZE);
60

  
61
  // Scratch buffer exclusively used to encode strings.
62
  private StringBuffer m_encodeBuf = new StringBuffer(40);
63

  
64
  // Current pad string.
65
  private String m_pad = "";
66

  
67
  // If set, indentation will be added to the XML document.
68
  private boolean m_autoPad;
69

  
70
  // Stack of strings. The string at the top is the tag name of the current
71
  // XML block. The string immediately below the top is the tag name of the
72
  // XML block that immediately encloses the current XML block.
73
  protected Stack<String> m_openElements = new Stack<String>();
74

  
75
  // Current pad level (0, 1, 2, ...).
76
  private int m_padLevel = 0;
77

  
78
  private String encoding = "UTF-8";
79

  
80
  /*
81
   * Create the pad strings.
82
   */
83
  static
84
  {
85
    s_padStrings = new String[NUM_PADSTRINGS];
86
    String pad = "";
87

  
88
    for (int i = 0; i < NUM_PADSTRINGS; i++)
89
    {
90
      s_padStrings[i] = "\n" + pad;
91
      pad += PAD;
92
    }
93

  
94
    StringBuffer tmp = new StringBuffer();
95

  
96
    for (int i = 0; i < NEWLINE_BYTES.length; i++)
97
    {
98
      tmp.append("&#");
99
      tmp.append(NEWLINE_BYTES[i]);
100
      tmp.append(";");
101
    }
102

  
103
    s_newlineXmlEnc = tmp.toString();
104
  }
105

  
106

  
107
  /**
108
  * Constructor. The XML document to be generated will automatically be
109
  * indented.
110
  */
111
  public XmlBuilder()
112
  {
113
    this(true);
114
  }
115

  
116
  /**
117
  * Constructor.
118
  *
119
  * @param  autoPad  if set, the XML document to be generated will
120
  *                  automatically be indented.
121
  */
122
  public XmlBuilder(boolean autoPad)
123
  {
124
    m_autoPad = autoPad;
125
    m_padLevel = 0;
126
    m_pad = s_padStrings[m_padLevel];
127
  }
128

  
129
  /**
130
   * Reset this XmlBuilder.
131
   */
132
  public void reset()
133
  {
134
    m_padLevel = 0;
135
    m_pad = s_padStrings[m_padLevel];
136
    m_xml.setLength(0);
137
  }
138

  
139
  /**
140
  * Adds raw data to the xml.
141
  */
142
  public void writeRaw(String raw)
143
  {
144
    m_xml.append(raw);
145
  }
146

  
147
  /**
148
  * Adds a comment to the xml.
149
  */
150
  public void writeComment(String comment)
151
  {
152
    if (m_autoPad)
153
    {
154
      m_xml.append(m_pad);
155
    }
156

  
157
    m_xml.append("<!-- ");
158
    encode(comment, m_xml);
159
    m_xml.append(" -->\n");
160
  }
161

  
162
  /**
163
   * Writes the XML document header.
164
   */
165
  public void writeHeader()
166
  {
167
	// XML document header.
168
	final String HEADER = "<?xml version=\"1.0\" encoding=\""+encoding+"\"?>\n";
169

  
170
    m_xml.append(HEADER);
171
  }
172
  
173
  /**
174
   * Sets the encoding used in the XML. By default UTF-8 is used.
175
   * @param encoding
176
   */
177
  public void setEncoding(String encoding) {
178
	  this.encoding  = encoding;
179
  }
180
  
181
  /**
182
  * Adds a opening and closing tag with charcter data.
183
  */
184
  public void writeTag(String name, String data)
185
  {
186
    name = encode(name);
187

  
188
    if (m_autoPad)
189
    {
190
      m_xml.append(m_pad);
191
    }
192

  
193
    m_xml.append("<");
194
    m_xml.append(name);
195
    m_xml.append(">");
196
    encode(data, m_xml);
197
    m_xml.append("</");
198
    m_xml.append(name);
199
    m_xml.append(">");
200
  }
201

  
202
  /**
203
  * Adds a opening and closing tag with attributes.
204
  */
205
  public void writeTag(String name, HashMap<Object, String> attributes)
206
  {
207
    if (m_autoPad)
208
    {
209
      m_xml.append(m_pad);
210
    }
211

  
212
    m_xml.append("<");
213
    encode(name, m_xml);
214
    m_xml.append(" ");
215

  
216
    Object elems[] = attributes.keySet().toArray();
217
    
218
    for (int i = 0; i < elems.length; i++)
219
    {
220
      String nm = (String)elems[i];
221
      String val = (String)attributes.get(nm);
222

  
223
      encode(nm, m_xml);
224
      m_xml.append("=\"");
225
      encode(val, m_xml);
226
      m_xml.append("\" ");
227
    }
228

  
229
    m_xml.append("/>");
230
  }
231

  
232
  /**
233
  * Adds a opening and closing tag with an attribute and character data.
234
  */
235
  public void writeTag(String name, String attr1Name, String attr1Value
236
  	, String attr2Name, String attr2Value)
237
  {
238
    if (m_autoPad)
239
    {
240
      m_xml.append(m_pad);
241
    }
242

  
243
    m_xml.append("<");
244
    encode(name, m_xml);
245
    m_xml.append(" ");
246

  
247
    encode(attr1Name, m_xml);
248
    m_xml.append("=\"");
249
    encode(attr1Value, m_xml);
250
    m_xml.append("\" ");
251

  
252
    encode(attr2Name, m_xml);
253
    m_xml.append("=\"");
254
    encode(attr2Value, m_xml);
255
    m_xml.append("\" ");
256

  
257
    m_xml.append("/>");
258
  }
259

  
260
  /**
261
  * Adds a opening and closing tag with an attribute and character data.
262
  */
263
  public void writeTag(String name, String data, String attrName, String attrValue)
264
  {
265
    name = encode(name);
266

  
267
    if (m_autoPad)
268
    {
269
      m_xml.append(m_pad);
270
    }
271

  
272
    m_xml.append("<");
273
    m_xml.append(name);
274
    m_xml.append(" ");
275

  
276
    encode(attrName, m_xml);
277
    m_xml.append("=\"");
278
    encode(attrValue, m_xml);
279
    m_xml.append("\" ");
280

  
281
    m_xml.append(">");
282
    encode(data, m_xml);
283
    m_xml.append("</");
284
    m_xml.append(name);
285
    m_xml.append(">");
286
  }
287

  
288
  /**
289
  * Adds a opening and closing tag with two attributes and character data.
290
  */
291
  public void writeTag(String name, String data, String attr1Name, String attr1Value
292
                      , String attr2Name, String attr2Value)
293
  {
294
    name = encode(name);
295

  
296
    if (m_autoPad)
297
    {
298
      m_xml.append(m_pad);
299
    }
300

  
301
    m_xml.append("<");
302
    m_xml.append(name);
303
    m_xml.append(" ");
304

  
305
    encode(attr1Name, m_xml);
306
    m_xml.append("=\"");
307
    encode(attr1Value, m_xml);
308
    m_xml.append("\" ");
309

  
310
    encode(attr2Name, m_xml);
311
    m_xml.append("=\"");
312
    encode(attr2Value, m_xml);
313
    m_xml.append("\" ");
314

  
315
    m_xml.append(">");
316
    encode(data, m_xml);
317
    m_xml.append("</");
318
    m_xml.append(name);
319
    m_xml.append(">");
320
  }
321

  
322
  /**
323
  * Adds a opening and closing tag with attributes and character data.
324
  */
325
  public void writeTag(String name, String data, HashMap<Object, String> attributes)
326
  {
327
    name = encode(name);
328

  
329
    if (m_autoPad)
330
    {
331
      m_xml.append(m_pad);
332
    }
333

  
334
    m_xml.append("<");
335
    m_xml.append(name);
336
    m_xml.append(" ");
337

  
338
    Object elems[] = attributes.keySet().toArray();
339
    
340
    for (int i = 0; i < elems.length; i++)
341
    {
342
      String nm = (String)elems[i];
343
      String val = (String)attributes.get(nm);
344

  
345
      encode(nm, m_xml);
346
      m_xml.append("=\"");
347
      encode(val, m_xml);
348
      m_xml.append("\" ");
349
    }
350

  
351
    m_xml.append(">");
352
    encode(data, m_xml);
353
    m_xml.append("</");
354
    m_xml.append(name);
355
    m_xml.append(">");
356
  }
357

  
358
  /**
359
  * Writes an opening tag
360
  */
361
  public void openTag(String name)
362
  {
363
    name = encode(name);
364

  
365
    m_openElements.push(name);              // must be encoded!
366

  
367
    if (m_autoPad)
368
    {
369
      m_xml.append(m_pad);
370
    }
371

  
372
    m_xml.append("<");
373
    m_xml.append(name);
374
    m_xml.append(">");
375

  
376
    if (m_autoPad)
377
    {
378
      m_padLevel++;
379

  
380
      if (m_padLevel < NUM_PADSTRINGS)
381
      {
382
        m_pad = s_padStrings[m_padLevel];
383
      }
384
      else                                  // really deep nesting level
385
      {
386
        m_pad += PAD;
387
      }
388
    }
389
  }
390

  
391
  /**
392
  * Writes an opening tag with one attribute.
393
  */
394
  public void openTag(String name, String attrName, String attrValue)
395
  {
396
    name = encode(name);
397

  
398
    m_openElements.push(name);              // must be encoded!
399

  
400
    if (m_autoPad)
401
    {
402
      m_xml.append(m_pad);
403
    }
404

  
405
    m_xml.append("<");
406
    m_xml.append(name);
407
    m_xml.append(" ");
408

  
409
    encode(attrName, m_xml);
410
    m_xml.append("=\"");
411
    encode(attrValue, m_xml);
412
    m_xml.append("\" ");
413

  
414
    m_xml.append(">");
415

  
416
    if (m_autoPad)
417
    {
418
      m_padLevel++;
419

  
420
      if (m_padLevel < NUM_PADSTRINGS)
421
      {
422
        m_pad = s_padStrings[m_padLevel];
423
      }
424
      else                                  // really deep nesting level
425
      {
426
        m_pad += PAD;
427
      }
428
    }
429
  }
430

  
431
  /**
432
  * Writes an opening tag with two attributes.
433
  */
434
  public void openTag(String name, String attr1Name, String attr1Value
435
                      , String attr2Name, String attr2Value)
436
  {
437
    name = encode(name);
438

  
439
    m_openElements.push(name);              // must be encoded!
440

  
441
    if (m_autoPad)
442
    {
443
      m_xml.append(m_pad);
444
    }
445

  
446
    m_xml.append("<");
447
    m_xml.append(name);
448
    m_xml.append(" ");
449

  
450
    encode(attr1Name, m_xml);
451
    m_xml.append("=\"");
452
    encode(attr1Value, m_xml);
453
    m_xml.append("\" ");
454

  
455
    encode(attr2Name, m_xml);
456
    m_xml.append("=\"");
457
    encode(attr2Value, m_xml);
458
    m_xml.append("\" ");
459

  
460
    m_xml.append(">");
461

  
462
    if (m_autoPad)
463
    {
464
      m_padLevel++;
465

  
466
      if (m_padLevel < NUM_PADSTRINGS)
467
      {
468
        m_pad = s_padStrings[m_padLevel];
469
      }
470
      else                                  // really deep nesting level
471
      {
472
        m_pad += PAD;
473
      }
474
    }
475
  }
476

  
477
  /**
478
  * Writes an opening tag with attributes.
479
  */
480
  public void openTag(String name, HashMap<Object, String> attributes)
481
  {
482
    name = encode(name);
483

  
484
    m_openElements.push(name);              // must be encoded!
485

  
486
    if (m_autoPad)
487
    {
488
      m_xml.append(m_pad);
489
    }
490

  
491
    m_xml.append("<");
492
    m_xml.append(name);
493
    m_xml.append(" ");
494

  
495
    Object elems[] = attributes.keySet().toArray();
496
    
497
    for (int i = 0; i < elems.length; i++)
498
    {
499
      String nm = (String)elems[i];
500
      String val = (String)attributes.get(nm);
501

  
502
      encode(nm, m_xml);
503
      m_xml.append("=\"");
504
      encode(val, m_xml);
505
      m_xml.append("\" ");
506
    }
507

  
508
    m_xml.append(">");
509

  
510
    if (m_autoPad)
511
    {
512
      m_padLevel++;
513

  
514
      if (m_padLevel < NUM_PADSTRINGS)
515
      {
516
        m_pad = s_padStrings[m_padLevel];
517
      }
518
      else                                  // really deep nesting level
519
      {
520
        m_pad += PAD;
521
      }
522
    }
523
  }
524

  
525
  /**
526
  * Closes an open tag.
527
  */
528
  public void closeTag()
529
  {
530
    if (m_autoPad)
531
    {
532
      if (m_padLevel > 0)
533
      {
534
        m_padLevel--;
535
      }
536

  
537
      if (m_padLevel < NUM_PADSTRINGS)
538
      {
539
        m_pad = s_padStrings[m_padLevel];
540
      }
541
      else                                  // really deep nesting level
542
      {
543
        int len = m_pad.length() - PAD.length();
544
        if (len > 0)
545
        {
546
          m_pad = m_pad.substring(0, len);
547
        }
548
      }
549

  
550
      m_xml.append(m_pad);
551
    }
552

  
553
	String name = (String)m_openElements.pop();      // already encoded
554

  
555
    m_xml.append("</");
556
    m_xml.append(name);
557
    m_xml.append(">");
558
  }
559

  
560
  /**
561
  * Get the xml.
562
  */
563
  public String getXML()
564
  {
565
    return m_xml.toString();
566
  }
567

  
568
  /**
569
   * Encodes the funny characters (e.g., '&', '<', '\"') in an XML
570
   * string.
571
   *
572
   * @param  src  XML string to encode.
573
   * @return the encoded string.
574
   */
575
  private String encode(String src)
576
  {
577
    m_encodeBuf.setLength(0);			// clear old contents
578
    encode(src, m_encodeBuf);
579
    return m_encodeBuf.toString();
580
  }
581

  
582
  /**
583
   * Encodes the funny characters (e.g., '&', '<', '\"') in an XML
584
   * string.
585
   *
586
   * @param  src  XML string to encode.
587
   * @param  dst  string buffer to write the encoded XML string to.
588
   */
589
  private static final void encode(String src, StringBuffer dst)
590
  {
591
    int n = src.length();
592
  	
593
    for (int i = 0; i < n; i++)
594
    {
595
      char c = src.charAt(i);
596

  
597
      switch(c)
598
      {
599
      case '&':
600
        dst.append("&amp;");
601
        break;
602
      case '<':
603
        dst.append("&lt;");
604
        break;
605
      case '>':
606
        dst.append("&gt;");
607
        break;
608
      case '\'':
609
        dst.append("&apos;");
610
        break;
611
      case '\"':
612
        dst.append("&quot;");
613
        break;
614
      case '\n':
615
        dst.append(s_newlineXmlEnc);
616
        break;
617
      default:
618
        dst.append(c); 
619
      }
620
    }
621
  }
622
}
623

  
0 624

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.122/org.gvsig.raster.wms.app.wmsclient/src/main/java/org/gvsig/raster/wms/app/wmsclient/wmc/ImportWebMapContextExtension.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
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., 51 Franklin Street, Fifth Floor, Boston,
19
* MA  02110-1301, USA.
20
*
21
*/
22

  
23
package org.gvsig.raster.wms.app.wmsclient.wmc;
24

  
25
import java.awt.Component;
26
import java.awt.geom.Rectangle2D;
27
import java.io.File;
28
import java.io.FileNotFoundException;
29
import java.util.Date;
30

  
31
import javax.swing.JOptionPane;
32
import javax.swing.filechooser.FileFilter;
33

  
34
import org.gvsig.andami.PluginServices;
35
import org.gvsig.andami.messages.NotificationManager;
36
import org.gvsig.andami.plugins.Extension;
37
import org.gvsig.andami.ui.mdiManager.IWindow;
38
import org.gvsig.app.project.Project;
39
import org.gvsig.app.project.ProjectManager;
40
import org.gvsig.app.project.documents.view.DefaultViewDocument;
41
import org.gvsig.app.project.documents.view.ViewManager;
42
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
43
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
44
import org.gvsig.fmap.dal.DALLocator;
45
import org.gvsig.fmap.dal.DataManager;
46
import org.gvsig.fmap.dal.coverage.exception.ImportMapContextException;
47
import org.gvsig.fmap.geom.Geometry;
48
import org.gvsig.fmap.geom.GeometryLocator;
49
import org.gvsig.fmap.geom.primitive.Envelope;
50
import org.gvsig.fmap.mapcontext.exceptions.UnsupportedVersionLayerException;
51
import org.gvsig.gui.beans.swing.JFileChooser;
52
import org.gvsig.raster.wms.app.wmsclient.gui.panel.WebMapContextFileChooserAccessory;
53
import org.gvsig.raster.wms.app.wmsclient.layer.FLyrWMS;
54
import org.gvsig.raster.wms.io.WMSDataParameters;
55
import org.gvsig.raster.wms.io.WMSServerExplorer;
56
import org.gvsig.raster.wms.io.WMSServerExplorerParameters;
57

  
58

  
59
public class ImportWebMapContextExtension extends Extension {
60

  
61
	public static final String WMC_FILECHOOSER_ID = "WMC_FILECHOOSER_ID";
62
	private String lastPath = null;
63

  
64
	public void initialize() {
65
		String[] arguments = PluginServices.getArguments();
66
		if (arguments[arguments.length-1].toLowerCase().endsWith(".cml")) {
67
			File wmcFile = new File(arguments[arguments.length-1]);
68
			if (!wmcFile.exists()) {
69
				NotificationManager.addError(PluginServices.getText(this, "could_not_find_web_map_context_file"), new FileNotFoundException());
70
				return;
71
			}
72

  
73
			readMapContextFile(wmcFile, null);
74
		}
75
	}
76

  
77
	@SuppressWarnings("deprecation")
78
	public void execute(String actionCommand) {
79
		if (actionCommand.equals("IMPORT")) {
80
			JFileChooser fc = new JFileChooser(WMC_FILECHOOSER_ID, lastPath);
81
			fc.setFileFilter(new FileFilter() {
82
				public boolean accept(File f) {
83
					return f.isDirectory() || f.getAbsolutePath().toLowerCase().endsWith(WebMapContext.FILE_EXTENSION);
84
				}
85

  
86
				public String getDescription() {
87
					return PluginServices.getText(this, "ogc_mapcontext_file")+" (*.cml)";
88
				}
89
			});
90
			IWindow v = PluginServices.getMDIManager().getActiveWindow();
91

  
92
			// If the current active view is a gvSIG's view, we'll keep its name to
93
			// show it at the JFileChooser's accessory.
94
			String currentViewName;
95
			if (v instanceof AbstractViewPanel) {
96
				currentViewName = ((AbstractViewPanel) v).getModel().getName();
97
			} else {
98
				currentViewName = null;
99
			}
100

  
101
			// Create an accessory for the Web Map Context's file chooser.
102
			WebMapContextFileChooserAccessory acc = new WebMapContextFileChooserAccessory(currentViewName);
103

  
104
			// Add the accessory to the file chooser
105
			fc.setAccessory(acc);
106

  
107
			// Nothing else than Web Map Context files allowed
108
			fc.setAcceptAllFileFilterUsed(false);
109

  
110
			if (fc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION){
111
				File f = fc.getSelectedFile();
112
				readMapContextFile(f, acc.getSelectedView());
113
				String fileName = f.getAbsolutePath();
114
				lastPath  = fileName.substring(0, fileName.lastIndexOf(File.separatorChar));
115

  
116
			}
117
			fc = null;
118
		}
119
	}
120

  
121
	/**
122
	 * Reads a WebMapContext (.cml) file and loads its layers into the destination
123
	 * view.
124
	 * @param wmcFile
125
	 * @param dstView
126
	 */
127
	@SuppressWarnings("unchecked")
128
	private void readMapContextFile(File wmcFile, DefaultViewDocument dstView) {
129
		WebMapContext wmc = new WebMapContext();
130
		try {
131
			wmc.readFile(wmcFile);
132
		} catch (UnsupportedVersionLayerException e) {
133
			JOptionPane.showMessageDialog(
134
					(Component) PluginServices.getMainFrame(),
135
					e.getMessage(),
136
					PluginServices.getText(this, "unsupported_version"),
137
					JOptionPane.ERROR_MESSAGE);
138
			return;
139
		} catch (ImportMapContextException e) {
140
			if (e.isCritical()) {
141
				// import impossible: show message and quit
142
				JOptionPane.showMessageDialog(
143
						(Component) PluginServices.getMainFrame(),
144
						e.getMessage(),
145
						PluginServices.getText(this, "problems_encountered_while_importing"),
146
						JOptionPane.ERROR_MESSAGE);
147
				return;
148
			} else {
149
				JOptionPane.showMessageDialog(
150
						(Component) PluginServices.getMainFrame(),
151
						e.getMessage() + "\n\n" +
152
						PluginServices.getText(this, "edit_layer_properties_to_fix_them"),
153
						PluginServices.getText(this, "problems_encountered_while_importing"),
154
						JOptionPane.ERROR_MESSAGE);
155
			}
156
		}
157

  
158
		if (dstView == null) {
159
			// Since the destination view is null, a new one will be added to
160
			// the project.
161
//			dstView = ProjectFactory.createView(null);
162
			dstView = (DefaultViewDocument) ProjectManager.getInstance().createDocument(ViewManager.TYPENAME);
163

  
164
			dstView.setName(wmc.title);
165
			dstView.setComment("Created from WebMapContext file: " + wmcFile.getName());
166

  
167
//			ProjectExtension pe = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
168
//			Project theProject = pe.getProject();
169
			final Project theProject = ProjectManager.getInstance().getCurrentProject();
170

  
171
			theProject.add(dstView);
172

  
173
			// show the view in a new window
174
			AbstractViewPanel v = null;
175
			v = new DefaultViewPanel(dstView);
176
			PluginServices.getMDIManager().addWindow(v);
177
		}
178

  
179
		for (int i = 0; i < wmc.layerList.size(); i++) {
180
			// WMS layers
181
			if (wmc.layerList.get(i) instanceof FLyrWMS) {
182
				FLyrWMS layer = wmc.layerList.get(i);
183
				WMSDataParameters params = wmc.paramsList.get(i);
184

  
185
				DataManager datamanager = DALLocator.getDataManager();
186

  
187
				/*
188
				 * will connect to get the online resources defined by
189
				 * server, because WMC only defines the original URL for
190
				 * the server but not for the operations.
191
				 */
192
				try {
193
					WMSServerExplorerParameters explorerParams = (WMSServerExplorerParameters) datamanager.createServerExplorerParameters(WMSServerExplorer.NAME);
194
					explorerParams.setHost(params.getURI().getPath());
195

  
196
					WMSServerExplorer explorer = (WMSServerExplorer) datamanager.createServerExplorer(explorerParams);
197

  
198
					layer.setExplorer(explorer);
199
					params.setOverrideHost(false);
200
					explorer.connect(null, true);
201

  
202
					params.setOnlineResources(explorer.getOnlineResources());
203
					layer.setParameters(params);
204

  
205
					Rectangle2D rec = wmc.bBox;
206
					Envelope envelope = GeometryLocator.getGeometryManager().createEnvelope(rec.getX(),rec.getY(),rec.getMaxX(),rec.getMaxY(), Geometry.SUBTYPES.GEOM2D);
207
					dstView.getMapContext().getViewPort().setEnvelope(envelope);
208
				} catch (Exception e) {
209
					NotificationManager.addInfo(PluginServices.getText(this, "connect_error")+"\n"+
210
							PluginServices.getText(this, "failed_restoring_online_resource_values")+
211
					" ["+new Date(System.currentTimeMillis()).toString()+"]",
212
					e);
213
				}
214

  
215
				dstView.getMapContext().getLayers().addLayer(layer);
216
			}
217
		}
218
	}
219

  
220
	public boolean isEnabled() {
221
		return true;
222
	}
223

  
224
	public boolean isVisible() {
225
		return true;
226
	}
227

  
228
}
0 229

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.122/org.gvsig.raster.wms.app.wmsclient/src/main/java/org/gvsig/raster/wms/app/wmsclient/wmc/ExportWebMapContextExtension.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
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., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
 
23
package org.gvsig.raster.wms.app.wmsclient.wmc;
24

  
25
import java.io.BufferedWriter;
26
import java.io.File;
27
import java.io.FileWriter;
28
import java.io.IOException;
29
import java.util.ArrayList;
30
import java.util.List;
31

  
32
import org.gvsig.andami.PluginServices;
33
import org.gvsig.andami.messages.NotificationManager;
34
import org.gvsig.andami.plugins.Extension;
35
import org.gvsig.andami.plugins.IExtension;
36
import org.gvsig.andami.ui.mdiManager.IWindow;
37
import org.gvsig.app.project.Project;
38
import org.gvsig.app.project.ProjectManager;
39
import org.gvsig.app.project.documents.Document;
40
import org.gvsig.app.project.documents.view.DefaultViewDocument;
41
import org.gvsig.app.project.documents.view.ViewManager;
42
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
43
import org.gvsig.fmap.mapcontext.layers.FLayer;
44
import org.gvsig.fmap.mapcontext.layers.FLayers;
45
import org.gvsig.raster.wms.app.wmsclient.gui.panel.WebMapContextSettingsPanel;
46
import org.gvsig.raster.wms.app.wmsclient.layer.FLyrWMS;
47

  
48

  
49
/**
50
 * Extension to export a view with WMS layers to a OGC's Web Map Context XML
51
 * file
52
 *
53
 * @author jaume dom?nguez faus - jaume.dominguez@iver.es
54
 * @author laura d?az s?nchez - laura.diaz@iver.es
55
 */
56
public class ExportWebMapContextExtension extends Extension {
57
	private static ArrayList<String>   supportedVersions;
58
	private AbstractViewPanel          viewToExport;
59
	private WebMapContextSettingsPanel mc;
60
	private static IExtension          thisExtension;
61

  
62
	{
63
		supportedVersions = new ArrayList<String>();
64
		supportedVersions.add("1.1.0");
65
	}
66

  
67
	public void initialize() {
68
		thisExtension = PluginServices
69
				.getExtension(ExportWebMapContextExtension.class);
70
	}
71

  
72
	public void execute(String actionCommand) {
73
		if (actionCommand.equals("EXPORT")) {
74
			// Here we collect the info
75
			DefaultViewDocument[] views = getExportableViews();
76
			if (views.length <= 0) {
77
				return;
78
			}
79
			mc = new WebMapContextSettingsPanel(views);
80
			PluginServices.getMDIManager().addWindow(mc);
81

  
82
		} else if (actionCommand.equals("DO_EXPORT")) {
83
			// Here the target file is produced (called from the WebMapContextSettingsPanel)
84
			String xml = mc.getXML();
85
			File f = mc.getTargetFile();
86
			if (xml != null) {
87
				createFile(f, xml);
88
			}
89

  
90
		}
91
	}
92

  
93
	/**
94
	 * Takes a File object and its XML contents and stores it as a regular
95
	 * file in the file system.
96
	 * @param f
97
	 * @param xml
98
	 */
99
	public static void createFile(File f, String xml) {
100
		if (xml != null) {
101
			try {
102
				if (!f.exists()) {
103
					f.createNewFile();
104
				}
105
				BufferedWriter bw = new BufferedWriter(new FileWriter(f));
106
				bw.write(xml);
107
				bw.close();
108
				bw = null;
109
			} catch (IOException e) {
110
				NotificationManager.addError(PluginServices.getText(
111
						thisExtension, "error_writting_file"), e);
112
			}
113
		}
114
	}
115

  
116
	public boolean isEnabled() {
117
		return true;
118
	}
119

  
120
	public boolean isVisible() {
121
		// Will be visible if the current project has, at least, one FLyrWMS.
122
//		Project project = ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject();
123
		final Project project = ProjectManager.getInstance().getCurrentProject();
124

  
125
		if (project == null) {
126
			return false;
127
		}
128
		IWindow f = PluginServices.getMDIManager().getActiveWindow();
129
		if (f instanceof AbstractViewPanel) {
130
			AbstractViewPanel v = (AbstractViewPanel) f;
131
			if (v != null && v  instanceof AbstractViewPanel) {
132
				// Check if the active contains WMS layers. If so, this view
133
				// will be the one to be exported.
134
				FLayers lyrs = v.getMapControl().getMapContext().getLayers();
135
				for (int i = 0; i < lyrs.getLayersCount(); i++) {
136
					FLayer lyr = lyrs.getLayer(i);
137
					if (WebMapContext.containsExportableLayers(lyr)) {
138
						viewToExport = v;
139
						return true;
140
					}
141
				}
142
			}
143
		}
144

  
145
		// Since the active view does not contain WMS layers then will
146
		// see what about the others. In this case, no view is set to be
147
		// the exported one.
148
		viewToExport = null;
149
		List<Document> views = project.getDocuments(ViewManager.TYPENAME);
150
		for (int i = 0; i < views.size(); i++) {
151
			DefaultViewDocument v = ((DefaultViewDocument) views.get(i));
152
			if (v != null) {
153
				FLayers lyrs = v.getMapContext().getLayers();
154
				for (int j = 0; j < lyrs.getLayersCount(); j++) {
155
					FLayer lyr = lyrs.getLayer(j);
156
					if (WebMapContext.containsExportableLayers(lyr)) {
157
						return true;
158
					}
159
				}
160
			}
161
		}
162
		return false;
163
	}
164

  
165
	/**
166
	 * <p>
167
	 * Searches the views in the current project that can be exported to a
168
	 * WebMapContext file (with ".cml" extension) and return them in a
169
	 * ProjectView array.<br>
170
	 * </p>
171
	 * <p>
172
	 * A view is exportable to WebMapContext if it contains at least one FLyrWMS
173
	 * and in a near future, any other OGC layer such as WebCoverageService, WFS, and so on. Only
174
	 * these layers will be exported. Other kind of layers are ignored since they
175
	 * are out of the OGC premises.
176
	 * </p>
177
	 * @return
178
	 */
179
	@SuppressWarnings({ "unchecked", "deprecation" })
180
	private DefaultViewDocument[] getExportableViews() {
181
//		Project project = ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject();
182
//		ArrayList views = project.getDocumentsByType(ProjectViewFactory.registerName);
183
		final Project project = ProjectManager.getInstance().getCurrentProject();
184

  
185
		List<Document> views = project.getDocuments(ViewManager.TYPENAME);
186

  
187
		List exportableViews = new ArrayList();
188
		if (viewToExport!=null) {
189
			exportableViews.add(viewToExport.getModel());
190
		}
191

  
192
		for (int i = 0; i < views.size(); i++) {
193
			DefaultViewDocument v = ((DefaultViewDocument) views.get(i));
194
			if (v != null) {
195
				FLayers lyrs = v.getMapContext().getLayers();
196
				for (int j = 0; j < lyrs.getLayersCount(); j++) {
197
					FLayer lyr = lyrs.getLayer(j);
198
					if (lyr instanceof FLyrWMS && !exportableViews.contains(v)) {
199
						exportableViews.add(v);
200
						break;
201
					}
202
				}
203
			}
204
		}
205
		return (DefaultViewDocument[]) exportableViews.toArray(new DefaultViewDocument[0]);
206
	}
207

  
208
}
0 209

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.122/org.gvsig.raster.wms.app.wmsclient/src/main/java/org/gvsig/raster/wms/app/wmsclient/wmc/WebMapContextTags.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
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., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
 
23
package org.gvsig.raster.wms.app.wmsclient.wmc;
24

  
25
/**
26
 * WebMapContextTags is a class with only static public fields containing the
27
 * String constants of the WebMapContext XML document.
28
 * @author jaume dominguez faus - jaume.dominguez@iver.es
29
 *
30
 */
31
public class WebMapContextTags {
32
	private WebMapContextTags() {};
33
	
34
	public static final String VIEW_CONTEXT = "ViewContext";
35
	public static final String VIEW_CONTEXT_0_1_4 = "WMS_Viewer_Context";
36
	public static final String VERSION = "version";
37
	public static final String ID = "id";
38
	public static final String XMLNS = "xmlns";
39
	public static final String XMLNS_XLINK = "xmlns:xlink";
40
	public static final String XMLNS_XLINK_VALUE = "http://www.w3.org/1999/xlink";
41
	public static final String XMLNS_VALUE = "http://www.opengis.net/context"; // "http://www.opengeospatial.net/context"
42
	public static final String XMLNS_XSI = "xmlns:xsi"; 
43
	public static final String XMLNS_XSI_VALUE = "http://www.w3.org/2001/XMLSchema-instance";
44
	public static final String XSI_SCHEMA_LOCATION = "xsi:schemaLocation";
45
	public static final String XSI_SCHEMA_LOCATION_VALUE = "http://www.opengeospatial.net/context context.xsd";
46
	public static final String GENERAL = "General";
47
	public static final String WIDTH = "width";
48
	public static final String HEIGHT = "height";
49
	public static final String WINDOW = "Window";
50
	public static final String SRS = "SRS";
51
	public static final String X_MIN = "minx";
52
	public static final String Y_MIN = "miny";
53
	public static final String X_MAX = "maxx";
54
	public static final String Y_MAX = "maxy";
55
	public static final String BOUNDING_BOX = "BoundingBox";
56
	public static final String TITLE = "Title";
57
	public static final String LAYER_LIST = "LayerList";
58
	public static final String LAYER = "Layer";
59
	public static final String QUERYABLE = "queryable";
60
	public static final String HIDDEN = "hidden";
61
	public static final String SERVICE = "service";
62
	public static final String WMS = "WMS";
63
	public static final String SERVER_TITLE = "title";
64
	public static final String SERVER = "Server";
65
	public static final String XLINK_TYPE = "xlink:type";
66
	public static final String XLINK_HREF = "xlink:href";
67
	public static final String ONLINE_RESOURCE = "OnlineResource";
68
	public static final String NAME = "Name";
69
	public static final String ABSTRACT = "Abstract";
70
	public static final String FORMAT_LIST = "FormatList";
71
	public static final String CURRENT = "current";
72
	public static final String FORMAT = "Format";
73
	public static final String STYLE_LIST = "StyleList";
74
	public static final String STYLE = "Style";
75
	public static final String KEYWORD_LIST = "KeywordList";
76
	public static final String KEYWORD = "Keyword";
77
	public static final String LOGO_URL = "LogoURL";
78
	public static final String DESCRIPTION_URL = "DescriptionURL";
79
	public static final String CONTACT_INFORMATION = "ContactInformation";
80
	public static final String CONTACT_PERSON_PRIMARY = "ContactPersonPrimary";
81
	public static final String CONTACT_PERSON = "ContactPerson";
82
	public static final String CONTACT_ORGANIZATION = "ContactOrganization";
83
	public static final String CONTACT_POSITION = "ContactPosition";
84
	public static final String CONTACT_ADDRESS = "ContactAddress";
85
	public static final String ADDRESS_TYPE = "AddressType";
86
	public static final String ADDRESS = "Address";
87
	public static final String CITY = "City";
88
	public static final String STATE_OR_PROVINCE = "StateOrProvince";
89
	public static final String POSTCODE = "PostCode";
90
	public static final String COUNTRY = "Country";
91
	public static final String CONTACT_VOICE_TELEPHONE = "ContactVoiceTelephone";
92
	public static final String CONTACT_FACSIMILE_TELEPHONE = "ContactFacsimileTelephone";
93
	public static final String CONTACT_ELECTRONIC_MAIL_ADDRESS = "ContactElectronicMailAddress";
94
	public static final String DIMENSION_LIST = "DimensionList";
95
	public static final String LEGEND_URL = "LegendURL";
96
	
97
}
0 98

  
org.gvsig.raster.wms/tags/org.gvsig.raster.wms-2.2.122/org.gvsig.raster.wms.app.wmsclient/src/main/java/org/gvsig/raster/wms/app/wmsclient/wmc/WebMapContext.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
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., 51 Franklin Street, Fifth Floor, Boston,
19
* MA  02110-1301, USA.
20
*
21
*/
22

  
23
package org.gvsig.raster.wms.app.wmsclient.wmc;
24

  
25
import java.awt.Dimension;
26
import java.awt.geom.Rectangle2D;
27
import java.io.BufferedReader;
28
import java.io.File;
29
import java.io.FileInputStream;
30
import java.io.FileNotFoundException;
31
import java.io.FileReader;
32
import java.io.IOException;
33
import java.net.URI;
34
import java.net.URISyntaxException;
35
import java.util.ArrayList;
36
import java.util.Arrays;
37
import java.util.HashMap;
38
import java.util.HashSet;
39
import java.util.Hashtable;
40
import java.util.List;
41
import java.util.Vector;
42

  
43
import org.cresques.cts.ICoordTrans;
44
import org.cresques.cts.IProjection;
45

  
46
import org.gvsig.app.ApplicationLocator;
47
import org.gvsig.app.project.documents.view.DefaultViewDocument;
48
import org.gvsig.fmap.crs.CRSFactory;
49
import org.gvsig.fmap.dal.coverage.exception.ImportMapContextException;
50
import org.gvsig.fmap.mapcontext.exceptions.UnsupportedVersionLayerException;
51
import org.gvsig.fmap.mapcontext.layers.FLayer;
52
import org.gvsig.fmap.mapcontext.layers.FLayers;
53
import org.gvsig.i18n.Messages;
54
import org.gvsig.raster.wms.app.wmsclient.layer.FLyrWMS;
55
import org.gvsig.raster.wms.io.RemoteWMSStyle;
56
import org.gvsig.raster.wms.io.WMSDataParameters;
57
import org.gvsig.raster.wms.io.WMSDataParametersImpl;
58

  
59
import org.kxml2.io.KXmlParser;
60
import org.slf4j.Logger;
61
import org.slf4j.LoggerFactory;
62
import org.xmlpull.v1.XmlPullParserException;
63

  
64

  
65
/**
66
 * Class that loads and produces WebMapContext files and holds its attributes.
67
 *
68
 * You can create a blank WebMapContext instance using the default constructor
69
 * or an already initialized instance by specifying a source file. In the last
70
 * case the file will be readed and the values loaded an holded by the instance.
71
 *
72
 * You can get the equivalent WebMapContext XML document by calling the method
73
 * getXML() supplying the ProjectView that you want to export and depending on
74
 * the value of the fileVersion field (currently you can use "1.1.0" (default),
75
 * "1.0.0" or "0.4.1" to specify the destination document version.
76
 *
77
 * @author jaume dominguez faus - jaume.dominguez@iver.es
78
 */
79
public class WebMapContext {
80
	public final static String FILE_EXTENSION = ".cml";
81
	private Logger  log = LoggerFactory.getLogger(WebMapContext.class);
82
	static final ArrayList<String> supportedVersions = new ArrayList<String>();
83
	static public final ArrayList<String> exportVersions    = new ArrayList<String>();
84
	static private HashSet supportedLayers = new HashSet();
85
	private File mapContextFile;
86
	private String encoding = "UTF-8";
87
	private String WMC_START_TAG;
88

  
89
	// MapContext stuff
90
	public String fileVersion = null;
91
	public Dimension windowSize = null;
92
	public String srs = null;
93
	public Rectangle2D bBox = null;
94
	public String title = null;
95
	public String id = null;
96
	public String xmlns = null;
97
	public String xmlns_xlink = null;
98
	public String xmlns_xsi = null;;
99
	public String xsi_schemaLocation = null;
100
	public String _abstract = null;
101
	public List<String> keywordList = null;
102
	public Dimension logoURLSize = null;
103
	public String logoURLFormat = null;
104
	public String logoURL = null;
105
	public String descriptionURLFormat = null;
106
	public String descriptionURL = null;
107
	public boolean contactInfo = false;
108
	public String contactPerson = null;
109
	public String contactOrganization = null;
110
	public String contactPosition = null;
111
	public String address = null;
112
	public String city = null;
113
	public String stateOrProvince = null;
114
	public String postCode = null;
115
	public String country = null;
116
	public String telephone = null;
117
	public String fax = null;
118
	public String email = null;
119

  
120
	private StringBuffer errorMessages;
121

  
122
	List<FLyrWMS>            layerList  = null;
123
	List<WMSDataParameters>  paramsList = null;
124

  
125
	Hashtable<Object, String[]>  srsList = null;
126

  
127
	/**
128
	 * key: server URL (URL)
129
	 * value: server title (String)
130
	 */
131
	Hashtable<String, String> serverTitles = null;
132

  
133
	/**
134
	 * key: layer FLyrWMS
135
	 * value: layer abstract (String)
136
	 */
137
	Hashtable layerAbstracts = null;
138

  
139
	/**
140
	 * key: layer FLyrWMS
141
	 * value: layer formats (String[])
142
	 */
143
	Hashtable layerFormats = null;
144

  
145
	/**
146
	 * key: layer FLyrWMS
147
	 * value: styles (FMapWMSStyle[])
148
	 */
149
	Hashtable layerStyles = null;
150

  
151

  
152
	static {
153
		supportedVersions.add("1.1.0");
154
		supportedVersions.add("1.0.0");
155
		supportedVersions.add("0.1.4");
156
	}
157

  
158
	static {
159
		exportVersions.add("1.1.0");
160
		exportVersions.add("1.0.0");
161
		exportVersions.add("0.1.4");
162
	}
163

  
164
	static {
165
		supportedLayers.add(FLyrWMS.class);
166
	}
167

  
168

  
169
	/**
170
	 * Initializes the WebMapContext properties from the values in the WebMapContext (.cml)
171
	 * file passed in the argument.
172
	 * @param file
173
	 * @throws UnsupportedVersionLayerException
174
	 * @throws ImportMapContextException
175
	 */
176
	public void readFile(File file) throws UnsupportedVersionLayerException, ImportMapContextException {
177
		this.mapContextFile = file;
178
		errorMessages = new StringBuffer();
179
		if (getVersion() != null) {
180
			if (supportedVersions.contains(getVersion())) {
181
				WMC_START_TAG = WebMapContextTags.VIEW_CONTEXT;
182
				if (getVersion().equals("0.1.4")) {
183
					WMC_START_TAG = WebMapContextTags.VIEW_CONTEXT_0_1_4;
184
					parse1_1_0(file);
185
				} else if (getVersion().equals("1.1.0")) {
186
					parse1_1_0(file);
187
				} else if (getVersion().equals("1.0.0")) {
188
					parse1_1_0(file);
189
				} else {
190
					parseDefaultVersion(file);
191
				}
192

  
193
				// Once parsed, check errors
194
				if (errorMessages.length() > 0) {
195
					throw new ImportMapContextException(errorMessages.toString(), false);
196
				}
197
			} else {
198
				throw new UnsupportedVersionLayerException(file.getName(), null);
199
			}
200
		}
201
	}
202

  
203

  
204
	/**
205
	 * If no version was recognized then will parse the default one which is supposed
206
	 * to be the best available.
207
	 * @param file
208
	 * @throws ImportMapContextException
209
	 */
210
	private void parseDefaultVersion(File file) throws ImportMapContextException {
211
		parse1_1_0(file);
212
	}
213

  
214
	/**
215
	 * Reads the header of the Weg Map Context file and determines which version
216
	 * it belongs to.
217
	 * @return String.
218
	 */
219
	private String getVersion() {
220
		if (fileVersion == null) {
221
			String v = null;
222
			try {
223
				FileReader fr = new FileReader(mapContextFile);
224
				KXmlParser parser = new KXmlParser();
225
				parser.setInput(fr);
226
				parser.nextTag();
227
	    		if ( parser.getEventType() != KXmlParser.END_DOCUMENT )	{
228
	    			if ((parser.getName().compareTo(WebMapContextTags.VIEW_CONTEXT) == 0) ||
229
	    				 parser.getName().compareTo(WebMapContextTags.VIEW_CONTEXT_0_1_4) == 0) {
230
	    				v = parser.getAttributeValue("", WebMapContextTags.VERSION);
231
	    			}
232
	    		}
233
			} catch (FileNotFoundException fnfEx) {
234
			} catch (XmlPullParserException xmlEx) {
235
				xmlEx.printStackTrace();
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff