gvsig-geoprocess / org.gvsig.geoprocess / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.algorithm / org.gvsig.geoprocess.algorithm.base / src / main / java / org / gvsig / geoprocess / algorithm / base / core / AlgorithmAbstractLibrary.java @ 237
History | View | Annotate | Download (3.13 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007,2012 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*/
|
21 |
package org.gvsig.geoprocess.algorithm.base.core; |
22 |
|
23 |
import java.util.Enumeration; |
24 |
import java.util.HashMap; |
25 |
import java.util.Locale; |
26 |
import java.util.Map; |
27 |
import java.util.MissingResourceException; |
28 |
import java.util.ResourceBundle; |
29 |
|
30 |
import org.gvsig.geoprocess.lib.api.GeoProcess; |
31 |
import org.gvsig.geoprocess.lib.api.GeoProcessLibrary; |
32 |
import org.gvsig.geoprocess.lib.api.GeoProcessLocator; |
33 |
import org.gvsig.tools.library.AbstractLibrary; |
34 |
|
35 |
/**
|
36 |
* Base class for the entry point of an algorithm
|
37 |
*
|
38 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
|
39 |
*/
|
40 |
public abstract class AlgorithmAbstractLibrary extends AbstractLibrary { |
41 |
|
42 |
/**
|
43 |
* @deprecated Use {@link #getLanguageStrings(String)} instead.
|
44 |
*/
|
45 |
protected HashMap<String, String> text = new HashMap<String, String>(); |
46 |
|
47 |
@Override
|
48 |
public void doRegistration() { |
49 |
registerAsServiceOf(GeoProcessLibrary.class); |
50 |
} |
51 |
|
52 |
/**
|
53 |
* @deprecated Use {@link #getLanguageStrings(String)} instead.
|
54 |
*/
|
55 |
protected void setLanguageStrings(String algorithmName) { |
56 |
this.text =
|
57 |
new HashMap<String, String>(getLanguageStrings(algorithmName)); |
58 |
} |
59 |
|
60 |
/**
|
61 |
* Returns the translations.
|
62 |
*
|
63 |
* @param algorithmName
|
64 |
*/
|
65 |
protected Map<String, String> getLanguageStrings(String algorithmName) { |
66 |
Map<String, String> text = new HashMap<String, String>(); |
67 |
String defaultFile = algorithmName + "_es"; |
68 |
String file = algorithmName + "_" + Locale.getDefault().getLanguage(); |
69 |
ResourceBundle labels = null; |
70 |
|
71 |
try {
|
72 |
labels = ResourceBundle.getBundle(file, Locale.getDefault()); |
73 |
} catch (final MissingResourceException e) { |
74 |
file = defaultFile; |
75 |
} |
76 |
|
77 |
try {
|
78 |
if(labels == null) |
79 |
labels = ResourceBundle.getBundle(file, Locale.getDefault()); |
80 |
final Enumeration<String> bundleKeys = labels.getKeys(); |
81 |
|
82 |
while (bundleKeys.hasMoreElements()) {
|
83 |
final String key = bundleKeys.nextElement(); |
84 |
final String value = labels.getString(key); |
85 |
text.put(key, value); |
86 |
} |
87 |
} catch (final MissingResourceException e) { |
88 |
file = defaultFile; |
89 |
} |
90 |
|
91 |
return text;
|
92 |
} |
93 |
|
94 |
protected void registerGeoProcess( |
95 |
Class<? extends GeoProcess> geoProcessClazz, |
96 |
Map<String, String> localeStrings) { |
97 |
GeoProcessLocator.getGeoProcessManager().registerGeoProcess( |
98 |
geoProcessClazz, localeStrings); |
99 |
} |
100 |
|
101 |
} |