Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extPublish / src / com / iver / cit / gvsig / publish / servers / PublishControler.java @ 10626

History | View | Annotate | Download (9.9 KB)

1
package com.iver.cit.gvsig.publish.servers;
2

    
3
import com.iver.andami.PluginServices;
4
import com.iver.andami.ui.mdiManager.IWindow;
5
import com.iver.cit.gvsig.fmap.MapControl;
6
import com.iver.cit.gvsig.fmap.drivers.raster.CmsRasterDriver;
7
import com.iver.cit.gvsig.fmap.layers.FLayer;
8
import com.iver.cit.gvsig.fmap.layers.FLayers;
9
import com.iver.cit.gvsig.fmap.layers.FLyrRaster;
10
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
11
import com.iver.cit.gvsig.project.documents.view.gui.View;
12
import com.iver.cit.gvsig.publish.Servers;
13
import com.iver.cit.gvsig.publish.layers.LayerLoader;
14
import com.iver.cit.gvsig.publish.model.ServiceInfo;
15
import com.iver.cit.gvsig.publish.servers.geoserver.GeoserverPublishControler;
16
import com.iver.cit.gvsig.publish.servers.mapserver.MapServerPublishControler;
17
import com.iver.utiles.swing.jcomboServer.ServerData;
18

    
19
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
20
 *
21
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
22
 *
23
 * This program is free software; you can redistribute it and/or
24
 * modify it under the terms of the GNU General Public License
25
 * as published by the Free Software Foundation; either version 2
26
 * of the License, or (at your option) any later version.
27
 *
28
 * This program is distributed in the hope that it will be useful,
29
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31
 * GNU General Public License for more details.
32
 *
33
 * You should have received a copy of the GNU General Public License
34
 * along with this program; if not, write to the Free Software
35
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
36
 *
37
 * For more information, contact:
38
 *
39
 *  Generalitat Valenciana
40
 *   Conselleria d'Infraestructures i Transport
41
 *   Av. Blasco Ib??ez, 50
42
 *   46010 VALENCIA
43
 *   SPAIN
44
 *
45
 *      +34 963862235
46
 *   gvsig@gva.es
47
 *      www.gvsig.gva.es
48
 *
49
 *    or
50
 *
51
 *   IVER T.I. S.A
52
 *   Salamanca 50
53
 *   46005 Valencia
54
 *   Spain
55
 *
56
 *   +34 963163400
57
 *   dac@iver.es
58
 */
59
/* CVS MESSAGES:
60
 *
61
 * $Id: PublishControler.java 10626 2007-03-06 16:55:54Z caballero $
62
 * $Log$
63
 * Revision 1.10  2007-03-06 16:50:30  caballero
64
 * Exceptions
65
 *
66
 * Revision 1.9  2006/11/22 12:48:21  jorpiell
67
 * Subidos algunos cambios para ver las capas en forma de ?rbol
68
 *
69
 * Revision 1.8  2006/11/22 09:51:01  jvhigon
70
 * reafactoring del ServiceInfo en marcha ...
71
 *
72
 * Revision 1.7  2006/11/20 14:17:47  dagilgon
73
 * *** empty log message ***
74
 *
75
 * Revision 1.6  2006/11/17 09:17:18  jorpiell
76
 * Cambios motivados por el cambio de RC2 a RC3 en el branch
77
 *
78
 * Revision 1.5  2006/10/05 12:13:43  jorpiell
79
 * A?adida una factor?a en la clase publishControler
80
 *
81
 * Revision 1.4  2006/10/03 10:30:14  dagilgon
82
 * adaptation to branch v10
83
 *
84
 * Revision 1.3  2006/09/28 15:04:02  fjp
85
 * Usar siempre que se pueda ISymbol en lugar de FSymbol
86
 *
87
 * Revision 1.2  2006/09/08 15:39:49  jorpiell
88
 * A?adida la capacidad de publicar con WFS
89
 *
90
 * Revision 1.1  2006/09/08 08:58:53  jorpiell
91
 * Se han renombrado y modificado algunas clases
92
 *
93
 *
94
 */
95
/**
96
 * @author Jorge Piera Llodr? (piera_jor@gva.es)
97
 */
