root / branches / v10 / extensions / extPublishMapserver / src / org / gvsig / publish / mapserver / model / wms / MapserverWMS.java @ 21391
History | View | Annotate | Download (7.72 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.infoproject.FilterProjectInfo; |
51 |
import org.gvsig.publish.infoproject.IDataSourceInfo; |
52 |
import org.gvsig.publish.mapserver.conf.MapFile; |
53 |
import org.gvsig.publish.mapserver.conf.MapFile.ConfigFile; |
54 |
import org.gvsig.publish.mapserver.model.Mapserver; |
55 |
import org.gvsig.publish.ogcmetadata.IOGCServiceMetadata; |
56 |
import org.gvsig.publish.ogcmetadata.OGCServiceMetadata; |
57 |
import org.gvsig.publish.serversmodel.PublishException; |
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 |
wmsMetadata.setTitle("Mapserver WMS");
|
82 |
wmsMetadata.setName("OGC:WMS");
|
83 |
//TODO: initializes the onlineresource with the server URL + mapfile
|
84 |
//String mapfileurl = getMapServer().getMapfileFile().getAbsolutePath();
|
85 |
wmsMetadata.setOnlineResource(getServer().getServerURL()); |
86 |
} |
87 |
|
88 |
private Mapserver getMapServer(){
|
89 |
//Cast to Mapserver
|
90 |
Mapserver mapserver = (Mapserver)getServer(); |
91 |
return mapserver;
|
92 |
} |
93 |
/**
|
94 |
* Preconditions:
|
95 |
* the objects config file, map, map.web and map.web.metadata has been created
|
96 |
*/
|
97 |
public void publish() throws PublishException{ |
98 |
//publish all the remote resources
|
99 |
super.publish();
|
100 |
|
101 |
//gets the mapfile from the server
|
102 |
ConfigFile mapfile = getMapServer().getConfigFile(); |
103 |
if (mapfile == null){ |
104 |
throw new PublishException("mapfile_not_defined"); |
105 |
} |
106 |
|
107 |
//generates the code into the MAP->WEB->METADATA
|
108 |
mapfile.web.metadata.wms_title = getTitle(); |
109 |
mapfile.web.metadata.wms_abstract = getAbstract(); |
110 |
if (getOnlineResource() != null){ |
111 |
mapfile.web.metadata.wms_onlineresource = getOnlineResource().toString(); |
112 |
} |
113 |
mapfile.web.metadata.wms_encoding ="utf8";
|
114 |
generateSRS(); |
115 |
generateLegend(); |
116 |
} |
117 |
|
118 |
private void generateSRS() { |
119 |
Set set = new HashSet(); |
120 |
for (int i= 0; i < getRemoteResourcesCount(); i++){ |
121 |
RemoteResource r = getRemoteResource(i); |
122 |
IDataSourceInfo ds = r.getLayerInfo().getDataSource(); |
123 |
if (ds != null){ |
124 |
String epsg = ds.getEPSG();
|
125 |
set.add(epsg); |
126 |
} |
127 |
} |
128 |
Iterator i = set.iterator();
|
129 |
ConfigFile mapfile = getMapServer().getConfigFile(); |
130 |
String aux=""; |
131 |
while (i.hasNext()){
|
132 |
aux = aux + " " + (String) i.next(); |
133 |
} |
134 |
mapfile.web.metadata.wms_srs = aux; |
135 |
} |
136 |
|
137 |
private void generateLegend(){ |
138 |
ConfigFile mapfile = getMapServer().getConfigFile(); |
139 |
mapfile.legend = new MapFile.Legend();
|
140 |
mapfile.legend.status = "ON";
|
141 |
mapfile.legend.imagecolor = new MapFile.RGB(-1,-1,-1); |
142 |
mapfile.legend.transparent = "ON";
|
143 |
} |
144 |
|
145 |
public String getClassName() { |
146 |
return "MapserverWMS"; |
147 |
} |
148 |
/*
|
149 |
* (non-Javadoc)
|
150 |
* @see org.gvsig.publish.serversmodel.Service#getXMLEntity()
|
151 |
*/
|
152 |
public XMLEntity getXMLEntity() {
|
153 |
XMLEntity xml=super.getXMLEntity();
|
154 |
//put version and name
|
155 |
xml.setName(getClassName()); |
156 |
xml.putProperty("version", getVersion());
|
157 |
//p?t its associations
|
158 |
XMLEntity child = new XMLEntity();
|
159 |
child.setName("wmsmetadata");
|
160 |
child.addChild(wmsMetadata.getXMLEntity()); |
161 |
xml.addChild(child); |
162 |
return xml;
|
163 |
} |
164 |
|
165 |
/*
|
166 |
* (non-Javadoc)
|
167 |
* @see org.gvsig.publish.serversmodel.Service#setXMLEntity(com.iver.utiles.XMLEntity)
|
168 |
*/
|
169 |
public void setXMLEntity(XMLEntity xml) { |
170 |
//check version
|
171 |
int version = xml.getIntProperty("version"); |
172 |
if (version != getVersion()){
|
173 |
PublishLogger.getLog().error("ERROR: " + getClassName()+ ": the version doesn't match!"); |
174 |
return;
|
175 |
} |
176 |
super.setXMLEntity(xml);
|
177 |
|
178 |
//set associations
|
179 |
XMLEntity child = xml.firstChild("name","wmsmetadata"); |
180 |
wmsMetadata.setXMLEntity(child.getChild(0));
|
181 |
} |
182 |
/*
|
183 |
* (non-Javadoc)
|
184 |
* @see org.gvsig.publish.serversmodel.Service#getFilter()
|
185 |
*/
|
186 |
public FilterProjectInfo getFilter() {
|
187 |
if (filter == null){ |
188 |
filter = new FilterProjectInfo();
|
189 |
} |
190 |
filter.setGroupedLayersEnabled(true);
|
191 |
filter.addAllowedDatasource(IDataSourceInfo.POSTGIS_TYPE); |
192 |
filter.addAllowedDatasource(IDataSourceInfo.SHAPE_TYPE); |
193 |
filter.addAllowedDatasource(IDataSourceInfo.RASTER_TYPE); |
194 |
return filter;
|
195 |
} |
196 |
/*
|
197 |
* (non-Javadoc)
|
198 |
* @see org.gvsig.publish.ogcmetadata.IOGCWMSMetadata#getOnlineResource()
|
199 |
*/
|
200 |
public URL getOnlineResource() { |
201 |
return wmsMetadata.getOnlineResource();
|
202 |
} |
203 |
/*
|
204 |
* (non-Javadoc)
|
205 |
* @see org.gvsig.publish.ogcmetadata.IOGCWMSMetadata#setOnlineResource(java.net.URL)
|
206 |
*/
|
207 |
public void setOnlineResource(URL url) { |
208 |
wmsMetadata.setOnlineResource(url); |
209 |
} |
210 |
/*
|
211 |
* (non-Javadoc)
|
212 |
* @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#getAbstract()
|
213 |
*/
|
214 |
public String getAbstract() { |
215 |
return wmsMetadata.getAbstract();
|
216 |
} |
217 |
/*
|
218 |
* (non-Javadoc)
|
219 |
* @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#getName()
|
220 |
*/
|
221 |
public String getName() { |
222 |
return wmsMetadata.getName();
|
223 |
} |
224 |
/*
|
225 |
* (non-Javadoc)
|
226 |
* @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#setAbstract(java.lang.String)
|
227 |
*/
|
228 |
public void setAbstract(String description) { |
229 |
wmsMetadata.setAbstract(description); |
230 |
} |
231 |
/*
|
232 |
* (non-Javadoc)
|
233 |
* @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#setName(java.lang.String)
|
234 |
*/
|
235 |
public void setName(String name) { |
236 |
wmsMetadata.setName(name); |
237 |
|
238 |
} |
239 |
|
240 |
/*
|
241 |
* (non-Javadoc)
|
242 |
* @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#getTitle()
|
243 |
*/
|
244 |
public String getTitle() { |
245 |
return wmsMetadata.getTitle();
|
246 |
} |
247 |
/*
|
248 |
* (non-Javadoc)
|
249 |
* @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#setTitle(java.lang.String)
|
250 |
*/
|
251 |
public void setTitle(String title) { |
252 |
wmsMetadata.setTitle(title); |
253 |
} |
254 |
/*
|
255 |
* (non-Javadoc)
|
256 |
* @see org.gvsig.publish.serversmodel.Service#getId()
|
257 |
*/
|
258 |
public String getId() { |
259 |
return "mapserver_wms"; |
260 |
} |
261 |
|
262 |
/*
|
263 |
* (non-Javadoc)
|
264 |
* @see org.gvsig.publish.IPublishPersistence#getVersion()
|
265 |
*/
|
266 |
public int getVersion() { |
267 |
return 1; |
268 |
} |
269 |
|
270 |
/*
|
271 |
* (non-Javadoc)
|
272 |
* @see org.gvsig.publish.serversmodel.Service#getRegisterTag()
|
273 |
*/
|
274 |
public String getRegisterTag() { |
275 |
return REGISTER_TAG;
|
276 |
} |
277 |
/*
|
278 |
* (non-Javadoc)
|
279 |
* @see java.lang.Object#toString()
|
280 |
*/
|
281 |
public String toString(){ |
282 |
return getRegisterTag();
|
283 |
} |
284 |
} |