X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fxwt%2FByteStream.java;h=69acc89545c61a3e7884043f9ff6b56957f79caa;hb=cf3587e2fd5966b7ebfd721d9413674224d1ad2a;hp=cd3982a34b4535a39c6633535e463215623959b1;hpb=68d5439acb83a212fb346a4e2d82260d7febc127;p=org.ibex.core.git diff --git a/src/org/xwt/ByteStream.java b/src/org/xwt/ByteStream.java index cd3982a..69acc89 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] +// Copyright 2003 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.getAbsolutePath(); } - public String getClassName() { return "ByteStream"; } - - 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 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.Callable getDOM = new JS.Callable() { + 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.Callable getUTF = new JS.Callable() { + 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"); } } };