svn-gvsig-desktop / branches / v10 / extensions / extPublishMapserver / src / org / gvsig / publish / mapserver / model / wcs / MapserverWCS.java @ 22616
History | View | Annotate | Download (7.75 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.wcs; |
42 |
|
43 |
import java.net.URL; |
44 |
import java.util.Enumeration; |
45 |
import java.util.Hashtable; |
46 |
|
47 |
import org.gvsig.publish.PublishLogger; |
48 |
import org.gvsig.publish.exceptions.PublishException; |
49 |
import org.gvsig.publish.infoproject.FilterProjectInfo; |
50 |
import org.gvsig.publish.infoproject.IDataSourceInfo; |
51 |
import org.gvsig.publish.infoproject.datasources.IFileInfo; |
52 |
import org.gvsig.publish.mapserver.conf.MapFile.ConfigFile; |
53 |
import org.gvsig.publish.mapserver.conf.MapFile.OutputFormat; |
54 |
import org.gvsig.publish.mapserver.model.Mapserver; |
55 |
import org.gvsig.publish.mapserver.util.MapserverUtilities; |
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 |
* Service WCS 1.0.0 implemented by Mapserver
|
64 |
* @author jvhigon
|
65 |
*
|
66 |
*/
|
67 |
public class MapserverWCS extends Service implements IOGCServiceMetadata{ |
68 |
public static String REGISTER_TAG="WCS 1.0.0"; |
69 |
|
70 |
//Associations
|
71 |
private OGCServiceMetadata ogcMetadata= null; |
72 |
|
73 |
private FilterProjectInfo filter;
|
74 |
/**
|
75 |
* Constructor
|
76 |
* @param server
|
77 |
*/
|
78 |
public MapserverWCS(Mapserver server) {
|
79 |
super(server);
|
80 |
ogcMetadata = new OGCServiceMetadata();
|
81 |
//the service always is OGC:WCS
|
82 |
ogcMetadata.setName("OGC:WCS");
|
83 |
//initializes de title with the server name and the service type
|
84 |
ogcMetadata.setTitle("Mapserver WCS 1.0.0");
|
85 |
ogcMetadata.setOnlineResource(getServer().getServerURL()); |
86 |
} |
87 |
|
88 |
|
89 |
public void publish() throws PublishException { |
90 |
//publish all the remote resources
|
91 |
super.publish();
|
92 |
//gets the mapfile from the server
|
93 |
ConfigFile mapfile = getMapServer().getConfigFile(); |
94 |
//generate outputformats
|
95 |
generateOutputformats(); |
96 |
//generates the code into the MAP->WEB->METADATA
|
97 |
mapfile.web.metadata.wcs_label = getTitle(); |
98 |
mapfile.web.metadata.wcs_description = getAbstract(); |
99 |
//mapfile.web.metadata.wms_onlineresource
|
100 |
mapfile.web.metadata.wcs_encoding ="utf8";
|
101 |
} |
102 |
|
103 |
|
104 |
/**
|
105 |
* Generate the outputformat objects in the mapfile.
|
106 |
* <p>
|
107 |
* we put the datasources in a hashmap in order to avoid duplicated outputformats
|
108 |
*
|
109 |
*/
|
110 |
private void generateOutputformats() { |
111 |
Hashtable table = new Hashtable(); |
112 |
for (int i= 0; i < getRemoteResourcesCount(); i++){ |
113 |
RemoteResource r = getRemoteResource(i); |
114 |
IDataSourceInfo ds = r.getLayerInfo().getDataSource(); |
115 |
IFileInfo file = (IFileInfo)ds; |
116 |
String key = file.getExtension().toUpperCase() + "##" + ds.getDataType(); |
117 |
table.put(key, ds); |
118 |
} |
119 |
for (Enumeration e = table.elements(); e.hasMoreElements(); ) { |
120 |
IDataSourceInfo ds = (IDataSourceInfo) e.nextElement(); |
121 |
String name = MapserverUtilities.getOutputformatName(ds);
|
122 |
String driver = MapserverUtilities.getOutputformatDriver(ds);
|
123 |
String mimetype = MapserverUtilities.getOutputformatMimetype(ds);
|
124 |
String imagemode = MapserverUtilities.getOutputformatImageMode(ds);
|
125 |
String extension = MapserverUtilities.getOuputformatExtension(ds);
|
126 |
|
127 |
if (name !=null && driver !=null){ |
128 |
OutputFormat of = new OutputFormat(name,driver,imagemode,extension,mimetype);
|
129 |
getMapServer().getConfigFile().add(of); |
130 |
} |
131 |
|
132 |
} |
133 |
|
134 |
} |
135 |
|
136 |
private Mapserver getMapServer(){
|
137 |
//Cast to Mapserver
|
138 |
Mapserver mapserver = (Mapserver)getServer(); |
139 |
return mapserver;
|
140 |
} |
141 |
/*
|
142 |
* (non-Javadoc)
|
143 |
* @see com.iver.utiles.IPersistance#getClassName()
|
144 |
*/
|
145 |
public String getClassName() { |
146 |
return "MapserverWCS"; |
147 |
} |
148 |
/*
|
149 |
* (non-Javadoc)
|
150 |
* @see org.gvsig.publish.serversmodel.Service#setXMLEntity(com.iver.utiles.XMLEntity)
|
151 |
*/
|
152 |
public void setXMLEntity(XMLEntity xml) { |
153 |
//check version
|
154 |
int version = xml.getIntProperty("version"); |
155 |
if (version != getVersion()){
|
156 |
PublishLogger.getLog().error("ERROR: " + getClassName()+ ": the version doesn't match!"); |
157 |
return;
|
158 |
} |
159 |
super.setXMLEntity(xml);
|
160 |
//set associations
|
161 |
XMLEntity child = xml.firstChild("name","ogcmetadata"); |
162 |
ogcMetadata.setXMLEntity(child.getChild(0));
|
163 |
|
164 |
} |
165 |
public XMLEntity getXMLEntity() {
|
166 |
XMLEntity xml=super.getXMLEntity();
|
167 |
//put version and name
|
168 |
xml.setName(getClassName()); |
169 |
xml.putProperty("version", getVersion());
|
170 |
|
171 |
//p?t its associations
|
172 |
XMLEntity child = new XMLEntity();
|
173 |
child.setName("ogcmetadata");
|
174 |
child.addChild(ogcMetadata.getXMLEntity()); |
175 |
xml.addChild(child); |
176 |
return xml;
|
177 |
} |
178 |
/*
|
179 |
* (non-Javadoc)
|
180 |
* @see org.gvsig.publish.serversmodel.Service#getFilter()
|
181 |
*/
|
182 |
public FilterProjectInfo getFilter() {
|
183 |
if (filter == null){ |
184 |
filter = new FilterProjectInfo();
|
185 |
} |
186 |
filter.setGroupedLayersEnabled(false);
|
187 |
filter.addAllowedDatasource(IDataSourceInfo.RASTER_TYPE); |
188 |
return filter;
|
189 |
} |
190 |
|
191 |
/*
|
192 |
* (non-Javadoc)
|
193 |
* @see org.gvsig.publish.serversmodel.Service#getId()
|
194 |
*/
|
195 |
public String getId() { |
196 |
|
197 |
return "mapserver_wcs"; |
198 |
} |
199 |
|
200 |
/*
|
201 |
* (non-Javadoc)
|
202 |
* @see org.gvsig.publish.serversmodel.Service#getRegisterTag()
|
203 |
*/
|
204 |
public String getRegisterTag() { |
205 |
|
206 |
return REGISTER_TAG;
|
207 |
} |
208 |
/*
|
209 |
* (non-Javadoc)
|
210 |
* @see org.gvsig.publish.ogcmetadata.IOGCServiceMetadata#getOnlineResource()
|
211 |
*/
|
212 |
public URL getOnlineResource() { |
213 |
|
214 |
return ogcMetadata.getOnlineResource();
|
215 |
} |
216 |
/*
|
217 |
* (non-Javadoc)
|
218 |
* @see org.gvsig.publish.ogcmetadata.IOGCServiceMetadata#setOnlineResource(java.net.URL)
|
219 |
*/
|
220 |
public void setOnlineResource(URL url) { |
221 |
ogcMetadata.setOnlineResource(url); |
222 |
|
223 |
} |
224 |
/*
|
225 |
* (non-Javadoc)
|
226 |
* @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#getAbstract()
|
227 |
*/
|
228 |
public String getAbstract() { |
229 |
return ogcMetadata.getAbstract();
|
230 |
} |
231 |
/*
|
232 |
* (non-Javadoc)
|
233 |
* @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#getName()
|
234 |
*/
|
235 |
public String getName() { |
236 |
return ogcMetadata.getName();
|
237 |
} |
238 |
/*
|
239 |
* (non-Javadoc)
|
240 |
* @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#setAbstract(java.lang.String)
|
241 |
*/
|
242 |
public void setAbstract(String description) { |
243 |
ogcMetadata.setAbstract(description); |
244 |
} |
245 |
/*
|
246 |
* (non-Javadoc)
|
247 |
* @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#setName(java.lang.String)
|
248 |
*/
|
249 |
public void setName(String name) { |
250 |
ogcMetadata.setName(name); |
251 |
|
252 |
} |
253 |
/*
|
254 |
* (non-Javadoc)
|
255 |
* @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#setTitle(java.lang.String)
|
256 |
*/
|
257 |
public void setTitle(String title) { |
258 |
ogcMetadata.setTitle(title); |
259 |
|
260 |
} |
261 |
/*
|
262 |
* (non-Javadoc)
|
263 |
* @see org.gvsig.publish.IPublishPersistence#getVersion()
|
264 |
*/
|
265 |
public int getVersion() { |
266 |
|
267 |
return 1; |
268 |
} |
269 |
|
270 |
/*
|
271 |
* (non-Javadoc)
|
272 |
* @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#getTitle()
|
273 |
*/
|
274 |
public String getTitle() { |
275 |
|
276 |
return ogcMetadata.getTitle();
|
277 |
} |
278 |
/*
|
279 |
* (non-Javadoc)
|
280 |
* @see java.lang.Object#toString()
|
281 |
*/
|
282 |
public String toString(){ |
283 |
return getRegisterTag();
|
284 |
} |
285 |
} |