root / trunk / extensions / extPublish / src-test / PublishControlerPruebas.java @ 11445
History | View | Annotate | Download (11 KB)
1 | 8961 | jvhigon | |
---|---|---|---|
2 | |||
3 | import java.awt.BasicStroke; |
||
4 | import java.awt.Color; |
||
5 | import java.util.ArrayList; |
||
6 | |||
7 | import org.gvsig.remoteservices.conf.mapserver.MapServerConfiguration; |
||
8 | import org.gvsig.remoteservices.conf.mapserver.MapServerConfiguration.ConfigFile; |
||
9 | import org.gvsig.remoteservices.conf.mapserver.MapServerConfiguration.MapClass; |
||
10 | import org.gvsig.remoteservices.conf.mapserver.MapServerConfiguration.MapLayer; |
||
11 | import org.gvsig.remoteservices.conf.mapserver.MapServerConfiguration.MetadataLayer; |
||
12 | import org.gvsig.remoteservices.conf.mapserver.MapServerConfiguration.PostgisLayer; |
||
13 | |||
14 | import com.iver.andami.PluginServices; |
||
15 | import com.iver.andami.ui.mdiManager.IWindow; |
||
16 | import com.iver.cit.gvsig.fmap.MapControl; |
||
17 | import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
||
18 | import com.iver.cit.gvsig.fmap.drivers.raster.CmsRasterDriver; |
||
19 | import com.iver.cit.gvsig.fmap.drivers.shp.IndexedShpDriver; |
||
20 | import com.iver.cit.gvsig.fmap.layers.FLayer; |
||
21 | import com.iver.cit.gvsig.fmap.layers.FLayerFileVectorial; |
||
22 | import com.iver.cit.gvsig.fmap.layers.FLayerGenericVectorial; |
||
23 | import com.iver.cit.gvsig.fmap.layers.FLayerJDBCVectorial; |
||
24 | import com.iver.cit.gvsig.fmap.layers.FLayers; |
||
25 | import com.iver.cit.gvsig.fmap.layers.FLyrRaster; |
||
26 | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
||
27 | import com.iver.cit.gvsig.fmap.layers.ISpatialDB; |
||
28 | import com.iver.cit.gvsig.fmap.rendering.Legend; |
||
29 | import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend; |
||
30 | import com.iver.cit.gvsig.fmap.rendering.VectorialIntervalLegend; |
||
31 | import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
||
32 | import com.iver.cit.gvsig.project.documents.view.gui.View; |
||
33 | import com.iver.cit.gvsig.publish.Servers; |
||
34 | import com.iver.cit.gvsig.publish.layers.LayerLoader; |
||
35 | import com.iver.cit.gvsig.publish.model.ServiceInfo; |
||
36 | import com.iver.cit.gvsig.publish.servers.geoserver.GeoserverPublishControler; |
||
37 | import com.iver.cit.gvsig.publish.servers.mapserver.MapServerPublishControler; |
||
38 | import com.iver.utiles.swing.jcomboServer.ServerData; |
||
39 | |||
40 | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
41 | *
|
||
42 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
43 | *
|
||
44 | * This program is free software; you can redistribute it and/or
|
||
45 | * modify it under the terms of the GNU General Public License
|
||
46 | * as published by the Free Software Foundation; either version 2
|
||
47 | * of the License, or (at your option) any later version.
|
||
48 | *
|
||
49 | * This program is distributed in the hope that it will be useful,
|
||
50 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
51 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
52 | * GNU General Public License for more details.
|
||
53 | *
|
||
54 | * You should have received a copy of the GNU General Public License
|
||
55 | * along with this program; if not, write to the Free Software
|
||
56 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
57 | *
|
||
58 | * For more information, contact:
|
||
59 | *
|
||
60 | * Generalitat Valenciana
|
||
61 | * Conselleria d'Infraestructures i Transport
|
||
62 | * Av. Blasco Ib??ez, 50
|
||
63 | * 46010 VALENCIA
|
||
64 | * SPAIN
|
||
65 | *
|
||
66 | * +34 963862235
|
||
67 | * gvsig@gva.es
|
||
68 | * www.gvsig.gva.es
|
||
69 | *
|
||
70 | * or
|
||
71 | *
|
||
72 | * IVER T.I. S.A
|
||
73 | * Salamanca 50
|
||
74 | * 46005 Valencia
|
||
75 | * Spain
|
||
76 | *
|
||
77 | * +34 963163400
|
||
78 | * dac@iver.es
|
||
79 | */
|
||
80 | /* CVS MESSAGES:
|
||
81 | *
|
||
82 | * $Id$
|
||
83 | * $Log$
|
||
84 | 10626 | caballero | * Revision 1.3 2007-03-06 16:50:30 caballero
|
85 | * Exceptions
|
||
86 | *
|
||
87 | * Revision 1.2 2006/11/22 15:57:03 jorpiell
|
||
88 | 8969 | jorpiell | * Se ha ajustado el interfaz de usuario
|
89 | *
|
||
90 | * Revision 1.1 2006/11/22 12:17:11 jvhigon
|
||
91 | 8961 | jvhigon | * ejemplo de setproperties
|
92 | *
|
||
93 | * Revision 1.8 2006/11/22 09:51:01 jvhigon
|
||
94 | * reafactoring del ServiceInfo en marcha ...
|
||
95 | *
|
||
96 | * Revision 1.7 2006/11/20 14:17:47 dagilgon
|
||
97 | * *** empty log message ***
|
||
98 | *
|
||
99 | * Revision 1.6 2006/11/17 09:17:18 jorpiell
|
||
100 | * Cambios motivados por el cambio de RC2 a RC3 en el branch
|
||
101 | *
|
||
102 | * Revision 1.5 2006/10/05 12:13:43 jorpiell
|
||
103 | * A?adida una factor?a en la clase publishControler
|
||
104 | *
|
||
105 | * Revision 1.4 2006/10/03 10:30:14 dagilgon
|
||
106 | * adaptation to branch v10
|
||
107 | *
|
||
108 | * Revision 1.3 2006/09/28 15:04:02 fjp
|
||
109 | * Usar siempre que se pueda ISymbol en lugar de FSymbol
|
||
110 | *
|
||
111 | * Revision 1.2 2006/09/08 15:39:49 jorpiell
|
||
112 | * A?adida la capacidad de publicar con WFS
|
||
113 | *
|
||
114 | * Revision 1.1 2006/09/08 08:58:53 jorpiell
|
||
115 | * Se han renombrado y modificado algunas clases
|
||
116 | *
|
||
117 | *
|
||
118 | */
|
||
119 | /**
|
||
120 | * @author Jorge Piera Llodr? (piera_jor@gva.es)
|
||
121 | */
|
||
122 | 8969 | jorpiell | public abstract class PublishControlerPruebas { |
123 | 10626 | caballero | |
124 | 8961 | jvhigon | /*
|
125 | private View view = null;
|
||
126 | private MapControl mapCtrl = null;
|
||
127 | private FLayers layers = null;
|
||
128 | private String service = null;
|
||
129 | protected ServiceInfo serviceInfo = null;
|
||
130 | */
|
||
131 | /**
|
||
132 | * Returs a publish controler
|
||
133 | * @param brand
|
||
134 | * @param type
|
||
135 | * @return
|
||
136 | */
|
||
137 | /*
|
||
138 | public static PublishControler getPublishControler(String brand,String type){
|
||
139 | if (brand.compareTo(Servers.SERVER_BRAND_MAPSERVER) == 0){
|
||
140 | return new MapServerPublishControler(type);
|
||
141 | } else if (brand.compareTo(Servers.SERVER_BRAND_GEOSERVER) == 0){
|
||
142 | return new GeoserverPublishControler(type);
|
||
143 | }
|
||
144 | return null;
|
||
145 | }
|
||
146 | */
|
||
147 | /**
|
||
148 | * Constructor
|
||
149 | *
|
||
150 | 10626 | caballero | *
|
151 | 8961 | jvhigon | public PublishControler(String service) {
|
152 | IWindow[] windows = PluginServices.getMDIManager().getAllWindows();
|
||
153 | for (int i=0 ; i<windows.length ; i++){
|
||
154 | if (windows[i] instanceof View){
|
||
155 | view = (View)windows[i];
|
||
156 | }
|
||
157 | }
|
||
158 | mapCtrl = view.getMapControl();
|
||
159 | layers = mapCtrl.getMapContext().getLayers();
|
||
160 | this.service = service;
|
||
161 | }
|
||
162 | */
|
||
163 | public abstract Object publish(ServerData serverData); |
||
164 | |||
165 | /**
|
||
166 | * @return Returns the layers.
|
||
167 | *
|
||
168 | public FLayers getLayers() {
|
||
169 | return layers;
|
||
170 | }
|
||
171 | */
|
||
172 | /**
|
||
173 | * @param layers The layers to set.
|
||
174 | *
|
||
175 | public void setLayers(FLayers layers) {
|
||
176 | this.layers = layers;
|
||
177 | }
|
||
178 | */
|
||
179 | /**
|
||
180 | * @return Returns the mapCtrl.
|
||
181 | *
|
||
182 | *
|
||
183 | public MapControl getMapCtrl() {
|
||
184 | return mapCtrl;
|
||
185 | }
|
||
186 | */
|
||
187 | /**
|
||
188 | * @param mapCtrl The mapCtrl to set.
|
||
189 | *
|
||
190 | public void setMapCtrl(MapControl mapCtrl) {
|
||
191 | this.mapCtrl = mapCtrl;
|
||
192 | }
|
||
193 | */
|
||
194 | /**
|
||
195 | * @return Returns the view.
|
||
196 | *
|
||
197 | *
|
||
198 | public View getView() {
|
||
199 | return view;
|
||
200 | }
|
||
201 | */
|
||
202 | /**
|
||
203 | * @param view The view to set.
|
||
204 | *
|
||
205 | public void setView(View view) {
|
||
206 | this.view = view;
|
||
207 | }
|
||
208 | */
|
||
209 | /**
|
||
210 | * @return Returns the service.
|
||
211 | *
|
||
212 | public String getService() {
|
||
213 | return service;
|
||
214 | }
|
||
215 | */
|
||
216 | /**
|
||
217 | * This method set all layer properties of the view.
|
||
218 | * Property: Value:
|
||
219 | * hasChilds true/false
|
||
220 | * mosaic: true/false
|
||
221 | 10626 | caballero | * time: true/false
|
222 | 8961 | jvhigon | *
|
223 | private void setLayerProperties(){
|
||
224 | for (int i = 0; i < getLayers().getLayersCount(); i++) {
|
||
225 | FLayer lyr = getLayers().getLayer(i);
|
||
226 | if (lyr.isVisible()){
|
||
227 | // try{
|
||
228 | if (lyr instanceof FLayers){
|
||
229 | lyr.setProperty("hasChilds","true");
|
||
230 | //Check if the layer name specify a MOSAIC or TIME layer
|
||
231 | if (lyr.getName().startsWith("[")){
|
||
232 | if (lyr.getName().startsWith("[" + LayerLoader.GROUP_LAYER_TIME)){
|
||
233 | lyr.setProperty("time", "true");
|
||
234 | }else if(lyr.getName().startsWith("[" + LayerLoader.GROUP_LAYER_MOSAIC)){
|
||
235 | lyr.setProperty("mosaic","true");
|
||
236 | }
|
||
237 | }
|
||
238 | FLayers groupLayers = (FLayers) lyr;
|
||
239 | for (int j= 0; j<groupLayers.getLayersCount(); j++){
|
||
240 | FLayer childLayer = groupLayers.getLayer(j);
|
||
241 | setLayerProperties(childLayer);
|
||
242 | 10626 | caballero | }
|
243 | 8961 | jvhigon | }else{
|
244 | lyr.setProperty("hasChilds","false");
|
||
245 | 10626 | caballero | setLayerProperties(lyr);
|
246 | 8961 | jvhigon | }
|
247 | // }catch(LayerException e){
|
||
248 | 10626 | caballero | //TODO: Should't print
|
249 | 8961 | jvhigon | // System.out.println("Layer Exception in PublishControler.java");
|
250 | // }
|
||
251 | }
|
||
252 | 10626 | caballero | }
|
253 | |||
254 | 8961 | jvhigon | }
|
255 | */
|
||
256 | /**
|
||
257 | * Property: Value:
|
||
258 | 10626 | caballero | * layerType RASTER, POSTGIS, SHAPE
|
259 | 8961 | jvhigon | *
|
260 | 10626 | caballero | *
|
261 | |||
262 | 8961 | jvhigon | private void setLayerProperties(FLayer lyr) {
|
263 | if (lyr instanceof FLyrVect){
|
||
264 | FLyrVect flyrVect = (FLyrVect)lyr;
|
||
265 | //Legend
|
||
266 | //setLegendProperties(flyrVect);
|
||
267 | System.out.println(flyrVect.getSource().getDriver().getName());
|
||
268 | //Postgis
|
||
269 | if(flyrVect.getSource().getDriver().getName().compareTo("PostGIS JDBC Driver")==0){
|
||
270 | flyrVect.setProperty("layerType", "POSTGIS");
|
||
271 | 10626 | caballero | setLayerPostGISProperties(flyrVect);
|
272 | 8961 | jvhigon | }
|
273 | //Shape
|
||
274 | if(flyrVect.getSource().getDriver().getName().compareTo("gvSIG shp driver")==0){
|
||
275 | flyrVect.setProperty("layerType", "SHAPE");
|
||
276 | setLayerShapeProperties(flyrVect);
|
||
277 | }
|
||
278 | } else if (lyr instanceof FLyrRaster){
|
||
279 | FLyrRaster lyrRaster = (FLyrRaster) lyr;
|
||
280 | if (lyrRaster.getSource().getDriver() instanceof CmsRasterDriver){
|
||
281 | lyrRaster.setProperty("layerType", "RASTER");
|
||
282 | setLayerRaster(lyrRaster);
|
||
283 | 10626 | caballero | }
|
284 | }
|
||
285 | |||
286 | 8961 | jvhigon | }
|
287 | */
|
||
288 | /**
|
||
289 | * Property
|
||
290 | * size
|
||
291 | * colorR
|
||
292 | * colorG
|
||
293 | * colorB
|
||
294 | * outlinecolorR
|
||
295 | * outlinecolorG
|
||
296 | * outlinecolorB
|
||
297 | * outlinecolor
|
||
298 | * transparency
|
||
299 | * @param lyr
|
||
300 | 10626 | caballero | *
|
301 | 8961 | jvhigon | private void setLegendProperties(FLyrVect lyr) {
|
302 | Legend legend = lyr.getLegend();
|
||
303 | if (legend instanceof SingleSymbolLegend) {
|
||
304 | //get color
|
||
305 | FSymbol sym = (FSymbol) legend.getDefaultSymbol();
|
||
306 | Color clr = sym.getColor();
|
||
307 | Color outLineclr = sym.getOutlineColor();
|
||
308 | lyr.setProperty("colorR", new Integer(outLineclr.getRed()).toString());
|
||
309 | lyr.setProperty("colorG", new Integer(outLineclr.getGreen()).toString());
|
||
310 | lyr.setProperty("colorB", new Integer(outLineclr.getBlue()).toString());
|
||
311 | 10626 | caballero | |
312 | try{
|
||
313 | Float size =
|
||
314 | |||
315 | 8961 | jvhigon | ((BasicStroke)sym.getStroke()).getLineWidth().intValue();
|
316 | lyr.setProperty("size", new Float(size).toString());
|
||
317 | }catch(Exception e){
|
||
318 | 10626 | caballero | |
319 | 8961 | jvhigon | }
|
320 | mapClasses.add(mapClass);
|
||
321 | }else if(legend instanceof VectorialUniqueValueLegend){
|
||
322 | VectorialUniqueValueLegend uniqueValueLegend = (VectorialUniqueValueLegend)legend;
|
||
323 | ISymbol[] symbols = uniqueValueLegend.getSymbols();
|
||
324 | for (int i=0 ; i<symbols.length ; i++){
|
||
325 | MapClass mapClass = new MapClass(symbols[i].getDescription());
|
||
326 | FSymbol auxSym = (FSymbol) symbols[i];
|
||
327 | Color clr = auxSym.getColor();
|
||
328 | Color outLineclr = auxSym.getOutlineColor();
|
||
329 | mapClass.estilo = new ConfigFile.StyleMap(clr,outLineclr);
|
||
330 | 10626 | caballero | mapClass.expression = "('[" + uniqueValueLegend.getFieldName() + "]' = '" +
|
331 | 8961 | jvhigon | symbols[i].getDescription() + "')";
|
332 | try{
|
||
333 | mapClass.size = new Float(((BasicStroke)auxSym.getStroke()).getLineWidth()).intValue();
|
||
334 | }catch(Exception e){
|
||
335 | 10626 | caballero | |
336 | 8961 | jvhigon | }
|
337 | mapClasses.add(mapClass);
|
||
338 | }
|
||
339 | 10626 | caballero | |
340 | 8961 | jvhigon | }else if(legend instanceof VectorialIntervalLegend){
|
341 | MapClass mapClass = new MapClass(getLayerName(lyrVect.getName()));
|
||
342 | |||
343 | FSymbol sym = (FSymbol) legend.getDefaultSymbol();
|
||
344 | Color clr = sym.getColor();
|
||
345 | Color outLineclr = sym.getOutlineColor();
|
||
346 | mapClass.estilo = new ConfigFile.StyleMap(clr,outLineclr);
|
||
347 | try{
|
||
348 | mapClass.size = new Float(((BasicStroke)sym.getStroke()).getLineWidth()).intValue();
|
||
349 | }catch(Exception e){
|
||
350 | 10626 | caballero | |
351 | }
|
||
352 | 8961 | jvhigon | mapClasses.add(mapClass);
|
353 | 10626 | caballero | }
|
354 | |||
355 | 8961 | jvhigon | }*/
|
356 | /*
|
||
357 | private void setLayerRaster(FLyrRaster lyrRaster) {
|
||
358 | 10626 | caballero | CmsRasterDriver driver = (CmsRasterDriver)lyrRaster.getSource().getDriver();
|
359 | 8961 | jvhigon | double resx = (driver.getFiles()[0].getExtent().maxX() - driver.getFiles()[0].getExtent().minX())/driver.getFiles()[0].getWidth();
|
360 | double resy = (driver.getFiles()[0].getExtent().maxY() - driver.getFiles()[0].getExtent().minY())/driver.getFiles()[0].getHeight();
|
||
361 | lyrRaster.setProperty("resx", new Double(resx).toString());
|
||
362 | lyrRaster.setProperty("resy", new Double(resy).toString());
|
||
363 | }
|
||
364 | |||
365 | private void setLayerShapeProperties(FLyrVect flyrVect) {
|
||
366 | // TODO Auto-generated method stub
|
||
367 | 10626 | caballero | |
368 | |||
369 | 8961 | jvhigon | }
|
370 | |||
371 | private void setLayerPostGISProperties(FLyrVect flyrVect) {
|
||
372 | // TODO Auto-generated method stub
|
||
373 | 10626 | caballero | |
374 | 8961 | jvhigon | }
|
375 | |||
376 | abstract public ServiceInfo getServiceInfo();
|
||
377 | */
|
||
378 | } |