From d4fc62b0a4738cdab3dd605d7ec34dab94341867 Mon Sep 17 00:00:00 2001 From: megacz Date: Fri, 30 Jan 2004 07:43:46 +0000 Subject: [PATCH] 2003/12/29 22:29:30 darcs-hash:20040130074346-2ba56-49cc6036217793fc1cced4bcc18cbba992293f86.gz --- src/org/xwt/Picture.java | 14 ++++---- src/org/xwt/Platform.java | 4 +-- src/org/xwt/SOAP.java | 6 ++-- src/org/xwt/{Res.java => Stream.java} | 60 ++++++++++++++++----------------- 4 files changed, 42 insertions(+), 42 deletions(-) rename src/org/xwt/{Res.java => Stream.java} (84%) diff --git a/src/org/xwt/Picture.java b/src/org/xwt/Picture.java index 4d563e0..82df487 100644 --- a/src/org/xwt/Picture.java +++ b/src/org/xwt/Picture.java @@ -17,17 +17,17 @@ import org.xwt.translators.*; public class Picture { public Picture() { this.res = null; } - public Picture(Res r) { this.res = r; } - private static Cache cache = new Cache(100); ///< Picture, keyed by the Res that loaded them + public Picture(Stream r) { this.res = r; } + private static Cache cache = new Cache(100); ///< Picture, keyed by the Stream that loaded them - public Res res = null; ///< the resource we were loaded from + public Stream res = null; ///< the resource we were loaded from public int width = -1; ///< the width of the image public int height = -1; ///< the height of the image public int[] data = null; ///< argb samples public boolean isLoaded = false; ///< true iff the image is fully loaded /** turns a resource into a Picture.Source and passes it to the callback */ - public static Picture load(final Res r, final Scheduler.Task callback) { + public static Picture load(final Stream r, final Scheduler.Task callback) { Picture ret = (Picture)cache.get(r); if (ret == null) cache.put(r, ret = Platform.createPicture(r)); final Picture p = ret; @@ -39,10 +39,10 @@ public class Picture { in = r.getInputStream(); } catch (IOException e) { in = null; - if (r instanceof Res.Ref) { + if (r instanceof Stream.Ref) { // add extensions to the resource, looking for the image - Res.Ref ref = (Res.Ref)r; - Res newr; + Stream.Ref ref = (Stream.Ref)r; + Stream newr; String[] exts = new String[] { ".png", ".jpeg", ".gif" }; for (int i=0; i < exts.length && in == null; i++) { diff --git a/src/org/xwt/Platform.java b/src/org/xwt/Platform.java index 7de9058..2ce88b1 100644 --- a/src/org/xwt/Platform.java +++ b/src/org/xwt/Platform.java @@ -101,12 +101,12 @@ public abstract class Platform { protected void postInit() { } protected Surface _createSurface(Box b, boolean framed) { return null; } - protected Picture _createPicture(Res r) { return null; } + protected Picture _createPicture(Stream r) { return null; } protected PixelBuffer _createPixelBuffer(int w, int h, Surface owner) { return null; } protected Font.Glyph _createGlyph(org.xwt.Font f, char c) { return new DefaultGlyph(f, c); } public static PixelBuffer createPixelBuffer(int w, int h, Surface s) { return platform._createPixelBuffer(w, h, s); } - public static Picture createPicture(Res r) { return platform._createPicture(r); } + public static Picture createPicture(Stream r) { return platform._createPicture(r); } public static Font.Glyph createGlyph(org.xwt.Font f, char c) { return platform._createGlyph(f, c); } public static Surface createSurface(Box b, boolean framed, boolean refreshable) { Surface ret = platform._createSurface(b, framed); diff --git a/src/org/xwt/SOAP.java b/src/org/xwt/SOAP.java index 2c4044f..480b589 100644 --- a/src/org/xwt/SOAP.java +++ b/src/org/xwt/SOAP.java @@ -92,7 +92,7 @@ class SOAP extends XMLRPC { } else if (me instanceof byte[]) { objects.removeElementAt(objects.size() - 1); - objects.addElement(new Res.ByteArray(Base64.decode(new String(content.getBuf(), 0, content.size())), null)); + objects.addElement(new Stream.ByteArray(Base64.decode(new String(content.getBuf(), 0, content.size())), null)); content.reset(); } else if (me instanceof Integer) { @@ -181,10 +181,10 @@ class SOAP extends XMLRPC { sb.append(((Boolean)o).booleanValue() ? "true" : "false"); sb.append("\r\n"); - } else if (o instanceof Res) { + } else if (o instanceof Stream) { try { sb.append(" <" + name + " xsi:type=\"SOAP-ENC:base64\">\r\n"); - InputStream is = ((Res)o).getInputStream(); + InputStream is = ((Stream)o).getInputStream(); byte[] buf = new byte[54]; while(true) { int numread = is.read(buf, 0, 54); diff --git a/src/org/xwt/Res.java b/src/org/xwt/Stream.java similarity index 84% rename from src/org/xwt/Res.java rename to src/org/xwt/Stream.java index b529a4e..8300478 100644 --- a/src/org/xwt/Res.java +++ b/src/org/xwt/Stream.java @@ -11,14 +11,14 @@ import org.bouncycastle.util.encoders.Base64; /** Base class for XWT resources */ -public abstract class Res extends JS { +public abstract class Stream extends JS { /** return a resource for a given url */ - public static final Res fromURL(String url) throws JSExn { - if (url.startsWith("http://")) return new Res.HTTP(url); - else if (url.startsWith("https://")) return new Res.HTTP(url); - else if (url.startsWith("data:")) return new Res.ByteArray(Base64.decode(url.substring(5)), null); - else if (url.startsWith("utf8:")) return new Res.ByteArray(url.substring(5).getBytes(), null); + public static final Stream fromURL(String url) throws JSExn { + if (url.startsWith("http://")) return new Stream.HTTP(url); + else if (url.startsWith("https://")) return new Stream.HTTP(url); + else if (url.startsWith("data:")) return new Stream.ByteArray(Base64.decode(url.substring(5)), null); + else if (url.startsWith("utf8:")) return new Stream.ByteArray(url.substring(5).getBytes(), null); throw new JSExn("invalid resource specifier " + url); } @@ -34,7 +34,7 @@ public abstract class Res extends JS { public final InputStream getInputStream() throws IOException { return getInputStream(""); } public abstract InputStream getInputStream(String path) throws IOException; - public Res addExtension(String extension) { return new Ref(this, extension); } + public Stream addExtension(String extension) { return new Ref(this, extension); } public Object get(Object key) throws JSExn { if ("".equals(key)) { @@ -65,14 +65,14 @@ public abstract class Res extends JS { public String getCacheKey() throws NotCacheableException { throw notCacheable; } /** subclass from this if you want a CachedInputStream for each path */ - public static class CachedRes extends Res { - private Res parent; + public static class CachedStream extends Stream { + private Stream parent; private boolean disk = false; private String key; public String getCacheKey() throws NotCacheableException { return key; } public String toString() { return key; } private Hash cachedInputStreams = new Hash(); - public CachedRes(Res p, String s, boolean d) throws NotCacheableException { + public CachedStream(Stream p, String s, boolean d) throws NotCacheableException { this.parent = p; this.disk = d; this.key = p.getCacheKey(); } public InputStream getInputStream(String path) throws IOException { @@ -95,7 +95,7 @@ public abstract class Res extends JS { // Useful Subclasses ////////////////////////////////////////////////////////////////////// /** HTTP or HTTPS resource */ - public static class HTTP extends Res { + public static class HTTP extends Stream { private String url; HTTP(String url) { while (url.endsWith("/")) url = url.substring(0, url.length() - 1); this.url = url; } public String toString() { return url; } @@ -104,7 +104,7 @@ public abstract class Res extends JS { } /** byte arrays */ - public static class ByteArray extends Res { + public static class ByteArray extends Stream { private byte[] bytes; private String cacheKey = null; ByteArray(byte[] bytes, String cacheKey) { this.bytes = bytes; this.cacheKey = cacheKey; } @@ -117,7 +117,7 @@ public abstract class Res extends JS { } /** a file */ - public static class File extends Res { + public static class File extends Stream { private String path; File(String path) { while (path.endsWith(java.io.File.separatorChar + "")) path = path.substring(0, path.length() - 1); @@ -130,9 +130,9 @@ public abstract class Res extends JS { } /** "unwrap" a Zip archive */ - public static class Zip extends Res { - private Res parent; - Zip(Res parent) { this.parent = parent; } + public static class Zip extends Stream { + private Stream parent; + Zip(Stream parent) { this.parent = parent; } public String toString() { return parent.toString() + "!zip"; } public String getCacheKey() throws NotCacheableException { return parent.getCacheKey() + "!zip:"; } public InputStream getInputStream(String path) throws IOException { @@ -147,9 +147,9 @@ public abstract class Res extends JS { } /** "unwrap" a Cab archive */ - public static class Cab extends Res { - private Res parent; - Cab(Res parent) { this.parent = parent; } + public static class Cab extends Stream { + private Stream parent; + Cab(Stream parent) { this.parent = parent; } public String toString() { return parent.toString() + "!cab"; } public String getCacheKey() throws NotCacheableException { return parent.getCacheKey() + "!cab:"; } public InputStream getInputStream(String path) throws IOException { @@ -159,7 +159,7 @@ public abstract class Res extends JS { } /** the Builtin resource */ - public static class Builtin extends Res { + public static class Builtin extends Stream { public Builtin() { }; public String getCacheKey() throws NotCacheableException { throw notCacheable; } // not cacheable public String toString() { return "builtin:"; } @@ -170,22 +170,22 @@ public abstract class Res extends JS { } /** what you get when you reference a subresource */ - public static class Ref extends Res { - Res parent; + public static class Ref extends Stream { + Stream parent; Object key; public String toString() { return parent.toString() + "/" + key; } - Ref(Res parent, Object key) { this.parent = parent; this.key = key; } + Ref(Stream parent, Object key) { this.parent = parent; this.key = key; } public String getCacheKey() throws NotCacheableException { return parent.getCacheKey() + "/" + key; } - public Res addExtension(String extension) { + public Stream addExtension(String extension) { return ((String)key).endsWith(extension) ? this : new Ref(parent, key + extension); } public InputStream getInputStream(String path) throws IOException { return parent.getInputStream("/" + key + path); } } /** provides redirection of a specified key */ - public static class Graft extends Res { - Res graftee; + public static class Graft extends Stream { + Stream graftee; Object replaced_key, replaced_val; - Graft(Res graftee, Object key, Object val) { this.graftee = graftee; this.replaced_key = key; this.replaced_val = val; } + Graft(Stream graftee, Object key, Object val) { this.graftee = graftee; this.replaced_key = key; this.replaced_val = val; } public boolean equals(Object o) { return this == o || graftee.equals(o); } public int hashCode() { return graftee.hashCode(); } public InputStream getInputStream(String s) throws IOException { return graftee.getInputStream(s); } @@ -205,10 +205,10 @@ public abstract class Res extends JS { } /** shadow resource which replaces the graft */ - public static class ProgressWatcher extends Res { - final Res watchee; + public static class ProgressWatcher extends Stream { + final Stream watchee; JSFunction callback; - ProgressWatcher(Res watchee, JSFunction callback) { this.watchee = watchee; this.callback = callback; } + ProgressWatcher(Stream watchee, JSFunction callback) { this.watchee = watchee; this.callback = callback; } public String toString() { return watchee.toString(); } public String getCacheKey() throws NotCacheableException { return watchee.getCacheKey(); } public InputStream getInputStream(String s) throws IOException { -- 1.7.10.4