Changed global getURL() function to return a MimePart object
instead of a string, so it is now possible to retrieve any kind of URL instead of just text URLs.
This commit is contained in:
parent
5e34cfdcc7
commit
e857528208
1 changed files with 11 additions and 7 deletions
|
@ -572,15 +572,19 @@ public final class HopExtension {
|
||||||
if (arguments.length < 1)
|
if (arguments.length < 1)
|
||||||
return ESNull.theNull;
|
return ESNull.theNull;
|
||||||
try {
|
try {
|
||||||
StringBuffer urltext = new StringBuffer ();
|
ByteArrayOutputStream body = new ByteArrayOutputStream ();
|
||||||
java.net.URL url = new java.net.URL (arguments[0].toString ());
|
java.net.URL url = new java.net.URL (arguments[0].toString ());
|
||||||
BufferedReader in = new BufferedReader (new InputStreamReader (url.openConnection ().getInputStream ()));
|
String filename = url.getFile ();
|
||||||
char[] c = new char[1024];
|
java.net.URLConnection con = url.openConnection ();
|
||||||
int read = -1;
|
String contentType = con.getContentType ();
|
||||||
while ((read = in.read (c)) > -1)
|
InputStream in = new BufferedInputStream (con.getInputStream ());
|
||||||
urltext.append (c, 0, read);
|
byte[] b = new byte[1024];
|
||||||
|
int read;
|
||||||
|
while ((read = in.read (b)) > -1)
|
||||||
|
body.write (b, 0, read);
|
||||||
in.close ();
|
in.close ();
|
||||||
return new ESString (urltext.toString ());
|
MimePart mime = new MimePart (filename, body.toByteArray(), contentType);
|
||||||
|
return ESLoader.normalizeObject (mime, evaluator);
|
||||||
} catch (Exception ignore) {}
|
} catch (Exception ignore) {}
|
||||||
return ESNull.theNull;
|
return ESNull.theNull;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue