Skip to content

Commit 51ec0b9

Browse files
hansonrhansonr
authored andcommitted
ensures Applet parameter name is case insensitive
1 parent 7e4649e commit 51ec0b9

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

sources/net.sf.j2s.java.core/src/swingjs/JSApp.java

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,33 @@
22

33
import java.util.Hashtable;
44
import java.util.Locale;
5+
import java.util.Map.Entry;
56

67
import swingjs.api.js.HTML5Applet;
78

89
@SuppressWarnings("rawtypes")
910
public class JSApp {
1011

1112
public JSApp() {
12-
// Frame only; not applet
13+
// Frame entry point
1314
}
1415

1516
public JSApp(Hashtable<String, Object> params) {
17+
// JApplet entry point
1618
setAppParams(params);
1719
}
18-
20+
21+
/**
22+
* Only called from setAppParams
23+
* @param name
24+
* @return
25+
*/
1926
public String getParameter(String name) {
20-
String s = (String) params.get(name);
21-
System.out.println("get parameter: " + name + " = " + s);
27+
String s = (String) params.get(name.toLowerCase());
2228
return (s == null ? null : "" + s); // because it may not be a string in JavaScript if inherited from Info
2329
}
2430

25-
protected Hashtable params;
31+
protected Hashtable<String, Object> params;
2632

2733
public String appletCodeBase;
2834
public String appletIdiomaBase;
@@ -52,6 +58,16 @@ public String getParameter(String name) {
5258
*/
5359
protected void setAppParams(Hashtable<String, Object> params) {
5460
this.params = params;
61+
// Although we allow params to hold mixed-case keys,
62+
// we need to ensure that it has the lower-case version
63+
// It was an early design flaw, unfortunately.
64+
// At least for now, this is the solution.
65+
for (Entry<String, Object> e: params.entrySet()) {
66+
String key = e.getKey();
67+
String lckey = key.toLowerCase();
68+
if (!key.equals(lckey))
69+
params.put(lckey, e.getValue());
70+
}
5571
String language = getParameter("language");
5672
if (language == null)
5773
language = JSUtil.J2S.getDefaultLanguage(false);
@@ -63,18 +79,18 @@ protected void setAppParams(Hashtable<String, Object> params) {
6379

6480
syncId = getParameter("syncId");
6581
fullName = htmlName + "__" + syncId + "__";
66-
params.put("fullName", fullName);
67-
Object o = params.get("codePath");
82+
params.put("fullname", fullName);
83+
Object o = params.get("codepath");
6884
if (o == null)
6985
o = "../java/";
7086
appletCodeBase = o.toString();
7187
appletIdiomaBase = appletCodeBase.substring(0,
7288
appletCodeBase.lastIndexOf("/", appletCodeBase.length() - 2) + 1)
7389
+ "idioma";
74-
o = params.get("documentBase");
90+
o = params.get("documentbase");
7591
appletDocumentBase = (o == null ? "" : o.toString());
76-
if (params.containsKey("maximumSize"))
77-
Math.max(((Integer) params.get("maximumSize")).intValue(), 100);
92+
if (params.containsKey("maximumsize"))
93+
Math.max(((Integer) params.get("maximumsize")).intValue(), 100);
7894
async = (testAsync || params.containsKey("async"));
7995
HTML5Applet applet = JSUtil.J2S.findApplet(htmlName);
8096
String javaver = JSUtil.J2S.getJavaVersion();

sources/net.sf.j2s.java.core/src/swingjs/JSAppletViewer.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public void run() {
262262
@Override
263263
public URL getDocumentBase() {
264264
try {
265-
return new URL((String) params.get("documentBase"));
265+
return new URL((String) params.get("documentbase"));
266266
} catch (MalformedURLException e) {
267267
return null;
268268
}
@@ -271,18 +271,17 @@ public URL getDocumentBase() {
271271
@Override
272272
public URL getCodeBase() {
273273
try {
274-
return new URL((String) params.get("codePath"));
274+
return new URL((String) params.get("codepath"));
275275
} catch (MalformedURLException e) {
276276
return null;
277277
}
278278
}
279279

280280
@Override
281281
public String getParameter(String name) {
282-
String s = (String) params.get(name);
283-
System.out.println("get parameter: " + name + " = " + s);
284-
return (s == null ? null : "" + s); // because it may not be a string in
285-
// JavaScript if inherited from Info
282+
String s = super.getParameter(name);
283+
System.out.println("JSApp get parameter: " + name + " = " + s);
284+
return s;
286285
}
287286

288287
@Override

sources/net.sf.j2s.java.core/srcjs/js/j2sApplet.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,10 +2287,10 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
22872287
};
22882288

22892289
J2S._setAppletParams = function(availableParams, params, Info, isHashtable) {
2290-
for ( var i in Info)
2290+
for (var i in Info) {
22912291
if (!availableParams
22922292
|| availableParams.indexOf(";" + i.toLowerCase() + ";") >= 0) {
2293-
if (Info[i] == null || i == "language"
2293+
if (Info[i] == null || lci == "language"
22942294
&& !J2S.featureDetection.supportsLocalization())
22952295
continue;
22962296
// params.put$TK$TV(i, (Info[i] === true ? Boolean.TRUE: Info[i]
@@ -2301,6 +2301,7 @@ if (ev.keyCode == 9 && ev.target["data-focuscomponent"]) {
23012301
else
23022302
params[i] = Info[i];
23032303
}
2304+
}
23042305
}
23052306

23062307
// The original Jmol "applet" was created as an

0 commit comments

Comments
 (0)