Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extPublish / src / org / gvsig / remoteservices / conf / mapserver / MapServerConfiguration.java @ 8682

History | View | Annotate | Download (27.5 KB)

1
package org.gvsig.remoteservices.conf.mapserver;
2

    
3
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
4
 *
5
 * Copyright (C) 2004-2006 IVER T.I. and Generalitat Valenciana.
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
20
 *
21
 * For more information, contact:
22
 *
23
 *   Generalitat Valenciana
24
 *   Conselleria d'Infraestructures i Transport
25
 *   Av. Blasco Ib??ez, 50
26
 *   46010 VALENCIA
27
 *   SPAIN
28
 *
29
 *   +34 963862235
30
 *   gvsig@gva.es
31
 *   www.gvsig.gva.es
32
 *
33
 *    or
34
 *
35
 *   IVER T.I. S.A
36
 *   Salamanca 50
37
 *   46005 Valencia
38
 *   Spain
39
 *
40
 *   +34 963163400
41
 *   dac@iver.es
42
 */
43
/* CVS MESSAGES:
44
 *
45
 * $Id$
46
 * $Log$
47
 * Revision 1.5  2006-11-13 08:25:04  dagilgon
48
 * a?adidas "etiquetas" CLASS (completada) y JOIN
49
 *
50
 * Revision 1.4  2006/10/18 07:56:56  dagilgon
51
 * a?adidos los outputformats
52
 *
53
 * Revision 1.3  2006/10/17 11:51:09  dagilgon
54
 * outputformats
55
 *
56
 * Revision 1.2  2006/10/16 11:40:36  dagilgon
57
 * arreglado path de mapserver
58
 *
59
 * Revision 1.1  2006/10/05 13:22:23  jvhigon
60
 * Debido al refactor del nobre en la libreria de maapserver y geoserver. Mapserver --> MapserverConfig
61
 *
62
 * Revision 1.25  2006/09/19 07:34:00  dagilgon
63
 * Corregida salida duplicada del campo crs en matadataweb
64
 *
65
 * Revision 1.24  2006/09/19 00:30:31  luisw2
66
 * Soporte para WCS en mapserver. Pendiente de verificar que va
67
 *
68
 * Revision 1.23  2006/09/18 08:41:22  dagilgon
69
 * A?adida clase leyend y label
70
 *
71
 * Revision 1.22  2006/09/14 12:06:16  jorpiell
72
 * A?adido el constructor con dos colores para el stylemap
73
 *
74
 * Revision 1.21  2006/09/13 12:08:31  luisw2
75
 * Adding WCS to mapserver ...
76
 *
77
 * Revision 1.19  2006/09/08 18:03:18  jorpiell
78
 * El EPSG se escribe en min?sculas y los times se escriben en orden
79
 *
80
 * Revision 1.18  2006/09/08 17:58:01  jorpiell
81
 * El EPSG se escribe en min?sculas y los times se escriben en orden
82
 *
83
 * Revision 1.17  2006/09/08 12:50:20  jorpiell
84
 * Se tiene en cuanta el par?metro TIME
85
 *
86
 * Revision 1.16  2006/09/08 10:50:05  jorpiell
87
 * A?adida la opci?n de generar una capa POSTGIS
88
 *
89
 * Revision 1.15  2006/09/08 10:14:04  luisw2
90
 * IRSLayer Added
91
 *
92
 * Revision 1.14  2006/09/08 07:12:03  luisw2
93
 * Minor corrections for raster; abstract added
94
 *
95
 * Revision 1.13  2006/09/07 19:25:01  luisw2
96
 * Correcciones en metadata
97
 *
98
 * Revision 1.12  2006/09/07 19:20:51  jorpiell
99
 * Classpath modificado
100
 *
101
 * Revision 1.11  2006/09/07 19:16:30  jorpiell
102
 * *** empty log message ***
103
 *
104
 * Revision 1.10  2006/09/07 18:11:06  luisw2
105
 * Adding Time to mapserver ...
106
 *
107
 * Revision 1.9  2006/09/07 16:34:28  luisw2
108
 * A?adido size
109
 *
110
 * Revision 1.8  2006/09/07 16:10:45  luisw2
111
 * a?adido flush() en el close;
112
 *
113
 * Revision 1.7  2006/09/07 12:59:44  jorpiell
114
 * Enganchada la interfaz gr?fica con el generador de ficheros
115
 *
116
 * Revision 1.6  2006/09/07 12:51:54  jorpiell
117
 * Enganchada la interfaz gr?fica con el generador de ficheros
118
 *
119
 * Revision 1.5  2006/09/07 12:47:39  jorpiell
120
 * A?adida la expression en el classMap
121
 *
122
 * Revision 1.4  2006/09/07 11:19:40  jvhigon
123
 * A?adido soporte para multiples class en una layer, y para layer sdentro de layer
124
 *
125
 * Revision 1.3  2006/09/01 06:59:00  luisw2
126
 * Headers mofification
127
 *
128
 */
