@@ -61,58 +61,6 @@ public class XMLResourceBundleControl extends Control {
6161 *
6262 * @author Andreas Dräger
6363 */
64- private static class XMLResourceBundle extends ResourceBundle {
65-
66- /**
67- * The wrapped element.
68- */
69- private Properties properties ;
70-
71- /**
72- *
73- * @param stream
74- * @throws IOException
75- * @throws InvalidPropertiesFormatException
76- */
77- public XMLResourceBundle (InputStream stream ) throws IOException ,
78- InvalidPropertiesFormatException {
79- Properties defaults = new Properties ();
80- defaults .loadFromXML (stream );
81- properties = new Properties (defaults );
82- }
83-
84- /* (non-Javadoc)
85- * @see java.util.ResourceBundle#getKeys()
86- */
87- @ Override
88- public Enumeration <String > getKeys () {
89- Set <String > key = properties .stringPropertyNames ();
90- return Collections .enumeration (key );
91- }
92-
93- /* (non-Javadoc)
94- * @see java.util.ResourceBundle#handleGetObject(java.lang.String)
95- */
96- @ Override
97- protected Object handleGetObject (String key ) {
98- String element = properties .getProperty (key );
99- if ((element != null ) && (element .length () > 0 )
100- && (element .charAt (0 ) == '[' )
101- && (element .charAt (element .length () - 1 ) == ']' )) {
102- return element .substring (1 , element .length () - 1 ).split (";" );
103- }
104- return element ;
105- }
106-
107- /* (non-Javadoc)
108- * @see java.lang.Object#toString()
109- */
110- @ Override
111- public String toString () {
112- return properties .toString ();
113- }
114-
115- }
11664
11765 /**
11866 * The extension for XML files.
@@ -141,21 +89,111 @@ public ResourceBundle newBundle(String baseName, Locale locale,
14189 ResourceBundle bundle = null ;
14290
14391 if (format .equalsIgnoreCase (XML )) {
144- // Localize resource file
145- String bundleName = toBundleName (baseName , locale );
146- String resName = toResourceName (bundleName , format );
147- InputStream is = loader .getResourceAsStream (resName );
148- if (is == null ) {
149- is = getClass ().getResourceAsStream ('/' + resName );
150- }
151- if (is != null ) {
152- // Create ResourceBundle object
153- bundle = new XMLResourceBundle (is );
154- is .close ();
92+ switch (baseName ){
93+ case "org.sbml.jsbml.resources.Messages" :
94+ bundle = new XMLResourcePlain ();
95+ break ;
96+ case "org.sbml.jsbml.resources.cfg.Messages" :
97+ bundle = new XMLResourceConfig ();
98+ break ;
99+ case "org.sbml.jsbml.ext.arrays.validator.constraints.Messages" :
100+ bundle = new XMLResourceConstraints ();
101+ break ;
102+ case "org.sbml.jsbml.ext.spatial.Messages" :
103+ bundle = new XMLResourceSpatial ();
104+ break ;
105+ case "org.sbml.jsbml.ext.dyn.Messages" :
106+ bundle = new XMLResourceDYN ();
107+ break ;
155108 }
156109 }
157110 // Return the bundle.
158111 return bundle ;
159112 }
160113
114+ public static class XMLResourcePlain extends XMLResourceBundle {
115+ public XMLResourcePlain () {
116+ try {
117+ setProperties ("/org/sbml/jsbml/resources/Messages.xml" );
118+ } catch (IOException e ) {
119+ throw new RuntimeException (e );
120+ }
121+ }
122+ }
123+
124+ public static class XMLResourceConfig extends XMLResourceBundle {
125+ public XMLResourceConfig () {
126+ try {
127+ setProperties ("/org/sbml/jsbml/resources/cfg/Messages.xml" );
128+ } catch (IOException e ) {
129+ throw new RuntimeException (e );
130+ }
131+ }
132+ }
133+
134+ public static class XMLResourceConstraints extends XMLResourceBundle {
135+ public XMLResourceConstraints () {
136+ try {
137+ setProperties ("/org/sbml/jsbml/ext/arrays/validator/constraints/Messages.xml" );
138+ } catch (IOException e ) {
139+ throw new RuntimeException (e );
140+ }
141+ }
142+ }
143+
144+ public static class XMLResourceSpatial extends XMLResourceBundle {
145+ public XMLResourceSpatial () {
146+ try {
147+ setProperties ("/org/sbml/jsbml/ext/spatial/Messages.xml" );
148+ } catch (IOException e ) {
149+ throw new RuntimeException (e );
150+ }
151+ }
152+ }
153+
154+ public static class XMLResourceDYN extends XMLResourceBundle {
155+ public XMLResourceDYN () {
156+ try {
157+ setProperties ("/org/sbml/jsbml/ext/dyn/Messages.xml" );
158+ } catch (IOException e ) {
159+ throw new RuntimeException (e );
160+ }
161+ }
162+ }
163+
164+ private static class XMLResourceBundle extends ResourceBundle {
165+ private Properties properties ;
166+
167+ public void setProperties (String resourceName ) throws IOException {
168+ Properties defaults = new Properties ();
169+ InputStream is = XMLResourceBundle .class .getResourceAsStream (resourceName );
170+ defaults .loadFromXML (is );
171+ properties = new Properties (defaults );
172+ assert is != null ;
173+ is .close ();
174+ }
175+
176+ @ Override
177+ public Enumeration <String > getKeys () {
178+ Set <String > key = properties .stringPropertyNames ();
179+ return Collections .enumeration (key );
180+ }
181+
182+ @ Override
183+ protected Object handleGetObject (String key ) {
184+ String element = properties .getProperty (key );
185+ if ((element != null ) && (element .length () > 0 )
186+ && (element .charAt (0 ) == '[' )
187+ && (element .charAt (element .length () - 1 ) == ']' )) {
188+ return element .substring (1 , element .length () - 1 ).split (";" );
189+ }
190+ return element ;
191+ }
192+
193+ @ Override
194+ public String toString () {
195+ return properties .toString ();
196+ }
197+ }
198+
161199}
0 commit comments