From f3ad5161a913d512a977ebab0767b27fa463f012 Mon Sep 17 00:00:00 2001 From: megacz Date: Fri, 30 Jan 2004 07:39:54 +0000 Subject: [PATCH] 2003/10/20 03:37:12 darcs-hash:20040130073954-2ba56-c6b4e58ed5d91df1ceb9dd91a2f22fe2c62f11c0.gz --- src/org/xwt/Res.java | 4 +--- src/org/xwt/XWT.java | 50 +++++++++++++++++++------------------------------- 2 files changed, 20 insertions(+), 34 deletions(-) diff --git a/src/org/xwt/Res.java b/src/org/xwt/Res.java index 4a8c7ed..60a9437 100644 --- a/src/org/xwt/Res.java +++ b/src/org/xwt/Res.java @@ -68,14 +68,12 @@ public abstract class Res extends JS { return ret; } - public static Res stringToRes(String url) { return stringToRes(url, false); } - public static Res stringToRes(String url, boolean permitLocalFilesystem) { + public static Res stringToRes(String url) { if (url.indexOf('!') != -1) return (Res)(new Zip(stringToRes(url.substring(0, url.lastIndexOf('!')))). get(url.substring(url.lastIndexOf('!') + 1))); if (url.startsWith("http://")) return new HTTP(url); if (url.startsWith("https://")) return new HTTP(url); - if (url.startsWith("file:") && permitLocalFilesystem) return new File(url.substring(5)); if (url.startsWith("cab:")) return new CAB(stringToRes(url.substring(4))); if (url.startsWith("data:")) return new ByteArray(Base64.decode(url.substring(5))); if (url.startsWith("utf8:")) return new ByteArray(url.substring(5).getBytes()); diff --git a/src/org/xwt/XWT.java b/src/org/xwt/XWT.java index 278532a..3c4d99f 100644 --- a/src/org/xwt/XWT.java +++ b/src/org/xwt/XWT.java @@ -133,49 +133,37 @@ public final class XWT extends JS.Obj { if (checkOnly) return Boolean.TRUE; if (args.length() != 1) return null; String file = Platform.fileDialog(args.elementAt(0).toString(), false); - return file == null ? null : Res.stringToRes("file:" + file); + return file == null ? null : new Res.File(file); - } else if (method.equals("saveFile")) { + } else if (method.equals("saveFile") || method.equals("saveFileAs")) { if (checkOnly) return Boolean.TRUE; - // FIXME - /* if (args.length() != 2) return null; - if (!(args.elementAt(1) instanceof ByteStream)) return null; + if (!(args.elementAt(1) instanceof Res)) return null; String file = args.elementAt(0).toString(); - if (safeFiles.get(Platform.isCaseSensitive() ? file : file.toLowerCase()) == null) { + if (method.equals("saveFileAs") || + safeFiles.get(Platform.isCaseSensitive() ? file : file.toLowerCase()) == null) { file = Platform.fileDialog(file, true); + // FIXME: throw exception here if (file == null) return null; safeFiles.put(Platform.isCaseSensitive() ? file : file.toLowerCase(), new Object()); } try { - ((ByteStream)args.elementAt(1)).writeTo(new FileOutputStream(file)); - return null; - } catch (IOException e) { - if (Log.on) Log.log(ByteStream.class, "IO Exception while writing a ByteStream to a file"); - if (Log.on) Log.log(ByteStream.class, e); - throw new JS.Exn("error while writing a ByteStream to a file"); - } - */ - - } else if (method.equals("saveFileAs")) { - // FIXME - /* - if (checkOnly) return Boolean.TRUE; - if (args.length() != 2) return null; - if (!(args.elementAt(1) instanceof ByteStream)) return null; - String file = args.elementAt(0).toString(); - file = Platform.fileDialog(file, true); - if (file == null) return null; - safeFiles.put(Platform.isCaseSensitive() ? file : file.toLowerCase(), new Object()); - try { - ((ByteStream)args.elementAt(1)).writeTo(new FileOutputStream(file)); + InputStream is = ((Res)args.elementAt(1)).getInputStream(); + FileOutputStream out = new FileOutputStream(file); + byte[] buffer = new byte[1024 * 16]; + while(true) { + int numread = is.read(buffer, 0, buffer.length); + if (numread == -1) break; + out.write(buffer, 0, numread); + } + is.close(); + out.close(); return null; } catch (IOException e) { - if (Log.on) Log.log(ByteStream.class, "IO Exception while writing a ByteStream to a file"); - if (Log.on) Log.log(ByteStream.class, e); - throw new JS.Exn("error while writing a ByteStream to a file"); + if (Log.on) Log.log(XWT.class, "IO Exception while writing a ByteStream to a file"); + if (Log.on) Log.log(XWT.class, e); + throw new JS.Exn("error while writing a Resource to a file"); } - */ } else if (method.equals("parseHTML")) { if (checkOnly) return Boolean.TRUE; -- 1.7.10.4