2002/06/23 21:35:39
[org.ibex.core.git] / src / org / xwt / XWT.java
index 2eeaadf..340033f 100644 (file)
@@ -53,6 +53,7 @@ public final class XWT extends JSObject {
         else if (name.equals("homeDir")) return System.getProperty("user.home");
         else if (name.equals("tempDir")) return System.getProperty("java.io.tempdir");
         else if (name.equals("recursivePrintObject")) return recursivePrintObject;
+        else if (name.equals("parseHTML")) return parseHTML;
         else if (name.equals("button")) {
             if (Surface.button1 && !Surface.button2 && !Surface.button3) return new Integer(1);
             else if (!Surface.button1 && Surface.button2 && !Surface.button3) return new Integer(1);
@@ -278,6 +279,23 @@ public final class XWT extends JSObject {
         };
 
     
+    private static final JSFunction parseHTML = new JSFunction() {
+            public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException {
+                if (args == null || args.length != 1 || args[0] == null) return null;
+                try {
+                    if (args[0] instanceof ByteStream) {
+                        return HTML.parseReader(new InputStreamReader(((ByteStream)args[0]).getInputStream()));
+                    } else {
+                        return HTML.parseReader(new StringReader(args[0].toString()));
+                    }
+                } catch (IOException e) {
+                    if (Log.on) Log.log(HTML.class, "IO Exception while parsing HTML");
+                    if (Log.on) Log.log(HTML.class, e);
+                    throw new JavaScriptException("error while parsing HTML");
+                }
+            }
+        };
+    
     private static void recurse(String indent, String name, Object o, Context cx) {
         if (!name.equals("")) name += " : ";
 
@@ -290,7 +308,7 @@ public final class XWT extends JSObject {
             for(int i=0; i<na.jsGet_length(); i++)
                 recurse(indent + "  ", i + "", na.get(i, null), cx);
 
-        } else if (o instanceof JSObject || o instanceof ScriptableObject) {
+        } else if (!(o instanceof NativeDate) && (o instanceof JSObject || o instanceof ScriptableObject)) {
             Log.log(cx.interpreterSourceFile, indent + name + "<object>");
             Scriptable s = (Scriptable)o;
             Object[] keys = s.getIds();