added FileObject support for getInfo and corrected error messages.
This commit is contained in:
parent
98a6050140
commit
7ac392b088
1 changed files with 14 additions and 2 deletions
|
@ -121,7 +121,7 @@ public class ImageObject {
|
|||
public Object call(Context cx, Scriptable scope,
|
||||
Scriptable thisObj, Object[] args) {
|
||||
if (args.length != 1) {
|
||||
throw new IllegalArgumentException("Image.getImageInfo() expects one argument");
|
||||
throw new IllegalArgumentException("Image.getInfo() expects one argument");
|
||||
}
|
||||
|
||||
Object arg = args[0];
|
||||
|
@ -142,6 +142,18 @@ public class ImageObject {
|
|||
} catch (FileNotFoundException fnf) {
|
||||
return null;
|
||||
}
|
||||
} else if (arg instanceof File) {
|
||||
try {
|
||||
in = new FileInputStream((File) arg);
|
||||
} catch (FileNotFoundException fnf) {
|
||||
return null;
|
||||
}
|
||||
} else if (arg instanceof FileObject) {
|
||||
try {
|
||||
in = new FileInputStream(((FileObject)arg).getFile());
|
||||
} catch (FileNotFoundException fnf) {
|
||||
return null;
|
||||
}
|
||||
} else if (arg instanceof String) {
|
||||
String str = (String) arg;
|
||||
// try to interpret argument as URL if it contains a colon,
|
||||
|
@ -165,7 +177,7 @@ public class ImageObject {
|
|||
}
|
||||
|
||||
if (in == null) {
|
||||
String msg = "Unrecognized argument in Image.getImageInfo(): ";
|
||||
String msg = "Unrecognized argument in Image.getInfo(): ";
|
||||
msg += arg == null ? "null" : arg.getClass().toString();
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue