Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / extensions / extPublishMapserver / src / org / gvsig / publish / mapserver / model / wms / MapserverWMS.java @ 22616

History | View | Annotate | Download (7.83 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004-2006 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *   Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Iba?ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *   +34 963862235
28
 *   gvsig@gva.es
29
 *   www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.publish.mapserver.model.wms;
42

    
43

    
44
import java.net.URL;
45
import java.util.HashSet;
46
import java.util.Iterator;
47
import java.util.Set;
48

    
49
import org.gvsig.publish.PublishLogger;
50
import org.gvsig.publish.exceptions.PublishException;
51
import org.gvsig.publish.infoproject.FilterProjectInfo;
52
import org.gvsig.publish.infoproject.IDataSourceInfo;
53
import org.gvsig.publish.mapserver.conf.MapFile;
54
import org.gvsig.publish.mapserver.conf.MapFile.ConfigFile;
55
import org.gvsig.publish.mapserver.model.Mapserver;
56
import org.gvsig.publish.ogcmetadata.IOGCServiceMetadata;
57
import org.gvsig.publish.ogcmetadata.OGCServiceMetadata;
58
import org.gvsig.publish.serversmodel.RemoteResource;
59
import org.gvsig.publish.serversmodel.Service;
60

    
61
import com.iver.utiles.XMLEntity;
62

    
63
/**
64
 * This class represents the service WMS implemented by Mapserver.
65
 * 
66
 * @author jvhigon
67
 *
68
 */
69
public class MapserverWMS extends Service implements IOGCServiceMetadata {
70
        public static final String REGISTER_TAG="WMS 1.1.1";
71
        private FilterProjectInfo filter;        
72
        private OGCServiceMetadata wmsMetadata = null;
73
        /**
74
         * Constructor
75
         *
76
         */
77
        public MapserverWMS(Mapserver mapserver){                
78
                super(mapserver);
79
                wmsMetadata = new OGCServiceMetadata();                                
80
                //initializes de title with the server name and the service type
81
                setTitle("Mapserver WMS");                
82
                setName("OGC:WMS");                
83
                setOnlineResource(getMapServer().getServerURL());
84
        }                
85
        private Mapserver getMapServer(){
86
                //Cast to Mapserver
87
                Mapserver mapserver = (Mapserver)getServer();
88
                return mapserver;
89
        }
90
        /**
91
         * Preconditions:
92
         * the objects config file, map, map.web and map.web.metadata has been created
93
         */
94
        public void publish() throws PublishException{
95
                //publish all the remote resources
96
                super.publish();
97

    
98
                //gets the mapfile from the server
99
                ConfigFile mapfile = getMapServer().getConfigFile();
100
                if (mapfile == null){
101
                        throw new PublishException("mapfile_not_defined");
102
                }
103

    
104
                //generates the code into the MAP->WEB->METADATA
105
                mapfile.web.metadata.wms_title = getTitle();
106
                mapfile.web.metadata.wms_abstract = getAbstract();                
107
                if (getOnlineResource() != null){
108
                        mapfile.web.metadata.wms_onlineresource = getOnlineResource().toString();
109
                }
110
                mapfile.web.metadata.wms_encoding ="UTF-8";
111
                generateSRS();
112
                generateLegend();
113
        }
114

    
115
        private void generateSRS() {
116
                Set set = new HashSet();                
117
                for (int i= 0; i < getRemoteResourcesCount(); i++){
118
                        RemoteResource r = getRemoteResource(i);
119
                        IDataSourceInfo ds;
120
                        ds = r.getLayerInfo().getDataSource();
121
                        if (ds != null){
122
                                String epsg = ds.getEPSG();                        
123
                                set.add(epsg);
124
                        }                        
125
                } 
126
                Iterator i = set.iterator();
127
                ConfigFile mapfile = getMapServer().getConfigFile();
128
                String aux="";
129
                while (i.hasNext()){
130
                        aux = aux + " " + (String) i.next();                        
131
                }                
132
                mapfile.web.metadata.wms_srs = aux; 
133
        }
134

    
135
        private void generateLegend(){
136
                ConfigFile mapfile = getMapServer().getConfigFile();
137
                mapfile.legend = new MapFile.Legend(); 
138
                mapfile.legend.status = "ON";
139
                mapfile.legend.imagecolor = new MapFile.RGB(-1,-1,-1); 
140
                mapfile.legend.transparent = "ON";
141
                mapfile.legend.legendlabel = new MapFile.Label();
142
                mapfile.legend.legendlabel.color = new MapFile.RGB(0,0,0);
143
                mapfile.legend.legendlabel.encoding = "UTF-8";
144
                mapfile.legend.legendlabel.font ="vera";
145
                mapfile.legend.legendlabel.type ="truetype";
146
                mapfile.legend.legendlabel.size = "8";
147
        }
148

    
149
        public String getClassName() {
150
                return "MapserverWMS";
151
        }
152
        /*
153
         * (non-Javadoc)
154
         * @see org.gvsig.publish.serversmodel.Service#getXMLEntity()
155
         */
156
        public XMLEntity getXMLEntity() {
157
                XMLEntity xml=super.getXMLEntity();
158
                //put version and name 
159
                xml.setName(getClassName());
160
                xml.putProperty("version", getVersion());
161
                //p?t its associations
162
                XMLEntity child = new XMLEntity();
163
                child.setName("wmsmetadata");
164
                child.addChild(wmsMetadata.getXMLEntity());                
165
                xml.addChild(child);
166
                return xml;
167
        }
168

    
169
        /*
170
         * (non-Javadoc)
171
         * @see org.gvsig.publish.serversmodel.Service#setXMLEntity(com.iver.utiles.XMLEntity)
172
         */
173
        public void setXMLEntity(XMLEntity xml) {
174
                //check version
175
                int version = xml.getIntProperty("version");
176
                if (version != getVersion()){
177
                        PublishLogger.getLog().error("ERROR: " + getClassName()+ ": the version doesn't match!");
178
                        return;
179
                }        
180
                super.setXMLEntity(xml);
181

    
182
                //set associations
183
                XMLEntity child = xml.firstChild("name","wmsmetadata");
184
                wmsMetadata.setXMLEntity(child.getChild(0));
185
        }
186
        /*
187
         * (non-Javadoc)
188
         * @see org.gvsig.publish.serversmodel.Service#getFilter()
189
         */
190
        public FilterProjectInfo getFilter() {
191
                if (filter == null){
192
                        filter = new FilterProjectInfo();
193
                }
194
                filter.setGroupedLayersEnabled(true);                
195
                filter.addAllowedDatasource(IDataSourceInfo.POSTGIS_TYPE);
196
                filter.addAllowedDatasource(IDataSourceInfo.SHAPE_TYPE);
197
                filter.addAllowedDatasource(IDataSourceInfo.RASTER_TYPE);
198
                return filter;
199
        }
200
        /*
201
         * (non-Javadoc)
202
         * @see org.gvsig.publish.ogcmetadata.IOGCWMSMetadata#getOnlineResource()
203
         */
204
        public URL getOnlineResource() {                
205
                return wmsMetadata.getOnlineResource();
206
        }
207
        /*
208
         * (non-Javadoc)
209
         * @see org.gvsig.publish.ogcmetadata.IOGCWMSMetadata#setOnlineResource(java.net.URL)
210
         */
211
        public void setOnlineResource(URL url) {
212
                wmsMetadata.setOnlineResource(url);
213
        }
214
        /*
215
         * (non-Javadoc)
216
         * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#getAbstract()
217
         */
218
        public String getAbstract() {                
219
                return wmsMetadata.getAbstract();
220
        }
221
        /*
222
         * (non-Javadoc)
223
         * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#getName()
224
         */
225
        public String getName() {                
226
                return wmsMetadata.getName();
227
        }
228
        /*
229
         * (non-Javadoc)
230
         * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#setAbstract(java.lang.String)
231
         */
232
        public void setAbstract(String description) {
233
                wmsMetadata.setAbstract(description);                
234
        }
235
        /*
236
         * (non-Javadoc)
237
         * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#setName(java.lang.String)
238
         */
239
        public void setName(String name) {
240
                wmsMetadata.setName(name);
241

    
242
        }
243

    
244
        /*
245
         * (non-Javadoc)
246
         * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#getTitle()
247
         */
248
        public String getTitle() {
249
                return wmsMetadata.getTitle();
250
        }
251
        /*
252
         * (non-Javadoc)
253
         * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#setTitle(java.lang.String)
254
         */
255
        public void setTitle(String title) {
256
                wmsMetadata.setTitle(title);                
257
        }
258
        /*
259
         * (non-Javadoc)
260
         * @see org.gvsig.publish.serversmodel.Service#getId()
261
         */
262
        public String getId() {
263
                return "mapserver_wms";
264
        }
265

    
266
        /*
267
         * (non-Javadoc)
268
         * @see org.gvsig.publish.IPublishPersistence#getVersion()
269
         */
270
        public int getVersion() {
271
                return 1;
272
        }
273

    
274
        /*
275
         * (non-Javadoc)
276
         * @see org.gvsig.publish.serversmodel.Service#getRegisterTag()
277
         */
278
        public String getRegisterTag() {                
279
                return REGISTER_TAG;
280
        }
281
        /*
282
         * (non-Javadoc)
283
         * @see java.lang.Object#toString()
284
         */
285
        public String toString(){
286
                return getRegisterTag();
287
        }
288
}