gvsig-publish / org.gvsig.publish / trunk / org.gvsig.publish / org.gvsig.publish.mapserver / org.gvsig.publish.lib.impl.mapserver / src / main / java / org / gvsig / publish / impl / mapserver / utils / MapServer.java @ 152
History | View | Annotate | Download (80.3 KB)
1 |
package org.gvsig.publish.impl.mapserver.utils; |
---|---|
2 |
|
3 |
import java.io.BufferedReader; |
4 |
import java.io.BufferedWriter; |
5 |
import java.io.File; |
6 |
import java.io.FileInputStream; |
7 |
import java.io.FileNotFoundException; |
8 |
import java.io.FileOutputStream; |
9 |
import java.io.FileWriter; |
10 |
import java.io.IOException; |
11 |
import java.io.InputStream; |
12 |
import java.io.InputStreamReader; |
13 |
import java.io.PrintWriter; |
14 |
import java.net.URL; |
15 |
import java.net.URLConnection; |
16 |
import java.util.ArrayList; |
17 |
import java.util.Arrays; |
18 |
import java.util.Iterator; |
19 |
import java.util.List; |
20 |
|
21 |
import javax.activation.MimetypesFileTypeMap; |
22 |
import javax.swing.JCheckBox; |
23 |
import javax.swing.JOptionPane; |
24 |
import javax.xml.bind.JAXBContext; |
25 |
import javax.xml.bind.JAXBException; |
26 |
import javax.xml.bind.Marshaller; |
27 |
import javax.xml.transform.Result; |
28 |
import javax.xml.transform.Source; |
29 |
import javax.xml.transform.Transformer; |
30 |
import javax.xml.transform.TransformerFactory; |
31 |
import javax.xml.transform.stream.StreamResult; |
32 |
import javax.xml.transform.stream.StreamSource; |
33 |
|
34 |
import org.apache.commons.io.FileUtils; |
35 |
import org.apache.commons.lang.StringUtils; |
36 |
import org.cresques.cts.IDatum; |
37 |
import org.cresques.cts.IProjection; |
38 |
import org.gvsig.app.project.documents.view.ViewDocument; |
39 |
import org.gvsig.complexlabel.impl.DefaultComplexLabelClass; |
40 |
import org.gvsig.complexlegend.ComplexLegendItem; |
41 |
import org.gvsig.complexlegend.VectorComplexLegend; |
42 |
import org.gvsig.fmap.dal.NewDataStoreParameters; |
43 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
44 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
45 |
import org.gvsig.fmap.dal.coverage.store.props.ColorTable; |
46 |
import org.gvsig.fmap.dal.exception.DataException; |
47 |
import org.gvsig.fmap.dal.exception.ReadException; |
48 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
49 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
50 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
51 |
import org.gvsig.fmap.dal.serverexplorer.db.DBServerExplorer; |
52 |
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorer; |
53 |
import org.gvsig.fmap.dal.serverexplorer.wfs.WFSServerExplorer; |
54 |
import org.gvsig.fmap.dal.store.db.DBStoreParameters; |
55 |
import org.gvsig.fmap.geom.primitive.Envelope; |
56 |
import org.gvsig.fmap.geom.primitive.Point; |
57 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
58 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
59 |
import org.gvsig.fmap.mapcontext.layers.operations.SingleLayer; |
60 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
61 |
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedLegend; |
62 |
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedVectorLegend; |
63 |
import org.gvsig.fmap.mapcontext.rendering.legend.ILegend; |
64 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelClass; |
65 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingMethod; |
66 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingStrategy; |
67 |
import org.gvsig.fmap.mapcontext.rendering.legend.styling.IPlacementConstraints; |
68 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol; |
69 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
70 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ITextSymbol; |
71 |
import org.gvsig.publish.PublishLocator; |
72 |
import org.gvsig.publish.PublishManager; |
73 |
import org.gvsig.publish.PublishManager.PublishSymbolConverterFactories; |
74 |
import org.gvsig.publish.PublishProperties; |
75 |
import org.gvsig.publish.impl.DefaultPublishManager; |
76 |
import org.gvsig.publish.impl.mapserver.MapserverProperties; |
77 |
import org.gvsig.publish.impl.mapserver.MapserverService; |
78 |
import org.gvsig.publish.impl.mapserver.MapserverToDynObjectHelper; |
79 |
import org.gvsig.publish.impl.mapserver.ToMapserverConverter; |
80 |
import org.gvsig.publish.mapserver641.AlignEnum; |
81 |
import org.gvsig.publish.mapserver641.BooleanEnum; |
82 |
import org.gvsig.publish.mapserver641.Class; |
83 |
import org.gvsig.publish.mapserver641.ExpressionType; |
84 |
import org.gvsig.publish.mapserver641.ItemType; |
85 |
import org.gvsig.publish.mapserver641.ItemType.Item; |
86 |
import org.gvsig.publish.mapserver641.Label; |
87 |
import org.gvsig.publish.mapserver641.Layer; |
88 |
import org.gvsig.publish.mapserver641.LayerSet; |
89 |
import org.gvsig.publish.mapserver641.Map; |
90 |
import org.gvsig.publish.mapserver641.OutputFormat; |
91 |
import org.gvsig.publish.mapserver641.PointType; |
92 |
import org.gvsig.publish.mapserver641.SizeType; |
93 |
import org.gvsig.publish.mapserver641.StateEnum; |
94 |
import org.gvsig.publish.mapserver641.Style; |
95 |
import org.gvsig.publish.mapserver641.Symbol; |
96 |
import org.gvsig.publish.mapserver641.Symbol.Points; |
97 |
import org.gvsig.publish.mapserver641.SymbolSet; |
98 |
import org.gvsig.publish.mapserver641.SymbolType; |
99 |
import org.gvsig.publish.mapserver641.Web; |
100 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
101 |
import org.gvsig.raster.gdal.io.GdalNative; |
102 |
import org.gvsig.raster.gdal.io.GdalProvider; |
103 |
import org.gvsig.raster.impl.provider.RasterProvider; |
104 |
import org.gvsig.raster.wms.app.wmsclient.layer.FLyrWMS; |
105 |
import org.gvsig.raster.wms.io.RemoteWMSStyle; |
106 |
import org.gvsig.raster.wms.io.WMSDataParameters; |
107 |
import org.gvsig.raster.wms.io.WMSServerExplorer; |
108 |
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling.IAttrInTableLabelingStrategy; |
109 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
110 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IPictureMarkerSymbol; |
111 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.text.ISimpleTextSymbol; |
112 |
import org.gvsig.symbology.fmap.rendering.VectorFilterExpressionLegend; |
113 |
import org.gvsig.timesupport.Interval; |
114 |
import org.gvsig.tools.ToolsLocator; |
115 |
import org.gvsig.tools.dataTypes.DataType; |
116 |
import org.gvsig.tools.dataTypes.DataTypes; |
117 |
import org.gvsig.tools.dynobject.DynField; |
118 |
import org.gvsig.tools.dynobject.DynObject; |
119 |
import org.slf4j.Logger; |
120 |
import org.slf4j.LoggerFactory; |
121 |
|
122 |
public class MapServer { |
123 |
|
124 |
private Logger logger = LoggerFactory.getLogger(MapServer.class); |
125 |
public static final String NAME = "Mapserver"; |
126 |
|
127 |
public static final String MAPSERVER_MAP_PROPERTIES = "MapServer-map-properties"; |
128 |
public static final String MAPSERVER_PANEL_PROPERTIES = "MapServer-panel-properties"; |
129 |
|
130 |
public static final String MAPSERVER_LAYER_PROPERTIES = "MapServer-layer-properties"; |
131 |
public static final String MAPSERVER_LAYERPANEL_PROPERTIES = "MapServer-layer-panel-properties"; |
132 |
|
133 |
public static final String MAPSERVER_SYMBOL_PROPERTIES = "MapServer-symbol-properties"; |
134 |
|
135 |
public static final String MAPFILE_FILE = "mapfile.map"; |
136 |
public static final String SYMBOLSET_FILE = "SymbolSet.sym"; |
137 |
public static final String TEMP_DIR = "mapserver"; |
138 |
public static final String IMAGE_FOLDER = "img"; |
139 |
|
140 |
private static final String WMS_PATH = "wms"; |
141 |
private static final String WFS_PATH = "wfs"; |
142 |
private static final String WCS_PATH = "wcs"; |
143 |
|
144 |
private static final int LAYER_MODE = 1; |
145 |
private static final int PROJECT_MODE = 2; |
146 |
|
147 |
public static final String FONTSET_FOLDER = "Font"; |
148 |
public static final String FONTSET_FILE = "FontSet.txt"; |
149 |
|
150 |
public static final String DEFAULT_FONT = "Arial"; |
151 |
public static final String DEFAULT_FILE = "Arial.ttf"; |
152 |
|
153 |
private SymbolSet symbolset;
|
154 |
private File symbolSetFile; |
155 |
private File fontSetFile; |
156 |
|
157 |
private PublishProperties properties;
|
158 |
|
159 |
private String srs_used = ""; |
160 |
private File file; |
161 |
|
162 |
private boolean isWMSService; |
163 |
private boolean isWFSService; |
164 |
private boolean isWCSService; |
165 |
|
166 |
private String overrideFiles; |
167 |
|
168 |
private boolean usesImages = false; |
169 |
private boolean usesFont = false; |
170 |
private boolean usesSymbols = false; |
171 |
private List<OutputFormat> auxOutputEdited = new ArrayList<OutputFormat>(); |
172 |
private boolean isEditedMapFile = false; |
173 |
private boolean isEditedLayer; |
174 |
private boolean hasLayer; |
175 |
private boolean hasLabels; |
176 |
private boolean isPropertiesPanel = false; |
177 |
|
178 |
|
179 |
private static String DEBUG = "5"; |
180 |
|
181 |
public MapServer(PublishProperties publishProperties) {
|
182 |
this.properties = publishProperties;
|
183 |
srs_used = getPublishProperties().getDefaultSRS(); |
184 |
} |
185 |
|
186 |
public Map publish(){ |
187 |
return publish(true); |
188 |
} |
189 |
|
190 |
|
191 |
public Map publish(boolean loadLayers) { |
192 |
isEditedMapFile = false;
|
193 |
|
194 |
ViewDocument doc = MapServerUtils.getCurrentViewDocument(); |
195 |
if (doc == null) { |
196 |
return null; |
197 |
} |
198 |
|
199 |
Map map = getPublishedMap(MapServerUtils.getCurrentViewDocument());
|
200 |
Web web = null;
|
201 |
if(isEditedMapFile && !map.getWeb().isEmpty()){
|
202 |
web = map.getWeb().get(0);
|
203 |
}else{
|
204 |
web = new Web();
|
205 |
} |
206 |
|
207 |
|
208 |
boolean isAllInSameDocument = false; |
209 |
boolean isSplitByLayer = false; |
210 |
if(getPublishProperties() instanceof MapserverProperties){ |
211 |
isAllInSameDocument = ((MapserverProperties) getPublishProperties()).getAllInSameDocument(); |
212 |
isSplitByLayer = ((MapserverProperties) getPublishProperties()).getIsSplitByLayer(); |
213 |
} |
214 |
|
215 |
|
216 |
ItemType itemType3 = new ItemType();
|
217 |
|
218 |
symbolset = new SymbolSet();
|
219 |
|
220 |
if(map == null){ |
221 |
map = new Map(); |
222 |
|
223 |
|
224 |
map.setDebug(DEBUG); |
225 |
try {
|
226 |
if (doc.getMapContext() != null |
227 |
&& doc.getMapContext().getFullEnvelope() != null) {
|
228 |
|
229 |
Envelope env = doc.getMapContext().getFullEnvelope(); |
230 |
Point lower = env.getLowerCorner();
|
231 |
Point upper = env.getUpperCorner();
|
232 |
if(lower != null){ |
233 |
map.getExtent().add(MapServerUtils.getDecreasedMin(lower.getX())); |
234 |
map.getExtent().add(MapServerUtils.getDecreasedMin(lower.getY())); |
235 |
} |
236 |
if(upper != null){ |
237 |
map.getExtent().add(MapServerUtils.getIncrementedMax(upper.getX())); |
238 |
map.getExtent().add(MapServerUtils.getIncrementedMax(upper.getY())); |
239 |
} |
240 |
} |
241 |
} catch (ReadException e2) {
|
242 |
logger.debug("Error reading MapServer properties");
|
243 |
} |
244 |
map.setImageColor(MapServerUtils.getRgbColorType(doc.getMapContext().getViewPort() |
245 |
.getBackColor())); |
246 |
map.setName(doc.getName()); |
247 |
IProjection proj = doc.getMapContext().getProjection(); |
248 |
IDatum datum = proj.getDatum(); |
249 |
map.getProjection().add(getCorrectProjection(proj.getAbrev())); |
250 |
map.setScaleDenom((double) doc.getMapContext().getScaleView());
|
251 |
if (!getPublishProperties().isDefaultPath() &&
|
252 |
!getPublishProperties().isAbsolutePath()) { |
253 |
map.setShapePath(getPublishProperties().getShapePath()); |
254 |
} |
255 |
SizeType st = new SizeType();
|
256 |
st.setX(MapServerUtils.getBigInteger(doc.getMapContext().getViewPort().getImageWidth())); |
257 |
st.setY(MapServerUtils.getBigInteger(doc.getMapContext().getViewPort().getImageHeight())); |
258 |
map.setSize(st); |
259 |
map.setUnits(MapServerUtils.getCorrectUnits(doc.getMapContext().getDistanceName().toLowerCase())); |
260 |
|
261 |
|
262 |
addItemProperty(itemType3, "ows_enable_request", "*"); |
263 |
|
264 |
String proxy_url = System.getProperty("http.proxyHost"); |
265 |
String proxy_port = System.getProperty("http.proxyPort"); |
266 |
if (isWMSService) {
|
267 |
addItemProperty(itemType3, "wms_title", getPublishProperties().getServiceName());
|
268 |
addItemProperty(itemType3, "wms_abstract", getPublishProperties().getServiceDescription());
|
269 |
if (!StringUtils.isBlank(srs_used)) {
|
270 |
addItemProperty(itemType3, "wms_srs", srs_used.toUpperCase());
|
271 |
} |
272 |
addItemProperty(itemType3, "wms_encoding", "UTF-8"); |
273 |
// if (proxy_url != null && proxy_url != "" && proxy_port != null
|
274 |
// && proxy_port != "" ) {
|
275 |
// addItemProperty(itemType3, "wms_proxy_auth_type", "basic");
|
276 |
// addItemProperty(itemType3, "wms_proxy_host", proxy_url);
|
277 |
// addItemProperty(itemType3, "wms_proxy_port", proxy_port);
|
278 |
// addItemProperty(itemType3, "wms_proxy_username", System.getProperty("http.proxyUserName"));
|
279 |
// addItemProperty(itemType3, "wms_proxy_password", System.getProperty("http.proxyPassword"));
|
280 |
// addItemProperty(itemType3, "wms_proxy_type", "http");
|
281 |
// }
|
282 |
} |
283 |
if (isWFSService) {
|
284 |
addItemProperty(itemType3, "wfs_title", getPublishProperties().getServiceName());
|
285 |
addItemProperty(itemType3, "wfs_abstract", getPublishProperties().getServiceDescription());
|
286 |
if (!StringUtils.isBlank(srs_used)) {
|
287 |
addItemProperty(itemType3, "wfs_srs", srs_used.toUpperCase());
|
288 |
} |
289 |
addItemProperty(itemType3, "wfs_encoding", "UTF-8"); |
290 |
addItemProperty(itemType3, "wfs_getfeature_formatlist", "shape-zip,geojson"); |
291 |
|
292 |
} |
293 |
if (isWCSService) {
|
294 |
addItemProperty(itemType3, "wcs_name", getPublishProperties().getServiceName());
|
295 |
addItemProperty(itemType3, "wcs_title", getPublishProperties().getServiceName());
|
296 |
addItemProperty(itemType3, "wcs_abstract", getPublishProperties().getServiceDescription());
|
297 |
addItemProperty(itemType3, "wcs_description", getPublishProperties().getServiceDescription());
|
298 |
if (!StringUtils.isBlank(srs_used)) {
|
299 |
addItemProperty(itemType3, "wcs_srs", srs_used.toUpperCase());
|
300 |
} |
301 |
addItemProperty(itemType3, "wcs_encoding", "UTF-8"); |
302 |
} |
303 |
|
304 |
if (!map.getExtent().isEmpty()){
|
305 |
if(map.getExtent().size()>3){ |
306 |
String ext1 = map.getExtent().get(0) + " "+ |
307 |
map.getExtent().get(1) + " "+ |
308 |
map.getExtent().get(2) + " "+ |
309 |
map.getExtent().get(3);
|
310 |
if (isWMSService) {
|
311 |
addItemProperty(itemType3, "wms_extent", ext1);
|
312 |
} |
313 |
if (isWFSService) {
|
314 |
addItemProperty(itemType3, "wfs_extent", ext1);
|
315 |
} |
316 |
if (isWCSService) {
|
317 |
addItemProperty(itemType3, "wcs_extent", ext1);
|
318 |
} |
319 |
} |
320 |
|
321 |
} |
322 |
|
323 |
|
324 |
} |
325 |
|
326 |
List<Layer> layerList = new ArrayList<Layer>(); |
327 |
if(loadLayers){
|
328 |
/**
|
329 |
* LAYER PARAMETERS
|
330 |
*/
|
331 |
|
332 |
symbolSetFile = null;
|
333 |
fontSetFile = null;
|
334 |
auxOutputEdited = new ArrayList<OutputFormat>(); |
335 |
overrideFiles = "";
|
336 |
usesImages = false;
|
337 |
usesFont = false;
|
338 |
usesSymbols = false;
|
339 |
|
340 |
|
341 |
getLayerInfo(doc.getMapContext().getLayers(), layerList, isAllInSameDocument, isSplitByLayer); |
342 |
} |
343 |
if(isWCSService && !auxOutputEdited.isEmpty()){
|
344 |
for(int k=0;k<auxOutputEdited.size(); k++){ |
345 |
if(!MapServerUtils.isOutputLoaded(map.getOutputFormat(), auxOutputEdited.get(k))){
|
346 |
OutputFormat out = auxOutputEdited.get(k); |
347 |
out.setName(MapServerUtils.createUniqueOutputFormatName( |
348 |
map.getOutputFormat(), |
349 |
out.getName())); |
350 |
map.getOutputFormat().add(out); |
351 |
} |
352 |
} |
353 |
}else{
|
354 |
if(map.getOutputFormat().isEmpty() && isWCSService){
|
355 |
map.getOutputFormat().addAll(MapServerUtils.getOutputFormatList()); |
356 |
} |
357 |
} |
358 |
|
359 |
if(isWFSService){
|
360 |
map.getOutputFormat().addAll(MapServerUtils.getWFSDefaultOutputFormat()); |
361 |
} |
362 |
|
363 |
if(file != null){ |
364 |
if (usesImages) {
|
365 |
web.setImagePath( |
366 |
MapServerUtils.relativePath( |
367 |
new File( |
368 |
file.getParent() + File.separator + IMAGE_FOLDER)
|
369 |
.getAbsolutePath(), |
370 |
file.getParent())); |
371 |
} |
372 |
if (usesFont) {
|
373 |
map.setFontSet(MapServerUtils.relativePath( |
374 |
getFontSetFile().getAbsolutePath(), file.getParent())); |
375 |
} |
376 |
map.setSymbolSet(MapServerUtils.relativePath( |
377 |
getSymbolSetFile().getAbsolutePath(), file.getParent())); |
378 |
}else{
|
379 |
//web.setLog("." + File.separator);
|
380 |
if (usesImages) {
|
381 |
web.setImagePath("./" + IMAGE_FOLDER);
|
382 |
} |
383 |
if (usesFont) {
|
384 |
map.setFontSet("./" + FONTSET_FILE);
|
385 |
} |
386 |
map.setSymbolSet("./" + SYMBOLSET_FILE);
|
387 |
} |
388 |
|
389 |
if(!isEditedMapFile){
|
390 |
web.setMetadata(getCorrectMetadata(itemType3)); |
391 |
|
392 |
if (!itemType3.getItem().isEmpty()) {
|
393 |
web.setMetadata(itemType3); |
394 |
} |
395 |
//web.setTempPath(System.getProperty("java.io.tmpdir"));
|
396 |
map.getWeb().add(web); |
397 |
}else{
|
398 |
web.setMetadata(getCorrectMetadata(web.getMetadata())); |
399 |
if(!isWCSService){
|
400 |
for(int i=map.getOutputFormat().size()-1; i>=0; i--){ |
401 |
map.getOutputFormat().remove(i); |
402 |
} |
403 |
} |
404 |
|
405 |
} |
406 |
|
407 |
if(file != null && hasMapfile()){ |
408 |
|
409 |
if(!file.exists() || getPublishProperties().getOverrideCurrentProject()){
|
410 |
parserFile(map, file); |
411 |
if(!isSplitByLayer){
|
412 |
SymbolSet auxSymbolSet = getSymbolSet(getSymbolSetFile()); |
413 |
loadSymbolsImages(auxSymbolSet); |
414 |
parserFile(auxSymbolSet, getSymbolSetFile()); |
415 |
} |
416 |
}else{
|
417 |
// if(getPublishProperties().getJoinToCurrent()){
|
418 |
if(!isSplitByLayer){
|
419 |
/** Merge de las capas **/
|
420 |
|
421 |
|
422 |
|
423 |
/** Merge de los s?mbolos **/
|
424 |
SymbolSet newsymbolset = new SymbolSet();
|
425 |
newsymbolset = (SymbolSet) parserFile(getSymbolSetFile(), newsymbolset); |
426 |
SymbolSet auxsset = new SymbolSet();
|
427 |
if(newsymbolset != null && |
428 |
auxsset.getSymbol() != null &&
|
429 |
newsymbolset.getSymbol() != null){
|
430 |
auxsset.getSymbol().addAll(newsymbolset.getSymbol()); |
431 |
} |
432 |
auxsset.getSymbol().addAll(getSymbolSet().getSymbol()); |
433 |
for(int i=0; i<getSymbolSet().getSymbol().size(); i++){ |
434 |
Symbol symAux = getSymbolSet().getSymbol().get(i); |
435 |
String name = MapServerUtils.createUniqueSymbolName(auxsset, symAux.getName());
|
436 |
if(!name.equals(symAux.getName())){
|
437 |
updateSymbolName(layerList, symAux.getName(), name); |
438 |
symAux.setName(name); |
439 |
} |
440 |
newsymbolset.getSymbol().add(symAux); |
441 |
auxsset.getSymbol().add(symAux); |
442 |
} |
443 |
|
444 |
loadSymbolsImages(newsymbolset); |
445 |
parserFile(newsymbolset, getSymbolSetFile()); |
446 |
} |
447 |
|
448 |
// }else{
|
449 |
// // TODO Merge de la definici?n en el mapfile.map
|
450 |
// }
|
451 |
} |
452 |
|
453 |
if(isAllInSameDocument){
|
454 |
map.getLayer().addAll(layerList); |
455 |
}else{
|
456 |
Map newmap = new Map(); |
457 |
newmap = (Map) parserFile(file, newmap);
|
458 |
|
459 |
if(getPublishProperties().getJoinToCurrent()){
|
460 |
mergeLayerDefinition(file, newmap, layerList, PROJECT_MODE); |
461 |
} |
462 |
|
463 |
if(!isSplitByLayer){
|
464 |
File mapfile = createMapFile(file, MapServerUtils.getCurrentViewDocument().getName());
|
465 |
if(!layerList.isEmpty()){
|
466 |
LayerSet layerset = new LayerSet();
|
467 |
layerset.getLayer().addAll(layerList); |
468 |
parserFile(layerset, mapfile); |
469 |
map.getInclude().add(mapfile.getName()); |
470 |
} |
471 |
//parserFile(map, file);
|
472 |
} |
473 |
if(!StringUtils.isBlank(map.getFontSet())){
|
474 |
newmap.setFontSet(map.getFontSet()); |
475 |
} |
476 |
if(!StringUtils.isBlank(map.getSymbolSet())){
|
477 |
newmap.setSymbolSet(map.getSymbolSet()); |
478 |
} |
479 |
|
480 |
Web auxWeb = new Web();
|
481 |
boolean isNewWeb = true; |
482 |
if(!newmap.getWeb().isEmpty()
|
483 |
&& !StringUtils.isBlank(newmap.getWeb().get(0).getImagePath())){
|
484 |
auxWeb = newmap.getWeb().get(0);
|
485 |
isNewWeb = false;
|
486 |
} |
487 |
|
488 |
if(!map.getWeb().isEmpty()){
|
489 |
for(int wmap = 0; wmap<map.getWeb().size(); wmap++){ |
490 |
Web wweb = map.getWeb().get(wmap); |
491 |
if(!StringUtils.isBlank(wweb.getImagePath())){
|
492 |
auxWeb.setImagePath(wweb.getImagePath()); |
493 |
if(isNewWeb){
|
494 |
newmap.getWeb().add(auxWeb); |
495 |
isNewWeb = false;
|
496 |
} |
497 |
} |
498 |
} |
499 |
} |
500 |
|
501 |
newmap.getInclude().addAll(map.getInclude()); |
502 |
parserFile(newmap, file); |
503 |
|
504 |
|
505 |
|
506 |
|
507 |
} |
508 |
|
509 |
} |
510 |
|
511 |
|
512 |
return map;
|
513 |
} |
514 |
|
515 |
|
516 |
private void loadSymbolsImages(SymbolSet newsymbolset) { |
517 |
if(newsymbolset != null){ |
518 |
for(int i=0; i<newsymbolset.getSymbol().size(); i++){ |
519 |
loadSymbolImages(newsymbolset.getSymbol().get(i)); |
520 |
} |
521 |
} |
522 |
} |
523 |
|
524 |
protected String addImageUrl(String url) { |
525 |
File originalFile = new File(MapServerUtils.getCorrectFilePathFromUrl(url)); |
526 |
String legFileName = originalFile.getName();
|
527 |
|
528 |
PublishManager manager = PublishLocator.getServiceManager().getPublishManager(); |
529 |
|
530 |
File file = getCurrentFile();
|
531 |
|
532 |
if(file != null){ |
533 |
File parentFile = new File(getCorrectPath(file.getParent())); |
534 |
|
535 |
if(parentFile.isDirectory()
|
536 |
&& parentFile.canWrite()){ |
537 |
File legfile = new File(getCorrectPath(parentFile.getAbsolutePath() |
538 |
+ File.separator + MapServer.IMAGE_FOLDER + File.separator + legFileName)); |
539 |
if(legfile.exists()){
|
540 |
if(!legfile.getAbsolutePath().equals(originalFile.getAbsolutePath())){
|
541 |
Object[] options = {manager.getTranslation("accept_all"), manager.getTranslation("accept"), |
542 |
manager.getTranslation("cancel"), manager.getTranslation("cancell_all")}; |
543 |
int n = -1; |
544 |
if(StringUtils.isBlank(getOverrideFiles())){
|
545 |
n = JOptionPane.showOptionDialog(null, |
546 |
legfile.getAbsolutePath()+"\n"+
|
547 |
manager.getTranslation("file_exists3")+"\n"+ |
548 |
manager.getTranslation("file_exists2"),
|
549 |
manager.getTranslation("file_exists"),
|
550 |
JOptionPane.YES_NO_OPTION,
|
551 |
JOptionPane.WARNING_MESSAGE,
|
552 |
null,
|
553 |
options, |
554 |
options[0]);
|
555 |
} |
556 |
if(n==0){ |
557 |
setOverrideFiles("true");
|
558 |
} |
559 |
if(n==3){ |
560 |
setOverrideFiles("false");
|
561 |
} |
562 |
if(n==1 || getOverrideFiles().equalsIgnoreCase("true")){ |
563 |
try {
|
564 |
FileUtils.copyFile(originalFile, legfile); |
565 |
} catch (IOException e) { |
566 |
logger.debug("Error copying MapServer file: " + originalFile);
|
567 |
} |
568 |
return legfile.getAbsolutePath();
|
569 |
} |
570 |
} |
571 |
}else{
|
572 |
try {
|
573 |
legfile.getParentFile().mkdirs(); |
574 |
FileUtils.copyFile(originalFile, legfile); |
575 |
} catch (IOException e) { |
576 |
logger.debug("Error copying Mapserver file: " + originalFile);
|
577 |
} |
578 |
return legfile.getAbsolutePath();
|
579 |
} |
580 |
} |
581 |
} |
582 |
return null; |
583 |
} |
584 |
|
585 |
private void loadSymbolImages(Symbol newsymbol) { |
586 |
if(newsymbol.getImage() != null && newsymbol.getImage() != ""){ |
587 |
String fileImageURL = addImageUrl(newsymbol.getImage());
|
588 |
|
589 |
String path = ""; |
590 |
if(fileImageURL != null){ |
591 |
File imageFile = new File(fileImageURL); |
592 |
path = getCorrectPath(imageFile.getAbsolutePath()); |
593 |
if(getCurrentFile() != null){ |
594 |
path = MapServerUtils.relativePath(imageFile.getAbsolutePath(), getCurrentFile().getParent()); |
595 |
} |
596 |
}else{
|
597 |
path = newsymbol.getImage(); |
598 |
} |
599 |
|
600 |
newsymbol.setImage(path.replace(File.separator, "/")); |
601 |
} |
602 |
} |
603 |
|
604 |
private void getLayerInfo(FLayers layers, List<Layer> layerList, boolean isAllInSameDocument, boolean isSplitByLayer) { |
605 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
606 |
FLayer layer = layers.getLayer(i); |
607 |
if(layer instanceof FLayers){ |
608 |
getLayerInfo((FLayers) layer, layerList, isAllInSameDocument, isSplitByLayer); |
609 |
}else{
|
610 |
try{
|
611 |
if(layer instanceof FLyrRaster && isWFSService && !isWMSService && !isWCSService){ |
612 |
continue;
|
613 |
} |
614 |
}catch(NoClassDefFoundError e1){ |
615 |
logger.info("No est? instalada la extensi?n de raster");
|
616 |
} |
617 |
if(layer instanceof FLyrVect && !isWFSService && !isWMSService && isWCSService){ |
618 |
continue;
|
619 |
} |
620 |
if(hasMapfile()){
|
621 |
Layer mapserverLayer = getPublishedLayer(layer); |
622 |
|
623 |
MapserverToDynObjectHelper helper = new MapserverToDynObjectHelper();
|
624 |
DynObject dynlayer = ToolsLocator.getDynObjectManager().createDynObject(helper.getLayerDefinition()); |
625 |
Layer auxLayer = helper.clone(mapserverLayer); |
626 |
|
627 |
if(isWFSService){
|
628 |
auxLayer.setLabelCache(null);
|
629 |
auxLayer.setOffsite(null);
|
630 |
auxLayer.setPostLabelCache(null);
|
631 |
auxLayer.setOpacity(null);
|
632 |
} |
633 |
//if(isEditedLayer){
|
634 |
auxLayer.setMetadata(getCorrectMetadata(auxLayer.getMetadata())); |
635 |
//}
|
636 |
|
637 |
SymbolSet sset = getPublishedSymbol(layer); |
638 |
List<Symbol> symIt = sset.getSymbol();
|
639 |
int m=0; |
640 |
while(m<symIt.size()){
|
641 |
Symbol sm = (Symbol) symIt.get(m); |
642 |
if(!isSharedWithOtherViews(layer, sm)){
|
643 |
if(!isSymbolInSet(sset, sm)){
|
644 |
sset.getSymbol().add(sm); |
645 |
} |
646 |
} |
647 |
m++; |
648 |
} |
649 |
mergeSymbolSet(this.symbolset, sset, PROJECT_MODE);
|
650 |
|
651 |
if(file != null){ |
652 |
if(!isAllInSameDocument && isSplitByLayer){
|
653 |
// File mapfile = createMapFile(file, mapserverLayer.getName());
|
654 |
// LayerSet layerset = new LayerSet();
|
655 |
// layerset.getLayer().add(mapserverLayer);
|
656 |
// parserFile(layerset, mapfile);
|
657 |
// map.getInclude().add(mapfile.getName());
|
658 |
//
|
659 |
// if(!sset.getSymbol().isEmpty()){
|
660 |
// File symbolsetfile = createSymbolSetFile(file, mapserverLayer.getName());
|
661 |
// parserFile(sset, symbolsetfile);
|
662 |
// map.getInclude().add(symbolsetfile.getName());
|
663 |
// }
|
664 |
// map.setSymbolSet("");
|
665 |
}else{
|
666 |
layerList.add(auxLayer); |
667 |
} |
668 |
} |
669 |
} |
670 |
} |
671 |
} |
672 |
} |
673 |
|
674 |
public Layer makepublish(FLayer layer) {
|
675 |
ViewDocument view = MapServerUtils.getViewDocumentFromLayer(layer); |
676 |
SymbolSet localSymbolSet = new SymbolSet();
|
677 |
hasLabels = false;
|
678 |
Layer lyr = new Layer();
|
679 |
ItemType itemType = new ItemType();
|
680 |
|
681 |
lyr.setTolerance(3.0);
|
682 |
|
683 |
if(layer.getParentLayer() != null && layer.getParentLayer().getName() != null && layer.getParentLayer().getName() != "root layer"){ |
684 |
lyr.setGroup("/"+layer.getParentLayer().getName());
|
685 |
// }else{
|
686 |
// lyr.setGroup("/"+view.getName());
|
687 |
} |
688 |
|
689 |
lyr.setDebug(DEBUG); |
690 |
String extent = ""; |
691 |
try {
|
692 |
if (layer.getFullEnvelope() != null) { |
693 |
Envelope env = layer.getFullEnvelope(); |
694 |
Point lower = env.getLowerCorner();
|
695 |
Point upper = env.getUpperCorner();
|
696 |
extent = MapServerUtils.getDecreasedMin(lower.getX()) + " " +
|
697 |
MapServerUtils.getDecreasedMin(lower.getY()) + " " +
|
698 |
MapServerUtils.getIncrementedMax(upper.getX())+ " " +
|
699 |
MapServerUtils.getIncrementedMax(upper.getY()); |
700 |
lyr.getExtent().add(MapServerUtils.getDecreasedMin(lower.getX())); |
701 |
lyr.getExtent().add(MapServerUtils.getDecreasedMin(lower.getY())); |
702 |
lyr.getExtent().add(MapServerUtils.getIncrementedMax(upper.getX())); |
703 |
lyr.getExtent().add(MapServerUtils.getIncrementedMax(upper.getY())); |
704 |
} |
705 |
} catch (ReadException e2) {
|
706 |
logger.debug("Error reading MapServer properties");
|
707 |
} |
708 |
if (layer.getMaxScale() != -1) |
709 |
lyr.setMaxScaleDenom(layer.getMaxScale()); |
710 |
if (layer.getMinScale() != -1) |
711 |
lyr.setMinScaleDenom(layer.getMinScale()); |
712 |
lyr.setName(layer.getName()); |
713 |
String projection = ""; |
714 |
if (layer.getProjection() != null) { |
715 |
lyr.getProjection().add( |
716 |
getCorrectProjection(layer.getProjection().getAbrev())); |
717 |
projection = layer.getProjection().getAbrev(); |
718 |
} |
719 |
lyr.setStatus(MapServerUtils.getStatus(layer.isVisible())); |
720 |
|
721 |
if (layer instanceof SingleLayer) { |
722 |
SingleLayer singlelayer = (SingleLayer) layer; |
723 |
String contype = MapServerUtils.getProviderName(singlelayer.getDataStore()
|
724 |
.getProviderName()); |
725 |
if (!contype.equals("local")) { |
726 |
lyr.setConnectionType(contype); |
727 |
} |
728 |
} |
729 |
|
730 |
if (isWMSService) {
|
731 |
addItemProperty(itemType, "wms_title", MapServerUtils.getNameWithoutExtension(layer.getName()));
|
732 |
addItemProperty(itemType, "wms_name", MapServerUtils.getNameWithoutExtension(layer.getName()));
|
733 |
addItemProperty(itemType, "wms_abstract", MapServerUtils.getNameWithoutExtension(layer.getName()));
|
734 |
|
735 |
String group = ""; |
736 |
if(layer.getParentLayer() != null && layer.getParentLayer().getName() != null && layer.getParentLayer().getName() != "root layer"){ |
737 |
group = "/"+layer.getParentLayer().getName();
|
738 |
}else{
|
739 |
group= "/"+view.getName();
|
740 |
} |
741 |
|
742 |
addItemProperty(itemType, "wms_layer_group", group);
|
743 |
if (extent != "") { |
744 |
addItemProperty(itemType, "wms_extent", extent);
|
745 |
} |
746 |
if (projection != null) { |
747 |
addItemProperty(itemType, "wms_srs", projection);
|
748 |
} |
749 |
addItemProperty(itemType, "gml_include_items", "all"); |
750 |
//addItemProperty(itemType, "gml_types", "auto");
|
751 |
|
752 |
lyr.setDump(BooleanEnum.TRUE); |
753 |
lyr.setTemplate(".");
|
754 |
} |
755 |
|
756 |
if (isWFSService) {
|
757 |
addItemProperty(itemType, "wfs_title", MapServerUtils.getNameWithoutExtension(layer.getName()));
|
758 |
addItemProperty(itemType, "wfs_abstract", MapServerUtils.getNameWithoutExtension(layer.getName()));
|
759 |
if (extent != "") { |
760 |
addItemProperty(itemType, "wfs_extent", extent);
|
761 |
} |
762 |
if (projection != null) { |
763 |
addItemProperty(itemType, "wfs_srs", projection);
|
764 |
} |
765 |
addItemProperty(itemType, "wfs_typename", MapServerUtils.getNameWithoutExtension(layer.getName()));
|
766 |
addIfNotExistsItemProperty(itemType, "gml_include_items", "all"); |
767 |
//addItemProperty(itemType, "gml_types", "auto");
|
768 |
} |
769 |
|
770 |
if(isWCSService){
|
771 |
addItemProperty(itemType, "wcs_label", MapServerUtils.getNameWithoutExtension(layer.getName()));
|
772 |
addItemProperty(itemType, "wcs_name", MapServerUtils.getNameWithoutExtension(layer.getName()));
|
773 |
addItemProperty(itemType, "wcs_abstract", MapServerUtils.getNameWithoutExtension(layer.getName()));
|
774 |
addItemProperty(itemType, "wcs_description", MapServerUtils.getNameWithoutExtension(layer.getName()));
|
775 |
if (extent != "") { |
776 |
addItemProperty(itemType, "wcs_extent", extent);
|
777 |
} |
778 |
if (projection != null) { |
779 |
addItemProperty(itemType, "ows_srs", projection);
|
780 |
} |
781 |
} |
782 |
|
783 |
if (layer instanceof FLyrVect) { |
784 |
FLyrVect flyrvect = (FLyrVect) layer; |
785 |
int alpha = (flyrvect.getTransparency() + 1) * 100 / 256; |
786 |
lyr.setOpacity("" + alpha);
|
787 |
try {
|
788 |
lyr.setType(MapServerUtils.getLayerType(flyrvect.getTypeVectorLayer())); |
789 |
} catch (Exception e) { |
790 |
logger.debug("Error setting type tp MapServer layer");
|
791 |
} |
792 |
|
793 |
try {
|
794 |
FeatureStore fstore = flyrvect.getFeatureStore(); |
795 |
if(isWFSService){
|
796 |
FeatureAttributeDescriptor[] pks = fstore
|
797 |
.getDefaultFeatureType().getPrimaryKey(); |
798 |
boolean isFirst = true; |
799 |
String keys = ""; |
800 |
for (int ix = 0; ix < pks.length; ix++) { |
801 |
if (!isFirst) {
|
802 |
keys += ", ";
|
803 |
} |
804 |
keys += pks[ix].getName(); |
805 |
isFirst = false;
|
806 |
} |
807 |
if(!StringUtils.isBlank(keys)){
|
808 |
addItemProperty(itemType, "gml_featureid", keys);
|
809 |
} |
810 |
|
811 |
|
812 |
DynField[] dynfields = fstore.getDefaultFeatureType().getDeclaredDynFields();
|
813 |
String geoattrName = fstore.getDefaultFeatureType().getDefaultGeometryAttributeName();
|
814 |
|
815 |
for(int fi =0; fi<dynfields.length; fi++){ |
816 |
DynField field = dynfields[fi]; |
817 |
String name = field.getName();
|
818 |
if(!geoattrName.equals(name)){
|
819 |
DataType type = field.getDataType(); |
820 |
String typeName = getMapserverTypeName(type);
|
821 |
if(typeName != null){ |
822 |
addItemProperty(itemType, "gml_"+name+"_type", typeName); |
823 |
} |
824 |
} |
825 |
} |
826 |
} |
827 |
|
828 |
if (fstore.getExplorer() != null) { |
829 |
if (fstore.getExplorer() instanceof FilesystemServerExplorer) { |
830 |
FilesystemServerExplorer fileExplorer = (FilesystemServerExplorer) fstore |
831 |
.getExplorer(); |
832 |
lyr.setData(getCorrectPath(fstore.getFullName())); |
833 |
if(isWFSService){
|
834 |
addItemProperty(itemType, "gml_featureid", "ID"); |
835 |
} |
836 |
} else {
|
837 |
lyr.setConnection(MapServerUtils.getHostWithoutParametersFromURL(getCorrectPath(fstore |
838 |
.getFullName()))); |
839 |
} |
840 |
|
841 |
try{
|
842 |
if (fstore.getExplorer() instanceof WFSServerExplorer) { |
843 |
WFSServerExplorer wfsExplorer = (WFSServerExplorer) fstore.getExplorer(); |
844 |
lyr.setMaxFeatures(MapServerUtils.getBigInteger(wfsExplorer.getMaxFeatures())); |
845 |
|
846 |
if (isWFSService) {
|
847 |
addItemProperty(itemType, "wfs_title", wfsExplorer.getTitle());
|
848 |
addItemProperty(itemType, "wfs_abstract", wfsExplorer.getAbstract());
|
849 |
if (extent != "") { |
850 |
addItemProperty(itemType, "wfs_extent", extent);
|
851 |
} |
852 |
if (projection != null) { |
853 |
addItemProperty(itemType, "wfs_srs", projection);
|
854 |
} |
855 |
} |
856 |
|
857 |
if (isWMSService) {
|
858 |
addItemProperty(itemType, "wms_title", wfsExplorer.getTitle());
|
859 |
addItemProperty(itemType, "wms_name", lyr.getName());
|
860 |
addItemProperty(itemType, "wms_abstract", wfsExplorer.getAbstract());
|
861 |
if (extent != "") { |
862 |
addItemProperty(itemType, "wms_extent", extent);
|
863 |
} |
864 |
if (projection != null) { |
865 |
addItemProperty(itemType, "wms_srs", projection);
|
866 |
} |
867 |
} |
868 |
|
869 |
addItemProperty(itemType, "wfs_typename", lyr.getName());
|
870 |
addItemProperty(itemType, "wfs_maxfeatures", wfsExplorer.getMaxFeatures()+""); |
871 |
addItemProperty(itemType, "wfs_version", wfsExplorer.getVersion());
|
872 |
addItemProperty(itemType, "wfs_connectiontimeout", wfsExplorer.getTimeOut()+""); |
873 |
|
874 |
} |
875 |
}catch(NoClassDefFoundError e1){ |
876 |
logger.info("No est? instalada la extensi?n de WFS");
|
877 |
} |
878 |
|
879 |
if (fstore.getExplorer() instanceof DBServerExplorer) { |
880 |
DBServerExplorer fileExplorer = (DBServerExplorer) fstore |
881 |
.getExplorer(); |
882 |
|
883 |
NewDataStoreParameters newdata = fileExplorer |
884 |
.getAddParameters(); |
885 |
DynField[] newfields = newdata.getDynClass()
|
886 |
.getDeclaredDynFields(); |
887 |
String connection = ""; |
888 |
String[] aux = fstore.getFullName().split(":"); |
889 |
if (aux.length > 1) { |
890 |
connection = aux[2];
|
891 |
} |
892 |
String proje = ""; |
893 |
String[] aux2 = getCorrectProjection( |
894 |
fstore.getSRSDefaultGeometry().getAbrev()) |
895 |
.split(":");
|
896 |
if (aux2.length > 0) { |
897 |
proje = aux2[1];
|
898 |
} |
899 |
|
900 |
FeatureAttributeDescriptor[] pks = fstore
|
901 |
.getDefaultFeatureType().getPrimaryKey(); |
902 |
boolean isFirst = true; |
903 |
String keys = ""; |
904 |
for (int ix = 0; ix < pks.length; ix++) { |
905 |
if (!isFirst) {
|
906 |
keys += ", ";
|
907 |
} |
908 |
keys += pks[ix].getName(); |
909 |
isFirst = false;
|
910 |
} |
911 |
|
912 |
// "the_geom from cartografia_base.aepptorg000 using unique gid using srid=4189"
|
913 |
if (connection != "" && proje != "" && keys != "") { |
914 |
String dataQuery = fstore.getDefaultFeatureType()
|
915 |
.getDefaultGeometryAttribute().getName() |
916 |
+ " from "
|
917 |
+ connection.replace("\"", ""); |
918 |
if(!StringUtils.isBlank(keys)){
|
919 |
dataQuery = dataQuery + " using unique " + keys;
|
920 |
} |
921 |
dataQuery = dataQuery + " using srid=" + proje;
|
922 |
if(lyr.getProjection().isEmpty()){
|
923 |
lyr.getProjection().add(getCorrectProjection( |
924 |
fstore.getSRSDefaultGeometry().getAbrev())); |
925 |
} |
926 |
lyr.setData(dataQuery); |
927 |
if(isWFSService){
|
928 |
addItemProperty(itemType, "gml_featureid", keys);
|
929 |
} |
930 |
} |
931 |
} |
932 |
|
933 |
//if(isWFSService){
|
934 |
String geoattrName = fstore.getDefaultFeatureType().getDefaultGeometryAttributeName();
|
935 |
//addItemProperty(itemType, "gml_geometries", geoattrName);
|
936 |
addItemProperty(itemType, "gml_geometries", "geometry"); |
937 |
|
938 |
String valid_type = MapServerUtils.getValidLayerType(lyr.getType());
|
939 |
if(valid_type != null){ |
940 |
//addItemProperty(itemType, "gml_"+geoattrName+"_type", valid_type);
|
941 |
addItemProperty(itemType, "gml_geometry_type", valid_type);
|
942 |
} |
943 |
//}
|
944 |
} |
945 |
} catch (Exception e1) { |
946 |
logger.debug("Error parsing MapServer project");
|
947 |
} |
948 |
|
949 |
if (flyrvect.getFeatureStore().getParameters() instanceof DBStoreParameters) { |
950 |
DBStoreParameters dbStore = (DBStoreParameters) flyrvect |
951 |
.getDataStore().getParameters(); |
952 |
lyr.setConnection("user=" + dbStore.getUser() + " password=" |
953 |
+ dbStore.getPassword() + " host=" + dbStore.getHost()
|
954 |
+ " port=" + dbStore.getPort() + " dbname=" |
955 |
+ dbStore.getDBName()); |
956 |
lyr.getProcessing().add("CLOSE_CONNECTION=DEFER");
|
957 |
lyr.setDump(BooleanEnum.TRUE); |
958 |
lyr.setConnectionType("POSTGIS");
|
959 |
} |
960 |
|
961 |
|
962 |
|
963 |
|
964 |
/**
|
965 |
* LEGEND PARAMETERS
|
966 |
*/
|
967 |
if(!isWFSService || isWMSService || isWCSService){
|
968 |
ILegend legend = flyrvect.getLegend(); |
969 |
try{
|
970 |
if(legend instanceof VectorComplexLegend){ |
971 |
VectorComplexLegend clegend = (VectorComplexLegend) legend; |
972 |
Iterator<ComplexLegendItem> it = clegend.getLegends().iterator();
|
973 |
while(it.hasNext()){
|
974 |
ComplexLegendItem item = (ComplexLegendItem) it.next(); |
975 |
getMapClass( |
976 |
layer, |
977 |
lyr, |
978 |
localSymbolSet, |
979 |
item.getLegend(), |
980 |
item.getMinScale(), |
981 |
item.getMaxScale()); |
982 |
} |
983 |
}else{
|
984 |
getMapClass(layer, lyr, localSymbolSet, legend, -1, -1); |
985 |
} |
986 |
}catch(NoClassDefFoundError e1){ |
987 |
logger.info("No est? instalada la extensi?n de leyendas complejas");
|
988 |
getMapClass(layer, lyr, localSymbolSet, legend, -1, -1); |
989 |
} |
990 |
} |
991 |
|
992 |
} |
993 |
|
994 |
try{
|
995 |
if (layer instanceof FLyrRaster) { |
996 |
FLyrRaster flyrraster = (FLyrRaster) layer; |
997 |
lyr.setType("RASTER");
|
998 |
lyr.setStatus(MapServerUtils.getStatus(false));
|
999 |
lyr.setConnectionType("RASTER");
|
1000 |
|
1001 |
if (flyrraster.getFileLayer() != null) { |
1002 |
lyr.setData(getCorrectPath(flyrraster.getURI())); |
1003 |
} |
1004 |
|
1005 |
RasterDataStore rasterstore = flyrraster.getDataStore(); |
1006 |
if(rasterstore != null && rasterstore.getProvider() != null){ |
1007 |
RasterProvider provider = (RasterProvider) rasterstore.getProvider(); |
1008 |
|
1009 |
|
1010 |
String outputName = flyrraster.getFileFormat();
|
1011 |
String extension = flyrraster.getFileFormat();
|
1012 |
String mimeType = ""; |
1013 |
if(outputName != "WMS" && extension != "WMS"){ |
1014 |
mimeType = URLConnection.guessContentTypeFromStream(
|
1015 |
new FileInputStream(flyrraster.getURI())); |
1016 |
if( mimeType == null){ |
1017 |
File f = new File(flyrraster.getURI()); |
1018 |
mimeType = MimetypesFileTypeMap.getDefaultFileTypeMap().getContentType(f); |
1019 |
} |
1020 |
} |
1021 |
String imageMode = MapServerUtils.getBandTypeName(rasterstore.getBands().getBandsDataType());
|
1022 |
|
1023 |
String[] formats = provider.getFormatList(); |
1024 |
Interval interval = provider.getInterval(); |
1025 |
|
1026 |
|
1027 |
if(provider instanceof GdalProvider){ |
1028 |
GdalProvider gdalprovider = (GdalProvider) provider; |
1029 |
int[] tps = gdalprovider.getDataType(); |
1030 |
|
1031 |
|
1032 |
if(gdalprovider.getNative() != null){ |
1033 |
GdalNative gdalnative = gdalprovider.getNative(); |
1034 |
|
1035 |
outputName = gdalnative.getDriverShortName(); |
1036 |
if(!StringUtils.isBlank(outputName)){
|
1037 |
if(MapServerUtils.getDefaultOutputFormatByName(outputName) != null){ |
1038 |
if(isWCSService){
|
1039 |
addItemProperty(itemType, "wcs_nativeformat", outputName);
|
1040 |
} |
1041 |
} |
1042 |
} |
1043 |
|
1044 |
ColorTable colortable = gdalnative.getColorTable(); |
1045 |
int[] types = gdalnative.getDataType(); |
1046 |
String gdalDriver = gdalnative.getGdalShortName();
|
1047 |
// STRING[] METADATS = PROVIDER.GETMETADATA().GETMETADATASTRING();
|
1048 |
// METADATS[0] = TIFFTAG_IMAGEDESCRIPTION:?XS1 XS2 XS3 SWIR
|
1049 |
// METADATS[1] = TIFFTAG_DATETIME:?2009:10:06 20:20:01
|
1050 |
|
1051 |
} |
1052 |
|
1053 |
if(isWCSService){
|
1054 |
addItemProperty(itemType, "wcs_bandcount", provider.getBandCount()+""); |
1055 |
String bandNames = ""; |
1056 |
ColorInterpretation colorint = provider.getColorInterpretation(); |
1057 |
for(int ci = 0; ci < colorint.length(); ci ++){ |
1058 |
String color = colorint.get(ci);
|
1059 |
bandNames = bandNames + " " + color;
|
1060 |
} |
1061 |
if(!StringUtils.isBlank(bandNames)){
|
1062 |
addItemProperty(itemType, "wcs_band_names", bandNames);
|
1063 |
} |
1064 |
|
1065 |
if(!StringUtils.isBlank(imageMode)){
|
1066 |
addItemProperty(itemType, "wcs_imagemode", imageMode);
|
1067 |
} |
1068 |
addItemProperty(itemType, "wcs_size", provider.getWidth() + " " + provider.getHeight()); |
1069 |
|
1070 |
|
1071 |
|
1072 |
for(int bi = 0; bi < rasterstore.getBandCount(); bi++){ |
1073 |
|
1074 |
OutputFormat aux = MapServerUtils.getDefaultOutputFormatByExtension(extension); |
1075 |
MapserverToDynObjectHelper helper = new MapserverToDynObjectHelper();
|
1076 |
DynObject dynOutputFormat = helper.createOutputFormat(aux); |
1077 |
OutputFormat outputFormat = helper.createOutputFormat(dynOutputFormat); |
1078 |
if(outputFormat == null){ |
1079 |
outputFormat = new OutputFormat();
|
1080 |
outputFormat.setExtension(extension); |
1081 |
outputFormat.setTransparent(StateEnum.OFF); |
1082 |
outputFormat.setMimeType(mimeType); |
1083 |
outputFormat.setImageMode(imageMode); |
1084 |
} |
1085 |
|
1086 |
outputFormat.setName( |
1087 |
MapServerUtils.createUniqueOutputFormatName(auxOutputEdited, outputName)); |
1088 |
//outputFormat.setImageMode(imageMode);
|
1089 |
outputFormat.setImageMode( |
1090 |
MapServerUtils.getBandTypeName(rasterstore.getBands().getBand(bi).getDataType())); |
1091 |
|
1092 |
// System.out.println("Info del documento:\n" + flyrraster.getURI() );
|
1093 |
// System.out.println(" Name: " + outputFormat.getName());
|
1094 |
// System.out.println(" Extensi?n: " + outputFormat.getExtension());
|
1095 |
// System.out.println(" Mime-type: " + outputFormat.getMimeType());
|
1096 |
// System.out.println(" Driver: " + outputFormat.getDriver());
|
1097 |
// System.out.println(" ImageMode: " + outputFormat.getImageMode());
|
1098 |
// System.out.println(" FormatOption: ----" );
|
1099 |
// System.out.println(" Transparent: OFF" );
|
1100 |
|
1101 |
this.auxOutputEdited.add(outputFormat);
|
1102 |
} |
1103 |
} |
1104 |
} |
1105 |
} |
1106 |
if (layer instanceof FLyrWMS) { |
1107 |
FLyrWMS flyrWMS = (FLyrWMS) layer; |
1108 |
RasterDataStore store = flyrWMS.getDataStore(); |
1109 |
if(store != null){ |
1110 |
IProjection proj = store.getProjection(); |
1111 |
if(lyr.getProjection().isEmpty() && proj != null){ |
1112 |
lyr.getProjection().add( |
1113 |
getCorrectProjection(proj.getAbrev())); |
1114 |
} |
1115 |
// String name2 = store.getFullName();
|
1116 |
// int index1 = name2.indexOf("[");
|
1117 |
// int index2 = name2.indexOf("]");
|
1118 |
// if(index1 >= 0 && index2 >= 0 && index1 < index2){
|
1119 |
// lyr.setName(name2.substring(index1+1, index2));
|
1120 |
// }else{
|
1121 |
// lyr.setName(name2);
|
1122 |
// }
|
1123 |
} |
1124 |
//lyr.setName(flyrWMS.getName());
|
1125 |
lyr.setStatus("OFF");
|
1126 |
lyr.setConnectionType("WMS");
|
1127 |
WMSServerExplorer explorer = (WMSServerExplorer) rasterstore |
1128 |
.getExplorer(); |
1129 |
lyr.setConnection(MapServerUtils.getHostWithoutParametersFromURL(explorer.getHost())); |
1130 |
if (isWMSService) {
|
1131 |
if(store != null){ |
1132 |
String name2 = store.getFullName();
|
1133 |
int index1 = name2.indexOf("["); |
1134 |
int index2 = name2.indexOf("]"); |
1135 |
if(index1 >= 0 && index2 >= 0 && index1 < index2){ |
1136 |
replaceItemProperty(itemType, "wms_name", name2.substring(index1+1, index2)); |
1137 |
} |
1138 |
} |
1139 |
addItemProperty(itemType, "wms_onlineresource",
|
1140 |
MapServerUtils.getHostWithoutParametersFromURL(explorer.getHost())); |
1141 |
} |
1142 |
addItemProperty(itemType, "wms_server_version", "1.1.1"); |
1143 |
if(lyr.getProjection().isEmpty()){
|
1144 |
addItemProperty(itemType, "wms_srs", "AUTO"); |
1145 |
} |
1146 |
|
1147 |
WMSDataParameters wmsparams = flyrWMS.getParameters(); |
1148 |
if (wmsparams.getStyles() != null) { |
1149 |
Iterator it4 = wmsparams.getStyles().iterator();
|
1150 |
while (it4.hasNext()) {
|
1151 |
RemoteWMSStyle wmsStyle = (RemoteWMSStyle) it4 |
1152 |
.next(); |
1153 |
if(wmsStyle != null && wmsStyle.getParent() != null){ |
1154 |
lyr.setName(wmsStyle.getParent().getName()); |
1155 |
|
1156 |
if (isWMSService) {
|
1157 |
//replaceItemProperty(itemType, "wms_title", wmsStyle.getParent().getTitle());
|
1158 |
addIfNotExistsItemProperty(itemType, "wms_name", wmsStyle.getParent().getName());
|
1159 |
replaceItemProperty(itemType, "wms_abstract", wmsStyle.getParent().getAbstract());
|
1160 |
replaceItemProperty(itemType, "wms_extent", extent);
|
1161 |
|
1162 |
if (wmsparams.getDynValue("srsstr") != null |
1163 |
&& wmsparams.getDynValue("srsstr") instanceof String) { |
1164 |
replaceItemProperty(itemType, "wms_srs", (String) wmsparams |
1165 |
.getDynValue("srsstr"));
|
1166 |
} |
1167 |
} |
1168 |
|
1169 |
if (isWFSService) {
|
1170 |
//addItemProperty(itemType, "wfs_title", wmsStyle.getParent().getTitle());
|
1171 |
replaceItemProperty(itemType, "wfs_typename", wmsStyle.getParent().getName());
|
1172 |
replaceItemProperty(itemType, "wfs_abstract", wmsStyle.getParent().getAbstract());
|
1173 |
replaceItemProperty(itemType, "wfs_extent", extent);
|
1174 |
|
1175 |
if (wmsparams.getDynValue("srsstr") != null |
1176 |
&& wmsparams.getDynValue("srsstr") instanceof String) { |
1177 |
addItemProperty(itemType, "wfs_srs", (String) wmsparams |
1178 |
.getDynValue("srsstr"));
|
1179 |
} |
1180 |
} |
1181 |
} |
1182 |
|
1183 |
if(explorer.getVersion() == "1.1.1" || |
1184 |
explorer.getVersion() == "1.0.0"){
|
1185 |
replaceItemProperty(itemType, "wms_server_version", explorer.getVersion());
|
1186 |
} |
1187 |
addItemProperty(itemType, "wms_format", wmsparams.getFormat());
|
1188 |
} |
1189 |
} |
1190 |
} |
1191 |
} |
1192 |
} catch (ValidateDataParametersException e) {
|
1193 |
logger.info("Error validating Mapserver data");
|
1194 |
} catch (DataException e) {
|
1195 |
logger.info("Error getting Mapserver data");
|
1196 |
} catch(NoClassDefFoundError e1){ |
1197 |
logger.info("No est? instalada la extensi?n de raster");
|
1198 |
} catch (Exception e) { |
1199 |
logger.info("Error getting Mapserver data");
|
1200 |
} |
1201 |
|
1202 |
if (!itemType.getItem().isEmpty()) {
|
1203 |
lyr.setMetadata(getCorrectMetadata(itemType)); |
1204 |
} |
1205 |
|
1206 |
layer.setProperty(MAPSERVER_SYMBOL_PROPERTIES, localSymbolSet); |
1207 |
mergeSymbolSet(getSymbolSet(), localSymbolSet, PROJECT_MODE); |
1208 |
|
1209 |
if(hasLabels){
|
1210 |
lyr.getProcessing().add("LABEL_NO_CLIP=True");
|
1211 |
} |
1212 |
|
1213 |
return lyr;
|
1214 |
} |
1215 |
|
1216 |
|
1217 |
|
1218 |
private void getMapClass( |
1219 |
FLayer layer, |
1220 |
Layer lyr, |
1221 |
SymbolSet localSymbolSet, |
1222 |
ILegend legend, |
1223 |
double minScale,
|
1224 |
double maxScale){
|
1225 |
FLyrVect flyrvect = (FLyrVect) layer; |
1226 |
|
1227 |
ISymbol[] syms = null; |
1228 |
if (legend instanceof IClassifiedLegend) { |
1229 |
IClassifiedLegend classLeg = (IClassifiedLegend) legend; |
1230 |
syms = classLeg.getSymbols(); |
1231 |
} else {
|
1232 |
syms = new ISymbol[1]; |
1233 |
syms[0] = legend.getDefaultSymbol();
|
1234 |
} |
1235 |
|
1236 |
|
1237 |
for (int li = 0; li < syms.length; li++) { |
1238 |
ISymbol sy = syms[li]; |
1239 |
org.gvsig.publish.mapserver641.Class mapClass = new org.gvsig.publish.mapserver641.Class();
|
1240 |
if(!StringUtils.isBlank(sy.getDescription())){
|
1241 |
sy.setDescription(sy.getDescription().replace("\"", "")); |
1242 |
} |
1243 |
if(maxScale != -1){ |
1244 |
mapClass.setMaxScaleDenom(maxScale); |
1245 |
} |
1246 |
if(minScale != -1){ |
1247 |
mapClass.setMinScaleDenom(minScale); |
1248 |
} |
1249 |
|
1250 |
try{
|
1251 |
if (legend instanceof IClassifiedVectorLegend && |
1252 |
!(legend instanceof VectorFilterExpressionLegend)) {
|
1253 |
IClassifiedVectorLegend classvectLeg = (IClassifiedVectorLegend) legend; |
1254 |
if(classvectLeg.getClassifyingFieldNames().length > 0){ |
1255 |
lyr.setClassItem(classvectLeg.getClassifyingFieldNames()[0]);
|
1256 |
} |
1257 |
ExpressionType expression = new ExpressionType();
|
1258 |
expression.setType("String");
|
1259 |
expression.setValue("\"" + sy.getDescription() + "\""); |
1260 |
List<ISymbol> symbolsleg = Arrays.asList(classvectLeg.getSymbols()); |
1261 |
int indexleg = symbolsleg.indexOf(sy);
|
1262 |
if(indexleg >= 0){ |
1263 |
Object[] values = classvectLeg.getValues(); |
1264 |
Object value = classvectLeg.getValues()[indexleg];
|
1265 |
if(value instanceof Double){ |
1266 |
Double doublevalue = (Double) value; |
1267 |
long longvalue = doublevalue.longValue();
|
1268 |
if(doublevalue == longvalue){
|
1269 |
String x = String.valueOf(doublevalue.longValue()); |
1270 |
expression.setValue("\"" + x + "\""); |
1271 |
}else{
|
1272 |
expression.setValue("\"" + doublevalue.toString() + "\""); |
1273 |
} |
1274 |
}else{
|
1275 |
expression.setValue("\"" + value + "\""); |
1276 |
} |
1277 |
} |
1278 |
mapClass.setExpression(expression); |
1279 |
} |
1280 |
|
1281 |
if (legend instanceof VectorFilterExpressionLegend) { |
1282 |
VectorFilterExpressionLegend expressionLegend = (VectorFilterExpressionLegend) legend; |
1283 |
Object[] values = expressionLegend.getValues(); |
1284 |
if(values.length > li){
|
1285 |
ExpressionType expression = new ExpressionType();
|
1286 |
expression.setType("String");
|
1287 |
expression.setValue("\"" + values[li].toString().replace("\"", "") + "\""); |
1288 |
mapClass.setExpression(expression); |
1289 |
} |
1290 |
} |
1291 |
} |
1292 |
catch(NoClassDefFoundError e1){ |
1293 |
logger.info("No est? instalada la extensi?n de base legends (org.gvsig.legend.vectorfilterexpression.app.mainplugin)");
|
1294 |
if (legend instanceof IClassifiedVectorLegend) { |
1295 |
IClassifiedVectorLegend classvectLeg = (IClassifiedVectorLegend) legend; |
1296 |
if(classvectLeg.getClassifyingFieldNames().length > 0){ |
1297 |
lyr.setClassItem(classvectLeg.getClassifyingFieldNames()[0]);
|
1298 |
} |
1299 |
} |
1300 |
} |
1301 |
|
1302 |
|
1303 |
//Label label = new Label();
|
1304 |
|
1305 |
|
1306 |
if(sy instanceof IMultiLayerSymbol){ |
1307 |
IMultiLayerSymbol multisy = (IMultiLayerSymbol) sy; |
1308 |
for(int fv=0; fv < multisy.getLayerCount(); fv++){ |
1309 |
mapClass = createMapClassObject(multisy.getLayer(fv), mapClass, localSymbolSet, layer, lyr, li); |
1310 |
} |
1311 |
}else{
|
1312 |
mapClass = createMapClassObject(sy, mapClass, localSymbolSet, layer, lyr, li); |
1313 |
} |
1314 |
|
1315 |
lyr.getClazz().add(mapClass); |
1316 |
|
1317 |
ILabelingStrategy labelingStrategy = flyrvect |
1318 |
.getLabelingStrategy(); |
1319 |
if (labelingStrategy != null){ |
1320 |
if (labelingStrategy.getUsedFields().length > 0) { |
1321 |
if(flyrvect.isLabeled()){
|
1322 |
|
1323 |
lyr.setLabelItem(labelingStrategy.getUsedFields()[0]);
|
1324 |
ILabelingMethod labelingMethod = labelingStrategy |
1325 |
.getLabelingMethod(); |
1326 |
|
1327 |
// IZoomConstraints zoomConstraints = labelingStrategy.getZoomConstraints();
|
1328 |
// if(zoomConstraints != null){
|
1329 |
// mapClass.setMaxScaleDenom((double) zoomConstraints.getMaxScale());
|
1330 |
// mapClass.setMinScaleDenom((double) zoomConstraints.getMinScale());
|
1331 |
// }
|
1332 |
|
1333 |
|
1334 |
|
1335 |
if(labelingStrategy instanceof IAttrInTableLabelingStrategy){ |
1336 |
Label label = new Label(); |
1337 |
label.setPosition("uc");
|
1338 |
if (sy instanceof ISimpleTextSymbol) { |
1339 |
ISimpleTextSymbol stextSym = (ISimpleTextSymbol) sy; |
1340 |
label.setAngle(stextSym.getRotation() + "");
|
1341 |
} |
1342 |
IPlacementConstraints placementConstraints = labelingStrategy.getPlacementConstraints(); |
1343 |
if(placementConstraints != null){ |
1344 |
String npos = MapServerUtils.getPositionFromPlacementConstraints(placementConstraints);
|
1345 |
if(npos != null){ |
1346 |
label.setPosition(npos); |
1347 |
} |
1348 |
String nang = MapServerUtils.getAngleFromPlacementConstraints(placementConstraints);
|
1349 |
if(nang != null){ |
1350 |
label.setAngle(nang); |
1351 |
} |
1352 |
} |
1353 |
IAttrInTableLabelingStrategy attr = (IAttrInTableLabelingStrategy) labelingStrategy; |
1354 |
if(attr.getColorFont() != null){ |
1355 |
label.setColor(MapServerUtils.getRgbColorType(attr.getColorFont())); |
1356 |
}else{
|
1357 |
if(attr.getFixedColor() != null){ |
1358 |
label.setColor(MapServerUtils.getRgbColorType(attr.getFixedColor())); |
1359 |
} |
1360 |
} |
1361 |
|
1362 |
label.setFont(getFontName(attr.getFont().getName())); |
1363 |
usesFont = true;
|
1364 |
label.setSize(attr.getFont().getSize() + "");
|
1365 |
if(attr.getFixedSize() >0 && attr.getFixedSize() > attr.getFont().getSize()){ |
1366 |
label.setSize(attr.getFixedSize()+"");
|
1367 |
} |
1368 |
label.setText("["+labelingStrategy.getUsedFields()[0]+"]"); |
1369 |
label.setType("TRUETYPE");
|
1370 |
label.setWrap(" ");
|
1371 |
label.setMaxLength(MapServerUtils.getBigInteger(15));
|
1372 |
label.setAlign(AlignEnum.LEFT); |
1373 |
|
1374 |
SizeType labelOffset = new SizeType();
|
1375 |
labelOffset.setX(MapServerUtils.getBigInteger(0));
|
1376 |
labelOffset.setY(MapServerUtils.getBigInteger(9));
|
1377 |
label.setOffset(labelOffset); |
1378 |
label.setPartials(BooleanEnum.FALSE); |
1379 |
label.setForce(BooleanEnum.FALSE); |
1380 |
|
1381 |
ILabelClass[] labelClasses = attr.getLabelingMethod().getLabelClasses();
|
1382 |
for(int i=0; i<labelClasses.length; i++){ |
1383 |
ILabelClass labelClass = (ILabelClass) labelClasses[i]; |
1384 |
if(labelClass instanceof DefaultComplexLabelClass){ |
1385 |
DefaultComplexLabelClass clabelClass = (DefaultComplexLabelClass) labelClass; |
1386 |
if(!(clabelClass.getMaxScale() < 0 || clabelClass.getMaxScale() == 1000000001)){ |
1387 |
label.setMaxScaleDenom(Double.toString(clabelClass.getMaxScale()));
|
1388 |
} |
1389 |
if(!(clabelClass.getMinScale() < 0)){ |
1390 |
label.setMinScaleDenom(Double.toString(clabelClass.getMinScale()));
|
1391 |
} |
1392 |
} |
1393 |
|
1394 |
} |
1395 |
|
1396 |
if(label.getText() != null && !label.getText().equals("[]") && !label.getText().equals("")){ |
1397 |
mapClass.getLabel().add(label); |
1398 |
}else{
|
1399 |
if(label.getText() == null){ |
1400 |
mapClass.getLabel().add(label); |
1401 |
} |
1402 |
} |
1403 |
hasLabels = true;
|
1404 |
}else{
|
1405 |
|
1406 |
for (int fg = 0; fg < labelingMethod.getLabelClasses().length; fg++) { |
1407 |
Label label = new Label(); |
1408 |
label.setPosition("uc");
|
1409 |
if (sy instanceof ISimpleTextSymbol) { |
1410 |
ISimpleTextSymbol stextSym = (ISimpleTextSymbol) sy; |
1411 |
label.setAngle(stextSym.getRotation() + "");
|
1412 |
} |
1413 |
IPlacementConstraints placementConstraints = labelingStrategy.getPlacementConstraints(); |
1414 |
if(placementConstraints != null){ |
1415 |
String npos = MapServerUtils.getPositionFromPlacementConstraints(placementConstraints);
|
1416 |
if(npos != null){ |
1417 |
label.setPosition(npos); |
1418 |
} |
1419 |
String nang = MapServerUtils.getAngleFromPlacementConstraints(placementConstraints);
|
1420 |
if(nang != null){ |
1421 |
label.setAngle(nang); |
1422 |
} |
1423 |
} |
1424 |
ILabelClass labelClass = labelingMethod |
1425 |
.getLabelClasses()[fg]; |
1426 |
ITextSymbol textLabel = labelClass.getTextSymbol(); |
1427 |
label.setColor(MapServerUtils.getRgbColorType(textLabel.getColor())); |
1428 |
// label.setMaxSize(MapServerUtils.getBigInteger(textLabel.getBounds()
|
1429 |
// .getWidth()));
|
1430 |
label.setFont(getFontName(textLabel.getFont().getName())); |
1431 |
usesFont = true;
|
1432 |
label.setSize(textLabel.getFont().getSize() + "");
|
1433 |
if(textLabel.isDrawWithHalo()){
|
1434 |
label.setOutlineColor(MapServerUtils.getRgbColorType(textLabel |
1435 |
.getHaloColor())); |
1436 |
label.setOutlineWidth(MapServerUtils.getBigInteger(textLabel |
1437 |
.getHaloWidth())); |
1438 |
} |
1439 |
label.setWrap(" ");
|
1440 |
label.setMaxLength(MapServerUtils.getBigInteger(15));
|
1441 |
label.setAlign(AlignEnum.LEFT); |
1442 |
|
1443 |
label.setType("TRUETYPE");
|
1444 |
SizeType labelOffset = new SizeType();
|
1445 |
labelOffset.setX(MapServerUtils.getBigInteger(0));
|
1446 |
labelOffset.setY(MapServerUtils.getBigInteger(9));
|
1447 |
label.setOffset(labelOffset); |
1448 |
label.setPartials(BooleanEnum.FALSE); |
1449 |
label.setForce(BooleanEnum.FALSE); |
1450 |
if(labelClass.getLabelExpressions().length>0){ |
1451 |
label.setText("["+labelClass.getLabelExpressions()[0]+"]"); |
1452 |
} |
1453 |
|
1454 |
if(labelClass instanceof DefaultComplexLabelClass){ |
1455 |
DefaultComplexLabelClass clabelClass = (DefaultComplexLabelClass) labelClass; |
1456 |
if(!(clabelClass.getMaxScale() < 0 || clabelClass.getMaxScale() == 1000000001)){ |
1457 |
label.setMaxScaleDenom(Double.toString(clabelClass.getMaxScale()));
|
1458 |
} |
1459 |
if(!(clabelClass.getMinScale() < 0)){ |
1460 |
label.setMinScaleDenom(Double.toString(clabelClass.getMinScale()));
|
1461 |
} |
1462 |
} |
1463 |
|
1464 |
|
1465 |
if(label.getText() != null && !label.getText().equals("[]") && !label.getText().equals("")){ |
1466 |
mapClass.getLabel().add(label); |
1467 |
}else{
|
1468 |
if(label.getText() == null){ |
1469 |
mapClass.getLabel().add(label); |
1470 |
} |
1471 |
} |
1472 |
lyr.setLabelCache(StateEnum.ON); |
1473 |
hasLabels = true;
|
1474 |
} |
1475 |
} |
1476 |
} |
1477 |
} |
1478 |
} |
1479 |
} |
1480 |
|
1481 |
} |
1482 |
|
1483 |
|
1484 |
private org.gvsig.publish.mapserver641.Class createMapClassObject(ISymbol sy,
|
1485 |
org.gvsig.publish.mapserver641.Class mapClass, SymbolSet localSymbolSet, FLayer layer, Layer lyr, int li){
|
1486 |
MapserverSymbol mapserverSymbol = null;
|
1487 |
List<Style> classStyles = null; |
1488 |
Symbol symbolStyle = null;
|
1489 |
|
1490 |
mapserverSymbol = toMapserver(sy); |
1491 |
classStyles = mapserverSymbol.getStyle(); |
1492 |
symbolStyle = mapserverSymbol.getSymbol(); |
1493 |
|
1494 |
String symbolName = symbolStyle.getName();
|
1495 |
if(StringUtils.isBlank(symbolStyle.getName())){
|
1496 |
if (StringUtils.isBlank(sy.getDescription())) {
|
1497 |
symbolName = layer.getName(); |
1498 |
} else {
|
1499 |
symbolName = layer.getName() + "-" + sy.getDescription();
|
1500 |
} |
1501 |
symbolName = MapServerUtils.createUniqueSymbolName(localSymbolSet, symbolName); |
1502 |
} |
1503 |
|
1504 |
mapserverSymbol.getSymbol().setName(symbolName); |
1505 |
SymbolType stype = new SymbolType();
|
1506 |
stype.setType("String");
|
1507 |
stype.setValue("\"" + symbolName + "\""); |
1508 |
|
1509 |
/**
|
1510 |
* CLASS PARAMETERS
|
1511 |
*/
|
1512 |
for(int is =0; is<classStyles.size(); is++){ |
1513 |
if (sy instanceof IPictureMarkerSymbol) { |
1514 |
usesImages = true;
|
1515 |
} |
1516 |
|
1517 |
if (!StringUtils.isBlank(sy.getDescription())) {
|
1518 |
mapClass.setName(sy.getDescription()); |
1519 |
} else {
|
1520 |
String className = MapServerUtils.getNameWithoutExtension(layer.getName());
|
1521 |
if (li > 0) { |
1522 |
className += "-" + li;
|
1523 |
} |
1524 |
mapClass.setName(className); |
1525 |
} |
1526 |
|
1527 |
if (sy instanceof IMarkerSymbol) { |
1528 |
IMarkerSymbol markSym = (IMarkerSymbol) sy; |
1529 |
mapClass.setSize(MapServerUtils.getBigInteger(markSym.getSize())); |
1530 |
} |
1531 |
|
1532 |
mapClass.setStatus(MapServerUtils.getStateEnumSymbol(sy.isShapeVisible())); |
1533 |
|
1534 |
|
1535 |
if (sy instanceof ITextSymbol) { |
1536 |
ITextSymbol textSym = (ITextSymbol) sy; |
1537 |
// mapClass.setText(textSym.getText());
|
1538 |
|
1539 |
// LabelLeader lleader = new LabelLeader();
|
1540 |
// lleader.setGridstep(getBigInteger(5));
|
1541 |
// lleader.setMaxdistance(getBigInteger(10));
|
1542 |
// Style lleaderStyle = new Style();
|
1543 |
// lleaderStyle.setColor(getRgbColorType(Color.RED));
|
1544 |
// lleaderStyle.setWidth("1");
|
1545 |
// lleader.getStyle().add(lleaderStyle);
|
1546 |
// mapClass.setLabelLeader(lleader);
|
1547 |
Label label = new Label(); |
1548 |
label.setColor(MapServerUtils.getRgbColorType(textSym.getColor())); |
1549 |
// label.setMaxSize(MapServerUtils.getBigInteger(textSym.getBounds()
|
1550 |
// .getWidth()));
|
1551 |
label.setFont(getFontName(textSym.getFont().getName())); |
1552 |
usesFont = true;
|
1553 |
label.setSize(textSym.getFont().getSize() + "");
|
1554 |
label.setOutlineColor(MapServerUtils.getRgbColorType(textSym |
1555 |
.getHaloColor())); |
1556 |
label.setOutlineWidth(MapServerUtils.getBigInteger(textSym.getHaloWidth())); |
1557 |
// label.setText(textSym.getText());
|
1558 |
label.setType("TRUETYPE");
|
1559 |
label.setWrap(" ");
|
1560 |
label.setMaxLength(MapServerUtils.getBigInteger(15));
|
1561 |
label.setAlign(AlignEnum.LEFT); |
1562 |
label.setPosition("uc");
|
1563 |
SizeType labelOffset = new SizeType();
|
1564 |
labelOffset.setX(MapServerUtils.getBigInteger(0));
|
1565 |
labelOffset.setY(MapServerUtils.getBigInteger(9));
|
1566 |
label.setOffset(labelOffset); |
1567 |
label.setPartials(BooleanEnum.FALSE); |
1568 |
|
1569 |
if (sy instanceof ISimpleTextSymbol) { |
1570 |
ISimpleTextSymbol stextSym = (ISimpleTextSymbol) sy; |
1571 |
label.setAngle(stextSym.getRotation() + "");
|
1572 |
} |
1573 |
if(label.getText() != null && !label.getText().equals("[]") && !label.getText().equals("")){ |
1574 |
mapClass.getLabel().add(label); |
1575 |
}else{
|
1576 |
if(label.getText() == null){ |
1577 |
mapClass.getLabel().add(label); |
1578 |
} |
1579 |
} |
1580 |
hasLabels = true;
|
1581 |
} |
1582 |
|
1583 |
if (classStyles.get(is).getSymbol() == null |
1584 |
&& lyr.getType() == "POINT"
|
1585 |
&& StringUtils.isBlank(symbolStyle.getImage()) |
1586 |
&& StringUtils.isBlank(symbolStyle.getType())) { |
1587 |
// Defino el Punto por defecto
|
1588 |
if (StringUtils.isBlank(symbolName)) {
|
1589 |
symbolName = MapServerUtils.getNameWithoutExtension(lyr.getName()) + "-sym";
|
1590 |
} |
1591 |
|
1592 |
symbolStyle.setName(symbolName); |
1593 |
symbolStyle.setFilled(BooleanEnum.TRUE); |
1594 |
symbolStyle.setType("ellipse");
|
1595 |
Points points = new Points();
|
1596 |
PointType pointType = new PointType();
|
1597 |
pointType.setX((float) 1); |
1598 |
pointType.setY((float) 1); |
1599 |
points.getPoint().add(pointType); |
1600 |
symbolStyle.setPoints(points); |
1601 |
|
1602 |
SymbolType syty = new SymbolType();
|
1603 |
stype.setType("String");
|
1604 |
stype.setValue("\"" + symbolName + "\""); |
1605 |
if(StringUtils.isBlank(classStyles.get(is).getSize())){
|
1606 |
classStyles.get(is).setSize("4");
|
1607 |
} |
1608 |
if(!StringUtils.isBlank(syty.getValue())){
|
1609 |
classStyles.get(is).setSymbol(syty); |
1610 |
} |
1611 |
} |
1612 |
|
1613 |
|
1614 |
if (!StringUtils.isBlank(symbolStyle.getType())) {
|
1615 |
String name = null; |
1616 |
// Busco si existe en el SymbolSet general
|
1617 |
if(!this.isPropertiesPanel ){ |
1618 |
for(int j=0; j<getSymbolSet().getSymbol().size(); j++){ |
1619 |
name = MapserverToDynObjectHelper.equals(getSymbolSet().getSymbol().get(j), symbolStyle); |
1620 |
} |
1621 |
} |
1622 |
if( name == null){ |
1623 |
//Busco coincidencias en el symbolset local
|
1624 |
for(int k=0; k<localSymbolSet.getSymbol().size(); k++){ |
1625 |
name = MapserverToDynObjectHelper.equals(localSymbolSet.getSymbol().get(k), symbolStyle); |
1626 |
} |
1627 |
//Si no hay coincidencias, a?ado al local
|
1628 |
if(name == null){ |
1629 |
name = symbolStyle.getName(); |
1630 |
localSymbolSet.getSymbol().add(symbolStyle); |
1631 |
} |
1632 |
} |
1633 |
|
1634 |
|
1635 |
if(!StringUtils.isBlank(name)){
|
1636 |
stype.setValue("\"" + name + "\""); |
1637 |
classStyles.get(is).setSymbol(stype); |
1638 |
usesSymbols = true;
|
1639 |
} |
1640 |
|
1641 |
} |
1642 |
|
1643 |
// if(!StringUtils.isBlank(symbolStyle.getType()) &&
|
1644 |
// (symbolStyle.getType().equalsIgnoreCase("svg") ||
|
1645 |
// symbolStyle.getType().equalsIgnoreCase("pixmap"))){
|
1646 |
// MapserverToDynObjectHelper helper = new MapserverToDynObjectHelper();
|
1647 |
// DynObject newDynStyle = helper.createStyle(classStyles.get(is));
|
1648 |
// Style newStyle = new Style();
|
1649 |
// helper.copyTo(newDynStyle, newStyle);
|
1650 |
//
|
1651 |
//
|
1652 |
// newStyle.setSymbol(null);
|
1653 |
// classStyles.get(is).setColor(null);
|
1654 |
// classStyles.get(is).setOutlineColor(null);
|
1655 |
//
|
1656 |
// mapClass.getStyle().remove(symbolStyle);
|
1657 |
// mapClass.getStyle().add(newStyle);
|
1658 |
// }
|
1659 |
|
1660 |
mapClass.getStyle().add(classStyles.get(is)); |
1661 |
|
1662 |
} |
1663 |
|
1664 |
return mapClass;
|
1665 |
} |
1666 |
|
1667 |
|
1668 |
|
1669 |
private String getMapserverTypeName(DataType type) { |
1670 |
switch(type.getType()){
|
1671 |
case DataTypes.BOOLEAN:
|
1672 |
return "xsd:boolean"; |
1673 |
case DataTypes.DATE:
|
1674 |
return "xsd:date"; |
1675 |
case DataTypes.INT:
|
1676 |
case DataTypes.LONG:
|
1677 |
return "xsd:integer"; |
1678 |
case DataTypes.DOUBLE:
|
1679 |
case DataTypes.FLOAT:
|
1680 |
return "xsd:double"; |
1681 |
case DataTypes.STRING:
|
1682 |
return "xsd:string"; |
1683 |
} |
1684 |
return "xsd:string"; |
1685 |
} |
1686 |
|
1687 |
public PublishProperties getPublishProperties() {
|
1688 |
return properties;
|
1689 |
} |
1690 |
|
1691 |
|
1692 |
|
1693 |
public boolean createWMSProject(){ |
1694 |
boolean exit = true; |
1695 |
if(!StringUtils.isBlank(getPublishProperties().getMapFile())){
|
1696 |
String servicePath = ""; |
1697 |
if(getPublishProperties().isWMSService()){
|
1698 |
servicePath = File.separator + WMS_PATH;
|
1699 |
exit = exit && createFile(servicePath); |
1700 |
} |
1701 |
} |
1702 |
return exit;
|
1703 |
} |
1704 |
|
1705 |
public boolean createWFSProject(){ |
1706 |
boolean exit = true; |
1707 |
if(!StringUtils.isBlank(getPublishProperties().getMapFile())){
|
1708 |
String servicePath = ""; |
1709 |
if(getPublishProperties().isWFSService()){
|
1710 |
servicePath = File.separator + WFS_PATH;
|
1711 |
exit = exit && createFile(servicePath); |
1712 |
} |
1713 |
} |
1714 |
return exit;
|
1715 |
} |
1716 |
|
1717 |
public boolean createWCSProject(){ |
1718 |
boolean exit = true; |
1719 |
if(!StringUtils.isBlank(getPublishProperties().getMapFile())){
|
1720 |
String servicePath = ""; |
1721 |
if(getPublishProperties().isWCSService()){
|
1722 |
servicePath = File.separator + WCS_PATH;
|
1723 |
exit = exit && createFile(servicePath); |
1724 |
} |
1725 |
} |
1726 |
return exit;
|
1727 |
} |
1728 |
|
1729 |
private boolean createFile(String path){ |
1730 |
file = new File(MapServerUtils.getCorrectFilePathFromUrl(getPublishProperties().getMapFile()) |
1731 |
+ path + File.separator + MAPFILE_FILE);
|
1732 |
File tempFile = null; |
1733 |
try {
|
1734 |
tempFile = File.createTempFile("gvSIG-publish-XML-", null); |
1735 |
} catch (IOException e2) { |
1736 |
logger.error("[MapserverPublishService - publish()] Error creating the file: "
|
1737 |
+ tempFile.getAbsolutePath() + " \n" + e2);
|
1738 |
return false; |
1739 |
} |
1740 |
if (!file.exists()) {
|
1741 |
try {
|
1742 |
file.getParentFile().mkdirs(); |
1743 |
if (hasMapfile()) {
|
1744 |
file.createNewFile(); |
1745 |
} |
1746 |
} catch (IOException e) { |
1747 |
logger.error("[MapserverPublishService - publish()] Error creating the file: "
|
1748 |
+ file.getAbsolutePath() + " \n" + e);
|
1749 |
return false; |
1750 |
} |
1751 |
}else{
|
1752 |
if (!file.canWrite()) {
|
1753 |
logger.error("[MapserverPublishService - publish()] Error writing in file: "
|
1754 |
+ file.getAbsolutePath()); |
1755 |
return false; |
1756 |
} |
1757 |
} |
1758 |
|
1759 |
return true; |
1760 |
} |
1761 |
|
1762 |
|
1763 |
public Map getPublishedMap(ViewDocument viewDoc) { |
1764 |
if(viewDoc.getProperty(MAPSERVER_PANEL_PROPERTIES) != null && |
1765 |
viewDoc.getProperty(MAPSERVER_PANEL_PROPERTIES) instanceof Boolean){ |
1766 |
boolean active = (Boolean) viewDoc.getProperty(MAPSERVER_PANEL_PROPERTIES); |
1767 |
if(active){
|
1768 |
Object prop = viewDoc.getProperty(MAPSERVER_MAP_PROPERTIES);
|
1769 |
if (prop != null && prop instanceof Map){ |
1770 |
Map aux = (Map) viewDoc.getProperty(MAPSERVER_MAP_PROPERTIES); |
1771 |
MapserverToDynObjectHelper helper = new MapserverToDynObjectHelper();
|
1772 |
DynObject dynMap = helper.createMap(aux); |
1773 |
isEditedMapFile = true;
|
1774 |
return helper.createMap(dynMap);
|
1775 |
} |
1776 |
} |
1777 |
} |
1778 |
return null; |
1779 |
} |
1780 |
|
1781 |
private boolean isSharedWithOtherViews(FLayer layer, Symbol sm) { |
1782 |
ViewDocument view = MapServerUtils.getViewDocumentFromLayer(layer); |
1783 |
Object obj = view.getProperty(MAPSERVER_SYMBOL_PROPERTIES);
|
1784 |
if (obj != null && obj instanceof SymbolSet) { |
1785 |
SymbolSet sset = (SymbolSet) obj; |
1786 |
return isSymbolInSet(sset, sm);
|
1787 |
}else{
|
1788 |
return isSymbolInSet(getSymbolSet(), sm);
|
1789 |
} |
1790 |
} |
1791 |
|
1792 |
private boolean isSymbolInSet(SymbolSet sset, Symbol sm){ |
1793 |
for (int i = 0; i < sset.getSymbol().size(); i++) { |
1794 |
if (sset.getSymbol().get(i).getName() != null && |
1795 |
sset.getSymbol().get(i).getName().equals(sm.getName()) && |
1796 |
sset.getSymbol().get(i).getType().equalsIgnoreCase(sm.getType())) { |
1797 |
return true; |
1798 |
} |
1799 |
} |
1800 |
return false; |
1801 |
} |
1802 |
|
1803 |
private SymbolSet getSymbolSet() {
|
1804 |
if (this.symbolset == null) { |
1805 |
this.symbolset = new SymbolSet(); |
1806 |
} |
1807 |
return this.symbolset; |
1808 |
} |
1809 |
|
1810 |
private SymbolSet getSymbolSet(File file) { |
1811 |
SymbolSet aux = new SymbolSet();
|
1812 |
if (this.symbolset != null) { |
1813 |
for (int i = 0; i < symbolset.getSymbol().size(); i++) { |
1814 |
|
1815 |
Symbol sym = symbolset.getSymbol().get(i); |
1816 |
MapserverToDynObjectHelper helper = new MapserverToDynObjectHelper();
|
1817 |
|
1818 |
|
1819 |
Symbol sym2 = new Symbol();
|
1820 |
helper.copyTo(helper.createSymbol(sym), sym2); |
1821 |
if (sym2.getImage() != null && sym2.getImage() != "") { |
1822 |
if(file != null){ |
1823 |
sym2.setImage(MapServerUtils.relativePath(sym.getImage(), file.getParent()).replace(File.separator, "/")); |
1824 |
} |
1825 |
} |
1826 |
aux.getSymbol().add(sym2); |
1827 |
} |
1828 |
} |
1829 |
return aux;
|
1830 |
} |
1831 |
|
1832 |
private SymbolSet getPublishedSymbol(FLayer layer) {
|
1833 |
if (layer.getProperty(MAPSERVER_SYMBOL_PROPERTIES) != null && |
1834 |
layer.getProperty(MAPSERVER_SYMBOL_PROPERTIES) instanceof SymbolSet){
|
1835 |
SymbolSet auxSymbols = (SymbolSet) layer.getProperty(MAPSERVER_SYMBOL_PROPERTIES); |
1836 |
for(int i=0; i<auxSymbols.getSymbol().size(); i++){ |
1837 |
Symbol auxSym = auxSymbols.getSymbol().get(i); |
1838 |
if(auxSym.getImage() != null && auxSym.getImage() != ""){ |
1839 |
usesImages = true;
|
1840 |
break;
|
1841 |
} |
1842 |
} |
1843 |
return auxSymbols;
|
1844 |
} |
1845 |
return getSymbolSet();
|
1846 |
} |
1847 |
|
1848 |
private File getSymbolSetFile() { |
1849 |
if (symbolSetFile == null) { |
1850 |
symbolSetFile = new File(file.getParentFile() |
1851 |
.getAbsolutePath() + File.separator + SYMBOLSET_FILE);
|
1852 |
} |
1853 |
return symbolSetFile;
|
1854 |
} |
1855 |
|
1856 |
|
1857 |
/**
|
1858 |
* MAPSERVER UTILS MANIPULATION
|
1859 |
*/
|
1860 |
|
1861 |
private void addItemProperty(ItemType itemType, String name, String value) { |
1862 |
if(!StringUtils.isBlank(name) && !StringUtils.isBlank(value)){
|
1863 |
Item item = new Item();
|
1864 |
item.setName(name); |
1865 |
item.setValue(value.trim()); |
1866 |
itemType.getItem().add(item); |
1867 |
} |
1868 |
} |
1869 |
|
1870 |
private void replaceItemProperty(ItemType itemType, String name, String value) { |
1871 |
if(!StringUtils.isBlank(name) && !StringUtils.isBlank(value)){
|
1872 |
boolean isReplaced = false; |
1873 |
for(int i=0; i<itemType.getItem().size(); i++){ |
1874 |
Item item = itemType.getItem().get(i); |
1875 |
if(item.getName() == name){
|
1876 |
item.setValue(value); |
1877 |
isReplaced = true;
|
1878 |
} |
1879 |
} |
1880 |
if(!isReplaced){
|
1881 |
addItemProperty(itemType, name, value); |
1882 |
} |
1883 |
} |
1884 |
} |
1885 |
|
1886 |
private void addIfNotExistsItemProperty(ItemType itemType, String name, String value) { |
1887 |
if(!StringUtils.isBlank(name) && !StringUtils.isBlank(value)){
|
1888 |
boolean exists = false; |
1889 |
for(int i=0; i<itemType.getItem().size(); i++){ |
1890 |
Item item = itemType.getItem().get(i); |
1891 |
if(item.getName() == name){
|
1892 |
exists = true;
|
1893 |
} |
1894 |
} |
1895 |
if(!exists){
|
1896 |
addItemProperty(itemType, name, value); |
1897 |
} |
1898 |
} |
1899 |
} |
1900 |
|
1901 |
public String getCorrectProjection(String abrev) { |
1902 |
if(srs_used == null){ |
1903 |
srs_used = "";
|
1904 |
} |
1905 |
if(!srs_used.toLowerCase().contains(abrev.toLowerCase())){
|
1906 |
srs_used = abrev + " " + srs_used;
|
1907 |
} |
1908 |
return "init=" + abrev.toLowerCase(); |
1909 |
} |
1910 |
|
1911 |
public String getCorrectPath(String fileFormat){ |
1912 |
return getCorrectPath(fileFormat, file);
|
1913 |
} |
1914 |
|
1915 |
public String getCorrectPath(String fileFormat, File origen) { |
1916 |
if (!getPublishProperties().isAbsolutePath()) {
|
1917 |
if(!getPublishProperties().isDefaultPath()
|
1918 |
&& !getPublishProperties().isAbsolutePath()){ |
1919 |
String spath = getPublishProperties().getShapePath();
|
1920 |
if(StringUtils.isBlank(getPublishProperties().getShapePath())){
|
1921 |
spath = "";
|
1922 |
} |
1923 |
String shapeFile = origen.getParent();
|
1924 |
if(getPublishProperties().getMapFile().endsWith("/")){ |
1925 |
shapeFile = shapeFile + spath; |
1926 |
}else{
|
1927 |
shapeFile = shapeFile + "/" + spath;
|
1928 |
} |
1929 |
//if(fileFormat.startsWith(getPublishProperties().getShapePath())){
|
1930 |
//fileFormat = MapServerUtils.relativePath(fileFormat, shapeFile);
|
1931 |
//}
|
1932 |
if(fileFormat.contains("/")){ |
1933 |
String[] aux = fileFormat.split("/"); |
1934 |
if(aux.length > 0){ |
1935 |
fileFormat = aux[aux.length-1];
|
1936 |
} |
1937 |
} |
1938 |
} |
1939 |
}else{
|
1940 |
if(!getPublishProperties().isDefaultPath()){
|
1941 |
String localPath = getPublishProperties().getLocalPath();
|
1942 |
if (localPath != null |
1943 |
&& fileFormat.startsWith(getPublishProperties() |
1944 |
.getLocalPath())) { |
1945 |
|
1946 |
if (!localPath.endsWith("/")) { |
1947 |
localPath = localPath + "/";
|
1948 |
} |
1949 |
String remotePath = getPublishProperties().getRemotePath();
|
1950 |
if (!remotePath.endsWith("/")) { |
1951 |
remotePath = remotePath + "/";
|
1952 |
} |
1953 |
fileFormat = fileFormat.replace(localPath, remotePath); |
1954 |
//fileFormat = "." + "/" + fileFormat;
|
1955 |
//fileFormat = MapServerUtils.getCorrectFilePathFromUrl(fileFormat);
|
1956 |
} |
1957 |
} |
1958 |
} |
1959 |
|
1960 |
return fileFormat;
|
1961 |
} |
1962 |
|
1963 |
private MapserverSymbol toMapserver(ISymbol sym) {
|
1964 |
PublishManager manager = PublishLocator.getServiceManager() |
1965 |
.getPublishManager(); |
1966 |
|
1967 |
List<PublishSymbolConverterFactories> facts = manager
|
1968 |
.getSymbolConverterFactories(sym, NAME); |
1969 |
Iterator<PublishSymbolConverterFactories> it = facts.iterator();
|
1970 |
|
1971 |
List<Style> styles = new ArrayList<Style>(); |
1972 |
styles.add(new Style()); |
1973 |
MapserverSymbol symbol = new MapserverSymbol(new Symbol(), styles, new Label()); |
1974 |
|
1975 |
int maxAccurance = 0; |
1976 |
while (it.hasNext()) {
|
1977 |
PublishSymbolConverterFactories fs = (PublishSymbolConverterFactories) it |
1978 |
.next(); |
1979 |
if (fs.getAccurance() > 0) { |
1980 |
if (fs.getFactory().createConverter(sym) instanceof ToMapserverConverter) { |
1981 |
ToMapserverConverter converter = (ToMapserverConverter) fs |
1982 |
.getFactory().createConverter(sym); |
1983 |
converter.setMapserverService(this);
|
1984 |
if (fs.getAccurance() == 100) { |
1985 |
return converter.convert(sym);
|
1986 |
} else {
|
1987 |
if(fs.getAccurance() > maxAccurance){
|
1988 |
maxAccurance = fs.getAccurance(); |
1989 |
symbol = converter.convert(sym, symbol); |
1990 |
} |
1991 |
} |
1992 |
} |
1993 |
} |
1994 |
} |
1995 |
|
1996 |
return symbol;
|
1997 |
} |
1998 |
|
1999 |
public void setOverrideFiles(String b) { |
2000 |
this.overrideFiles = b;
|
2001 |
} |
2002 |
|
2003 |
public String getOverrideFiles() { |
2004 |
return this.overrideFiles; |
2005 |
} |
2006 |
|
2007 |
public File getCurrentFile() { |
2008 |
return file;
|
2009 |
} |
2010 |
|
2011 |
public void resetCurrentFile(){ |
2012 |
setCurrentFile(null);
|
2013 |
} |
2014 |
|
2015 |
public void setCurrentFile(File f) { |
2016 |
file = f; |
2017 |
} |
2018 |
|
2019 |
private File createMapFile(File file2, String name2) { |
2020 |
int loop = 1; |
2021 |
String end = ""; |
2022 |
File f = new File(file2.getParent() + File.separator + name2 + ".map"); |
2023 |
while(f.exists()){
|
2024 |
if(loop > 1){ |
2025 |
end = "-" + loop;
|
2026 |
} |
2027 |
f = new File(file2.getParent() + File.separator + name2 + end+ ".map"); |
2028 |
loop++; |
2029 |
} |
2030 |
return f;
|
2031 |
} |
2032 |
|
2033 |
private File createSymbolSetFile(File file2, String name2) { |
2034 |
int loop = 1; |
2035 |
String end = ""; |
2036 |
File f = new File(file2.getParent() + File.separator + name2 + "-sym.map"); |
2037 |
while(f.exists()){
|
2038 |
if(loop > 1){ |
2039 |
end = "-" + loop;
|
2040 |
} |
2041 |
f = new File(file2.getParent() + File.separator + name2 + "-sym"+ end+ ".map"); |
2042 |
loop++; |
2043 |
} |
2044 |
return f;
|
2045 |
} |
2046 |
|
2047 |
private File getFontSetFile() { |
2048 |
if (fontSetFile == null && file != null) { |
2049 |
fontSetFile = new File(file.getParentFile() |
2050 |
.getAbsolutePath() + File.separator + FONTSET_FILE);
|
2051 |
if(!fontSetFile.exists()){
|
2052 |
try {
|
2053 |
fontSetFile.createNewFile(); |
2054 |
} catch (IOException e) { |
2055 |
logger.warn("Error creating FontSet.txt file ", e);
|
2056 |
} |
2057 |
} |
2058 |
} |
2059 |
return fontSetFile;
|
2060 |
} |
2061 |
|
2062 |
private void mergeLayerDefinition(File file2, Map map, List<Layer> layerList, int layerMode) { |
2063 |
switch(layerMode){
|
2064 |
case LAYER_MODE:
|
2065 |
//
|
2066 |
|
2067 |
break;
|
2068 |
case PROJECT_MODE:
|
2069 |
for(int i=0; i<map.getInclude().size(); i++){ |
2070 |
String auxPath = map.getInclude().get(i).replace("//", File.separator); |
2071 |
File auxFile = new File(file2.getParentFile() |
2072 |
.getAbsolutePath() + File.separator + auxPath);
|
2073 |
|
2074 |
LayerSet auxLayerSet = (LayerSet) parserFile(auxFile, new LayerSet());
|
2075 |
boolean auxLayersModified = false; |
2076 |
boolean dontShow = false; |
2077 |
int n = -1; |
2078 |
for(int j=auxLayerSet.getLayer().size()-1; j>=0; j--){ |
2079 |
Layer auxLayer = auxLayerSet.getLayer().get(j); |
2080 |
for(int k=layerList.size()-1; k>=0; k--){ |
2081 |
Layer auxCurrentLayer = layerList.get(k); |
2082 |
if(auxLayer.getName().equals(auxCurrentLayer.getName())){
|
2083 |
if(!dontShow){
|
2084 |
PublishManager manager = getPublishProperties().getManager(); |
2085 |
Object[] options = {manager.getTranslation("keep_previous"), manager.getTranslation("update_to_new"), |
2086 |
manager.getTranslation("keep_both")};
|
2087 |
|
2088 |
JCheckBox checkbox = new JCheckBox(manager.getTranslation("not_again")); |
2089 |
String message = auxPath+" "+ |
2090 |
manager.getTranslation("layer_exists3")+
|
2091 |
" '"+ auxCurrentLayer.getName() +"'\n"+ |
2092 |
manager.getTranslation("layer_exists2");
|
2093 |
Object[] params = {message, checkbox}; |
2094 |
|
2095 |
n = JOptionPane.showOptionDialog(null, |
2096 |
params, |
2097 |
manager.getTranslation("layer_exists"),
|
2098 |
JOptionPane.YES_NO_OPTION,
|
2099 |
JOptionPane.WARNING_MESSAGE,
|
2100 |
null,
|
2101 |
options, |
2102 |
options[0]);
|
2103 |
|
2104 |
|
2105 |
dontShow = checkbox.isSelected(); |
2106 |
} |
2107 |
|
2108 |
if(n==0){ |
2109 |
layerList.remove(auxCurrentLayer); |
2110 |
} |
2111 |
|
2112 |
if(n==1){ |
2113 |
auxLayerSet.getLayer().remove(auxLayer); |
2114 |
auxLayersModified = true;
|
2115 |
} |
2116 |
} |
2117 |
} |
2118 |
} |
2119 |
if(auxLayerSet.getLayer().size()==0){ |
2120 |
map.getInclude().remove(i); |
2121 |
i = i--; |
2122 |
} |
2123 |
|
2124 |
if(auxLayersModified){
|
2125 |
parserFile(auxLayerSet, auxFile); |
2126 |
} |
2127 |
|
2128 |
|
2129 |
} |
2130 |
break;
|
2131 |
} |
2132 |
} |
2133 |
|
2134 |
private void mergeSymbolSet(SymbolSet symbolSet, SymbolSet localSymbolSet, int layerMode) { |
2135 |
switch(layerMode){
|
2136 |
case LAYER_MODE:
|
2137 |
//
|
2138 |
|
2139 |
break;
|
2140 |
case PROJECT_MODE:
|
2141 |
Iterator<Symbol> it = localSymbolSet.getSymbol().iterator();
|
2142 |
while(it.hasNext()){
|
2143 |
Symbol sym = (Symbol) it.next(); |
2144 |
if(sym.getType().equalsIgnoreCase("svg") || sym.getType().equalsIgnoreCase("pixmap")){ |
2145 |
File originalFile = new File(sym.getImage()); |
2146 |
// if(originalFile.isFile()){
|
2147 |
// sym.setImage(MapServerUtils.relativePath(
|
2148 |
// originalFile.getAbsolutePath(),
|
2149 |
// originalFile.getParentFile().getParent()));
|
2150 |
// }
|
2151 |
} |
2152 |
boolean isAnUpdate= false; |
2153 |
for(int i=0; i<symbolSet.getSymbol().size(); i++){ |
2154 |
if(symbolSet.getSymbol().get(i).getName().equals(sym.getName())){
|
2155 |
symbolSet.getSymbol().set(i, sym); |
2156 |
isAnUpdate = true;
|
2157 |
} |
2158 |
} |
2159 |
if(!isAnUpdate){
|
2160 |
symbolSet.getSymbol().add(sym); |
2161 |
} |
2162 |
} |
2163 |
break;
|
2164 |
} |
2165 |
} |
2166 |
|
2167 |
private Layer getPublishedLayer(FLayer flayer) {
|
2168 |
isEditedLayer = false;
|
2169 |
if(flayer.getProperty(MAPSERVER_LAYERPANEL_PROPERTIES) != null && |
2170 |
flayer.getProperty(MAPSERVER_LAYERPANEL_PROPERTIES) instanceof Boolean){ |
2171 |
boolean active = (Boolean) flayer.getProperty(MAPSERVER_LAYERPANEL_PROPERTIES); |
2172 |
if(active){
|
2173 |
Object prop = flayer.getProperty(MAPSERVER_LAYER_PROPERTIES);
|
2174 |
if (prop != null && prop instanceof Layer){ |
2175 |
isEditedLayer = true;
|
2176 |
Layer auxLayer = (Layer) flayer.getProperty(MAPSERVER_LAYER_PROPERTIES); |
2177 |
for(int i=0; i<auxLayer.getClazz().size();i++){ |
2178 |
Class auxClass = auxLayer.getClazz().get(i);
|
2179 |
for(int j=0; j<auxClass.getLabel().size(); j++){ |
2180 |
Label auxLabel = auxClass.getLabel().get(j);
|
2181 |
usesFont = true;
|
2182 |
if(!StringUtils.isBlank(auxLabel.getFont())){
|
2183 |
getFontName(auxLabel.getFont().replace("\"", "")); |
2184 |
} |
2185 |
} |
2186 |
} |
2187 |
return auxLayer;
|
2188 |
} |
2189 |
} |
2190 |
} |
2191 |
return makepublish(flayer);
|
2192 |
} |
2193 |
|
2194 |
|
2195 |
|
2196 |
|
2197 |
private void updateSymbolName(List<Layer> layerList, String oldName, String newName) { |
2198 |
for(int i=0; i<layerList.size(); i++){ |
2199 |
List<org.gvsig.publish.mapserver641.Class> clss = layerList.get(i).getClazz();
|
2200 |
for(int j=0; j<clss.size(); j++){ |
2201 |
List<Style> styles = clss.get(j).getStyle(); |
2202 |
Iterator<Style> it = styles.iterator(); |
2203 |
while(it.hasNext()){
|
2204 |
Style style = (Style) it.next(); |
2205 |
if(style.getSymbol() != null && |
2206 |
!StringUtils.isBlank(style.getSymbol().getValue()) && |
2207 |
style.getSymbol().getValue().equals("\""+oldName+"\"")){ |
2208 |
style.getSymbol().setValue("\""+newName+"\""); |
2209 |
} |
2210 |
} |
2211 |
} |
2212 |
} |
2213 |
} |
2214 |
|
2215 |
|
2216 |
|
2217 |
private String getFontName(String name2) { |
2218 |
String auxName = name2.replace(" ", "_").toLowerCase(); |
2219 |
if (!isFontLoaded(auxName)) {
|
2220 |
auxName = addFontFile(auxName); |
2221 |
} |
2222 |
return "\"" + auxName + "\""; |
2223 |
} |
2224 |
|
2225 |
private String addFontFile(String fontName) { |
2226 |
InputStream input = DefaultPublishManager.class
|
2227 |
.getResourceAsStream("/org/gvsig/publish/impl/mapserver/Font/"
|
2228 |
+ FONTSET_FILE); |
2229 |
String fontFile = getFontFile(input, fontName);
|
2230 |
if (fontFile == null) { |
2231 |
fontName = DEFAULT_FONT; |
2232 |
fontFile = DEFAULT_FILE; |
2233 |
} |
2234 |
if (!isFontLoaded(fontName) && file != null) { |
2235 |
try {
|
2236 |
PrintWriter out = new PrintWriter(new BufferedWriter( |
2237 |
new FileWriter(getFontSetFile(), true))); |
2238 |
String filePath = FONTSET_FOLDER + "/" + fontFile; |
2239 |
URL srcFile = DefaultPublishManager.class
|
2240 |
.getResource("/org/gvsig/publish/impl/mapserver/Font/" + fontFile);
|
2241 |
out.println(fontName + " " + filePath);
|
2242 |
out.close(); |
2243 |
|
2244 |
File origen = new File(srcFile.getFile()); |
2245 |
File destino = new File(getCorrectPath(file.getParent() |
2246 |
+ File.separator + filePath));
|
2247 |
FileUtils.copyURLToFile(srcFile, |
2248 |
new File(getCorrectPath(file.getParent() |
2249 |
+ File.separator + filePath)));
|
2250 |
} catch (IOException e) { |
2251 |
// exception handling left as an exercise for the reader
|
2252 |
} |
2253 |
} |
2254 |
return fontName;
|
2255 |
} |
2256 |
|
2257 |
private boolean isFontLoaded(String fontName) { |
2258 |
try {
|
2259 |
File fontFile = getFontSetFile();
|
2260 |
if (fontFile == null) { |
2261 |
return false; |
2262 |
} |
2263 |
InputStream input = new FileInputStream(fontFile); |
2264 |
String fontFileName = getFontFile(input, fontName);
|
2265 |
if (fontFileName != null) { |
2266 |
return true; |
2267 |
} |
2268 |
} catch (FileNotFoundException e) { |
2269 |
logger.info("Error getting Mapserver fonts file");
|
2270 |
} |
2271 |
return false; |
2272 |
} |
2273 |
|
2274 |
private String getFontFile(InputStream input, String fontName) { |
2275 |
BufferedReader in = new BufferedReader(new InputStreamReader(input)); |
2276 |
try {
|
2277 |
String line = in.readLine();
|
2278 |
while (line != null) { |
2279 |
if (line.toLowerCase().startsWith(fontName.toLowerCase())) {
|
2280 |
String[] fields = line.split("\\s"); |
2281 |
if (fields.length > 1) { |
2282 |
return fields[fields.length - 1]; |
2283 |
} |
2284 |
} |
2285 |
line = in.readLine(); |
2286 |
} |
2287 |
} catch (IOException e) { |
2288 |
logger.info("Error reading Mapserver fonts file");
|
2289 |
return null; |
2290 |
} |
2291 |
return null; |
2292 |
} |
2293 |
|
2294 |
private ItemType getCorrectMetadata(ItemType itemType3) {
|
2295 |
for(int i=itemType3.getItem().size()-1; i>=0; i--){ |
2296 |
Item item = itemType3.getItem().get(i); |
2297 |
if(!isWMSService
|
2298 |
&& item.getName().startsWith("wms_")){
|
2299 |
itemType3.getItem().remove(item); |
2300 |
} |
2301 |
if(!isWFSService
|
2302 |
&& item.getName().startsWith("wfs_")){
|
2303 |
itemType3.getItem().remove(item); |
2304 |
} |
2305 |
if(!isWCSService
|
2306 |
&& item.getName().startsWith("wcs_")){
|
2307 |
itemType3.getItem().remove(item); |
2308 |
} |
2309 |
if(!isWMSService
|
2310 |
&& !isWFSService |
2311 |
&& !isWCSService |
2312 |
&& item.getName().startsWith("ows_")){
|
2313 |
itemType3.getItem().remove(item); |
2314 |
} |
2315 |
} |
2316 |
return itemType3;
|
2317 |
} |
2318 |
|
2319 |
|
2320 |
public void loadWMSService(){ |
2321 |
isWMSService = true;
|
2322 |
isWFSService = false;
|
2323 |
isWCSService = false;
|
2324 |
} |
2325 |
|
2326 |
public void loadWFSService(){ |
2327 |
isWMSService = false;
|
2328 |
isWFSService = true;
|
2329 |
isWCSService = false;
|
2330 |
} |
2331 |
|
2332 |
public void loadWCSService(){ |
2333 |
isWMSService = false;
|
2334 |
isWFSService = false;
|
2335 |
isWCSService = true;
|
2336 |
} |
2337 |
|
2338 |
public void loadAllServices(){ |
2339 |
isWMSService = true;
|
2340 |
isWFSService = true;
|
2341 |
isWCSService = true;
|
2342 |
} |
2343 |
|
2344 |
public void unloadAllServices(){ |
2345 |
isWMSService = false;
|
2346 |
isWFSService = false;
|
2347 |
isWCSService = false;
|
2348 |
} |
2349 |
|
2350 |
public boolean hasMapfile(){ |
2351 |
return isWMSService || isWFSService || isWCSService;
|
2352 |
} |
2353 |
|
2354 |
|
2355 |
public Object parserFile(File file, Object mapObject) { |
2356 |
File tempFile = new File(MapServerUtils.getNameWithoutExtension(file.getAbsolutePath())+".xml"); |
2357 |
|
2358 |
if(!tempFile.exists()){
|
2359 |
return null; |
2360 |
} |
2361 |
JAXBContext jaxbContext2; |
2362 |
try {
|
2363 |
jaxbContext2 = JAXBContext.newInstance(mapObject.getClass()); |
2364 |
javax.xml.bind.Unmarshaller jaxbUnMarshaller2 = jaxbContext2.createUnmarshaller(); |
2365 |
//jaxbUnMarshaller2.setProperty(Unmarshaller.JAXB_FORMATTED_OUTPUT, true);
|
2366 |
Object obj = jaxbUnMarshaller2.unmarshal(tempFile);
|
2367 |
return obj;
|
2368 |
} catch (JAXBException e) {
|
2369 |
logger.info("Error umarshalling Mapserver data");
|
2370 |
} |
2371 |
|
2372 |
return null; |
2373 |
} |
2374 |
|
2375 |
public void parserFile(Object mapObject, File file) { |
2376 |
parserFile(mapObject, file, false);
|
2377 |
} |
2378 |
|
2379 |
public void parserFile(Object mapObject, File file, boolean removeTemporal) { |
2380 |
FileOutputStream fos = null; |
2381 |
try {
|
2382 |
String extension = ".xml"; |
2383 |
if(removeTemporal){
|
2384 |
extension = ".tmp" + extension;
|
2385 |
} |
2386 |
File tempFile = new File(MapServerUtils.getNameWithoutExtension(file.getAbsolutePath())+extension); |
2387 |
|
2388 |
// Proceso de transformaci?n de los datos
|
2389 |
JAXBContext jaxbContext2 = JAXBContext.newInstance(mapObject.getClass()); |
2390 |
javax.xml.bind.Marshaller jaxbMarshaller2 = jaxbContext2.createMarshaller(); |
2391 |
jaxbMarshaller2.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
|
2392 |
jaxbMarshaller2.marshal(mapObject, tempFile); |
2393 |
|
2394 |
Source xmlSource2 = new StreamSource(tempFile); |
2395 |
InputStream input = DefaultPublishManager.class
|
2396 |
.getResourceAsStream("/org/gvsig/publish/impl/mapserver/mapfile.xsl");
|
2397 |
Source xsltSource2 = new StreamSource(input); |
2398 |
|
2399 |
// create an instance of TransformerFactory
|
2400 |
TransformerFactory transFact2 = new org.apache.xalan.processor.TransformerFactoryImpl(); |
2401 |
Transformer trans2 = transFact2.newTransformer(xsltSource2);
|
2402 |
|
2403 |
fos = new FileOutputStream(file); |
2404 |
Result fileResult = new StreamResult(fos); |
2405 |
trans2.transform(xmlSource2, fileResult); |
2406 |
|
2407 |
if(removeTemporal){
|
2408 |
tempFile.delete(); |
2409 |
} |
2410 |
|
2411 |
|
2412 |
} catch (Exception e) { |
2413 |
logger.warn("", e);
|
2414 |
}finally {
|
2415 |
if (fos != null) { |
2416 |
try {
|
2417 |
fos.close(); |
2418 |
} catch (IOException e) { |
2419 |
logger.info("Error parsing Mapserver data to a file");
|
2420 |
} |
2421 |
} |
2422 |
} |
2423 |
} |
2424 |
|
2425 |
public void restoreFile(File xmlFile, File file2){ |
2426 |
FileOutputStream fos = null; |
2427 |
try {
|
2428 |
Source xmlSource2 = new StreamSource(xmlFile); |
2429 |
InputStream input2 = DefaultPublishManager.class
|
2430 |
.getResourceAsStream("/org/gvsig/publish/impl/mapserver/mapfile.xsl");
|
2431 |
Source xsltSource2 = new StreamSource(input2); |
2432 |
|
2433 |
// // create an instance of TransformerFactory
|
2434 |
TransformerFactory transFact2 = new org.apache.xalan.processor.TransformerFactoryImpl(); |
2435 |
Transformer trans2 = transFact2.newTransformer(xsltSource2);
|
2436 |
|
2437 |
fos = new FileOutputStream(file2); |
2438 |
Result fileResult = new StreamResult(fos); |
2439 |
trans2.transform(xmlSource2, fileResult); |
2440 |
|
2441 |
|
2442 |
|
2443 |
//tempFile.delete();
|
2444 |
|
2445 |
} catch (Exception e) { |
2446 |
logger.warn("", e);
|
2447 |
}finally {
|
2448 |
if (fos != null) { |
2449 |
try {
|
2450 |
fos.close(); |
2451 |
} catch (IOException e) { |
2452 |
logger.info("Error restoring Mapserver data");
|
2453 |
} |
2454 |
} |
2455 |
} |
2456 |
|
2457 |
} |
2458 |
|
2459 |
public Layer makepublish(FLayer lyr, boolean b) { |
2460 |
this.isPropertiesPanel = b;
|
2461 |
return makepublish(lyr);
|
2462 |
} |
2463 |
} |