Revision 32032

View differences:

tags/gvsig_topologia-0_1_0-1235/extensions/extPublishMapserver/config/config.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<plugin-config>
3
	<depends plugin-name="com.iver.cit.gvsig" />
4
	<depends plugin-name="org.gvsig.publish" />
5
	<libraries library-dir="."/>
6
	<resourceBundle name="text"/>
7
	<extensions>
8
		<extension class-name="org.gvsig.publish.mapserver.MapserverExtension"
9
			description="MapserverPublish Extension"
10
			active="true"
11
			priority="1">
12
		</extension>		
13
	</extensions>
14
</plugin-config>
0 15

  
tags/gvsig_topologia-0_1_0-1235/extensions/extPublishMapserver/config/text_de.properties
1
#mapserver_text_de.properties
2
publishms_change_view_message=Anwendung neustarten, damit die \u00C4nderungen wirksam werden
3
publishms_change_view_properties=Anwendung neustarten, damit die \u00C4nderungen wirksam werden
4
publishms_debug=Fehler beseitigen
5
publishms_mapserver_imagepath=Tempor\u00E4res Verzeichnis
6
publishms_mapserver_layer_properties=Mapserver Layer Eigenschaften
7
publishms_mapserver_mapfile=Konfigurationsdatei
8
publishms_mapserver_mapname=Name der Karte
9
publishms_mapserver_properties=Mapserver Eigenschaften
10
publishms_publish_message=Publikation erfolgreich abgeschlossen.\nDie Originaldateien m\u00FCssen dem Anwender, der die Mapserver CGI aufruft, frei zug\u00E4nglich sein.\nAchtung\: Jedes Passwort kann in den erzeugten Dateien lesbar sein\!\!
11
publishms_mapserver_shapepath=Shape- Pfad
12
publishms_mapserver_url=URL
13
publishms_mosaic=Imagekatalog
14
publishms_name=Name
15
publishms_nothing_to_publish=Nichts zum publizieren. F\u00FCgen sie die entsprechenden Dateien hinzu.
16
publishms_publish_mapserver=Mapserver Publikation
17
publishms_publish_view=GUI Publikation
18
publishms_restart=neu starten
19
publishms_the_mapfile_is_not_defined=Datei ausw\u00E4hlen wohin die Konfigurationsdatei generiert werden soll.
0 20

  
tags/gvsig_topologia-0_1_0-1235/extensions/extPublishMapserver/config/text.properties
1
#mapserver basic
2
publishms_mapserver_url=URL
3
publishms_mapserver_mapfile=Fichero de configuraci?n
4
#mapserver advanced
5
publishms_mapserver_imagepath=Directorio temporal
6
publishms_mapserver_shapepath=Directorio datos
7
publishms_debug=Depuraci?n
8
#preferences page
9
publishms_publish_view=GUI de publicaci?n
10
publishms_change_view_properties=Debe reiniciar la aplicaci?n para que los cambios sean efectivos
11
publishms_restart=Reinicie la aplicaci?n
12
publishms_publish_mapserver=Publicaci?n en Mapserver
13
#mapserver layer
14
publishms_mapserver_layer_properties=Propiedades capa Mapserver
15
publishms_mosaic=Mosaico de im?genes
16
#Model Mapserver
17
publishms_nothing_to_publish=Nada que publicar. A?ada recursos a la publicaci?n.
18
publishms_the_mapfile_is_not_defined=Seleccione un fichero para escribir la configuraci?n.
19
publishms_publish_message=Publicaci?n generada correctamente.\nAseg?rese que las fuentes de datos son accesibles por parte del usuario que ejecuta el CGI de Mapserver.\nCualquier contrase?a aparecer? en los ficheros generados sin encriptar.
20
publishms_no_services_defined=No se ha definido ning?n servicio.
21
publihsms_permission_denied=Imposible generar los ficheros de configuraci?n. Permiso denegado.
22

  
23
#publishms_mapserver_properties=Propiedades Servidor Mapserver
24
#publishms_mapserver_mapname=Nombre del mapa
25
#publishms_name=Nombre 
0 26

  
tags/gvsig_topologia-0_1_0-1235/extensions/extPublishMapserver/config/text_en.properties
1
publishms_nothing_to_publish=Nothing to publish. Add a new resource.
2
publishms_the_mapfile_is_not_defined=Select a file to write the configuration.
3
publishms_debug=Debug
4
publishms_mapserver_properties=Mapserver properties
5
publishms_mapserver_mapname=Map name
6
publishms_mapserver_url=URL
7
publishms_mapserver_mapfile=Configuration file
8
publishms_name=Name
9
publishms_mapserver_imagepath=Temp directory
10
publishms_mapserver_shapepath=ShapePath
11
publishms_change_view_message=Restart the application in order to apply changes
12
publishms_restart=Restart application
13
publishms_publish_view=Publication GUI
14
publishms_publish_mapserver=Mapserver publication
15
#mapserver layer properties
16
publishms_mapserver_layer_properties=Mapserver layer properties
17
publishms_mosaic=Image Mosaic
18
#publish message
19
publishms_publish_message=Publication generated successfully.\nData sources must be accessible by the user who executes the Mapserver CGI.\nFurthermore, any password can be read in the mapfile !!
20
publihsms_permission_denied=Cannot generate the configuration files. Permission denied.
0 21

  
tags/gvsig_topologia-0_1_0-1235/extensions/extPublishMapserver/src/org/gvsig/publish/mapserver/util/MapserverUtilities.java
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.util;
42

  
43
import org.gvsig.publish.infoproject.IDataSourceInfo;
44
import org.gvsig.publish.infoproject.datasources.IDataBaseInfo;
45
import org.gvsig.publish.infoproject.datasources.IFileInfo;
46
import org.gvsig.publish.infoproject.datasources.IRasterDSInfo;
47

  
48
/**
49
 * Utilities for publishing in Mapserver
50
 * @author jvhigon
51
 *
52
 */
