Global.helma.Image.getInfo (arg)
Sourcecode in /home/hannes/helma/modules/helma/Image.js:
35:   helma.Image.getInfo = function(arg) {
36:       if (arguments.length != 1) {
37:           throw new java.lang.IllegalArgumentException(
38:               "Image.getInfo() expects one argument"
39:           );
40:       }
41:   
42:       var inp, result;
43:       var info = new Packages.helma.image.ImageInfo();
44:      // FIXME: we need a byte object for comparison
45:      var b = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 1024);
46:  
47:      try {
48:          if (arg instanceof java.io.InputStream) {
49:              inp = new java.io.InputStream(arg);
50:          // FIXME: here comes a dirty hack to check for a byte array
51:          } else if (arg.getClass && arg.getClass() == b.getClass()) {
52:              inp = new java.io.ByteArrayInputStream(arg);
53:          } else if (arg instanceof java.io.File) {
54:              inp = new java.io.FileInputStream(arg);
55:          } else if (arg instanceof helma.File) {
56:              inp = new java.io.FileInputStream(arg.getFile());
57:          } else if (typeof arg == "string") {
58:              var str = arg;
59:              // try to interpret argument as URL if it contains a colon,
60:              // otherwise or if URL is malformed interpret as file name.
61:              if (str.indexOf(":") > -1) {
62:                  try {
63:                      var url = new java.net.URL(str);
64:                      inp = url.openStream();
65:                  } catch (mux) {
66:                      inp = new java.io.FileInputStream(str);
67:                  }
68:              } else {
69:                  inp = new java.io.FileInputStream(str);
70:              }
71:          }
72:          if (inp == null) {
73:              var msg = "Unrecognized argument in Image.getInfo(): ";
74:              msg += (arg == null ? "null" : arg.getClass().toString());
75:              throw new java.lang.IllegalArgumentException(msg);
76:          }
77:          info.setInput(inp);
78:          if (info.check()) {
79:              result = info;
80:          }
81:      } catch (e) {
82:          // do nothing, returns null later
83:      } finally {
84:          if (inp != null) {
85:              try {
86:                  inp.close();
87:              } catch (e) {}
88:          }
89:      }
90:  
91:      return result;
92:  }