Statistics
| Revision:

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

History | View | Annotate | Download (27.6 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.6  2006-11-17 13:33:59  dagilgon
48
 * *** empty log message ***
49
 *
50
 * Revision 1.5  2006/11/13 08:25:04  dagilgon
51
 * a?adidas "etiquetas" CLASS (completada) y JOIN
52
 *
53
 * Revision 1.4  2006/10/18 07:56:56  dagilgon
54
 * a?adidos los outputformats
55
 *
56
 * Revision 1.3  2006/10/17 11:51:09  dagilgon
57
 * outputformats
58
 *
59
 * Revision 1.2  2006/10/16 11:40:36  dagilgon
60
 * arreglado path de mapserver
61
 *
62
 * Revision 1.1  2006/10/05 13:22:23  jvhigon
63
 * Debido al refactor del nobre en la libreria de maapserver y geoserver. Mapserver --> MapserverConfig
64
 *
65
 * Revision 1.25  2006/09/19 07:34:00  dagilgon
66
 * Corregida salida duplicada del campo crs en matadataweb
67
 *
68
 * Revision 1.24  2006/09/19 00:30:31  luisw2
69
 * Soporte para WCS en mapserver. Pendiente de verificar que va
70
 *
71
 * Revision 1.23  2006/09/18 08:41:22  dagilgon
72
 * A?adida clase leyend y label
73
 *
74
 * Revision 1.22  2006/09/14 12:06:16  jorpiell
75
 * A?adido el constructor con dos colores para el stylemap
76
 *
77
 * Revision 1.21  2006/09/13 12:08:31  luisw2
78
 * Adding WCS to mapserver ...
79
 *
80
 * Revision 1.19  2006/09/08 18:03:18  jorpiell
81
 * El EPSG se escribe en min?sculas y los times se escriben en orden
82
 *
83
 * Revision 1.18  2006/09/08 17:58:01  jorpiell
84
 * El EPSG se escribe en min?sculas y los times se escriben en orden
85
 *
86
 * Revision 1.17  2006/09/08 12:50:20  jorpiell
87
 * Se tiene en cuanta el par?metro TIME
88
 *
89
 * Revision 1.16  2006/09/08 10:50:05  jorpiell
90
 * A?adida la opci?n de generar una capa POSTGIS
91
 *
92
 * Revision 1.15  2006/09/08 10:14:04  luisw2
93
 * IRSLayer Added
94
 *
95
 * Revision 1.14  2006/09/08 07:12:03  luisw2
96
 * Minor corrections for raster; abstract added
97
 *
98
 * Revision 1.13  2006/09/07 19:25:01  luisw2
99
 * Correcciones en metadata
100
 *
101
 * Revision 1.12  2006/09/07 19:20:51  jorpiell
102
 * Classpath modificado
103
 *
104
 * Revision 1.11  2006/09/07 19:16:30  jorpiell
105
 * *** empty log message ***
106
 *
107
 * Revision 1.10  2006/09/07 18:11:06  luisw2
108
 * Adding Time to mapserver ...
109
 *
110
 * Revision 1.9  2006/09/07 16:34:28  luisw2
111
 * A?adido size
112
 *
113
 * Revision 1.8  2006/09/07 16:10:45  luisw2
114
 * a?adido flush() en el close;
115
 *
116
 * Revision 1.7  2006/09/07 12:59:44  jorpiell
117
 * Enganchada la interfaz gr?fica con el generador de ficheros
118
 *
119
 * Revision 1.6  2006/09/07 12:51:54  jorpiell
120
 * Enganchada la interfaz gr?fica con el generador de ficheros
121
 *
122
 * Revision 1.5  2006/09/07 12:47:39  jorpiell
123
 * A?adida la expression en el classMap
124
 *
125
 * Revision 1.4  2006/09/07 11:19:40  jvhigon
126
 * A?adido soporte para multiples class en una layer, y para layer sdentro de layer
127
 *
128
 * Revision 1.3  2006/09/01 06:59:00  luisw2
129
 * Headers mofification
130
 *
131
 */
132
import java.awt.Color;
133
import java.awt.Dimension;
134
import java.awt.geom.Rectangle2D;
135
import java.io.File;
136
import java.io.FileNotFoundException;
137
import java.io.FileOutputStream;
138
import java.io.PrintStream;
139
import java.util.ArrayList;
140
import java.util.Iterator;
141
import java.awt.Point;
142

    
143
import org.gvsig.remoteservices.conf.IRSLayer;
144

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

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

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

173
        PROJECTION
174
                "init=epsg:23030"   ##required
175
        END
176

177
        #
178
        # Start of layer definitions
179
        #
180

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

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

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

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

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