root / branches / v10 / extensions / extPublishMapserver / src / org / gvsig / publish / mapserver / model / Mapserver.java @ 17833
History | View | Annotate | Download (6.38 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 |
|
45 |
import org.gvsig.publish.PublishLogger; |
46 |
import org.gvsig.publish.mapserver.conf.MapFile; |
47 |
import org.gvsig.publish.mapserver.conf.SymbolsFile; |
48 |
import org.gvsig.publish.serversmodel.PublishException; |
49 |
import org.gvsig.publish.serversmodel.Server; |
50 |
|
51 |
import com.iver.andami.PluginServices; |
52 |
import com.iver.utiles.FileUtils; |
53 |
import com.iver.utiles.NotExistInXMLEntity; |
54 |
import com.iver.utiles.XMLEntity; |
55 |
/**
|
56 |
* Server that represents Mapserver
|
57 |
* <p>
|
58 |
*
|
59 |
* @author jvhigon
|
60 |
*
|
61 |
*/
|
62 |
public class Mapserver extends Server { |
63 |
|
64 |
/*
|
65 |
* Constant to identify the server
|
66 |
*/
|
67 |
public static final String SERVER_MAPSERVER = "Mapserver"; |
68 |
/*
|
69 |
* dependences
|
70 |
*/
|
71 |
private MapFile.ConfigFile mapfile = null; |
72 |
private File mapfile_file = null; |
73 |
private String symbolsfilename = null; |
74 |
private File imagepath_file = null; |
75 |
private String shapepath=null; |
76 |
/**
|
77 |
* Constructor
|
78 |
*/
|
79 |
public Mapserver(){
|
80 |
super();
|
81 |
setTitle(getType()); |
82 |
} |
83 |
|
84 |
/**
|
85 |
* @return String to identify Mapserver
|
86 |
* @see Server#getType()
|
87 |
*/
|
88 |
public String getType() { |
89 |
return SERVER_MAPSERVER;
|
90 |
} |
91 |
/**
|
92 |
* Generates the publication in Mapserver.
|
93 |
* @see Server#publish()
|
94 |
*/
|
95 |
public void publish() throws PublishException { |
96 |
|
97 |
//check if there is anything to publish
|
98 |
if (getProjectInfo() == null){ |
99 |
throw new PublishException(PluginServices.getText(this,"nothing_to_publish")); |
100 |
} |
101 |
//check if the mapfile is set
|
102 |
if (getMapfileFile()==null){ |
103 |
throw new PublishException(PluginServices.getText(this,"the_mapfile_is_not_defined")); |
104 |
} |
105 |
|
106 |
//creates the mapfile
|
107 |
mapfile = new MapFile.ConfigFile();
|
108 |
|
109 |
//creates the symbols file
|
110 |
String aux = FileUtils.getFileWithoutExtension(getMapfileFile());
|
111 |
symbolsfilename = aux + ".sym";
|
112 |
SymbolsFile.WellKnowSymbolsFile symbolsfile = new SymbolsFile.WellKnowSymbolsFile();
|
113 |
symbolsfile.generate(symbolsfilename); |
114 |
|
115 |
//creates IMAGEPATH
|
116 |
if (getImagePath()!=null){ |
117 |
mapfile.web.imagepath = getImagePath().getAbsolutePath(); |
118 |
} |
119 |
//creates the SHAPEPATH
|
120 |
if(getShapepath() !=null){ |
121 |
mapfile.mapShapePath = getShapepath(); |
122 |
} |
123 |
//generates the mapfile object MAP
|
124 |
generateMapObject(); |
125 |
|
126 |
//call publish() method publish of its services
|
127 |
super.publish();
|
128 |
//At the end write the configuration
|
129 |
mapfile.generate(getMapfileFile().getAbsolutePath()); |
130 |
} |
131 |
/**
|
132 |
* MAP
|
133 |
*/
|
134 |
private void generateMapObject() { |
135 |
//set the map name
|
136 |
getConfigFile().mapName = getTitle(); |
137 |
//TODO: I must create the method ProjectInfo.getBoundingBox() with the larger bbox (of all the views)
|
138 |
//At the moment I'm using the bbox of the first view
|
139 |
getConfigFile().extent = getProjectInfo().getViewsInfo()[0].getBBox();
|
140 |
//set the relative path to symbolsfile
|
141 |
String aux[] = symbolsfilename.split(File.separator); |
142 |
getConfigFile().symbolset = aux[aux.length -1];
|
143 |
//set the absolute path to symbolsfile
|
144 |
//getConfigFile().symbolset = symbolsfilename;
|
145 |
//add projection object, the projection of the first view
|
146 |
getConfigFile().projection = new MapFile.CRS(getProjectInfo().getViewsInfo()[0].getEPSG(),true); |
147 |
} |
148 |
|
149 |
|
150 |
/**
|
151 |
* check compatible
|
152 |
*
|
153 |
*/
|
154 |
public void postInitialize() { |
155 |
// TODO Auto-generated method stub
|
156 |
|
157 |
} |
158 |
/**
|
159 |
*
|
160 |
* @return the mapfile
|
161 |
*/
|
162 |
public MapFile.ConfigFile getConfigFile(){
|
163 |
return mapfile;
|
164 |
} |
165 |
|
166 |
/**
|
167 |
*
|
168 |
* @return mapfile File
|
169 |
*/
|
170 |
public File getMapfileFile(){ |
171 |
return mapfile_file;
|
172 |
} |
173 |
/**
|
174 |
* Sets the mapfile file
|
175 |
* @param
|
176 |
*/
|
177 |
public void setMapfileFile(File file){ |
178 |
mapfile_file = file; |
179 |
} |
180 |
|
181 |
/**
|
182 |
* Gets the IMAGEPATH
|
183 |
* @return
|
184 |
*/
|
185 |
public File getImagePath() { |
186 |
return imagepath_file;
|
187 |
} |
188 |
/**
|
189 |
* Sets the IMAGEPATH directory
|
190 |
* @param imagepath
|
191 |
*/
|
192 |
public void setImagePath(File imagepath_file) { |
193 |
this.imagepath_file = imagepath_file;
|
194 |
} |
195 |
|
196 |
|
197 |
public String getClassName() { |
198 |
return "Mapserver_v1"; |
199 |
} |
200 |
/**
|
201 |
* Initializes the Mapserver
|
202 |
* @see Server#setXMLEntity(XMLEntity)
|
203 |
*/
|
204 |
public void setXMLEntity(XMLEntity xml) { |
205 |
//check version
|
206 |
String classid = xml.getStringProperty("className"); |
207 |
if (!classid.equals(getClassName())){
|
208 |
return;
|
209 |
} |
210 |
super.setXMLEntity(xml);
|
211 |
String file = xml.getStringProperty("mapfile"); |
212 |
//TODO check the creation of the file
|
213 |
setMapfileFile(new File(file)); |
214 |
file = xml.getStringProperty("imagepath");
|
215 |
if (file !=null) |
216 |
setImagePath(new File(file)); |
217 |
try{
|
218 |
setShapepath(xml.getStringProperty("shapepath"));
|
219 |
}catch (NotExistInXMLEntity e){
|
220 |
PublishLogger.getLog().warn("WARNING Mapserver: the property shapepath doesn't exist");
|
221 |
} |
222 |
|
223 |
} |
224 |
/**
|
225 |
* Gets the xmlEntity from Server and put its specific properties
|
226 |
* @see Server#getXMLEntity()
|
227 |
*/
|
228 |
public XMLEntity getXMLEntity() {
|
229 |
XMLEntity xml=super.getXMLEntity();
|
230 |
//put version
|
231 |
xml.putProperty("className", getClassName());
|
232 |
//put Mapserver properties
|
233 |
if (getMapfileFile() != null) |
234 |
xml.putProperty("mapfile", getMapfileFile().toString());
|
235 |
|
236 |
if (getImagePath() == null){ |
237 |
xml.putProperty("imagepath", null); |
238 |
}else{
|
239 |
xml.putProperty("imagepath", getImagePath().toString());
|
240 |
} |
241 |
if (shapepath !=null){ |
242 |
xml.putProperty("shapepath", shapepath);
|
243 |
} |
244 |
return xml;
|
245 |
} |
246 |
|
247 |
public String getShapepath() { |
248 |
return shapepath;
|
249 |
} |
250 |
|
251 |
public void setShapepath(String shapepath) { |
252 |
this.shapepath = shapepath;
|
253 |
} |
254 |
|
255 |
} |