svn-gvsig-desktop / trunk / extensions / extPublishMapserver / src / org / gvsig / publish / mapserver / model / Mapserver.java @ 32205
History | View | Annotate | Download (8.43 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; |
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.mapserver.conf.MapFile.ConfigFile; |
52 |
import org.gvsig.publish.serversmodel.PublicationProcess; |
53 |
import org.gvsig.publish.serversmodel.Server; |
54 |
|
55 |
import com.iver.utiles.FileUtils; |
56 |
import com.iver.utiles.NotExistInXMLEntity; |
57 |
import com.iver.utiles.XMLEntity; |
58 |
/**
|
59 |
* Server that represents Mapserver
|
60 |
* <p>
|
61 |
*
|
62 |
* @author jvhigon
|
63 |
*
|
64 |
*/
|
65 |
public class Mapserver extends Server { |
66 |
|
67 |
public static final String REGISTER_TAG="Mapserver 5.x"; |
68 |
|
69 |
private MapserverProcess process =null; |
70 |
/*
|
71 |
* dependences
|
72 |
*/
|
73 |
private MapFile.ConfigFile config = null; |
74 |
private SymbolsFile.WellKnowSymbolsFile symbolsconfig = null; |
75 |
private FontsFile.WellKnowFontsFile fontsconfig=null; |
76 |
private File mapfile = null; |
77 |
private File symbolsfile = null; |
78 |
//private String symbolsfilename = null;
|
79 |
private File imagepath_file = null; |
80 |
private String shapepath=null; |
81 |
|
82 |
private boolean debug=false; |
83 |
/**
|
84 |
* Constructor
|
85 |
*/
|
86 |
public Mapserver(){
|
87 |
super();
|
88 |
} |
89 |
|
90 |
/**
|
91 |
* Generates the publication in Mapserver.
|
92 |
* TODO: at the moment, you only can publish its first service
|
93 |
* @see Server#publish()
|
94 |
*/
|
95 |
public String publish() throws PublishException { |
96 |
//creates the mapfile
|
97 |
config = new MapFile.ConfigFile();
|
98 |
//creates the symbols file
|
99 |
symbolsconfig = new SymbolsFile.WellKnowSymbolsFile();
|
100 |
//creates the fonts file
|
101 |
fontsconfig = new FontsFile.WellKnowFontsFile();
|
102 |
//check if there is anything to publish
|
103 |
if (getService(0) == null){ |
104 |
throw new PublishException("publishms_no_services_defined"); |
105 |
} |
106 |
if (getService(0).getRemoteResourcesCount() == 0){ |
107 |
throw new PublishException("publishms_nothing_to_publish"); |
108 |
} |
109 |
//check if the mapfile is set
|
110 |
if (getMapfileFile()==null){ |
111 |
throw new PublishException("publishms_the_mapfile_is_not_defined"); |
112 |
} |
113 |
|
114 |
String aux = FileUtils.getFileWithoutExtension(getMapfileFile());
|
115 |
|
116 |
symbolsfile = new File(aux+".sym"); |
117 |
symbolsconfig.generate(symbolsfile.getAbsolutePath()); |
118 |
fontsconfig.generate(symbolsfile.getParent() + "/" + "fonts.txt"); |
119 |
|
120 |
//creates IMAGEPATH
|
121 |
if (getImagePath()!=null){ |
122 |
config.web.imagepath = getImagePath().getAbsolutePath(); |
123 |
} |
124 |
//creates the SHAPEPATH
|
125 |
if(getShapepath() !=null){ |
126 |
config.mapShapePath = getShapepath(); |
127 |
} |
128 |
//debug
|
129 |
config.debug = isDebug(); |
130 |
|
131 |
//generates the mapfile object MAP
|
132 |
generateMapObject(); |
133 |
|
134 |
//call publish() method publish of its services
|
135 |
super.publish();
|
136 |
//At the end write the configuration
|
137 |
try {
|
138 |
config.generate(getMapfileFile().getAbsolutePath(), "UTF-8");
|
139 |
} catch (FileNotFoundException e) { |
140 |
throw new PublishException("publihsms_permission_denied"); |
141 |
} |
142 |
//return message
|
143 |
return "publishms_publish_message"; |
144 |
} |
145 |
/**
|
146 |
* MAP
|
147 |
*/
|
148 |
private void generateMapObject() { |
149 |
//set the map name
|
150 |
getConfigFile().mapName = "map_generated_by_gvsig";
|
151 |
//TODO: I must create the method ProjectInfo.getBoundingBox() with the larger bbox (of all the views)
|
152 |
//At the moment I'm using the bbox of the first view
|
153 |
getConfigFile().extent = getPublication().getProjectInfo().getViewsInfo()[0].getBBox();
|
154 |
//set the relative path to symbolsfile
|
155 |
|
156 |
getConfigFile().symbolset = symbolsfile.getName(); |
157 |
getConfigFile().fontset = "fonts.txt";
|
158 |
//set the absolute path to symbolsfile
|
159 |
//getConfigFile().symbolset = symbolsfilename;
|
160 |
//add projection object, the projection of the first view
|
161 |
getConfigFile().projection = new MapFile.CRS(getPublication().getProjectInfo().getViewsInfo()[0].getEPSG(),true); |
162 |
} |
163 |
|
164 |
|
165 |
/**
|
166 |
* check compatible
|
167 |
*
|
168 |
*/
|
169 |
public void postInitialize() { |
170 |
// TODO Auto-generated method stub
|
171 |
|
172 |
} |
173 |
/**
|
174 |
*
|
175 |
* @return the mapfile
|
176 |
*/
|
177 |
public MapFile.ConfigFile getConfigFile(){
|
178 |
return config;
|
179 |
} |
180 |
|
181 |
/**
|
182 |
*
|
183 |
* @return mapfile File
|
184 |
*/
|
185 |
public File getMapfileFile(){ |
186 |
return mapfile;
|
187 |
} |
188 |
/**
|
189 |
* Sets the mapfile file
|
190 |
* @param
|
191 |
*/
|
192 |
public void setMapfileFile(File file){ |
193 |
mapfile = file; |
194 |
} |
195 |
|
196 |
/**
|
197 |
* Gets the IMAGEPATH
|
198 |
* @return
|
199 |
*/
|
200 |
public File getImagePath() { |
201 |
return imagepath_file;
|
202 |
} |
203 |
/**
|
204 |
* Sets the IMAGEPATH directory
|
205 |
* @param imagepath
|
206 |
*/
|
207 |
public void setImagePath(File imagepath_file) { |
208 |
this.imagepath_file = imagepath_file;
|
209 |
} |
210 |
|
211 |
|
212 |
public String getClassName() { |
213 |
return "Mapserver"; |
214 |
} |
215 |
/**
|
216 |
* Initializes the Mapserver
|
217 |
* @see Server#setXMLEntity(XMLEntity)
|
218 |
*/
|
219 |
public void setXMLEntity(XMLEntity xml) { |
220 |
//check version
|
221 |
int version = xml.getIntProperty("version"); |
222 |
if (version != getVersion()){
|
223 |
PublishLogger.getLog().error("ERROR: " + getClassName() + ": the version doesn't match!"); |
224 |
return;
|
225 |
} |
226 |
super.setXMLEntity(xml);
|
227 |
//set mapfile
|
228 |
try{
|
229 |
String file = xml.getStringProperty("mapfile"); |
230 |
setMapfileFile(new File(file)); |
231 |
}catch (NotExistInXMLEntity e){
|
232 |
PublishLogger.getLog().warn("WARNING " + getClassName() + ":mapfile doesn't exist"); |
233 |
} |
234 |
//set imagepath
|
235 |
String file = xml.getStringProperty("imagepath"); |
236 |
if (file !=null) |
237 |
setImagePath(new File(file)); |
238 |
//set shapepath
|
239 |
try{
|
240 |
setShapepath(xml.getStringProperty("shapepath"));
|
241 |
}catch (NotExistInXMLEntity e){
|
242 |
PublishLogger.getLog().warn("WARNING Mapserver: the property shapepath doesn't exist");
|
243 |
} |
244 |
setDebug(xml.getBooleanProperty("isdebug"));
|
245 |
} |
246 |
/*
|
247 |
* (non-Javadoc)
|
248 |
* @see org.gvsig.publish.serversmodel.Server#getXMLEntity()
|
249 |
*/
|
250 |
public XMLEntity getXMLEntity() {
|
251 |
XMLEntity xml=super.getXMLEntity();
|
252 |
//put version and name
|
253 |
xml.setName(getClassName()); |
254 |
xml.putProperty("version", getVersion());
|
255 |
//put Mapserver properties
|
256 |
if (getMapfileFile() != null) |
257 |
xml.putProperty("mapfile", getMapfileFile().getAbsolutePath());
|
258 |
|
259 |
if (getImagePath() == null){ |
260 |
xml.putProperty("imagepath", null); |
261 |
}else{
|
262 |
xml.putProperty("imagepath", getImagePath().getAbsolutePath());
|
263 |
} |
264 |
|
265 |
if (shapepath !=null){ |
266 |
xml.putProperty("shapepath", shapepath);
|
267 |
} |
268 |
xml.putProperty("isdebug", isDebug());
|
269 |
return xml;
|
270 |
} |
271 |
|
272 |
public String getShapepath() { |
273 |
return shapepath;
|
274 |
} |
275 |
|
276 |
public void setShapepath(String shapepath) { |
277 |
this.shapepath = shapepath;
|
278 |
} |
279 |
|
280 |
/*
|
281 |
* (non-Javadoc)
|
282 |
* @see org.gvsig.publish.serversmodel.Server#getId()
|
283 |
*/
|
284 |
public String getId() { |
285 |
|
286 |
return "mapserver_id"; |
287 |
} |
288 |
|
289 |
/*
|
290 |
* (non-Javadoc)
|
291 |
* @see org.gvsig.publish.serversmodel.Server#getVersion()
|
292 |
*/
|
293 |
public int getVersion() { |
294 |
return 1; |
295 |
} |
296 |
|
297 |
/*
|
298 |
* (non-Javadoc)
|
299 |
* @see org.gvsig.publish.serversmodel.Server#getRegisterTag()
|
300 |
*/
|
301 |
public String getRegisterTag() { |
302 |
return REGISTER_TAG;
|
303 |
} |
304 |
|
305 |
/*
|
306 |
* (non-Javadoc)
|
307 |
* @see java.lang.Object#toString()
|
308 |
*/
|
309 |
public String toString(){ |
310 |
return getRegisterTag();
|
311 |
} |
312 |
/**
|
313 |
* @return the debug
|
314 |
*/
|
315 |
public boolean isDebug() { |
316 |
return debug;
|
317 |
} |
318 |
/**
|
319 |
* @param debug the debug to set
|
320 |
*/
|
321 |
public void setDebug(boolean debug) { |
322 |
this.debug = debug;
|
323 |
} |
324 |
/*
|
325 |
* (non-Javadoc)
|
326 |
* @see org.gvsig.publish.serversmodel.Server#getPublicationProcess()
|
327 |
*/
|
328 |
public PublicationProcess getPublicationProcess() {
|
329 |
//if (process == null){
|
330 |
process = new MapserverProcess(this); |
331 |
//}
|
332 |
return process;
|
333 |
} |
334 |
|
335 |
public void setConfigFile(ConfigFile mapfile2) { |
336 |
this.config = mapfile2;
|
337 |
} |
338 |
|
339 |
} |