gvsig-desktop-customize / trunk / org.gvsig.customize.app / org.gvsig.customize.app.mainplugin / src / main / java / org / gvsig / customize / CustomizeTask.java @ 1
History | View | Annotate | Download (25.4 KB)
1 |
package org.gvsig.customize; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.io.IOException; |
5 |
import java.util.ArrayList; |
6 |
import java.util.HashSet; |
7 |
import java.util.Iterator; |
8 |
import java.util.List; |
9 |
import java.util.Locale; |
10 |
import java.util.Set; |
11 |
import java.util.regex.Matcher; |
12 |
import java.util.regex.Pattern; |
13 |
import javax.swing.JOptionPane; |
14 |
import org.apache.commons.io.FileUtils; |
15 |
import org.apache.commons.lang.BooleanUtils; |
16 |
import org.apache.commons.lang3.LocaleUtils; |
17 |
import org.apache.commons.lang3.StringUtils; |
18 |
import org.cresques.cts.IProjection; |
19 |
import org.gvsig.andami.LocaleManager; |
20 |
import org.gvsig.andami.PluginServices; |
21 |
import org.gvsig.andami.PluginsLocator; |
22 |
import org.gvsig.andami.PluginsManager; |
23 |
import org.gvsig.andami.actioninfo.ActionInfo; |
24 |
import org.gvsig.andami.actioninfo.ActionInfoManager; |
25 |
import org.gvsig.andami.firewall.FirewallConfiguration; |
26 |
import org.gvsig.andami.persistence.serverData.ServerDataPersistence; |
27 |
import org.gvsig.andami.ui.mdiFrame.MainFrame; |
28 |
import org.gvsig.app.ApplicationLocator; |
29 |
import org.gvsig.app.ApplicationManager; |
30 |
import org.gvsig.app.project.ProjectManager; |
31 |
import org.gvsig.app.project.ProjectPreferences; |
32 |
import org.gvsig.app.project.documents.view.ViewManager; |
33 |
import org.gvsig.installer.lib.api.InstallerLocator; |
34 |
import org.gvsig.installer.lib.api.InstallerManager; |
35 |
import org.gvsig.installer.lib.api.PackageInfo; |
36 |
import org.gvsig.installer.lib.api.execution.InstallPackageService; |
37 |
import org.gvsig.tools.ToolsLocator; |
38 |
import org.gvsig.tools.dynobject.DynObject; |
39 |
import org.gvsig.tools.packageutils.PackageManager; |
40 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
41 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
42 |
import org.gvsig.tools.task.SimpleTaskStatus; |
43 |
import org.gvsig.utils.swing.jcomboServer.ServerData; |
44 |
import org.slf4j.Logger; |
45 |
import org.slf4j.LoggerFactory; |
46 |
|
47 |
public class CustomizeTask implements Runnable { |
48 |
|
49 |
private final static Logger logger = LoggerFactory.getLogger(CustomizeExtension.class); |
50 |
|
51 |
private static final String PROXY_SECTION = "httpproxy"; |
52 |
private static final String CRS_SECTION = "crs"; |
53 |
private static final String THEME_SECTION = "theme"; |
54 |
|
55 |
private int errorCount = 0; |
56 |
private DynObject pluginProperties = null; |
57 |
private Class scriptingExtension = null; |
58 |
private PluginServices plugin = null; |
59 |
|
60 |
public CustomizeTask() {
|
61 |
} |
62 |
|
63 |
private static class MyServerData { |
64 |
|
65 |
private final ServerDataPersistence serversDataPersistence; |
66 |
|
67 |
public MyServerData(ServerDataPersistence serversDataPersistence) {
|
68 |
this.serversDataPersistence = serversDataPersistence;
|
69 |
} |
70 |
|
71 |
public List<ServerData> getServerData() { |
72 |
return this.serversDataPersistence.getServerData(); |
73 |
} |
74 |
|
75 |
public void remove(String serverAddress) { |
76 |
if (StringUtils.isBlank(serverAddress)) {
|
77 |
return;
|
78 |
} |
79 |
Iterator<ServerData> it = getServerData().iterator();
|
80 |
while (it.hasNext()) {
|
81 |
ServerData x = it.next(); |
82 |
if (serverAddress.equalsIgnoreCase(x.getServerAddress())) {
|
83 |
it.remove(); |
84 |
return;
|
85 |
} |
86 |
} |
87 |
} |
88 |
|
89 |
public void add(String server, String protocol) { |
90 |
if (StringUtils.isBlank(server)) {
|
91 |
return;
|
92 |
} |
93 |
this.add(new ServerData(server, protocol)); |
94 |
} |
95 |
|
96 |
public void add(ServerData server) { |
97 |
String address = server.getServerAddress().trim();
|
98 |
for (int i = 0; i < getServerData().size(); i++) { |
99 |
ServerData sd = getServerData().get(i); |
100 |
if (sd.getServerAddress().trim().equals(address)) {
|
101 |
getServerData().set(i, server); |
102 |
return;
|
103 |
} |
104 |
} |
105 |
getServerData().add(server); |
106 |
} |
107 |
|
108 |
public boolean contains(String serverAddress) { |
109 |
if (StringUtils.isBlank(serverAddress)) {
|
110 |
return false; |
111 |
} |
112 |
serverAddress = serverAddress.trim(); |
113 |
for (int i = 0; i < getServerData().size(); i++) { |
114 |
String address = getServerData().get(i).getServerAddress().trim();
|
115 |
if (serverAddress.equalsIgnoreCase(address)) {
|
116 |
return true; |
117 |
} |
118 |
} |
119 |
return false; |
120 |
} |
121 |
} |
122 |
|
123 |
private PluginServices getPlugin() {
|
124 |
if (this.plugin == null) { |
125 |
PluginsManager pluginsManager = PluginsLocator.getManager(); |
126 |
this.plugin = pluginsManager.getPlugin(this); |
127 |
} |
128 |
return this.plugin; |
129 |
} |
130 |
|
131 |
protected PluginServices getPlugin(String name) { |
132 |
PluginsManager pluginsManager = PluginsLocator.getManager(); |
133 |
return pluginsManager.getPlugin(name);
|
134 |
} |
135 |
|
136 |
private Class getScriptingExtension() { |
137 |
if (this.scriptingExtension == null) { |
138 |
try {
|
139 |
this.scriptingExtension = Class.forName("org.gvsig.scripting.app.extension.ScriptingExtension"); |
140 |
} catch (Throwable ex) { |
141 |
return null; |
142 |
} |
143 |
} |
144 |
return this.scriptingExtension; |
145 |
} |
146 |
|
147 |
protected void errors_add(String message, Throwable th) { |
148 |
errorCount++; |
149 |
logger.warn(message, th); |
150 |
} |
151 |
|
152 |
protected int errors_count() { |
153 |
return errorCount;
|
154 |
} |
155 |
|
156 |
protected void errors_reset() { |
157 |
this.errorCount = 0; |
158 |
} |
159 |
|
160 |
protected DynObject getPluginProperties() {
|
161 |
if (this.pluginProperties == null) { |
162 |
this.pluginProperties = this.getPlugin().getPluginProperties(); |
163 |
} |
164 |
return this.pluginProperties; |
165 |
} |
166 |
|
167 |
protected void setProperty(String name, Object value) { |
168 |
this.getPluginProperties().setDynValue(name, value);
|
169 |
} |
170 |
|
171 |
protected Object getProperty(String name) { |
172 |
return this.getPluginProperties().getDynValue(name); |
173 |
} |
174 |
|
175 |
protected String getPropertyString(String name) { |
176 |
return (String) this.getProperty(name); |
177 |
} |
178 |
|
179 |
protected int getPropertyInt(String name) { |
180 |
return ((Integer) this.getProperty(name)).intValue(); |
181 |
} |
182 |
|
183 |
protected boolean getPropertyBoolean(String name) { |
184 |
return ((Boolean) this.getProperty(name)).booleanValue(); |
185 |
} |
186 |
|
187 |
protected void setValue(DynObject config, String section, String option, String value) { |
188 |
Object subconfig = config.getDynValue(section);
|
189 |
if (subconfig instanceof DynObject) { |
190 |
((DynObject) subconfig).setDynValue(option, value); |
191 |
} else {
|
192 |
config.setDynValue(option, value); |
193 |
} |
194 |
} |
195 |
|
196 |
protected String getValue(DynObject config, String section, String option, String defaultValue) { |
197 |
String value = null; |
198 |
Object subconfig = null; |
199 |
if (!StringUtils.isBlank(section)) {
|
200 |
subconfig = config.getDynValue(section); |
201 |
} |
202 |
if (subconfig instanceof DynObject) { |
203 |
Object v = ((DynObject) subconfig).getDynValue(option);
|
204 |
if (v != null) { |
205 |
value = v.toString(); |
206 |
} |
207 |
} else {
|
208 |
Object v = config.getDynValue(option);
|
209 |
if (v != null) { |
210 |
value = v.toString(); |
211 |
} |
212 |
} |
213 |
if (StringUtils.isBlank(value)) {
|
214 |
return defaultValue;
|
215 |
} |
216 |
if (THEME_SECTION.equalsIgnoreCase(section)) {
|
217 |
return value;
|
218 |
} |
219 |
if (value.contains("${")) { |
220 |
value = expand(config, section, value); |
221 |
} |
222 |
return value;
|
223 |
} |
224 |
private static final Pattern VARIABLE = Pattern.compile("[$][{]([a-zA-Z0-9_/]+)[}]"); |
225 |
|
226 |
private String expand(DynObject config, String section, String s) { |
227 |
String s2 = s;
|
228 |
String v = null; |
229 |
Matcher m = VARIABLE.matcher(s);
|
230 |
while (m.find()) {
|
231 |
String name = m.group(1); |
232 |
String[] ss = name.split("/"); |
233 |
switch (ss.length) {
|
234 |
case 2: |
235 |
v = getValue(config, ss[0], ss[1], ""); |
236 |
break;
|
237 |
case 1: |
238 |
v = getValue(config, section, ss[0], ""); |
239 |
break;
|
240 |
default:
|
241 |
v = name; |
242 |
} |
243 |
s2 = m.replaceFirst(v); |
244 |
m = VARIABLE.matcher(s2); |
245 |
} |
246 |
|
247 |
return s2;
|
248 |
} |
249 |
|
250 |
private void configureLocale(DynObject config) { |
251 |
if (!BooleanUtils.isTrue((Boolean) getProperty("configureLocale"))) { |
252 |
return;
|
253 |
} |
254 |
try {
|
255 |
LocaleManager localeManager = PluginsLocator.getLocaleManager(); |
256 |
String localeCode = getValue(config, null, "default_locale", "en"); |
257 |
Locale locale = LocaleUtils.toLocale(localeCode);
|
258 |
localeManager.setCurrentLocale(locale); |
259 |
|
260 |
logger.info("Set default locale to '" + localeCode + "'."); |
261 |
setProperty("configureLocale", Boolean.FALSE); |
262 |
} catch (Exception ex) { |
263 |
errors_add("Can't apply locale configuration.", ex);
|
264 |
} |
265 |
} |
266 |
|
267 |
private void configureHttpproxy(DynObject config) { |
268 |
if (!BooleanUtils.isTrue((Boolean) getProperty("configureHTTPPproxy"))) { |
269 |
return;
|
270 |
} |
271 |
try {
|
272 |
FirewallConfiguration conf = getFirewallConfiguration(); |
273 |
String host = getValue(config, "httpproxy", "host", ""); |
274 |
String port = getValue(config, "httpproxy", "port", ""); |
275 |
String nonProxyHosts = getValue(config, "httpproxy", "nonProxyHosts", ""); |
276 |
String userName = getValue(config, "httpproxy", "username", ""); |
277 |
String password = getValue(config, "httpproxy", "password", ""); |
278 |
String enabled = getValue(config, "httpproxy", "enabled", "false"); |
279 |
conf.setHost(host, port); |
280 |
conf.setNonProxyHosts(nonProxyHosts); |
281 |
if (!StringUtils.isBlank(userName)) {
|
282 |
conf.setUserName(userName); |
283 |
} |
284 |
if (!StringUtils.isBlank(password)) {
|
285 |
conf.setPassword(password); |
286 |
} |
287 |
conf.setEnabled(BooleanUtils.toBoolean(enabled)); |
288 |
conf.apply(); |
289 |
logger.info("Set httpproxy host:port to '" + host + ":" + port + "', enabled " + BooleanUtils.toBoolean(enabled) + "."); |
290 |
setProperty("configureHTTPPproxy", Boolean.FALSE); |
291 |
} catch (Exception ex) { |
292 |
errors_add("Can't apply proxy configuration.", ex);
|
293 |
} |
294 |
} |
295 |
|
296 |
private FirewallConfiguration getFirewallConfiguration() {
|
297 |
FirewallConfiguration conf = (FirewallConfiguration) ToolsLocator.getInstance().get(ToolsLocator.FIREWALL_MANAGER_NAME); |
298 |
// FirewallConfiguration conf = PluginsLocator.getManager().getFirewallConfiguration();
|
299 |
return conf;
|
300 |
} |
301 |
|
302 |
private boolean configureHttpproxyUser(DynObject config) { |
303 |
try {
|
304 |
FirewallConfiguration conf = getFirewallConfiguration(); |
305 |
String userName = conf.getUserName();
|
306 |
String password = conf.getPassword();
|
307 |
|
308 |
HttpProxyLoginDialog dialog = new HttpProxyLoginDialog();
|
309 |
if (StringUtils.isBlank(userName)) {
|
310 |
userName = getValue(config, "httpproxy", "username", ""); |
311 |
} |
312 |
if (StringUtils.isBlank(password)) {
|
313 |
password = getValue(config, "httpproxy", "password", ""); |
314 |
} |
315 |
|
316 |
dialog.setUserName(userName); |
317 |
dialog.setPassword(password); |
318 |
if (dialog.login()) {
|
319 |
conf.setUserName(dialog.getUserName()); |
320 |
conf.setPassword(dialog.getPassword()); |
321 |
conf.setEnabled(true);
|
322 |
conf.apply(); |
323 |
} else {
|
324 |
conf.setUserName(dialog.getUserName()); |
325 |
conf.setPassword("");
|
326 |
conf.setEnabled(false);
|
327 |
conf.apply(); |
328 |
} |
329 |
logger.info("Set httpproxy user to '" + conf.getUserName() + "'."); |
330 |
logger.info("Set httpproxy password.");
|
331 |
// Set values in config to allow variable sustitution
|
332 |
setValue(config, "httpproxy", "username", conf.getUserName()); |
333 |
setValue(config, "httpproxy", "password", conf.getPassword()); |
334 |
return true; |
335 |
} catch (Exception ex) { |
336 |
errors_add("Can't apply username/password proxy configuration.", ex);
|
337 |
return false; |
338 |
} |
339 |
} |
340 |
|
341 |
private void configureCRS(DynObject config) { |
342 |
if (!BooleanUtils.isTrue((Boolean) getProperty("configureProjection"))) { |
343 |
return;
|
344 |
} |
345 |
try {
|
346 |
ProjectManager projectManager = ApplicationLocator.getProjectManager(); |
347 |
ProjectPreferences projectPreferences = projectManager.getProjectPreferences(); |
348 |
DynObject crsOptions = (DynObject) config.getDynValue("CRS");
|
349 |
IProjection proj = (IProjection) crsOptions.getDynValue("default_projection");
|
350 |
projectPreferences.setDefaultProjection(proj.getFullCode()); |
351 |
logger.info("Set default projection to '" + proj.getFullCode() + "'."); |
352 |
setProperty("configureProjection", Boolean.FALSE); |
353 |
} catch (Exception ex) { |
354 |
errors_add("Can't apply CRS configuration.", ex);
|
355 |
} |
356 |
} |
357 |
|
358 |
private void configureServers(String protocol, String pluginName, List<DynObject> servers) { |
359 |
if (!getPropertyBoolean("configureOGCServers_" + protocol)) { |
360 |
return;
|
361 |
} |
362 |
if (pluginName == null) { |
363 |
logger.info("Skip '" + pluginName + "' servers configurations.."); |
364 |
return;
|
365 |
} |
366 |
PluginServices plugin = getPlugin(pluginName); |
367 |
if (plugin == null) { |
368 |
logger.info("Skip '" + pluginName + "' servers configurations. Plugin not installed."); |
369 |
return;
|
370 |
} |
371 |
ServerDataPersistence serversDataPersistence = (ServerDataPersistence) plugin.getPluginProperties().getDynValue("Servers");
|
372 |
if (serversDataPersistence == null) { |
373 |
serversDataPersistence = new ServerDataPersistence(protocol);
|
374 |
plugin.getPluginProperties().setDynValue("Servers", serversDataPersistence);
|
375 |
} |
376 |
MyServerData serversData = new MyServerData(serversDataPersistence);
|
377 |
|
378 |
for (int i = 0; i < servers.size(); i++) { |
379 |
String server = (String) servers.get(i).getDynValue("url"); |
380 |
boolean remove = BooleanUtils.isTrue((Boolean) servers.get(i).getDynValue("remove")); |
381 |
if (remove) {
|
382 |
serversData.remove(server); |
383 |
logger.info("Remove '" + protocol + "' server '" + server + "'."); |
384 |
} else {
|
385 |
if (!serversData.contains(server)) {
|
386 |
serversData.add(server, protocol); |
387 |
logger.info("Insert '" + protocol + "' server '" + server + "'."); |
388 |
} |
389 |
} |
390 |
} |
391 |
plugin.savePluginProperties(); |
392 |
logger.info("Save properties of plugin '" + pluginName + "'."); |
393 |
setProperty("configureOGCServers_" + protocol, Boolean.FALSE); |
394 |
|
395 |
} |
396 |
|
397 |
private void createActionsScripts(DynObject config) { |
398 |
List<DynObject> scriptActions = (List<DynObject>) config.getDynValue("scriptActions"); |
399 |
if (scriptActions == null) { |
400 |
return;
|
401 |
} |
402 |
ActionInfoManager actionManager = PluginsLocator.getActionInfoManager(); |
403 |
|
404 |
for (int i = 0; i < scriptActions.size(); i++) { |
405 |
DynObject scriptAction = scriptActions.get(i); |
406 |
String name = (String) scriptAction.getDynValue("name"); |
407 |
ActionInfo action = actionManager.getAction(name); |
408 |
if (action == null) { |
409 |
String script = (String) scriptAction.getDynValue("script"); |
410 |
String label = (String) scriptAction.getDynValue("label"); |
411 |
String icon = (String) scriptAction.getDynValue("icon"); |
412 |
long position = ((Long) (scriptAction.getDynValue("position"))).longValue(); |
413 |
String tip = (String) scriptAction.getDynValue("tip"); |
414 |
createActionScript(name, script, label, icon, position, tip); |
415 |
} else {
|
416 |
logger.info("Can't create action script, action '" + name + "' already defined."); |
417 |
} |
418 |
} |
419 |
} |
420 |
|
421 |
private void addTOCActions(DynObject config) { |
422 |
List<DynObject> viewTOCActions = (List<DynObject>) config.getDynValue("viewTocActions"); |
423 |
if (viewTOCActions == null) { |
424 |
return;
|
425 |
} |
426 |
ActionInfoManager actionManager = PluginsLocator.getActionInfoManager(); |
427 |
ProjectManager projectManager = ApplicationLocator.getProjectManager(); |
428 |
ViewManager viewManager = (ViewManager) projectManager.getDocumentManager(ViewManager.TYPENAME); |
429 |
for (int i = 0; i < viewTOCActions.size(); i++) { |
430 |
DynObject viewTOCAction = viewTOCActions.get(i); |
431 |
String name = (String) viewTOCAction.getDynValue("name"); |
432 |
ActionInfo action = actionManager.getAction(name); |
433 |
if (action != null) { |
434 |
String group = (String) viewTOCAction.getDynValue("group"); |
435 |
int grouporder = ((Long) (viewTOCAction.getDynValue("grouporder"))).intValue(); |
436 |
viewManager.addTOCContextAction(action, group, grouporder); |
437 |
} else {
|
438 |
logger.info("Can't add context menu entry to the view TOC. Action '" + name + "' don't exists."); |
439 |
} |
440 |
} |
441 |
} |
442 |
|
443 |
private void addMenuActions(DynObject config) { |
444 |
List<DynObject> menuActions = (List<DynObject>) config.getDynValue("menuActions"); |
445 |
if (menuActions == null) { |
446 |
return;
|
447 |
} |
448 |
ActionInfoManager actionManager = PluginsLocator.getActionInfoManager(); |
449 |
ApplicationManager application = ApplicationLocator.getManager(); |
450 |
for (int i = 0; i < menuActions.size(); i++) { |
451 |
DynObject menuAction = menuActions.get(i); |
452 |
String name = (String) menuAction.getDynValue("name"); |
453 |
ActionInfo action = actionManager.getAction(name); |
454 |
if (action != null) { |
455 |
String text = (String) menuAction.getDynValue("text"); |
456 |
application.addMenu(action, text); |
457 |
} else {
|
458 |
logger.info("Can't add menu entry. Action '" + name + "' don't exists."); |
459 |
} |
460 |
} |
461 |
} |
462 |
|
463 |
private void addToolActions(DynObject config) { |
464 |
List<DynObject> toolActions = (List<DynObject>) config.getDynValue("toolActions"); |
465 |
if (toolActions == null) { |
466 |
return;
|
467 |
} |
468 |
ActionInfoManager actionManager = PluginsLocator.getActionInfoManager(); |
469 |
ApplicationManager application = ApplicationLocator.getManager(); |
470 |
for (int i = 0; i < toolActions.size(); i++) { |
471 |
DynObject toolAction = toolActions.get(i); |
472 |
String name = (String) toolAction.getDynValue("name"); |
473 |
ActionInfo action = actionManager.getAction(name); |
474 |
if (action != null) { |
475 |
String toolbarName = (String) toolAction.getDynValue("toolbarName"); |
476 |
application.addTool(action, toolbarName); |
477 |
} else {
|
478 |
logger.info("Can't add tool entry. Action '" + name + "' don't exists."); |
479 |
} |
480 |
} |
481 |
} |
482 |
|
483 |
private ActionInfo createActionScript(String actionName, String scriptName, String label, String iconName, long position, String tip) { |
484 |
ActionInfoManager actionManager = PluginsLocator.getActionInfoManager(); |
485 |
|
486 |
Class scriptingExtension = this.getScriptingExtension(); |
487 |
if (scriptingExtension == null) { |
488 |
logger.warn("Can't create action script '" + actionName + "', can't locate scripting extension"); |
489 |
return null; |
490 |
} |
491 |
if (StringUtils.isBlank(iconName)) {
|
492 |
iconName = null;
|
493 |
} |
494 |
if (StringUtils.isBlank(tip)) {
|
495 |
tip = actionName; |
496 |
} |
497 |
|
498 |
ActionInfo action = actionManager.createAction(scriptingExtension, actionName, label, scriptName, iconName, null, position, tip);
|
499 |
return actionManager.registerAction(action);
|
500 |
} |
501 |
|
502 |
@Override
|
503 |
public void run() { |
504 |
|
505 |
errors_reset(); |
506 |
|
507 |
MainFrame mainWindow = PluginsLocator.getMainFrame(); |
508 |
|
509 |
try {
|
510 |
Configuration configManager = new Configuration(); |
511 |
DynObject config = configManager.load(); |
512 |
|
513 |
if (config == null) { |
514 |
PluginsLocator.getMainFrame().messageDialog( |
515 |
"_No_se_ha_podido_acceder_a_la_configuracion_de_personalizacion_Consulte_el_registro_de_errores_si_precisa_mas_informacion",
|
516 |
"_Atencion",
|
517 |
JOptionPane.WARNING_MESSAGE
|
518 |
); |
519 |
return;
|
520 |
} |
521 |
|
522 |
configureLocale(config); |
523 |
configureHttpproxy(config); |
524 |
DynObject httpProxyConfiguration = (DynObject) config.getDynValue("httpproxy");
|
525 |
if (((Boolean) (httpProxyConfiguration.getDynValue("promptUserAndPassword"))).booleanValue()) { |
526 |
configureHttpproxyUser(config); |
527 |
} |
528 |
|
529 |
configureCRS(config); |
530 |
|
531 |
mainWindow.message("_Updating_server_information", JOptionPane.INFORMATION_MESSAGE); |
532 |
configureServers( |
533 |
"WMS",
|
534 |
"org.gvsig.raster.wms.app.wmsclient",
|
535 |
(List<DynObject>) config.getDynValue("wmsUrls") |
536 |
); |
537 |
configureServers( |
538 |
"WMTS",
|
539 |
"org.gvsig.raster.wmts.app.wmtsclient",
|
540 |
(List<DynObject>) config.getDynValue("wmsUrls") |
541 |
); |
542 |
configureServers( |
543 |
"WCS",
|
544 |
"org.gvsig.raster.wcs.app.wcsclient",
|
545 |
(List<DynObject>) config.getDynValue("wmsUrls") |
546 |
); |
547 |
configureServers( |
548 |
"WFS",
|
549 |
"org.gvsig.wfs.app.mainplugin",
|
550 |
(List<DynObject>) config.getDynValue("wmsUrls") |
551 |
); |
552 |
|
553 |
//
|
554 |
// configureAllPlugins(config);
|
555 |
//
|
556 |
createActionsScripts(config); |
557 |
|
558 |
addTOCActions(config); |
559 |
addMenuActions(config); |
560 |
addToolActions(config); |
561 |
|
562 |
} catch (Exception ex) { |
563 |
errors_add("Problems apply defaut configuration.", ex);
|
564 |
} |
565 |
|
566 |
if (errors_count() > 0) { |
567 |
mainWindow.messageDialog( |
568 |
"_Se_han_producido_errores_actualizando_la_configuracion_por_defecto_Consulte_el_registro_de_errores_si_precisa_mas_informacion",
|
569 |
"_Setting_custom_configuration",
|
570 |
JOptionPane.WARNING_MESSAGE
|
571 |
); |
572 |
} |
573 |
installAdditionalPackages(); |
574 |
mainWindow.message(null, JOptionPane.INFORMATION_MESSAGE); |
575 |
} |
576 |
|
577 |
private Set loadDefaultPackages(File packages) throws IOException { |
578 |
Set defaultPackages = new HashSet<String>(); |
579 |
|
580 |
List<String> lines = FileUtils.readLines(packages); |
581 |
defaultPackages.clear(); |
582 |
for (String line : lines) { |
583 |
line = line.trim(); |
584 |
if (line.startsWith("#") || line.startsWith(";")) { |
585 |
continue;
|
586 |
} |
587 |
defaultPackages.add(line.toLowerCase()); |
588 |
} |
589 |
return defaultPackages;
|
590 |
} |
591 |
|
592 |
private void installAdditionalPackages() { |
593 |
File defaultPackagesFile = new File(getPlugin().getPluginDirectory(), "defaultPackages"); |
594 |
if (!defaultPackagesFile.exists()) {
|
595 |
return;
|
596 |
} |
597 |
|
598 |
SimpleTaskStatus taskStatus = ToolsLocator.getTaskStatusManager().createDefaultSimpleTaskStatus("Installing additional components");
|
599 |
try {
|
600 |
taskStatus.add(); |
601 |
taskStatus.setAutoremove(true);
|
602 |
taskStatus.message("Preparing package list");
|
603 |
|
604 |
ToolsSwingLocator.getWindowManager().showWindow( |
605 |
new InstallPackagesPanel(taskStatus),
|
606 |
"Terminating installation",
|
607 |
WindowManager.MODE.WINDOW |
608 |
); |
609 |
|
610 |
PluginsManager pluginsManmager = PluginsLocator.getManager(); |
611 |
InstallerManager installerManager = InstallerLocator.getInstallerManager(); |
612 |
InstallPackageService installer = null;
|
613 |
List<PackageInfo> packagesToInstall = new ArrayList<PackageInfo>(); |
614 |
Set<String> defaultSelectedPacakgeCodes = loadDefaultPackages( |
615 |
defaultPackagesFile |
616 |
); |
617 |
|
618 |
installer = installerManager.getInstallPackageService(); |
619 |
|
620 |
taskStatus.message("Searching available packages");
|
621 |
installer.addBundlesFromDirectory(pluginsManmager.getInstallFolder()); |
622 |
|
623 |
taskStatus.message("Filtering packages");
|
624 |
for (String packageCode : defaultSelectedPacakgeCodes) { |
625 |
PackageInfo pkg = installer.getPackageInfo(packageCode); |
626 |
if (pkg != null) { |
627 |
File folder = installerManager.getAddonFolder(pkg.getCode());
|
628 |
if (folder == null) { |
629 |
packagesToInstall.add(pkg); |
630 |
} |
631 |
} |
632 |
} |
633 |
|
634 |
taskStatus.setRangeOfValues(1, packagesToInstall.size());
|
635 |
for (int i = 0; i < packagesToInstall.size(); i++) { |
636 |
PackageInfo pkg = packagesToInstall.get(i); |
637 |
taskStatus.setCurValue(i+1);
|
638 |
taskStatus.message("Installing " + pkg.getCode());
|
639 |
try {
|
640 |
// installer.installPackage(pluginsManmager.getApplicationFolder(), pkg);
|
641 |
} catch (Throwable th) { |
642 |
logger.warn("can't install package '" + pkg.getCode() + "'.", th); |
643 |
} |
644 |
} |
645 |
taskStatus.message("Installation terminated");
|
646 |
taskStatus.terminate(); |
647 |
|
648 |
} catch (Throwable th) { |
649 |
taskStatus.cancel(); |
650 |
logger.warn("can't install additional packages.", th);
|
651 |
|
652 |
} finally {
|
653 |
taskStatus.remove(); |
654 |
} |
655 |
} |
656 |
|
657 |
} |