98
public abstract class PublishControler {
99
        private View view = null;
100
        private MapControl mapCtrl = null;
101
        private FLayers layers = null;
102
        private String service = null;
103
        protected ServiceInfo serviceInfo = null;
104

    
105
        /**
106
         * Returs a publish controler
107
         * @param brand
108
         * @param type
109
         * @return
110
         */
111
        public static PublishControler getPublishControler(String brand,String type){
112
                if (brand.compareTo(Servers.SERVER_BRAND_MAPSERVER) == 0){
113
                        return new MapServerPublishControler(type);
114
                } else if (brand.compareTo(Servers.SERVER_BRAND_GEOSERVER) == 0){
115
                        return new GeoserverPublishControler(type);
116
                }
117
                return null;
118
        }
119
        
120
        /**
121
         * Constructor
122
         * 
123
         */
124
        public PublishControler(String service) {
125
                IWindow[] windows = PluginServices.getMDIManager().getAllWindows();
126
                for (int i=0 ; i<windows.length ; i++){
127
                    if (windows[i] instanceof View){
128
                            view = (View)windows[i];
129
                    }
130
                }
131
                mapCtrl = view.getMapControl();
132
                layers = mapCtrl.getMapContext().getLayers();
133
                this.service = service;
134
        }
135
        
136
        public abstract Object publish(ServerData serverData);
137
        
138
        public abstract void writeFile();
139

    
140
        /**
141
         * @return Returns the layers.
142
         */
143
        public FLayers getLayers() {
144
                return layers;
145
        }
146

    
147
        /**
148
         * @param layers The layers to set.
149
         */
150
        public void setLayers(FLayers layers) {
151
                this.layers = layers;
152
        }
153

    
154
        /**
155
         * @return Returns the mapCtrl.
156
         */
157
        public MapControl getMapCtrl() {
158
                return mapCtrl;
159
        }
160

    
161
        /**
162
         * @param mapCtrl The mapCtrl to set.
163
         */
164
        public void setMapCtrl(MapControl mapCtrl) {
165
                this.mapCtrl = mapCtrl;
166
        }
167

    
168
        /**
169
         * @return Returns the view.
170
         */
171
        public View getView() {
172
                return view;
173
        }
174

    
175
        /**
176
         * @param view The view to set.
177
         */
178
        public void setView(View view) {
179
                this.view = view;
180
        }
181

    
182
        /**
183
         * @return Returns the service.
184
         */
185
        public String getService() {
186
                return service;
187
        }
188
        /**
189
         * This method set all layer properties of the view.
190
         * Property:     Value:
191
         * hasChilds          true/false
192
         * mosaic:        true/false
193
         * time:          true/false 
194
         */
195
        private void setLayerProperties(){
196
                for (int i = 0; i < getLayers().getLayersCount(); i++) {
197
                        FLayer lyr = getLayers().getLayer(i);
198
                        if (lyr.isVisible()){
199
//                                try{
200
                                        if (lyr instanceof FLayers){
201
                                                lyr.setProperty("hasChilds","true");
202
                                                //Check if the layer name specify a MOSAIC or TIME layer
203
                                                if (lyr.getName().startsWith("[")){
204
                                                        if (lyr.getName().startsWith("[" + LayerLoader.GROUP_LAYER_TIME)){
205
                                                                lyr.setProperty("time", "true");
206
                                                        }else if(lyr.getName().startsWith("[" + LayerLoader.GROUP_LAYER_MOSAIC)){
207
                                                                lyr.setProperty("mosaic","true");
208
                                                        }
209
                                                }
210
                                                FLayers groupLayers = (FLayers) lyr;
211
                                                for (int j= 0; j<groupLayers.getLayersCount(); j++){
212
                                                        FLayer childLayer = groupLayers.getLayer(j);
213
                                                        setLayerProperties(childLayer);
214
                                                }                                                
215
                                        }else{
216
                                                lyr.setProperty("hasChilds","false");
217
                                                setLayerProperties(lyr);                                                
218
                                        }
219
        //                        }catch(LayerException e){
220
                                        //TODO: Should't print 
221
        //                                System.out.println("Layer Exception in PublishControler.java");
222
        //                        }
223
                        }
224
                } 
225
                
226
        }
227
        /**
228
         * Property:     Value:
229
         * layerType          RASTER, POSTGIS, SHAPE 
230
         * 
231
         */
232
         
233
        private void setLayerProperties(FLayer lyr) {
234
                if (lyr instanceof FLyrVect){
235
                        FLyrVect flyrVect = (FLyrVect)lyr;
236
                        //Legend
237
                        //setLegendProperties(flyrVect);
238
                        System.out.println(flyrVect.getSource().getDriver().getName());
239
                        //Postgis
240
                        if(flyrVect.getSource().getDriver().getName().compareTo("PostGIS JDBC Driver")==0){
241
                                flyrVect.setProperty("layerType", "POSTGIS");
242
                                setLayerPostGISProperties(flyrVect);                                
243
                        }
244
                        //Shape
245
                        if(flyrVect.getSource().getDriver().getName().compareTo("gvSIG shp driver")==0){
246
                                flyrVect.setProperty("layerType", "SHAPE");
247
                                setLayerShapeProperties(flyrVect);
248
                        }
249
                } else if (lyr instanceof FLyrRaster){
250
                        FLyrRaster lyrRaster = (FLyrRaster) lyr;
251
                        if (lyrRaster.getSource().getDriver() instanceof CmsRasterDriver){
252
                                lyrRaster.setProperty("layerType", "RASTER");
253
                                setLayerRaster(lyrRaster);
254
                        }                        
255
                }        
256
                
257
        }
258
/**
259
 * Property
260
 *     size
261
 *     colorR
262
 *     colorG
263
 *     colorB
264
 *     outlinecolorR
265
 *     outlinecolorG
266
 *     outlinecolorB
267
 *     outlinecolor
268
 *     transparency
269
 * @param lyr
270
 * /
271
        private void setLegendProperties(FLyrVect lyr) {
272
                Legend legend = lyr.getLegend();
273
                if (legend instanceof SingleSymbolLegend) {
274
                        //get color
275
                        FSymbol sym = (FSymbol) legend.getDefaultSymbol();
276
                        Color clr = sym.getColor();
277
                        Color outLineclr = sym.getOutlineColor();
278
                        lyr.setProperty("colorR", new Integer(outLineclr.getRed()).toString());
279
                        lyr.setProperty("colorG", new Integer(outLineclr.getGreen()).toString());
280
                        lyr.setProperty("colorB", new Integer(outLineclr.getBlue()).toString());
281
                                                                        
282
                        try{                                
283
                                Float size = 
284
                                                                
285
                                ((BasicStroke)sym.getStroke()).getLineWidth().intValue();
286
                                lyr.setProperty("size", new Float(size).toString());
287
                                }catch(Exception e){
288
                                
289
                        }
290
                        mapClasses.add(mapClass);
291
                }else if(legend instanceof VectorialUniqueValueLegend){
292
                        VectorialUniqueValueLegend uniqueValueLegend = (VectorialUniqueValueLegend)legend;
293
                        ISymbol[] symbols = uniqueValueLegend.getSymbols();
294
                        for (int i=0 ; i<symbols.length ; i++){
295
                                MapClass mapClass = new MapClass(symbols[i].getDescription());
296
                                FSymbol auxSym = (FSymbol) symbols[i];
297
                                Color clr = auxSym.getColor();
298
                                Color outLineclr = auxSym.getOutlineColor();
299
                                mapClass.estilo = new ConfigFile.StyleMap(clr,outLineclr);
300
                                mapClass.expression = "('[" + uniqueValueLegend.getFieldName() + "]' = '" + 
301
                                                symbols[i].getDescription() + "')";
302
                                try{
303
                                        mapClass.size = new Float(((BasicStroke)auxSym.getStroke()).getLineWidth()).intValue();
304
                                }catch(Exception e){
305
                                
306
                                }
307
                                mapClasses.add(mapClass);
308
                        }
309
                        
310
                }else if(legend instanceof VectorialIntervalLegend){
311
                        MapClass mapClass = new MapClass(getLayerName(lyrVect.getName()));
312

313
                        FSymbol sym = (FSymbol) legend.getDefaultSymbol();
314
                        Color clr = sym.getColor();
315
                        Color outLineclr = sym.getOutlineColor();
316
                        mapClass.estilo = new ConfigFile.StyleMap(clr,outLineclr);
317
                        try{
318
                                mapClass.size = new Float(((BasicStroke)sym.getStroke()).getLineWidth()).intValue();
319
                        }catch(Exception e){
320
                        
321
                        }        
322
                        mapClasses.add(mapClass);
323
                }                        
324
                
325
        }*/
326

    
327
        private void setLayerRaster(FLyrRaster lyrRaster) {
328
                CmsRasterDriver driver =  (CmsRasterDriver)lyrRaster.getSource().getDriver();                
329
                double resx = (driver.getFiles()[0].getExtent().maxX() - driver.getFiles()[0].getExtent().minX())/driver.getFiles()[0].getWidth();
330
                double resy = (driver.getFiles()[0].getExtent().maxY() - driver.getFiles()[0].getExtent().minY())/driver.getFiles()[0].getHeight();
331
                lyrRaster.setProperty("resx", new Double(resx).toString());
332
                lyrRaster.setProperty("resy", new Double(resy).toString());
333
        }
334

    
335
        private void setLayerShapeProperties(FLyrVect flyrVect) {
336
                // TODO Auto-generated method stub
337
                
338
                
339
        }
340

    
341
        private void setLayerPostGISProperties(FLyrVect flyrVect) {
342
                // TODO Auto-generated method stub
343
                
344
        }
345

    
346
        abstract public ServiceInfo getServiceInfo();
347
}