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