X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FByteStream.java;h=5aa85264a291b50374554bc78b7234e46fbd8579;hb=345865827e473f64410c7e3c07e73d20a8db7c4f;hp=ab2dac128f0d3c234eed2418fa8d1ebd8c685f19;hpb=ae5ffa8160bbd04b3f2ae0722ea089542ab0350e;p=org.ibex.core.git diff --git a/src/org/xwt/ByteStream.java b/src/org/xwt/ByteStream.java index ab2dac1..5aa8526 100644 --- a/src/org/xwt/ByteStream.java +++ b/src/org/xwt/ByteStream.java @@ -1,94 +1,82 @@ // Copyright 2002 Adam Megacz, see the COPYING file for licensing [GPL] + package org.xwt; import java.io.*; import java.util.*; +import org.xwt.js.*; import org.xwt.util.*; -import org.mozilla.javascript.*; /** A ByteStream encapsulates a source of a stream of bytes -- * currently either a local file or a Base64-encoded XMLRPC/SOAP element */ - -public class ByteStream extends JSObject { +public class ByteStream extends JS.Obj { private byte[] bytes = null; private File file = null; private ByteStream() { setSeal(true); } + ByteStream(String filename) { this(); this.file = new File(filename); } + ByteStream(byte[] bytes) { this(); this.bytes = bytes; } public String toString() { return "ByteStream, source=" + (file == null ? "memory" : file.getAbsolutePath()); } - public String getClassName() { return "ByteStream"; } - - ByteStream(String filename) { - this(); - this.file = new File(filename); - } - - ByteStream(byte[] bytes) { - this(); - this.bytes = bytes; - } - public Object get(String name, Scriptable start) { - if (name == null) return null; - else if (name.equals("getUTF")) return getUTF; + public Object get(Object name) { + if (name.equals("getUTF")) return getUTF; else if (name.equals("getDOM")) return getDOM; else if (name.equals("fileName")) return file == null ? null : file.getAbsolutePath(); else return null; } - /** Helper class for defining functions. */ - private abstract class JSFunction extends JSObject implements Function { - JSFunction() { this.setSeal(true); } - public Scriptable construct(Context cx, Scriptable scope, java.lang.Object[] args) { return null; } - } - private class XMLHelper extends XML { Vector obStack = new Vector(); - public void startElement(String name, String[] keys, Object[] vals, int line, int col) throws SAXException { - JSObject o = new JSObject(); - o.put("$name", null, name); - for(int i=0; i= 1 ? (Scriptable)obStack.elementAt(0) : null; + return obStack.size() >= 1 ? (JS)obStack.elementAt(0) : null; } } @@ -113,16 +101,16 @@ public class ByteStream extends JSObject { os.close(); } - private final JSFunction getDOM = new JSFunction() { - public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException { - if (args.length != 0) return null; + private final JS.Function getDOM = new JS.Function() { + public Object _call(JS.Array args) throws JS.Exn { + if (args.length() != 0) return null; return new XMLHelper().doParse(); } }; - private final JSFunction getUTF = new JSFunction() { - public Object call(Context cx, Scriptable thisObj, Scriptable ctorObj, Object[] args) throws JavaScriptException { - if (args.length != 0) return null; + private final JS.Function getUTF = new JS.Function() { + public Object _call(JS.Array args) throws JS.Exn { + if (args.length() != 0) return null; try { CharArrayWriter caw = new CharArrayWriter(); InputStream is = getInputStream(); @@ -137,7 +125,7 @@ public class ByteStream extends JSObject { } catch (IOException e) { if (Log.on) Log.log(ByteStream.class, "IO Exception while reading from file"); if (Log.on) Log.log(ByteStream.class, e); - throw new JavaScriptException("error while reading from ByteStream"); + throw new JS.Exn("error while reading from ByteStream"); } } };