53
public class MapserverUtilities {
54
	/**
55
	 * 
56
	 * @param datasource
57
	 * @return outputformat name in format "extensionfile_datatype". It returns null If imagemode is null   
58
	 */
59
	public static String getOutputformatName(IRasterDSInfo datasource){
60
		IFileInfo file = (IFileInfo)datasource;
61
		//String aux = file.getExtension().toUpperCase() + "_" + datasource.getDataType();
62
		String aux = null;
63
		if (getOutputformatImageMode(datasource) !=null)
64
			aux = file.getExtension().toUpperCase() + "_" + getOutputformatImageMode(datasource);
65
		return aux;
66
	}
67
	/**
68
	 * 
69
	 * @param datasource
70
	 * @return Gets a valid DRIVER value for Mapserver outputformat (GDAL/Gtiff, GDAL/ECW, GDAL/HFA)
71
	 * <p>
72
	 * It can be null if the driver is not Gtiff, ECW or HFA
73
	 * TODO: add other drivers 
74
	 */
75
	public static String getOutputformatDriver(IDataSourceInfo ds){
76
		IFileInfo file = (IFileInfo)ds;		
77
		String extension = file.getExtension().toLowerCase();
78
		if (extension.equals("tif")||extension.equals("tiff")){
79
			return "GDAL/Gtiff";
80
		}
81
		if (extension.equals("ecw")){
82
			return "GDAL/ECW";
83
		}
84
		if (extension.equals("img")){
85
			return "GDAL/HFA";
86
		}
87
		if (extension.equals("jpg") || extension.equals("jpeg")){
88
			return "GD/JPEG";
89
		}
90
		return null;
91
	}
92
	/**
93
	 * 
94
	 * @param datasource
95
	 * @return Gets a valid MIMETYPE value for Mapserver outputformats
96
	 */
97
	public static String getOutputformatMimetype(IDataSourceInfo datasource){
98
		IFileInfo file = (IFileInfo)datasource;		
99
		String aux = file.getExtension().toLowerCase();
100
		aux ="image/" + aux; 
101
		return  aux;
102
	}	
103
	/**
104
	 * @see http://mapserver.org/mapfile/outputformat.html
105
	 * @param datasource
106
	 * @return Gets a valid IMAGEMODE value for Mapserver outputformats. The values can be PC256/RGB/RGBA/INT16/FLOAT32
107
	 * <p>
108
	 * It can be null if the datatype is not supported by mapserver. 
109
	 * We query the first band of the datasource
110
	 * TODO: Review the mapping between raster data type - Mapserver data type 
111
	 */
112
	public static String getOutputformatImageMode(IRasterDSInfo datasource){			
113
		int aux = datasource.getDataType(0);
114
		switch(aux){
115
			case IRasterDSInfo.TYPE_BYTE:
116
				return "BYTE";
117
			case IRasterDSInfo.TYPE_DOUBLE:
118
				return "FLOAT64";
119
			case IRasterDSInfo.TYPE_FLOAT:
120
				return "FLOAT32";
121
			case IRasterDSInfo.TYPE_INT:
122
				return "INT16";
123
			case IRasterDSInfo.TYPE_SHORT:
124
				return "RGB";
125
			case IRasterDSInfo.TYPE_USHORT:
126
				return "PC256";
127
			case IRasterDSInfo.TYPE_UNDEFINED:
128
				return "RGBA";
129
		}
130
		return null;
131
	}
132
	/**
133
	 * 
134
	 * @param datasource
135
	 * @return Gets a valid EXTENSION value for Mapserver outputformats.
136
	 */
137
	public static String getOuputformatExtension(IDataSourceInfo datasource) {
138
		IFileInfo file = (IFileInfo)datasource;		
139
		String aux = file.getExtension().toLowerCase();
140
		return aux;
141
	}
142
	/**
143
	 * Utility for calculating the parameter DATA in the Mapfile. When the data source is a file it calculates
144
	 * the absolute path to the file or the relative path if the shapepath is defined. On the other hand, if the datasource is a 
145
	 * database connection, it calculates the data clause. 
146
	 *  
147
	 * 
148
	 * @param ds data source
149
	 * @param shapepath
150
	 * @param localMountPoint
151
	 * @return the data section in the mapfile. It can be null.
152
	 *
153
	public static String getDataParameter(IDataSourceInfo ds, String shapepath, File localMountPoint){
154
		String res = null;
155
		if (ds.getType() == IDataSourceInfo.SHAPE_TYPE || ds.getType() == IDataSourceInfo.RASTER_TYPE){
156
			String path = ((IFileInfo)ds).getAbsolutePath();
157
			if (shapepath == null){
158
				res = path;
159
			}else{
160
				if (localMountPoint == null){
161
					res = ((IFileInfo)ds).getFileName();
162
				}else{
163
					res = path.substring(localMountPoint.getAbsolutePath().length());
164
					if (res.startsWith(File.separator)){
165
						res = res.substring(1);
166
					}
167
				}
168
			}
169
		}
170
		if (ds.getType() == IDataSourceInfo.POSTGIS_TYPE){
171
			IDataBaseInfo db = (IDataBaseInfo)ds;
172
			String table = db.getTableName();
173
			res = "the_geom from "  + table + " using unique " + db.getGID() + " using srid=" + ds.getSRID();
174
		}
175
		return res;
176
	}
177
	*/
178
	
179
	/**
180
	 * Utility for calculate the CONNECTIONTYPE parameter in the Mapfile. If the datasource is a shapefile or a raster file it will return null
181
	 * @param ds data source 
182
	 * @return "POSTGIS" or null
183
	 */
184
	public static String getConnectionTypeParameter(IDataSourceInfo ds){
185
		String res = null;
186
		if (ds.getType() == IDataSourceInfo.POSTGIS_TYPE){
187
			res = "POSTGIS";
188
		}
189
		return res;
190
	}
191
	/**
192
	 * Utility for calculate the CONNECTION parameter in the Mapfile. If the datasource is a shapefile or a raster file it will return null
193
	 * @param ds data source 
194
	 * @return a string which identifies a connection or null
195
	 */
196
	public static String getConnectionParameter(IDataSourceInfo ds){
197
		String res = null;
198
		if (ds.getType() == IDataSourceInfo.POSTGIS_TYPE){			
199
			IDataBaseInfo db = (IDataBaseInfo)ds;
200
			res = "user=" + db.getUser() + " password=" 
201
			+ db.getPassword() + " host=" + db.getHost() 
202
			+ " port=" + db.getPort() + " dbname=" + db.getDatabaseName(); 			
203
		}
204
		return res;
205
	}
206
	/**
207
	 * Utility for complete the TYPE parameter in the mapfile.
208
	 * @param ds
209
	 * @return "LINE" "POINT" "POLYGON" "RASTER"
210
	 */
211
	public static String getTypeParameter(IDataSourceInfo ds){
212
	/*	String res = "?";
213
		if (ds.getType() == IDataSourceInfo.RASTER){
214
			res = "RASTER";
215
		}else{
216
			res = ds.getGeomType();
217
		}
218
		return res;*/
219
		return ds.getGeomType();
220
	}
221
}
0 222

  
tags/gvsig_topologia-0_1_0-1235/extensions/extPublishMapserver/src/org/gvsig/publish/mapserver/model/wfs/MapserverWFSLayer.java
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.wfs;
42

  
43
import java.awt.geom.Rectangle2D;
44

  
45
import org.gvsig.publish.PublishLogger;
46
import org.gvsig.publish.exceptions.PublishException;
47
import org.gvsig.publish.infoproject.IDataSourceInfo;
48
import org.gvsig.publish.infoproject.ILayerInfo;
49
import org.gvsig.publish.infoproject.datasources.IDataBaseInfo;
50
import org.gvsig.publish.mapserver.conf.MapFile;
51
import org.gvsig.publish.mapserver.conf.MapFile.CRS;
52
import org.gvsig.publish.mapserver.conf.MapFile.Layer;
53
import org.gvsig.publish.mapserver.model.Mapserver;
54
import org.gvsig.publish.mapserver.util.MapserverUtilities;
55
import org.gvsig.publish.ogcmetadata.IOGCCommonMetadata;
56
import org.gvsig.publish.ogcmetadata.OGCCommonMetadata;
57
import org.gvsig.publish.serversmodel.RemoteResource;
58

  
59
import com.iver.utiles.XMLEntity;
60

  
61
public class MapserverWFSLayer extends RemoteResource implements IOGCCommonMetadata {
62

  
63
	public final static String REGISTER_TAG="mapserver_wfs_feature";
64
	//associations
65
	private OGCCommonMetadata ogcMetadata = null;
66
	private MapFile.Layer config = null;
67
	/**
68
	 * Constructor
69
	 * 
70
	 * @param service
71
	 */
72
	public MapserverWFSLayer(MapserverWFS service) {
73
		super(service);
74
		ogcMetadata = new OGCCommonMetadata();		
75
	}
76

  
77
	/**
78
	 * Initializes the remote resource name and title with the name and title of the layer
79
	 *
80
	 * @see org.gvsig.publish.serversmodel.RemoteResource#setLayerInfo(org.gvsig.publish.infoproject.ILayerInfo)
81
	 */
82
	public void setLayerInfo(ILayerInfo layerInfo) {
83
		super.setLayerInfo(layerInfo);
84
		setName(getLayerInfo().getName());
85
		setTitle(getLayerInfo().getTitle());
86
		setAbstract("generated by gvSIG");	
87
	}
88

  
89
	/**
90
	 * Generates a new layer configuration in the mapfile when is invoked 
91
	 * @see org.gvsig.publish.serversmodel.RemoteResource#publish()
92
	 */
93
	public void publish() throws PublishException {
94
		config = new MapFile.Layer();
95
		getMapServer().getConfigFile().add(config);
96
		generateLayerSection();
97
		//publish all its childs		
98
		super.publish();
99
	}
100
	/**
101
	 * Creates the object MAP->LAYER
102
	 * @throws PublishException
103
	 */
104
	private void generateLayerSection() throws PublishException{
105
		//LAYER
106
		config.name = getName();
107
		config.status = "ON";
108
		config.debug = getMapServer().isDebug();
109
		config.type = MapserverUtilities.getTypeParameter(getLayerInfo().getDataSource());
110
		generateDataParameter();
111
		config.connectiontype = MapserverUtilities.getConnectionTypeParameter(getLayerInfo().getDataSource());
112
		config.connection = MapserverUtilities.getConnectionParameter(getLayerInfo().getDataSource());		
113
		config.dump = true;		
114

  
115
		//PROJECTION 		
116
		config.layercrs = new CRS(getLayerInfo().getDataSource().getEPSG(),true);				
117
		//METADATA
118
		generateMetadata(config);
119

  
120
	}
121
	/**
122
	 * Generates the LAYER->DATA parameter 
123
	 *  
124
	 */
125
	private void generateDataParameter(){
126
		IDataSourceInfo ds = getLayerInfo().getDataSource();
127
		if (ds.getType() == IDataSourceInfo.POSTGIS_TYPE){
128
			IDataBaseInfo db = (IDataBaseInfo)ds;
129
			String table = db.getTableName();
130
			String schema = db.getSchemaName();
131
			if (schema !=null){
132
				table = schema+ "." + table;
133
			}
134
			config.data ="the_geom from "  + table + " using unique " + db.getGID() + " using srid=" + ds.getSRID(); 
135
		}else{
136
			config.data = getService().getServer().getPublication().getServerSideFilePath(ds);
137
		}				
138
	}
139

  
140
	private Mapserver getMapServer(){
141
		//Cast to Mapserver
142
		Mapserver mapserver = (Mapserver)getService().getServer();
143
		return mapserver;
144
	}
145
	/**
146
	 * Generates the METADATA object
147
	 * @param mapLayer
148
	 */
149
	private void generateMetadata(Layer mapLayer){
150
		//add metadata
151
		mapLayer.metadata.wfs_name = getName();
152
		mapLayer.metadata.wfs_title = getTitle();
153
		mapLayer.metadata.wfs_abstract = getAbstract();
154
		Rectangle2D aux = getLayerInfo().getDataSource().getNativeBBox();
155
		String bbox = aux.getMinX() + " " + aux.getMinY() + " " + aux.getMaxX() + " " + aux.getMaxY();
156
		mapLayer.metadata.wfs_extent = bbox;
157
		mapLayer.metadata.gml_include_items = "all";
158

  
159
	}
160
	/*
161
	 * (non-Javadoc)
162
	 * @see com.iver.utiles.IPersistance#getClassName()
163
	 */		
164
	public String getClassName() {
165
		return "MapserverWFSLayer";
166
	}
167
	/*
168
	 * (non-Javadoc)
169
	 * @see org.gvsig.publish.serversmodel.RemoteResource#getXMLEntity()
170
	 */
171
	public XMLEntity getXMLEntity() {		
172
		XMLEntity xml=super.getXMLEntity();
173
		//put version and name
174
		xml.setName(getClassName());
175
		xml.putProperty("version", getVersion());
176
		//put associations
177
		XMLEntity child = new XMLEntity();
178
		child.setName("ogcmetadata");
179
		child.addChild(ogcMetadata.getXMLEntity());
180
		xml.addChild(child);
181
//		child = new XMLEntity();
182
//		child.setName("mapserverlayer");
183
//		child.addChild(layerMapserver.getXMLEntity());
184
//		xml.addChild(child);	
185
		return xml;
186
	}
187
	/*
188
	 * (non-Javadoc)
189
	 * @see org.gvsig.publish.serversmodel.RemoteResource#setXMLEntity(com.iver.utiles.XMLEntity)
190
	 */
191
	public void setXMLEntity(XMLEntity xml) {
192
		//check version
193
		int version = xml.getIntProperty("version");
194
		if (version != getVersion()){
195
			PublishLogger.getLog().error("ERROR: " + getClassName() + ": the version doesn't match!");			
196
			return;
197
		}
198
		super.setXMLEntity(xml);						
199
		//set associations
200
		XMLEntity child = xml.firstChild("name","ogcmetadata");
201
		ogcMetadata.setXMLEntity(child.getChild(0));		
202
//		child = xml.firstChild("name","mapserverlayer");
203
//		layerMapserver.setXMLEntity(child.getChild(0));
204

  
205
	}
206

  
207
	/*
208
	 * (non-Javadoc)
209
	 * @see org.gvsig.publish.serversmodel.RemoteResource#getRegisterTag()
210
	 */
211
	public String getRegisterTag() {		
212
		return REGISTER_TAG;
213
	}
214
	/*
215
	 * (non-Javadoc)
216
	 * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#getTitle()
217
	 */
218
	public String getTitle() {
219
		return ogcMetadata.getTitle();
220
	}
221
	/*
222
	 * (non-Javadoc)
223
	 * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#getAbstract()
224
	 */
225
	public String getAbstract() {		
226
		return ogcMetadata.getAbstract();
227
	}
228
	/*
229
	 * (non-Javadoc)
230
	 * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#getName()
231
	 */
232
	public String getName() {		
233
		return ogcMetadata.getName();
234
	}
235
	/*
236
	 * (non-Javadoc)
237
	 * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#setAbstract(java.lang.String)
238
	 */
239
	public void setAbstract(String description) {
240
		ogcMetadata.setAbstract(description);		
241
	}
242
	/*
243
	 * (non-Javadoc)
244
	 * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#setName(java.lang.String)
245
	 */
246
	public void setName(String name) {
247
		ogcMetadata.setName(name);		
248
	}
249
	/*
250
	 * (non-Javadoc)
251
	 * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#setTitle(java.lang.String)
252
	 */
253
	public void setTitle(String title) {
254
		ogcMetadata.setTitle(title);		
255
	}
256
	/*
257
	 * (non-Javadoc)
258
	 * @see org.gvsig.publish.IPublishPersistence#getVersion()
259
	 */
260
	public int getVersion() {		
261
		return 1;
262
	}
263
	/*
264
	 * (non-Javadoc)
265
	 * @see java.lang.Object#toString()
266
	 */
267
	public String toString(){
268
		return getName();
269
	}
270
}
0 271

  
tags/gvsig_topologia-0_1_0-1235/extensions/extPublishMapserver/src/org/gvsig/publish/mapserver/model/wfs/MapserverWFS.java
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.wfs;
42

  
43
import java.net.URL;
44

  
45
import org.gvsig.publish.PublishLogger;
46
import org.gvsig.publish.exceptions.PublishException;
47
import org.gvsig.publish.infoproject.IDataSourceInfo;
48
import org.gvsig.publish.infoproject.filter.FilterProjectInfo;
49
import org.gvsig.publish.mapserver.conf.MapFile.ConfigFile;
50
import org.gvsig.publish.mapserver.model.Mapserver;
51
import org.gvsig.publish.ogcmetadata.IOGCServiceMetadata;
52
import org.gvsig.publish.ogcmetadata.OGCServiceMetadata;
53
import org.gvsig.publish.serversmodel.Service;
54

  
55
import com.iver.utiles.XMLEntity;
56
/**
57
 * Service WFS 1.0.0 implemented by Mapserver
58
 *  
59
 * @author jvhigon
60
 *
61
 */
