Skip to content

Commit

Permalink
mar oct 14 17:34:46 CDT 2008
Browse files Browse the repository at this point in the history
  • Loading branch information
vic committed Oct 14, 2008
1 parent 62158f6 commit 2949c87
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
17 changes: 2 additions & 15 deletions core/src/main/java/com/jwmsolutions/jwmscript/JWMScriptApplet.java
Expand Up @@ -35,8 +35,8 @@ private String readURLString(URL url) throws Exception {
}

public void init() {
JSObject window = JSObject.getWindow(this);
try {
JSObject window = JSObject.getWindow(this);
this.handle = new JSHandle(window, getAppletContext());
URLSetPolicy policy = new URLSetPolicy();
java.security.Policy.setPolicy(policy);
Expand All @@ -47,23 +47,10 @@ public void init() {
this.handle = new JSHandle(jsObject, getAppletContext());
jsObject.call("initialize", new Object[] { this });
} catch (Throwable t) {
alertException(t);
window.call("alert", new Object[] { getBacktrace(t) } );
}
}

public void alert(Object message) {
String str = String.valueOf(message);
str = str.replaceAll("[\"\']", "\\\\$0").replaceAll("[\n\f]", "\\\\n");
handle.eval("alert(\""+str+"\");");
}

private void alertException(Throwable e) {
StringWriter writer = new StringWriter();
PrintWriter print = new PrintWriter(writer, true);
e.printStackTrace(print);
alert(writer.toString());
}

public String getBacktrace(Object o) {
if (o instanceof Throwable) {
Throwable e = (Throwable) o;
Expand Down
12 changes: 10 additions & 2 deletions core/src/main/resources/com/jwmsolutions/jwmscript/JWMScript.js
Expand Up @@ -19,6 +19,11 @@
});
},

relative : function(path, to) {
to = to || document.location.toString();
return to.toString().replace(/\/[^\/]*$/, "/")+path;
},

copy_ary : function(obj) {
var ary = new Array();
for (var i = 0; i < obj.length; i++) {
Expand Down Expand Up @@ -100,7 +105,11 @@
var urlArray = java.lang.reflect.Array.newInstance(java.net.URL, a.length);
for (var i = 0; i < a.length; i++) {
var url = a[i];
java.lang.reflect.Array.set(urlArray, i, (typeof url == "string") ? new java.net.URL(url) : url);
if (typeof(url) == "string") {
if (!url.match(/^\w+:/)) { url = util.relative(url); }
url = new java.net.URL(url);
}
java.lang.reflect.Array.set(urlArray, i, url);
}
return urlArray;
},
Expand All @@ -121,7 +130,6 @@
this.javaObject = javaObject;
var instances = window.JWMScript.instances || {};
var id = this.javaObject.getParameter("object_id");
alert("INITING "+id);
instances[id].initialize(this);
}),

Expand Down
22 changes: 13 additions & 9 deletions core/src/main/resources/com/jwmsolutions/jwmscript/applet.js
Expand Up @@ -22,15 +22,14 @@ JWMScript = function() {

applet : function() {
var str = "";
str += ' <APPLET ';
str += ' ARCHIVE="'+this.archive+'" ';
str += ' CODE="com.jwmsolutions.jwmscript.JWMScriptApplet" ';
str += ' ALT="JWMScript Applet" ';
str += ' NAME="'+this.id+'" ';
str += ' WIDTH="0" HEIGHT="0" ';
str += ' <applet ';
if (this.codebase) { str += ' codebase="'+this.codebase+'" '; }
str += ' archive="'+this.archive+'" ';
str += ' code="com.jwmsolutions.jwmscript.JWMScriptApplet" ';
str += ' width="0" height="0" mayscript="mayscript" scriptable="true" ';
str += ' > ';
str += ' <PARAM NAME="object_id" VALUE="'+this.id+'"> ';
str += ' </APPLET> ';
str += ' <param name="object_id" value="'+this.id+'"> ';
str += ' </applet> ';
return str;
},

Expand Down Expand Up @@ -59,6 +58,8 @@ JWMScript = function() {
str += (' <param name="scriptable" value="true" />');
}

str += (' <param name="object_id" value="'+this.id+'" />');

if (nav.match(/Netscape/)) {
str += ('</embed>');
} else {
Expand All @@ -72,4 +73,7 @@ JWMScript = function() {
};

JWMScript = JWMScript();

JWMScript.relative = function(path, to) {
to = to || document.location.toString();
return to.toString().replace(/\/[^\/]*$/, "/")+path;
};

0 comments on commit 2949c87

Please sign in to comment.