root / branches / v2_0_0_prep / extensions / extWMS / src / org / gvsig / wmc / ExportWebMapContextExtension.java @ 31496
History | View | Annotate | Download (9.2 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
|
42 |
/* CVS MESSAGES:
|
43 |
*
|
44 |
* $Id: ExportWebMapContextExtension.java 31496 2009-11-04 12:53:20Z jjdelcerro $
|
45 |
* $Log$
|
46 |
* Revision 1.14 2007-01-08 07:57:34 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.13 2006/09/27 13:28:38 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.12 2006/09/20 10:38:43 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.11 2006/09/20 07:45:21 caballero
|
56 |
* constante registerName
|
57 |
*
|
58 |
* Revision 1.10 2006/09/18 08:28:44 caballero
|
59 |
* cambio de nombre
|
60 |
*
|
61 |
* Revision 1.9 2006/09/15 10:44:24 caballero
|
62 |
* extensibilidad de documentos
|
63 |
*
|
64 |
* Revision 1.8 2006/08/29 07:56:15 cesar
|
65 |
* Rename the *View* family of classes to *Window* (ie: SingletonView to SingletonWindow, ViewInfo to WindowInfo, etc)
|
66 |
*
|
67 |
* Revision 1.7 2006/08/29 07:13:43 cesar
|
68 |
* Rename class com.iver.andami.ui.mdiManager.View to com.iver.andami.ui.mdiManager.IWindow
|
69 |
*
|
70 |
* Revision 1.6 2006/07/21 10:31:05 jaume
|
71 |
* *** empty log message ***
|
72 |
*
|
73 |
* Revision 1.5 2006/06/19 11:20:26 jorpiell
|
74 |
* Cambiadas las comprobaciones de una clase con == por instanceof.
|
75 |
*
|
76 |
* Revision 1.4 2006/05/30 08:56:57 jaume
|
77 |
* fixed bug http://www.gvsig.org/phpcollab/tasks/viewtask.php?id=279&msg=addAssignment&PHPSESSID=3fea791a62107ef5325283641039b311#etDAnchor
|
78 |
*
|
79 |
* Revision 1.3 2006/05/12 07:47:39 jaume
|
80 |
* removed unnecessary imports
|
81 |
*
|
82 |
* Revision 1.2 2006/05/03 11:10:54 jaume
|
83 |
* *** empty log message ***
|
84 |
*
|
85 |
* Revision 1.1 2006/05/03 07:51:21 jaume
|
86 |
* *** empty log message ***
|
87 |
*
|
88 |
* Revision 1.7 2006/05/02 16:12:12 jorpiell
|
89 |
* Se ha cambiado la interfaz Extension por dos clases: una interfaz (IExtension) y una clase abstract(Extension). A partir de ahora todas las extensiones deben heredar de Extension
|
90 |
*
|
91 |
* Revision 1.6 2006/05/02 15:57:44 jaume
|
92 |
* Few better javadoc
|
93 |
*
|
94 |
* Revision 1.5 2006/04/25 11:40:56 jaume
|
95 |
* *** empty log message ***
|
96 |
*
|
97 |
* Revision 1.4 2006/04/21 10:27:32 jaume
|
98 |
* exporting now supported
|
99 |
*
|
100 |
* Revision 1.3 2006/04/20 17:11:54 jaume
|
101 |
* Attempting to export
|
102 |
*
|
103 |
* Revision 1.2 2006/04/19 16:34:29 jaume
|
104 |
* *** empty log message ***
|
105 |
*
|
106 |
* Revision 1.1 2006/04/19 07:57:29 jaume
|
107 |
* *** empty log message ***
|
108 |
*
|
109 |
* Revision 1.3 2006/04/12 17:10:53 jaume
|
110 |
* *** empty log message ***
|
111 |
*
|
112 |
* Revision 1.2 2006/04/07 12:10:37 jaume
|
113 |
* *** empty log message ***
|
114 |
*
|
115 |
* Revision 1.1 2006/04/04 14:22:22 jaume
|
116 |
* Now exports MapContext (not yet tested)
|
117 |
*
|
118 |
*
|
119 |
*/
|
120 |
package org.gvsig.wmc; |
121 |
|
122 |
import java.io.BufferedWriter; |
123 |
import java.io.File; |
124 |
import java.io.FileWriter; |
125 |
import java.io.IOException; |
126 |
import java.util.ArrayList; |
127 |
import java.util.List; |
128 |
|
129 |
import org.gvsig.andami.PluginServices; |
130 |
import org.gvsig.andami.messages.NotificationManager; |
131 |
import org.gvsig.andami.plugins.Extension; |
132 |
import org.gvsig.andami.plugins.IExtension; |
133 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
134 |
import org.gvsig.app.extension.ProjectExtension; |
135 |
import org.gvsig.app.project.Project; |
136 |
import org.gvsig.app.project.Project; |
137 |
import org.gvsig.app.project.ProjectManager; |
138 |
import org.gvsig.app.project.documents.Document; |
139 |
import org.gvsig.app.project.documents.view.DefaultViewDocument; |
140 |
import org.gvsig.app.project.documents.view.ViewManager; |
141 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
142 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
143 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
144 |
import org.gvsig.wms.fmap.layers.FLyrWMS; |
145 |
import org.gvsig.wms.gui.panels.WebMapContextSettingsPanel; |
146 |
|
147 |
|
148 |
/**
|
149 |
* Extension to export a view with WMS layers to a OGC's Web Map Context XML
|
150 |
* file
|
151 |
*
|
152 |
* @author jaume dom?nguez faus - jaume.dominguez@iver.es
|
153 |
* @author laura d?az s?nchez - laura.diaz@iver.es
|
154 |
*/
|
155 |
public class ExportWebMapContextExtension extends Extension { |
156 |
private static ArrayList supportedVersions; |
157 |
private DefaultViewPanel viewToExport;
|
158 |
private WebMapContextSettingsPanel mc;
|
159 |
private static IExtension thisExtension; |
160 |
|
161 |
{ |
162 |
supportedVersions = new ArrayList(); |
163 |
supportedVersions.add("1.1.0");
|
164 |
} |
165 |
|
166 |
public void initialize() { |
167 |
thisExtension = PluginServices |
168 |
.getExtension(ExportWebMapContextExtension.class); |
169 |
} |
170 |
|
171 |
public void execute(String actionCommand) { |
172 |
if (actionCommand.equals("EXPORT")) { |
173 |
// Here we collect the info
|
174 |
DefaultViewDocument[] views = getExportableViews();
|
175 |
if (views.length <= 0) { |
176 |
return;
|
177 |
} |
178 |
mc = new WebMapContextSettingsPanel(views);
|
179 |
PluginServices.getMDIManager().addWindow(mc); |
180 |
|
181 |
} else if (actionCommand.equals("DO_EXPORT")) { |
182 |
// Here the target file is produced (called from the WebMapContextSettingsPanel)
|
183 |
String xml = mc.getXML();
|
184 |
File f = mc.getTargetFile();
|
185 |
if (xml != null) { |
186 |
createFile(f, xml); |
187 |
} |
188 |
|
189 |
} |
190 |
} |
191 |
|
192 |
/**
|
193 |
* Takes a File object and its XML contents and stores it as a regular
|
194 |
* file in the file system.
|
195 |
* @param f
|
196 |
* @param xml
|
197 |
*/
|
198 |
public static void createFile(File f, String xml) { |
199 |
if (xml != null) { |
200 |
try {
|
201 |
if (!f.exists()) {
|
202 |
f.createNewFile(); |
203 |
} |
204 |
BufferedWriter bw = new BufferedWriter(new FileWriter(f)); |
205 |
bw.write(xml); |
206 |
bw.close(); |
207 |
bw = null;
|
208 |
} catch (IOException e) { |
209 |
NotificationManager.addError(PluginServices.getText( |
210 |
thisExtension, "error_writting_file"), e);
|
211 |
} |
212 |
} |
213 |
} |
214 |
|
215 |
public boolean isEnabled() { |
216 |
return true; |
217 |
} |
218 |
|
219 |
public boolean isVisible() { |
220 |
// Will be visible if the current project has, at least, one FLyrWMS.
|
221 |
// Project project = ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject();
|
222 |
final Project project = ProjectManager.getInstance().getCurrentProject();
|
223 |
|
224 |
if (project == null) { |
225 |
return false; |
226 |
} |
227 |
IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
228 |
if (f instanceof DefaultViewPanel) { |
229 |
DefaultViewPanel v = (DefaultViewPanel) f; |
230 |
if (v != null && v instanceof DefaultViewPanel) { |
231 |
// Check if the active contains WMS layers. If so, this view
|
232 |
// will be the one to be exported.
|
233 |
FLayers lyrs = v.getMapControl().getMapContext().getLayers(); |
234 |
for (int i = 0; i < lyrs.getLayersCount(); i++) { |
235 |
FLayer lyr = lyrs.getLayer(i); |
236 |
if (WebMapContext.containsExportableLayers(lyr)) {
|
237 |
viewToExport = v; |
238 |
return true; |
239 |
} |
240 |
} |
241 |
} |
242 |
} |
243 |
|
244 |
// Since the active view does not contain WMS layers then will
|
245 |
// see what about the others. In this case, no view is set to be
|
246 |
// the exported one.
|
247 |
viewToExport = null;
|
248 |
List<Document> views = project.getDocuments(ViewManager.TYPENAME); |
249 |
for (int i = 0; i < views.size(); i++) { |
250 |
DefaultViewDocument v = ((DefaultViewDocument) views.get(i)); |
251 |
if (v != null) { |
252 |
FLayers lyrs = v.getMapContext().getLayers(); |
253 |
for (int j = 0; j < lyrs.getLayersCount(); j++) { |
254 |
FLayer lyr = lyrs.getLayer(j); |
255 |
if (WebMapContext.containsExportableLayers(lyr)) {
|
256 |
return true; |
257 |
} |
258 |
} |
259 |
} |
260 |
} |
261 |
return false; |
262 |
} |
263 |
|
264 |
/**
|
265 |
* <p>
|
266 |
* Searches the views in the current project that can be exported to a
|
267 |
* WebMapContext file (with ".cml" extension) and return them in a
|
268 |
* ProjectView array.<br>
|
269 |
* </p>
|
270 |
* <p>
|
271 |
* A view is exportable to WebMapContext if it contains at least one FLyrWMS
|
272 |
* and in a near future, any other OGC layer such as WCS, WFS, and so on. Only
|
273 |
* these layers will be exported. Other kind of layers are ignored since they
|
274 |
* are out of the OGC premises.
|
275 |
* </p>
|
276 |
* @return
|
277 |
*/
|
278 |
private DefaultViewDocument[] getExportableViews() { |
279 |
// Project project = ((ProjectExtension) PluginServices.getExtension(ProjectExtension.class)).getProject();
|
280 |
// ArrayList views = project.getDocumentsByType(ProjectViewFactory.registerName);
|
281 |
final Project project = ProjectManager.getInstance().getCurrentProject();
|
282 |
|
283 |
List<Document> views = project.getDocuments(ViewManager.TYPENAME); |
284 |
|
285 |
List exportableViews = new ArrayList(); |
286 |
if (viewToExport!=null) { |
287 |
exportableViews.add(viewToExport.getModel()); |
288 |
} |
289 |
|
290 |
for (int i = 0; i < views.size(); i++) { |
291 |
DefaultViewDocument v = ((DefaultViewDocument) views.get(i)); |
292 |
if (v != null) { |
293 |
FLayers lyrs = v.getMapContext().getLayers(); |
294 |
for (int j = 0; j < lyrs.getLayersCount(); j++) { |
295 |
FLayer lyr = lyrs.getLayer(j); |
296 |
if (lyr instanceof FLyrWMS && !exportableViews.contains(v)) { |
297 |
exportableViews.add(v); |
298 |
break;
|
299 |
} |
300 |
} |
301 |
} |
302 |
} |
303 |
return (DefaultViewDocument[]) exportableViews.toArray(new DefaultViewDocument[0]); |
304 |
} |
305 |
|
306 |
} |