129
import java.awt.Color;
130
import java.awt.Dimension;
131
import java.awt.geom.Rectangle2D;
132
import java.io.File;
133
import java.io.FileNotFoundException;
134
import java.io.FileOutputStream;
135
import java.io.PrintStream;
136
import java.util.ArrayList;
137
import java.util.Iterator;
138
import java.awt.Point;
139

    
140
import org.gvsig.remoteservices.conf.IRSLayer;
141

    
142
/**
143
 * Allows to write a .map Mapserver configuration file.
144
 *
145
 * @author David Gilsanz
146
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
147
 */
148

    
149
/* MAP
150
        NAME test_postgis
151
        STATUS ON
152
        SIZE 400 300
153
        #SYMBOLSET ../etc/symbols.sym
154
        EXTENT 638610.4375 4222780 789330 4484662.5
155
        UNITS METERS
156
        SHAPEPATH "/home/shapes/"
157
        IMAGECOLOR 255 255 255
158
        #FONTSET ../etc/fonts.txt
159

160
        WEB
161
                #  IMAGEPATH "/ms4w/tmp/ms_tmp/"
162
                #  IMAGEURL "/ms_tmp/"
163
                 METADATA
164
                            "wms_title"     "test postgis"  ##required
165
                            "wms_onlineresource" "http://localhost/mapserver/mapserv"   ##required
166
                            "wms_srs"       "EPSG:42304 EPSG:42101 EPSG:4269 EPSG:4326 EPSG:23030"  ##recommended
167
                  END
168
        END
169

170
        PROJECTION
171
                "init=epsg:23030"   ##required
172
        END
173

174
        #
175
        # Start of layer definitions
176
        #
177

178
        LAYER
179
                  NAME "autopistas"
180
                  DATA "the_geom from autopistas"
181
                CONNECTIONTYPE POSTGIS
182
                CONNECTION "user=david password=pwd dbname=betel host=localhost port=5434"
183
                STATUS ON
184
                TYPE LINE
185
                METADATA
186
                            "wms_title"  "Autopistas GV"   ##required
187
                            "wms_extent" "638610.4375 4222780 789330 4484662.5"
188
                  END
189
                  PROJECTION
190
                            "init=epsg:23030"   ##recommended
191
                  END
192
                  CLASS
193
                    NAME "Autopistas"
194
                    STYLE
195
                            COLOR 200 255 0
196
                            OUTLINECOLOR 120 120 120
197
                    END    
198
              END
199
    END 
200

201
END # Map File    
202
*/
203
public abstract class MapServerConfiguration {
204
        public static final String SHP_TYPE_LINE = "LINE";
205
        public static final String SHP_TYPE_POLYLINE = "POLYLINE";
206
        public static final String SHP_TYPE_POINT = "POINT";
207
        public static final String SHP_TYPE_POLYGON = "POLYGON"; 
208
        
209
        public static class RGB {
210
                int r,g,b;
211
                public RGB(int red,int green,int blue){
212
                        r=red;
213
                        g=green;
214
                        b=blue;                        
215
                }
216
                public String toString(){
217
                        return ""+r+" "+g+" "+b;
218
                }
219
        }
220
        
221
        public static class CRS extends MapServerConfiguration {
222
                boolean init = false;
223
                String crs = "";
224
                public CRS(String crs, boolean init) {
225
                        this.crs = crs;
226
                        this.init =init;
227
                }
228
                
229
                public String toString() {
230
                        String str = "";
231
                        if (init){
232
                                str += "init=";
233
                                return str+crs.toLowerCase();
234
                        }
235
                        return crs; //LWS .toLowerCase();
236
                }
237
                
238
                public void toMap() {
239
                        toMapln("PROJECTION");
240
                        tabIn();
241
                        toMapln("\""+this+"\"");
242
                        tabOut();
243
                        toMapln("END");
244
                }
245
                
246
                /**
247
                 * @return Returns the crs.
248
                 */
249
                public String getCrs() {
250
                        return crs;
251
                }
252
        }
253
        
254
        public static class OutputFormat extends MapServerConfiguration {
255
                /*
256
                OUTPUTFORMAT
257
                        NAME GEOTIFF_INT16
258
                        DRIVER "GDAL/GTiff"
259
                        IMAGEMODE INT16
260
                        EXTENSION "tif"
261
                END        
262
                 */
263
                public String name = null;
264
                public String driver = null;
265
                public String imageMode = null;
266
                public String extension = null;
267
                
268
                /**
269
                 * Creates a new OutputFormat.
270
                 * @param name
271
                 * @param driver
272
                 * @param imageMode
273
                 * @param extension
274
                 */
275
                public OutputFormat(String name, String driver, String imageMode, String extension) {
276
                        this.name = name;
277
                        this.driver = driver;
278
                        this.imageMode = imageMode;
279
                        this.extension = extension;
280
                }
281
                
282
                public void toMap() {
283
                        toMapln("OUTPUTFORMAT");
284
                        tabIn();
285
                        toMapln("NAME "+name+"");
286
                        toMapln("DRIVER \""+driver+"\"");
287
                        toMapln("IMAGEMODE "+imageMode+"");
288
                        toMapln("EXTENSION \""+extension+"\"");
289
                        tabOut();
290
                        toMapln("END");
291
                }
292
        }
293
        public static class Label extends MapServerConfiguration{
294
                
295
                public String angle = null;
296
                public String antialias = null;
297
                public RGB backgroundcolor = null;
298
                public RGB backgroundshadowcolor = null;
299
                public Point backgroundshadowsize = null;
300
                public String buffer = null;
301
                public RGB color = null;
302
                public String encoding = null;
303
                public String force = null;
304
                public String maxsize = null;
305
                public String mindistance = null;
306
                public String minfeaturesize = null;
307
                public String minsize = null;
308
                public Point offset = null;
309
                public RGB outlinecolor = null;
310
                public String partials = null;
311
                public String position = null;
312
                public RGB shadowcolor = null;
313
                public Point shadowsize = null;
314
                public String size = null;
315
                public String type = null;
316
                public String wrap = null;
317
                
318
                public void tomap(){
319
                        toMapln("LABEL");
320
                        tabIn();
321
                        if(angle != null)
322
                                toMapln("ANGLE "+angle.toUpperCase()+"");
323
                        if(antialias != null)
324
                                toMapln("ANTIALIAS \""+antialias+"\"");
325
                        if(backgroundcolor != null)
326
                                toMapln("BACKGROUNDCOLOR "+backgroundcolor.toString()+"");
327
                        if(backgroundshadowcolor != null)
328
                                toMapln("BACKGROUNDSHADOWCOLOR "+backgroundshadowcolor.toString()+"");
329
                        if(backgroundshadowsize != null)
330
                                toMapln("BACKGROUNDSHADOWSIZE "+backgroundshadowsize.toString()+"");
331
                        if(buffer != null)
332
                                toMapln("BUFFER \""+buffer+"\"");
333
                        if(color != null)
334
                                toMapln("COLOR "+color.toString()+"");
335
                        if(encoding != null)
336
                                toMapln("ENCODING \""+encoding+"\"");
337
                        if(force != null)
338
                                toMapln("FORCE \""+force+"\"");
339
                        if(maxsize != null)
340
                                toMapln("MAXSIZE "+maxsize+"");
341
                        if(mindistance != null)
342
                                toMapln("MINDISTANCE "+mindistance+"");
343
                        if(minfeaturesize != null)
344
                                toMapln("MINFEATURESIZE "+minfeaturesize+"" +"");
345
                        if(minsize != null)
346
                                toMapln("MINSIZE "+minsize+"");
347
                        if(offset != null)
348
                                toMapln("OFFSET "+offset.toString()+"");
349
                        if(outlinecolor != null)
350
                                toMapln("OUTLINECOLOR "+outlinecolor.toString()+"");
351
                        if(partials != null)
352
                                toMapln("PARTIALS \""+partials+"\"");
353
                        if(position != null)
354
                                toMapln("POSITION \""+position+"\"");
355
                        if(shadowcolor!= null)
356
                                toMapln("SHADOWCOLOR "+shadowcolor.toString()+"");
357
                        if(shadowsize != null)
358
                                toMapln("SHADOWSIZE "+shadowsize.toString()+"");
359
                        if(size != null)
360
                                toMapln("SIZE \""+size.toUpperCase()+"\"");
361
                        if(type != null)
362
                                toMapln("TYPE \""+type+"\"");
363
                        if(wrap != null)
364
                                toMapln("WRAP \""+wrap+"\"");
365
                        tabOut();
366
                        toMapln("END");
367
                }
368
        }
369
        
370
        public static class Legend extends MapServerConfiguration{
371
                public RGB imagecolor = null;
372
                public RGB outlinecolor = null;
373
                public String interlace = null;
374
                public Label legendlabel = null;
375
                public String position = null;
376
                public Point keysize = null;
377
                public Point keyspacing = null;
378
                public String postlabelcache = null;
379
                public String status = null;
380
                public String template = null;
381
                public String transparent = null;
382
                
383
                public void toMap(){
384
                        toMapln("LEGEND");
385
                        tabIn();
386
                        if(imagecolor != null)
387
                                toMapln("IMAGECOLOR "+imagecolor.toString());
388
                        if(outlinecolor != null)
389
                                toMapln("OUTLINECOLOR "+outlinecolor.toString());
390
                        if(interlace != null){
391
                                toMapln("INTERLACE \""+interlace.toUpperCase()+"\"");
392
                        }
393
                        if(legendlabel != null){
394
                                legendlabel.tomap();
395
                        }
396
                        if(position != null)
397
                                toMapln("POSITION \""+position+"\"");
398
                        if(keysize != null)
399
                                toMapln("KEYSIZE "+keysize.toString());
400
                        if(keyspacing != null)
401
                                toMapln("KEYSPACING "+keyspacing.toString());
402
                        if(postlabelcache != null)
403
                                toMapln("POSTLABELCACHE \""+postlabelcache+"\"");
404
                        if(status != null)
405
                                toMapln("STATUS \""+status.toUpperCase()+"\"");
406
                        if(template!=null){
407
                                toMapln("TEMPLATE \""+template+"\"");
408
                        }
409
                        if(transparent != null){
410
                                toMapln("TRANSPARENT \""+transparent.toUpperCase()+"\"");
411
                        }
412
                        tabOut();
413
                        toMapln("END");
414
                }
415
        }
416
        
417
        public static class Metadata extends MapServerConfiguration {
418
                public String prefix = "wms";
419
                public String title = null;
420
                public String abstrac = null;
421
                public String label = null;
422
                public String name = null;
423
                
424
                public void setServiceAsWFS() {
425
                        prefix = "wfs";
426
                }
427
                
428
                public void setServiceAsWMS() {
429
                        prefix = "wms";
430
                }
431
                public void setServiceAsWCS() {
432
                        prefix = "wcs";
433
                }
434
//                
435
                void startMetadataToMap(){
436
                        toMapln("METADATA");
437
                        tabIn();
438
                        if (name != null)
439
                                toMapln("\""+prefix+"_name\" \""+name+"\"");
440
                        if (label != null)
441
                                toMapln("\""+prefix+"_label\" \""+label+"\"");
442
                        if (title != null)
443
                                toMapln("\""+prefix+"_title\" " +"\""+title+"\"");
444
                        if (abstrac != null)
445
                                toMapln("\""+prefix+"_astract\" " +"\""+abstrac+"\"");
446
                        if (crs != null)
447
                                toMapln("\""+prefix+"_srs\" \""+crs+"\"");
448
                        if (extent != null)
449
                                toMapln("\""+prefix+"_extent\" \""+extentToMapString()+"\"");
450
                }
451
                
452
                void endMetadataToMap() {
453
                        tabOut();
454
                        toMapln("END");
455
                }
456
        }
457
        
458
        public static class MetadataWeb extends Metadata {
459
                //Atributos wms_xxxx WEB
460
                public String onlineresource = null;
461
                public String ows_schemas_location = null;
462
                public String timeFormat = null;
463
                public String keywordlist = null;
464
                
465
                void metadataToMap(){
466
                        startMetadataToMap();                
467
                        if (keywordlist != null)
468
                                toMapln("\""+prefix+"_keywordlist\" \""+keywordlist+"\"");
469
                        toMapln("\""+prefix+"_onlineresource\" \""+onlineresource+"\"");
470
                        //if (crs != null)
471
                        //        toMapln("\""+prefix+"_srs\" \""+crs+"\"");
472
                        if (ows_schemas_location != null)
473
                                toMapln("\"ows_schemas_location\" \""+ows_schemas_location+"\"");
474
                        if (timeFormat != null)
475
                                toMapln("\""+prefix+"_timeformat\" \""+timeFormat+"\"");
476
                        endMetadataToMap();
477
                }
478
        }
479
        
480
        public static class MetadataLayer extends Metadata {
481
                //Atributos wms_xxxx LAYER        
482
                public String gml_include_items = null;
483
                public String timeExtent = null;
484
                public String timeDefault = null;
485
                public String timeItem = null;
486
                // WCS
487
                public String description = null;
488
                public String resolution = null;
489
                public String formats = null;
490
                public String bandCount = null;
491
                public String nativeFormat = null;
492
                public String rangesetAxes = null;
493
                public String rangesetLabels = null;
494
                public String rangesetName = null;
495
                
496
                public void setRangeset(String str) {
497
                        rangesetAxes = rangesetLabels = rangesetName = str;
498
                }
499
                
500
                void metadataToMap(){
501
                        startMetadataToMap();
502
                        if (gml_include_items != null)
503
                                toMapln("\"gml_include_items\" \""+gml_include_items+"\"");
504
                        // WMS with TIME
505
                        if (timeExtent != null)
506
                                toMapln("\""+prefix+"_timeextent\" \""+timeExtent+"\"");
507
                        if (timeDefault != null)
508
                                toMapln("\""+prefix+"_timedefault\" \""+timeDefault+"\"");
509
                        if (timeItem != null)
510
                                toMapln("\""+prefix+"_timeitem\" \""+timeItem+"\"");
511
                        // WCS
512
                        if (description != null)
513
                                toMapln("\""+prefix+"_description\" \""+description+"\"");
514
                        if (resolution != null)
515
                                toMapln("\""+prefix+"_resolution\" \""+resolution+"\"");
516
                        if (formats != null)
517
                                toMapln("\""+prefix+"_formats\" \""+formats+"\"");
518
                        if (bandCount != null)
519
                                toMapln("\""+prefix+"_bandcount\" \""+bandCount+"\"");
520
                        if (nativeFormat != null)
521
                                toMapln("\""+prefix+"_nativeformat\" \""+nativeFormat+"\"");
522
                        if (rangesetAxes != null)
523
                                toMapln("\""+prefix+"_rangeset_axes\" \""+rangesetAxes+"\"");
524
                        if (rangesetLabels != null)
525
                                toMapln("\""+prefix+"_rangeset_labels\" \""+rangesetLabels+"\"");
526
                        if (rangesetName != null)
527
                                toMapln("\""+prefix+"_rangeset_name\" \""+rangesetName+"\"");
528
                        
529
                        endMetadataToMap();
530
                }
531
        }
532
        
533
        public static class StyleMap extends MapServerConfiguration {
534
                public RGB styleColor = null;
535
                public RGB styleColorOutline = null;
536
                public int size = -1;
537
                public StyleMap(RGB line, RGB fill) {
538
                        styleColor = fill;
539
                        styleColorOutline = line;
540
                }
541
                public StyleMap(Color color, Color outLineColor) {
542
                        RGB rgbStyleColor = null;
543
                        RGB rgbStyleColorOutline = null;
544
                        try{
545
                                rgbStyleColor = (new RGB(color.getRed(),
546
                                                color.getGreen(),
547
                                                color.getBlue()));
548
                        }catch(NullPointerException e){
549
                                //Line color is empty
550
                        }
551
                        try{
552
                                rgbStyleColorOutline = (new RGB(outLineColor.getRed(),
553
                                                outLineColor.getGreen(),
554
                                                outLineColor.getBlue()));
555
                        }catch(NullPointerException e){
556
                                //Fill color is empty
557
                        }
558
                        styleColor = rgbStyleColor;
559
                        styleColorOutline = rgbStyleColorOutline;
560
                }                
561
                void styleToMap(){
562
                        toMapln("STYLE ");
563
                        tabIn();
564
                        if (styleColor != null){
565
                                toMapln("COLOR "+styleColor);
566
                        }
567
                        if (styleColorOutline != null){
568
                                toMapln("OUTLINECOLOR "+styleColorOutline);
569
                        }
570
                        if (size > -1)
571
                                toMapln("SIZE "+size);
572
                        tabOut();
573
                        toMapln("END");
574
                }
575
        }
576
        
577
        public static class WebMap extends MapServerConfiguration{
578
                public MetadataWeb metadata = null;
579
                public String imagepath = null;
580
                public String imageurl = null;
581
                public String log = null;
582
                
583
                void webToMap(){
584
                        toMapln("WEB");
585
                        tabIn();
586
                        if (log != null)
587
                                toMapln("LOG \""+log+"\"");
588
                        toMapln("IMAGEPATH \""+imagepath+"\"");
589
                        toMapln("IMAGEURL \""+imageurl+"\"");
590
                        metadata.metadataToMap();
591
                        tabOut();
592
                        toMapln("END");
593
                }
594
        }
595
        public static class JoinMap extends MapServerConfiguration{
596
                
597
                public String connection=null;
598
                public String connectiontype=null;
599
                public String from=null;
600
                public String name=null;
601
                public String table=null;
602
                public String template=null;
603
                public String to=null;
604
                public String type=null;
605
                
606
                void tomap(){
607
                        toMapln("JOIN");
608
                        tabIn();
609
                        if (connection != null)
610
                                toMapln("CONNECTION \"" + connection+"\"");
611
                        if (connectiontype != null)
612
                                toMapln("CONNECTIONTYPE \"" + connectiontype+"\"");
613
                        if (from != null)
614
                                toMapln("FROM \"" + from+"\"");
615
                        if (name != null)
616
                                toMapln("NAME \"" + name+"\"");
617
                        if (table != null)
618
                                toMapln("TABLE \"" + table+"\"");
619
                        if (to != null)
620
                                toMapln("TO \"" + to+"\"");
621
                        if (type != null)
622
                                toMapln("TYPE \"" + type+"\"");
623
                        tabOut();                
624
                        toMapln("END");
625
                        
626
                }
627
        }
628
        
629
        public static class MapClass extends MapServerConfiguration {
630
                public RGB backgroundcolor=null;
631
                public RGB color=null;
632
                public String debug=null;
633
                public String expression=null;
634
                public JoinMap join=null;
635
                public String keyimage=null;
636
                public Label etiqueta = null;
637
                public String maxscale =null;
638
                public String maxsize=null;
639
                public String minscale=null;
640
                public String minsize=null;
641
                public String name;
642
                public RGB outlinecolor=null;
643
                public int size=-1;
644
                public StyleMap estilo = null;
645
                public String symbol=null;
646
                public String template = null;
647
                public String text=null;
648
                public MapClass(String n) {
649
                        name = n;
650
                }
651
                public void classToMap(){
652
                        toMapln("CLASS");
653
                        tabIn();
654
                        if (backgroundcolor != null)
655
                                toMapln("BACKGROUND \"" + backgroundcolor.toString()+"\"");
656
                        if (color != null)
657
                                toMapln("COLOR \"" + color.toString()+"\"");
658
                        if (debug != null)
659
                                toMapln("DEBUG \"" + debug+"\"");
660
                        if (expression != null)
661
                                toMapln("EXPRESSION \"" + expression+"\"");
662
                        if (join != null)
663
                                join.tomap();
664
                        if (keyimage != null)
665
                                toMapln("KEYIMAGE \"" + keyimage+"\"");
666
                        if (maxscale != null)
667
                                toMapln("MAXSCALE \"" + maxscale+"\"");
668
                        if (maxsize != null)
669
                                toMapln("MAXSIZE \"" + maxsize+"\"");
670
                        if (minscale != null)
671
                                toMapln("MINSCALE \"" + minscale+"\"");
672
                        if (minsize != null)
673
                                toMapln("MINSIZE \"" + minsize+"\"");
674
                        if (outlinecolor != null)
675
                                toMapln("OUTLINECOLOR \"" + outlinecolor.toString()+"\"");
676
                        if (size > -1)
677
                                toMapln("SIZE \""+size+"\"");
678
                        if (estilo != null)
679
                                estilo.styleToMap();
680
                        if (symbol != null)
681
                                toMapln("SYMBOL \"" + symbol+"\"");        
682
                        if (template != null)
683
                                toMapln("TEMPLATE \"" + template+"\"");                        
684
                        if (text != null)
685
                                toMapln("TEXT \"" + text+"\"");                        
686
                        if (expression != null){
687
                                toMapln("EXPRESSION \"" + expression+"\"");
688
                        }
689
                        toMapln("NAME \""+name+"\"");
690
                        if (template != null)
691
                                toMapln("TEMPLATE \""+template+"\"");
692
                        if (etiqueta != null)
693
                                etiqueta.tomap();
694
                        tabOut();
695
                        toMapln("END");
696
                }
697
        }
698
        
699
        public abstract static class MapLayer extends MapServerConfiguration
700
                implements IRSLayer {
701
                public String name = null;
702
                public String title=null;
703
                public String status = "ON";
704
                public String type = null;
705
                public int transparency = -1;
706
                public ArrayList classList = null;
707
                public ArrayList layerList = null;
708
                public String data = null;
709
                public MetadataLayer metadata = null;
710
                public boolean dump = false;
711
                public CRS layercrs=null;
712
                public String tileIndex = null;
713
                public String tileItem = null;
714
                
715
                
716
                public MapLayer() {
717
                        super();
718
                        metadata=new MetadataLayer();
719
                }
720
                
721
                public void setDump(boolean d) {
722
                        dump = d;
723
                }
724
                
725
                void startToMap() {
726
                        toMapln("LAYER");
727
                        tabIn(); 
728
                        toMapln("NAME \""+name+"\"");
729
//                        if (title != null)
730
//                                toMapln("TITLE \""+title+"\"");
731
                        toMapln("STATUS "+status);
732
                        if (transparency > -1)
733
                                toMapln("TRANSPARENCY " + transparency);
734
                        if (tileIndex != null)
735
                                toMapln("TILEINDEX \""+tileIndex+"\"");
736
                        if (tileItem != null)
737
                                toMapln("TILEITEM \""+tileItem+"\"");
738
                        if (type != null)
739
                                toMapln("TYPE "+type);
740
                        if (dump)
741
                                toMapln("DUMP TRUE # required");
742
                        if (data != null)
743
                                toMapln("DATA \""+data+"\"");
744
                }
745
                
746
                void endToMap() {
747
                        tabOut();
748
                        toMapln("END # Layer");
749
                }
750
                
751
                public void addClass(MapClass c) {
752
                        if (classList == null)
753
                                classList = new ArrayList();
754
                        classList.add(c);
755
                }
756
                
757
                public void classListToMap() {
758
                        if (classList != null) {
759
                                Iterator iter = classList.iterator();
760
                                while (iter.hasNext()) {
761
                                        MapClass c = (MapClass) iter.next();
762
                                        c.classToMap();
763
                                }
764
                        }
765
                        
766
                }
767
                
768
                public void addLayer(MapLayer c) {
769
                        if (layerList == null)
770
                                layerList = new ArrayList();
771
                        layerList.add(c);
772
                }
773
                
774
                public void layerListToMap() {
775
                        if (layerList != null) {
776
                                Iterator iter = layerList.iterator();
777
                                tabIn(); 
778
                                while (iter.hasNext()) {
779
                                        MapLayer l = (MapLayer) iter.next();
780
                                        l.layerToMap();
781
                                }
782
                                tabOut();
783
                        }
784
                }
785
                
786
                public abstract void layerToMap();
787
                
788
                public String getName() {
789
                        return name;
790
                }
791
                
792
                public void setName(String name) {
793
                        this.name = name;
794
                        metadata.name = name;
795
                        setTitle(name);
796
                }
797
                
798
                public String getTitle() {
799
                        return title;
800
                }
801
                
802
                public void setTitle(String title) {
803
                        this.title = title;
804
                        metadata.title = title;
805
                }
806

    
807
                public void setExtent(double minx, double miny, double maxx, double maxy) {
808
                        super.setExtent(minx, miny, maxx, maxy);
809
                        metadata.setExtent(extent);
810
                }
811
                
812
                public void setExtent(Rectangle2D extent) {
813
                        super.setExtent(extent);
814
                        metadata.setExtent(extent);
815
                }
816

    
817
        }
818
        
819
        public static class ShpLayer extends MapLayer {                
820
                public void layerToMap() {
821
                        startToMap();
822
                        metadata.metadataToMap();
823
                        if (layercrs != null) layercrs.toMap();
824
                        classListToMap();
825
                        endToMap();
826
                }
827
        }
828
        
829
        public static class PostgisLayer extends MapLayer {
830
                public String user;
831
                public String pass;
832
                public String host;
833
                public String dbname;
834
                public String port;
835
                
836
                public String tabla;
837
                public String data;
838
                
839
                public void setConnParams(String user, String pass, String host,
840
                                String dbname, String port) {
841
                        this.user = user;
842
                        this.pass = pass;
843
                        this.host = host;
844
                        this.dbname = dbname;
845
                        this.port = port;
846
                }
847
                
848
                public void layerToMap() {
849
                        startToMap();
850
                        toMapln("DATA \""+data+"\"");
851
                        toMapln("CONNECTIONTYPE POSTGIS");
852
                        StringBuffer connection = new StringBuffer();
853
                        connection.append("CONNECTION \"user="+user);
854
                        if (pass != null){
855
                                connection.append(" password="+pass);
856
                        }
857
                        connection.append(" dbname="+dbname+" host="+host+" port="+port+"\"");
858
                        toMapln(connection.toString());
859
                        metadata.metadataToMap();
860
                        if (layercrs != null) layercrs.toMap();
861
                        classListToMap();
862
                        endToMap();
863
                }
864
        }
865
        
866
        public static class RasterLayer extends MapLayer {                
867
                public void layerToMap() {
868
                        startToMap();
869
                        metadata.metadataToMap();
870
                        if (layercrs != null) layercrs.toMap();
871
                        classListToMap();
872
                        endToMap();
873
                }
874
        }
875
        
876
        public static class ConfigFile extends MapServerConfiguration {
877
                /**
878
                 * Atributos wms_xxxx comunes a WEB y LAYER.
879
                 * @author david
880
                 */
881
                
882
                public String mapFileName = null;
883
                public String fName = null;
884
                public String mapName = null;
885
                public String mapStatus = null;
886
                public String mapUnits= null;
887
                public String mapShapePath; 
888
                public Dimension mapSize = null;
889
                public CRS mapcrs= null;
890
                public WebMap www = null;
891
                public String symbolset = null;
892
                public String fontset = null;
893
                public RGB imageColor = null;
894
                public Legend leyenda = null;
895
                
896
                private ArrayList outputFormats = new ArrayList();
897
                private ArrayList layers = new ArrayList(); 
898
                
899
                public ConfigFile() {
900
                        www = new MapServerConfiguration.WebMap();
901
                        www.metadata=new MapServerConfiguration.MetadataWeb();
902
                }
903
                
904
                public void generate() {
905
                        generate(null);
906
                }
907
                
908
                public void generate(String donde) {
909
                        openMapFile(donde);
910
                        toMapln("MAP");
911
                        tabIn();
912
                        toMapln("NAME "+mapName);
913
                        if (mapSize != null)
914
                                toMapln("SIZE "+mapSize.width+" "+mapSize.height);
915
                        if (extent != null)
916
                        toMapln("EXTENT "+extentToMapString());
917
                        toMapln("STATUS "+mapStatus);
918
                        toMapln("UNITS "+mapUnits);
919
                        // OUTPUTFORMATS
920
                        {
921
                                Iterator iter = outputFormats.iterator();
922
                                while(iter.hasNext()) {
923
                                        OutputFormat o = (OutputFormat) iter.next();
924
                                        o.toMap();
925
                                }
926
                        }
927
                        
928
                        toMapln("SHAPEPATH \""+mapShapePath+"\"");
929
                        /*
930
                        toMapln("OUTPUTFORMAT");
931
                        tabIn();
932
                        toMapln("NAME GEOTIFFINT16");
933
                        toMapln("DRIVER \"GDAL/GTiff\"");
934
                        toMapln("IMAGEMODE INT16");
935
                        toMapln("EXTENSION \"tif\"");
936
                        tabOut();
937
                        toMapln("END");
938
                        toMapln("OUTPUTFORMAT");
939
                        tabIn();
940
                        toMapln("NAME IMG");
941
                        toMapln("DRIVER \"GDAL/HFA\"");
942
                        toMapln("IMAGEMODE BYTE");
943
                        toMapln("EXTENSION \"img\"");
944
                        tabOut();
945
                        toMapln("END");
946
                        toMapln("OUTPUTFORMAT");
947
                        tabIn();
948
                        toMapln("NAME GEOTIFF");
949
                        toMapln("DRIVER \"GDAL/GTiff\"");
950
                        toMapln("IMAGEMODE BYTE");
951
                        toMapln("EXTENSION \"tif\"");
952
                        tabOut();
953
                        toMapln("END");
954
                        */
955
                        if (symbolset != null)
956
                                toMapln("SYMBOLSET "+symbolset);
957
                        if (symbolset != null)
958
                                toMapln("FONTSET "+symbolset);
959
                        if (imageColor != null)
960
                                toMapln("IMAGECOLOR \""+imageColor+"\"");
961
                        if(leyenda!=null){
962
                                leyenda.toMap();
963
                        }
964
                        www.webToMap();
965
                        if (mapcrs != null)
966
                                projectionToMap(mapcrs,true);
967
                        // LAYERS
968
                        {
969
                                Iterator iter = layers.iterator();
970
                                while(iter.hasNext()) {
971
                                        MapLayer l = (MapLayer) iter.next();
972
                                        l.layerToMap();
973
                                }
974
                        }
975
                        tabOut();
976
                        toMapln("END # Map File");
977
                        closeMapFile();
978
                }
979
                
980
                void openMapFile(String donde) {
981
                        setMapFileName(donde);
982
                        if (mapFileName == null)
983
                                return;
984
                        File wmsmap = new File( mapFileName );
985
                        if (wmsmap.exists());
986
                                wmsmap.delete();
987
                        try{
988
                                //salida = new PrintStream(new BufferedOutputStream(new FileOutputStream(wmsmap)));
989
                                salida = new PrintStream(new FileOutputStream(wmsmap));        
990
                        } catch(FileNotFoundException e){
991
                                System.out.println("Fichero no encontrado.");
992
                        }
993
                        System.out.println(mapFileName+" abierto.");            
994
                        
995
                }
996
                
997
                void closeMapFile() {
998
                        if (salida != null) {
999
                                salida.flush();
1000
                                salida.close();
1001
                        }
1002
                }
1003
                
1004
                public String getMapFileName() {
1005
                        return mapFileName;
1006
                }
1007
                
1008
                public void setMapFileName(String mapFileName) {
1009
                        this.mapFileName = mapFileName;
1010
                }
1011
                
1012
                public void add(MapLayer l) {
1013
                        layers.add(l);
1014
                }
1015
                public int layersCnt() {
1016
                        return layers.size();
1017
                }
1018
                public MapLayer getLayer(int i) {
1019
                        return (MapLayer) layers.get(i);
1020
                }
1021
                public void add(OutputFormat of) {
1022
                        outputFormats.add(of);
1023
                }
1024
        }
1025
        
1026
        static PrintStream salida = null;
1027
        static String tabstop = "";
1028
        public Rectangle2D extent = null;
1029
        public CRS crs = null;
1030
        
1031
        /**
1032
         * 
1033
         * @param minx
1034
         * @param miny
1035
         * @param maxx
1036
         * @param maxy
1037
         */
1038
        public void setExtent(double minx, double miny, double maxx, double maxy) {
1039
                extent = new Rectangle2D.Double();
1040
                extent.setFrameFromDiagonal(minx, miny, maxx, maxy);
1041
        }
1042
        
1043
        public void setExtent(Rectangle2D extent) {
1044
                this.extent = extent;
1045
        }
1046
        
1047
        
1048
        String extentToMapString(Rectangle2D ext) {
1049
                if (ext != null)
1050
                        return ext.getMinX()+" "+ext.getMinY()+" "+ext.getMaxX()+" "+ext.getMaxY();
1051
                return "";
1052
        }
1053
        String extentToMapString() {
1054
                if (extent != null)
1055
                        return extentToMapString(extent);
1056
                return "";
1057
        }
1058

    
1059
        void projectionToMap(CRS prj, boolean init) {
1060
                if (prj == null)
1061
                        return;
1062
                toMapln("PROJECTION");
1063
                if (init == true)
1064
                        prj.toString();
1065
                tabIn();
1066
                toMapln("\""+prj+"\"");
1067
                tabOut();
1068
                toMapln("END");
1069
        }
1070
        
1071
        public String replicate(String str, int n) {
1072
                int i;
1073
                String ret = "";
1074
                for(i=0;i<n;i++){
1075
                        ret += str;
1076
                }
1077
                return ret;
1078
        }
1079
        
1080
        public void tabIn() {
1081
                tabstop += "   ";
1082
        }
1083
        
1084
        public void tabOut() {
1085
                tabstop = tabstop.substring(0,tabstop.length()-3);
1086
        }
1087
        
1088
        void toMapln(String str){
1089
                if (salida == null)
1090
                        System.out.println(tabstop+str);
1091
                else
1092
                        salida.println(tabstop+str);        
1093
        }
1094
}