62
public class MapserverWFS extends Service implements IOGCServiceMetadata {
63
	public static String REGISTER_TAG="WFS 1.0.0";
64
	//Associations
65
	private OGCServiceMetadata ogcmetadata;
66
	private FilterProjectInfo filter;
67
		
68
	/**
69
	 * Constructor
70
	 * @param server
71
	 */
72
	public MapserverWFS(Mapserver server) {
73
		super(server);
74
		ogcmetadata = new OGCServiceMetadata();
75
		//the service always is OGC:WFS
76
		ogcmetadata.setName("OGC:WFS");	
77
		//initializes de title with the server name and the service type
78
		ogcmetadata.setTitle("Service WFS 1.0.0");
79
		ogcmetadata.setOnlineResource(getServer().getServerURL());
80
	}
81
	
82
	public void publish() throws PublishException {
83
		//publish all the remote resources
84
		super.publish();
85
		
86
		//gets the mapfile from the server
87
		ConfigFile mapfile = getMapServer().getConfigFile();
88

  
89
		//generates the code into the MAP->WEB->METADATA
90
		mapfile.web.metadata.wfs_title = getTitle();
91
		mapfile.web.metadata.wfs_abstract = getAbstract();
92
		//mapfile.web.metadata.wms_onlineresource
93
		mapfile.web.metadata.wfs_encoding ="utf8";
94
	}
95

  
96
	
97
	private Mapserver getMapServer(){
98
		//Cast to Mapserver
99
		Mapserver mapserver = (Mapserver)getServer();
100
		return mapserver;
101
	}
102
	
103
	public String getClassName() {
104
		return "MapserverWFS";
105
	}
106
	public XMLEntity getXMLEntity() {		
107
		XMLEntity xml=super.getXMLEntity();
108
		//put version and name 
109
		xml.setName(getClassName());
110
		xml.putProperty("version", getVersion());
111
		
112
		//p?t its associations
113
		XMLEntity child = new XMLEntity();
114
		child.setName("ogcmetadata");
115
		child.addChild(ogcmetadata.getXMLEntity());		
116
		xml.addChild(child);
117
				
118
		return xml;
119
	}
120
	public void setXMLEntity(XMLEntity xml) {
121
		//check version
122
		int version = xml.getIntProperty("version");
123
		if (version != getVersion()){
124
			PublishLogger.getLog().error("ERROR: " + getClassName()+ ": the version doesn't match!");
125
			return;
126
		}	
127
		super.setXMLEntity(xml);
128
		//set associations
129
		XMLEntity child = xml.firstChild("name","ogcmetadata");
130
		ogcmetadata.setXMLEntity(child.getChild(0));
131
	}
132

  
133
	/*
134
	 * (non-Javadoc)
135
	 * @see org.gvsig.publish.serversmodel.Service#getFilter()
136
	 */
137
	public FilterProjectInfo getFilter() {
138
		if (filter == null){
139
			filter = new FilterProjectInfo();
140
		}
141
		filter.setGroupedLayersEnabled(false);		
142
		filter.addAllowedDatasource(IDataSourceInfo.POSTGIS_TYPE);
143
		filter.addAllowedDatasource(IDataSourceInfo.SHAPE_TYPE);		
144
		return filter;
145
	}
146

  
147
	/*
148
	 * (non-Javadoc)
149
	 * @see org.gvsig.publish.serversmodel.Service#getId()
150
	 */
151
	public String getId() {
152
		
153
		return "mapserver_wfs";
154
	}
155

  
156
	/*
157
	 * (non-Javadoc)
158
	 * @see org.gvsig.publish.serversmodel.Service#getRegisterTag()
159
	 */
160
	public String getRegisterTag() {		
161
		return REGISTER_TAG;
162
	}
163
	/*
164
	 * (non-Javadoc)
165
	 * @see org.gvsig.publish.ogcmetadata.IOGCServiceMetadata#getOnlineResource()
166
	 */
167
	public URL getOnlineResource() {		
168
		return ogcmetadata.getOnlineResource();
169
	}
170
	/*
171
	 * (non-Javadoc)
172
	 * @see org.gvsig.publish.ogcmetadata.IOGCServiceMetadata#setOnlineResource(java.net.URL)
173
	 */
174
	public void setOnlineResource(URL url) {
175
		ogcmetadata.setOnlineResource(url);
176
		
177
	}
178
	/*
179
	 * (non-Javadoc)
180
	 * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#getAbstract()
181
	 */
182
	public String getAbstract() {		
183
		return ogcmetadata.getAbstract();
184
	}
185
	/*
186
	 * (non-Javadoc)
187
	 * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#getName()
188
	 */
189
	public String getName() {		
190
		return ogcmetadata.getName();
191
	}
192
	/*
193
	 * (non-Javadoc)
194
	 * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#setAbstract(java.lang.String)
195
	 */
196
	public void setAbstract(String description) {
197
		ogcmetadata.setAbstract(description);		
198
	}
199
	/*
200
	 * (non-Javadoc)
201
	 * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#setName(java.lang.String)
202
	 */
203
	public void setName(String name) {
204
		ogcmetadata.setName(name);	
205
	}
206
	/*
207
	 * (non-Javadoc)
208
	 * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#setTitle(java.lang.String)
209
	 */
210
	public void setTitle(String title) {
211
		ogcmetadata.setTitle(title);		
212
	}
213
	/*
214
	 * (non-Javadoc)
215
	 * @see org.gvsig.publish.IPublishPersistence#getVersion()
216
	 */
217
	public int getVersion() {
218
		return 1;
219
	}
220
	/*
221
	 * (non-Javadoc)
222
	 * @see org.gvsig.publish.ogcmetadata.IOGCCommonMetadata#getTitle()
223
	 */
224
	public String getTitle() {		
225
		return ogcmetadata.getTitle();
226
	}
227
	/*
228
	 * (non-Javadoc)
229
	 * @see java.lang.Object#toString()
230
	 */
231
	public String toString(){
232
		return getRegisterTag();
233
	}
234
}
0 235

  
tags/gvsig_topologia-0_1_0-1235/extensions/extPublishMapserver/src/org/gvsig/publish/mapserver/model/MapserverLayer.java
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;
42

  
43

  
44
import com.iver.utiles.IPersistence;
45
import com.iver.utiles.XMLEntity;
46

  
47
public class MapserverLayer implements IPersistence {
48
	 
49
	
50
	private boolean isMosaic;
51
	
52

  
53
	public boolean isMosaic() {
54
		return isMosaic;
55
	}
56

  
57
	public void setMosaic(boolean isMosaic) {
58
		this.isMosaic = isMosaic;
59
	}
60
	
61
	public String getClassName() {		
62
		return "MapserverLayer";
63
	}
64
			
65
	/**
66
	 * This function initializes the object from the xml
67
	 * @param xml 
68
	 */
69
	public void setXMLEntity(XMLEntity xml) {
70
		//check version
71
		String version = xml.getName();
72
		if (!version.equals(getClassName())){
73
			return;
74
		}	
75
		//set properties
76
		setMosaic(xml.getBooleanProperty("ismosaic"));		
77
	}
78

  
79
	public XMLEntity getXMLEntity() {
80
		XMLEntity xml=new XMLEntity();
81
		//put version
82
		xml.setName(getClassName());
83
		//put properties
84
		xml.putProperty("ismosaic" , isMosaic());
85
		return xml;
86
	}
87

  
88
}
0 89

  
tags/gvsig_topologia-0_1_0-1235/extensions/extPublishMapserver/src/org/gvsig/publish/mapserver/model/Mapserver.java
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;
42

  
43
import java.io.File;
44
import java.io.FileNotFoundException;
45

  
46
import org.gvsig.publish.PublishLogger;
47
import org.gvsig.publish.exceptions.PublishException;
48
import org.gvsig.publish.mapserver.conf.FontsFile;
49
import org.gvsig.publish.mapserver.conf.MapFile;
50
import org.gvsig.publish.mapserver.conf.SymbolsFile;
51
import org.gvsig.publish.serversmodel.Server;
52

  
53
import com.iver.utiles.FileUtils;
54
import com.iver.utiles.NotExistInXMLEntity;
55
import com.iver.utiles.XMLEntity;
56
/**
57
 * Server that represents Mapserver
58
 * <p>
59
 * 
60
 * @author jvhigon
61
 *
62
 */
