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());
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;