Revision 21391 branches/v10/extensions/extPublishMapserver/src/org/gvsig/publish/mapserver/model/wfs/MapserverWFSLayer.java
MapserverWFSLayer.java | ||
---|---|---|
46 | 46 |
import org.gvsig.publish.infoproject.IDataSourceInfo; |
47 | 47 |
import org.gvsig.publish.infoproject.ILayerInfo; |
48 | 48 |
import org.gvsig.publish.infoproject.datasources.IDataBaseInfo; |
49 |
import org.gvsig.publish.infoproject.datasources.IFileInfo;
|
|
49 |
import org.gvsig.publish.mapserver.conf.MapFile;
|
|
50 | 50 |
import org.gvsig.publish.mapserver.conf.MapFile.CRS; |
51 |
import org.gvsig.publish.mapserver.conf.MapFile.ConfigFile; |
|
52 |
import org.gvsig.publish.mapserver.conf.MapFile.MapLayer; |
|
53 |
import org.gvsig.publish.mapserver.conf.MapFile.PostgisLayer; |
|
54 |
import org.gvsig.publish.mapserver.conf.MapFile.ShpLayer; |
|
51 |
import org.gvsig.publish.mapserver.conf.MapFile.Layer; |
|
55 | 52 |
import org.gvsig.publish.mapserver.model.Mapserver; |
56 | 53 |
import org.gvsig.publish.mapserver.util.MapserverUtilities; |
57 | 54 |
import org.gvsig.publish.ogcmetadata.IOGCCommonMetadata; |
... | ... | |
66 | 63 |
public final static String REGISTER_TAG="mapserver_wfs_feature"; |
67 | 64 |
//associations |
68 | 65 |
private OGCCommonMetadata ogcMetadata = null; |
66 |
private MapFile.Layer config = null; |
|
69 | 67 |
/** |
70 | 68 |
* Constructor |
71 | 69 |
* |
... | ... | |
73 | 71 |
*/ |
74 | 72 |
public MapserverWFSLayer(MapserverWFS service) { |
75 | 73 |
super(service); |
76 |
ogcMetadata = new OGCCommonMetadata(); |
|
74 |
ogcMetadata = new OGCCommonMetadata();
|
|
77 | 75 |
} |
78 | 76 |
|
79 | 77 |
/** |
... | ... | |
91 | 89 |
* (non-Javadoc) |
92 | 90 |
* @see org.gvsig.publish.serversmodel.RemoteResource#publish() |
93 | 91 |
*/ |
94 |
public void publish() throws PublishException { |
|
95 |
IDataSourceInfo dataSource = getLayerInfo().getDataSource(); |
|
96 |
|
|
97 |
if (dataSource != null){ |
|
98 |
|
|
99 |
if (dataSource.getType() == IDataSourceInfo.SHAPE_TYPE){ |
|
100 |
generateShapeLayer(dataSource); |
|
101 |
} |
|
102 |
if (dataSource.getType() == IDataSourceInfo.POSTGIS_TYPE){ |
|
103 |
generatePostGISLayer(dataSource); |
|
104 |
} |
|
92 |
public void publish() throws PublishException { |
|
93 |
if (config==null){ |
|
94 |
config = new MapFile.Layer(); |
|
95 |
getMapServer().getConfigFile().add(config); |
|
105 | 96 |
} |
97 |
generateLayerSection(); |
|
106 | 98 |
//publish all its childs |
107 | 99 |
super.publish(); |
108 | 100 |
|
109 | 101 |
} |
102 |
private void generateLayerSection() throws PublishException{ |
|
103 |
//LAYER |
|
104 |
config.name = getName(); |
|
105 |
config.status = "ON"; |
|
106 |
config.debug = getMapServer().isDebug(); |
|
107 |
config.type = MapserverUtilities.getTypeParameter(getLayerInfo().getDataSource()); |
|
108 |
generateDataParameter(); |
|
109 |
config.connectiontype = MapserverUtilities.getConnectionTypeParameter(getLayerInfo().getDataSource()); |
|
110 |
config.connection = MapserverUtilities.getConnectionParameter(getLayerInfo().getDataSource()); |
|
111 |
config.dump = true; |
|
112 |
|
|
113 |
//PROJECTION |
|
114 |
config.layercrs = new CRS(getLayerInfo().getDataSource().getEPSG(),true); |
|
115 |
//METADATA |
|
116 |
generateMetadata(config); |
|
117 |
|
|
118 |
} |
|
119 |
/** |
|
120 |
* Generates the LAYER->DATA parameter |
|
121 |
*/ |
|
122 |
private void generateDataParameter() { |
|
123 |
IDataSourceInfo ds = getLayerInfo().getDataSource(); |
|
124 |
if (ds.getType() == IDataSourceInfo.POSTGIS_TYPE){ |
|
125 |
IDataBaseInfo db = (IDataBaseInfo)ds; |
|
126 |
String table = db.getTableName(); |
|
127 |
config.data ="the_geom from " + table + " using unique " + db.getGID() + " using srid=" + ds.getSRID(); |
|
128 |
}else{ |
|
129 |
config.data = getService().getServer().getPublication().getServerSideFilePath(ds); |
|
130 |
} |
|
131 |
} |
|
132 |
|
|
110 | 133 |
private Mapserver getMapServer(){ |
111 | 134 |
//Cast to Mapserver |
112 | 135 |
Mapserver mapserver = (Mapserver)getService().getServer(); |
113 | 136 |
return mapserver; |
114 | 137 |
} |
115 |
private void generatePostGISLayer(IDataSourceInfo dataSource) { |
|
116 |
//get the mapfile |
|
117 |
ConfigFile mapfile = ((Mapserver)getService().getServer()).getConfigFile(); |
|
118 |
IDataBaseInfo db = (IDataBaseInfo)dataSource; |
|
119 |
// //LAYER |
|
120 |
PostgisLayer lyr = new PostgisLayer(); |
|
121 |
lyr.name = getName(); |
|
122 |
lyr.data = db.getGeometryColumn() + " from " + db.getTableName() + " using unique " + db.getGID(); |
|
123 |
lyr.host =db.getHost(); |
|
124 |
lyr.user =db.getUser(); |
|
125 |
lyr.pass = db.getPassword(); |
|
126 |
lyr.dbname =db.getDatabaseName(); |
|
127 |
lyr.port = db.getPort(); |
|
128 |
lyr.type = dataSource.getDataType(); |
|
129 |
lyr.dump = true; |
|
130 |
|
|
131 |
//PROJECTION (I get the srid from the geometry_columns) |
|
132 |
lyr.layercrs = new CRS(dataSource.getEPSG(),true); |
|
133 |
//METADATA |
|
134 |
generateMetadata(lyr); |
|
135 |
lyr.metadata.wfs_featureid = ((IDataBaseInfo) getLayerInfo().getDataSource()).getGID(); |
|
136 |
|
|
137 |
//adds the layer into the map |
|
138 |
mapfile.add(lyr); |
|
139 |
} |
|
140 |
|
|
141 |
private void generateShapeLayer(IDataSourceInfo dataSource) { |
|
142 |
//get the mapfile |
|
143 |
ConfigFile mapfile = ((Mapserver)getService().getServer()).getConfigFile(); |
|
144 |
//get the file |
|
145 |
IFileInfo file = (IFileInfo)dataSource; |
|
146 |
//LAYER |
|
147 |
ShpLayer lyr = new ShpLayer(); |
|
148 |
lyr.name = getName(); |
|
149 |
lyr.data = MapserverUtilities.getDataPath(file.getAbsolutePath(), getMapServer().getShapepath(), getMapServer().getLocalMountPoint()); |
|
150 |
lyr.type = dataSource.getDataType(); |
|
151 |
lyr.dump = true; |
|
152 |
//lyr.maxscale = new Double(getLayerInfo().getMaxscale()).toString(); |
|
153 |
//lyr.minscale = new Double(getLayerInfo().getMinscale()).toString(); |
|
154 |
//PROJECTION (I must query the layer to know the shape projection) |
|
155 |
lyr.layercrs = new CRS(getLayerInfo().getEPSGString(),true); |
|
156 |
//METADATA |
|
157 |
generateMetadata(lyr); |
|
158 |
//adds the layer into the map |
|
159 |
mapfile.add(lyr); |
|
160 |
} |
|
161 |
/** |
|
138 |
/** |
|
162 | 139 |
* Generates the METADATA object |
163 | 140 |
* @param mapLayer |
164 | 141 |
*/ |
165 |
private void generateMetadata(MapLayer mapLayer){
|
|
142 |
private void generateMetadata(Layer mapLayer){ |
|
166 | 143 |
//add metadata |
167 | 144 |
mapLayer.metadata.wfs_name = getName(); |
168 | 145 |
mapLayer.metadata.wfs_title = getTitle(); |
Also available in: Unified diff