63
public class Mapserver extends Server {
64

  
65
	public static final String REGISTER_TAG="Mapserver 5.x";
66
	
67
	/*
68
	 * dependences
69
	 */
70
	private MapFile.ConfigFile config = null;
71
	private SymbolsFile.WellKnowSymbolsFile symbolsconfig = null;
72
	private FontsFile.WellKnowFontsFile fontsconfig=null;
73
	private File mapfile = null;
74
	private File symbolsfile = null;
75
	//private String symbolsfilename = null;	
76
	private File imagepath_file = null;
77
	private String shapepath=null;
78
	
79
	private boolean debug=false;
80
	/**
81
	 * Constructor
82
	 */
83
	public Mapserver(){
84
		super();		
85
	}
86
		
87
	/**
88
	 * Generates the publication in Mapserver.  
89
	 * TODO: at the moment, you only can publish its first service
90
	 * @see Server#publish()
91
	 */
92
	public String publish() throws PublishException {
93
		//creates the mapfile
94
		config = new MapFile.ConfigFile();
95
		//creates the symbols file
96
		symbolsconfig = new SymbolsFile.WellKnowSymbolsFile();
97
		//creates the fonts file
98
		fontsconfig = new FontsFile.WellKnowFontsFile();
99
		//check if there is anything to publish 		
100
		if (getService(0) == null){
101
			throw new PublishException("publishms_no_services_defined");
102
		}
103
		if (getService(0).getRemoteResourcesCount() == 0){
104
			throw new PublishException("publishms_nothing_to_publish");
105
		}
106
		//check if the mapfile is set
107
		if (getMapfileFile()==null){			
108
			throw new PublishException("publishms_the_mapfile_is_not_defined");
109
		}
110
		
111
		String aux = FileUtils.getFileWithoutExtension(getMapfileFile());		
112
		
113
		symbolsfile = new File(aux+".sym");
114
		symbolsconfig.generate(symbolsfile.getAbsolutePath());
115
		fontsconfig.generate(symbolsfile.getParent() + "/" + "fonts.txt");
116
		
117
		//creates IMAGEPATH
118
		if (getImagePath()!=null){
119
			config.web.imagepath = getImagePath().getAbsolutePath();
120
		}
121
		//creates the SHAPEPATH
122
		if(getShapepath() !=null){
123
			config.mapShapePath = getShapepath();
124
		}
125
		//debug 		
126
		config.debug = isDebug();
127
		
128
		//generates the mapfile object MAP
129
		generateMapObject();				
130
	
131
		//call publish() method publish of its services
132
		super.publish();
133
		//At the end write the configuration
134
		try {
135
			config.generate(getMapfileFile().getAbsolutePath(), "UTF-8");
136
		} catch (FileNotFoundException e) {
137
			throw new PublishException("publihsms_permission_denied"); 
138
		}
139
		//return message
140
		return "publishms_publish_message";
141
	}
142
	/**
143
	 * MAP
144
	 */
145
	private void generateMapObject() {		
146
		//set the map name 
147
		getConfigFile().mapName = "map_generated_by_gvsig";		
148
		//TODO: I must create the method ProjectInfo.getBoundingBox() with the larger bbox (of all the views)
149
		//At the moment I'm using the bbox of the first view
150
		getConfigFile().extent = getPublication().getProjectInfo().getViewsInfo()[0].getBBox();
151
		//set the relative path to symbolsfile
152
		
153
		getConfigFile().symbolset = symbolsfile.getName();
154
		getConfigFile().fontset = "fonts.txt";
155
		//set the absolute path to symbolsfile
156
		//getConfigFile().symbolset = symbolsfilename;
157
		//add projection object, the projection of the first view
158
		getConfigFile().projection = new MapFile.CRS(getPublication().getProjectInfo().getViewsInfo()[0].getEPSG(),true);		
159
	}
160
	
161

  
162
	/**
163
	 * check compatible	 
164
	 * 
165
	 */
166
	public void postInitialize() {
167
		// TODO Auto-generated method stub
168

  
169
	}
170
	/**
171
	 * 
172
	 * @return the mapfile
173
	 */
174
	public MapFile.ConfigFile getConfigFile(){		
175
		return config;
176
	}
177

  
178
	/**
179
	 * 
180
	 * @return mapfile File
181
	 */
182
	public File getMapfileFile(){
183
		return mapfile;
184
	}
185
	/**
186
	 * Sets the mapfile file
187
	 * @param 
188
	 */
189
	public void setMapfileFile(File file){
190
		mapfile = file;
191
	}
192
	
193
	/**
194
	 * Gets the IMAGEPATH
195
	 * @return
196
	 */
197
	public File getImagePath() {
198
		return imagepath_file;
199
	}
200
	/**
201
	 * Sets the IMAGEPATH directory 
202
	 * @param imagepath
203
	 */	
204
	public void setImagePath(File imagepath_file) {
205
		this.imagepath_file = imagepath_file;
206
	}
207
	
208
	
209
	public String getClassName() {
210
		return "Mapserver";
211
	}		
212
	/**
213
	 * Initializes the Mapserver
214
	 * @see Server#setXMLEntity(XMLEntity)
215
	 */
216
	public void setXMLEntity(XMLEntity xml) {
217
		//check version
218
		int version = xml.getIntProperty("version");
219
		if (version != getVersion()){
220
			PublishLogger.getLog().error("ERROR: " + getClassName() + ": the version doesn't match!");
221
			return;
222
		}	
223
		super.setXMLEntity(xml);
224
		//set mapfile
225
		try{
226
			String file = xml.getStringProperty("mapfile");
227
			setMapfileFile(new File(file));			
228
		}catch (NotExistInXMLEntity e){
229
			PublishLogger.getLog().warn("WARNING " + getClassName() + ":mapfile doesn't exist");
230
		}		
231
		//set imagepath
232
		String file = xml.getStringProperty("imagepath");
233
		if (file !=null)
234
			setImagePath(new File(file));
235
		//set shapepath		
236
		try{
237
			setShapepath(xml.getStringProperty("shapepath"));
238
		}catch (NotExistInXMLEntity e){
239
			PublishLogger.getLog().warn("WARNING Mapserver: the property shapepath doesn't exist");
240
		}
241
		setDebug(xml.getBooleanProperty("isdebug"));
242
	}
243
	/*
244
	 * (non-Javadoc)
245
	 * @see org.gvsig.publish.serversmodel.Server#getXMLEntity()
246
	 */
247
	public XMLEntity getXMLEntity() {
248
		XMLEntity xml=super.getXMLEntity();
249
		//put version and name 
250
		xml.setName(getClassName());
251
		xml.putProperty("version", getVersion());
252
		//put Mapserver properties
253
		if (getMapfileFile() != null)
254
			xml.putProperty("mapfile", getMapfileFile().getAbsolutePath());
255
			
256
		if (getImagePath() == null){
257
			xml.putProperty("imagepath", null);
258
		}else{
259
			xml.putProperty("imagepath", getImagePath().getAbsolutePath());
260
		}
261
		
262
		if (shapepath !=null){
263
			xml.putProperty("shapepath", shapepath);
264
		}
265
		xml.putProperty("isdebug", isDebug());
266
		return xml;
267
	}
268

  
269
	public String getShapepath() {
270
		return shapepath;
271
	}
272

  
273
	public void setShapepath(String shapepath) {
274
		this.shapepath = shapepath;
275
	}
276

  
277
	/*
278
	 * (non-Javadoc)
279
	 * @see org.gvsig.publish.serversmodel.Server#getId()
280
	 */
281
	public String getId() {
282
		
283
		return "mapserver_id";
284
	}
285

  
286
	/*
287
	 * (non-Javadoc)
288
	 * @see org.gvsig.publish.serversmodel.Server#getVersion()
289
	 */
290
	public int getVersion() {		
291
		return 1;
292
	}
293

  
294
	/*
295
	 * (non-Javadoc)
296
	 * @see org.gvsig.publish.serversmodel.Server#getRegisterTag()
297
	 */
298
	public String getRegisterTag() {
299
		return REGISTER_TAG;
300
	}
301
	
302
	/*
303
	 * (non-Javadoc)
304
	 * @see java.lang.Object#toString()
305
	 */
306
	public String toString(){
307
		return getRegisterTag();
308
	}
309
	/**
310
	 * @return the debug
311
	 */
312
	public boolean isDebug() {
313
		return debug;
314
	}
315
	/**
316
	 * @param debug the debug to set
317
	 */
318
	public void setDebug(boolean debug) {
319
		this.debug = debug;
320
	}
321

  
322
}
0 323

  
tags/gvsig_topologia-0_1_0-1235/extensions/extPublishMapserver/src/org/gvsig/publish/mapserver/model/wms/MapserverWMSLayer.java
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
import java.awt.Color;
44
import java.awt.geom.Rectangle2D;
45
import java.io.File;
46
import java.io.IOException;
47

  
48
import org.gvsig.publish.PublishLogger;
49
import org.gvsig.publish.exceptions.PublishException;
50
import org.gvsig.publish.infoproject.IDataSourceInfo;
51
import org.gvsig.publish.infoproject.ILabelingInfo;
52
import org.gvsig.publish.infoproject.ILayerInfo;
53
import org.gvsig.publish.infoproject.ISymbolInfo;
54
import org.gvsig.publish.infoproject.datasources.IDataBaseInfo;
55
import org.gvsig.publish.infoproject.legends.IIntervalLegendInfo;
56
import org.gvsig.publish.infoproject.legends.ISingleSymbolLegendInfo;
57
import org.gvsig.publish.infoproject.legends.IUniqueValuesLegendInfo;
58
import org.gvsig.publish.infoproject.symbols.IFillSymbolInfo;
59
import org.gvsig.publish.infoproject.symbols.ILineSymbolInfo;
60
import org.gvsig.publish.infoproject.symbols.IMarkerSymbolInfo;
61
import org.gvsig.publish.infoproject.symbols.ITextSymbolInfo;
62
import org.gvsig.publish.mapserver.conf.MapFile;
63
import org.gvsig.publish.mapserver.conf.MapFile.CRS;
64
import org.gvsig.publish.mapserver.conf.MapFile.ConfigFile;
65
import org.gvsig.publish.mapserver.conf.MapFile.Label;
66
import org.gvsig.publish.mapserver.conf.MapFile.Layer;
67
import org.gvsig.publish.mapserver.conf.MapFile.MapClass;
68
import org.gvsig.publish.mapserver.conf.MapFile.RGB;
69
import org.gvsig.publish.mapserver.conf.MapFile.StyleMap;
70
import org.gvsig.publish.mapserver.model.Mapserver;
71
import org.gvsig.publish.mapserver.model.MapserverLayer;
72
import org.gvsig.publish.mapserver.util.MapserverUtilities;
73
import org.gvsig.publish.ogcmetadata.IOGCLayerMetadata;
74
import org.gvsig.publish.ogcmetadata.OGCLayerMetadata;
75
import org.gvsig.publish.serversmodel.RemoteResource;
76

  
77
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
78

  
79
import com.iver.utiles.FileUtils;
80
import com.iver.utiles.XMLEntity;
81
/**
82
 * This class represents a kind of remote resource, a Mapserver-WMS layer.   
83
 * 
84
 * @author jvhigon
85
 *
86
 */
87
public class MapserverWMSLayer extends RemoteResource implements IOGCLayerMetadata{
88
	public static final String REGISTER_TAG="mapserver_wms_layer";
89
	//Associations	
90
	private OGCLayerMetadata ogcmetadata = null;
91
	private MapserverLayer specificParams = null;
92
	private MapFile.Layer config = null;
93
	/**
94
	 * Constructor
95
	 * @param service
96
	 */
97
	public MapserverWMSLayer(MapserverWMS service){
98
		super(service);		
99
		ogcmetadata = new OGCLayerMetadata();
100
		specificParams = new MapserverLayer();			
101
	}
102

  
103
	public MapserverLayer getLayerMapserver() {
104
		return specificParams;
105
	}
106

  
107
	public void setLayerMapserver(MapserverLayer layerMapserver) {
108
		this.specificParams = layerMapserver;
109
	}
110

  
111
	private ConfigFile getMapfile(){
112
		MapserverWMS wms = (MapserverWMS)getService();
113
		Mapserver server = (Mapserver) wms.getServer();
114
		return server.getConfigFile();
115
	}
116

  
117

  
118
	/**
119
	 * Initializes the remote resource name and title with the name and title of the layer
120
	 */
121
	public void setLayerInfo(ILayerInfo layerInfo) {
122
		super.setLayerInfo(layerInfo);
123
		setName(getLayerInfo().getName());
124
		setTitle(getLayerInfo().getTitle());
125
		setAbstract("generated by gvSIG");
126
	}
127

  
128
	private Mapserver getMapServer(){
129
		//Cast to Mapserver
130
		Mapserver mapserver = (Mapserver)getService().getServer();
131
		return mapserver;
132
	}
133
	/**
134
	 * Generates a new layer configuration in the mapfile when is invoked
135
	 * @see org.gvsig.publish.serversmodel.RemoteResource#publish()
136
	 */
137
	public void publish() throws PublishException{
138
		//only for no group layers
139
		//TODO: wms_group_abstract ...
140

  
141
		if (getLayerInfo().getDataSource() != null){
142
			config = new MapFile.Layer();
143
			getMapfile().add(config);
144
			generateLayerSection();
145
		}
146
		//publish all its childs		
147
		super.publish();
148
	}
149

  
150
	private void generateLayerSection() throws PublishException{		
151

  
152
		config.name = getName();
153
		config.status = "ON";
154
		config.debug = getMapServer().isDebug();
155
		config.type = MapserverUtilities.getTypeParameter(getLayerInfo().getDataSource());
156
		generateDataParameter();		
157
		config.connectiontype = MapserverUtilities.getConnectionTypeParameter(getLayerInfo().getDataSource());
158
		config.connection = MapserverUtilities.getConnectionParameter(getLayerInfo().getDataSource());		
159
		config.maxscale = new Double(getLayerInfo().getMaxscale()).toString();
160
		config.minscale = new Double(getLayerInfo().getMinscale()).toString();
161
		config.transparency = getLayerInfo().getOpacityPercent();
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff