Cleaned up parameter handling differences between imageCtor and GetInfo.call, added MimeTipe to imageCtor, etc.

This commit is contained in:
lehni 2005-10-20 09:14:00 +00:00
parent 34eaf86d50
commit 67d7e915ee

View file

@ -26,7 +26,6 @@ import org.mozilla.javascript.Function;
import org.mozilla.javascript.FunctionObject; import org.mozilla.javascript.FunctionObject;
import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject; import org.mozilla.javascript.ScriptableObject;
import org.mozilla.javascript.NativeJavaArray;
import org.mozilla.javascript.NativeJavaObject; import org.mozilla.javascript.NativeJavaObject;
import org.mozilla.javascript.BaseFunction; import org.mozilla.javascript.BaseFunction;
import org.mozilla.javascript.Wrapper; import org.mozilla.javascript.Wrapper;
@ -73,16 +72,17 @@ public class ImageObject {
ImageGenerator generator = ImageGenerator.getInstance(); ImageGenerator generator = ImageGenerator.getInstance();
if (args.length == 1) { if (args.length == 1) {
if (args[0] instanceof NativeJavaArray) { Object arg = args[0];
Object array = ((NativeJavaArray) args[0]).unwrap();
if (array instanceof byte[]) { if (arg instanceof Wrapper) {
img = generator.createImage((byte[]) array); arg = ((Wrapper) arg).unwrap();
} }
} else if (args[0] instanceof byte[]) {
img = generator.createImage((byte[]) args[0]); if (arg instanceof byte[]) {
} else if (args[0] instanceof String) { img = generator.createImage((byte[]) arg);
} else if (arg instanceof String) {
// the string could either be a url or a local filename, let's try both: // the string could either be a url or a local filename, let's try both:
String str = args[0].toString(); String str = arg.toString();
try { try {
URL url = new URL(str); URL url = new URL(str);
img = generator.createImage(url); img = generator.createImage(url);
@ -90,24 +90,24 @@ public class ImageObject {
// try the local file now: // try the local file now:
img = generator.createImage(str); img = generator.createImage(str);
} }
} else if (args[0] instanceof NativeJavaObject) { } else if (arg instanceof MimePart) {
// see wether a standard java image object is wrapped in a helma image: img = generator.createImage(((MimePart) arg).getContent());
Object arg = ((NativeJavaObject) args[0]).unwrap(); } else if (arg instanceof File) {
if (arg instanceof MimePart) { img = generator.createImage(((File) arg).getPath());
img = generator.createImage(((MimePart) arg).getContent()); } else if (arg instanceof FileObject) {
} else { img = generator.createImage(((FileObject) arg).getFile().getPath());
Image image = null; } else {
if (arg instanceof BufferedImage) { Image image = null;
// no need to wait for buffered images: if (arg instanceof BufferedImage) {
image = (Image) arg; // no need to wait for buffered images:
} else if (arg instanceof Image) { image = (Image) arg;
// wait for all the other image types: } else if (arg instanceof Image) {
image = ImageWaiter.waitForImage((Image) arg); // wait for all the other image types:
} image = ImageWaiter.waitForImage((Image) arg);
if (image != null) { }
img = new ImageWrapper(image, image.getWidth(null), image.getHeight(null), generator); if (image != null) {
} img = new ImageWrapper(image, image.getWidth(null), image.getHeight(null), generator);
} }
} }
} else if (args.length == 2) { } else if (args.length == 2) {
if (args[0] instanceof Number && if (args[0] instanceof Number &&
@ -168,8 +168,8 @@ public class ImageObject {
in = (InputStream) arg; in = (InputStream) arg;
} else if (arg instanceof byte[]) { } else if (arg instanceof byte[]) {
in = new ByteArrayInputStream((byte[]) arg); in = new ByteArrayInputStream((byte[]) arg);
} else if (arg instanceof File) { } else if (arg instanceof MimePart) {
in = new FileInputStream((File) arg); in = new ByteArrayInputStream(((MimePart) arg).getContent());
} else if (arg instanceof File) { } else if (arg instanceof File) {
in = new FileInputStream((File) arg); in = new FileInputStream((File) arg);
} else if (arg instanceof FileObject) { } else if (arg instanceof FileObject) {