Sourcecode in MetaWeblogApi/metaWeblogAPI.js:
1: function newMediaObject(blogid, username, password, fileObject) {
2: var usr = root.blogger.getUser(username, password);
3: var blog = root.blogger.getBlog(blogid.toString());
4: if (!blog)
5: throw("Couldn't find the blog " + blogid);
6: var level = blog.members.getMembershipLevel(usr);
7: var str = new java.lang.String(fileObject.bits);
8: var bytes = Packages.helma.util.Base64.decode(str.toCharArray());
9: var param = new Object();
10: var ret = new Object();
11: if (fileObject.type.toLowerCase().startsWith("image/")) {
12: // handle new image
13: try {
14: blog.images.checkAdd(usr, level);
15: param.rawimage = new Packages.helma.util.MimePart(fileObject.name, bytes, fileObject.type);
16: param.maxheight = fileObject.antville_maxheight;
17: param.maxwidth = fileObject.antville_maxwidth;
18: param.alttext = fileObject.description;
19: var result = blog.images.evalImg(param, usr);
20: var mediaObject = result.obj;
21: ret.antville_alias = mediaObject.alias;
22: ret.antville_staticUrl = mediaObject.getUrl();
23: ret.antville_popupUrl = mediaObject.getPopupUrl();
24: ret.antville_width = mediaObject.width;
25: ret.antville_height = mediaObject.height;
26: ret.antville_macro = "<% image name=\"" + blog.alias + "/" + mediaObject.alias + "\" %>";
27: if (mediaObject.thumbnail) {
28: ret.antville_popupmacro = "<% image name=\"" + blog.alias + "/" + mediaObject.alias + "\" as=\"popup\" %>";
29: ret.antville_thumbmacro = "<% image name=\"" + blog.alias + "/" + mediaObject.alias + "\" as=\"thumbnail\" %>";
30: }
31: } catch (e) {
32: if (e instanceof DenyException)
33: throw("You're not allowed to upload images to the blog " + blog.alias);
34: else
35: throw("Error while creating new Media Object: " + e.toString());
36: }
37: } else {
38: // handle new file
39: try {
40: blog.files.checkAdd(usr, level);
41: param.rawfile = new Packages.helma.util.MimePart(fileObject.name, bytes, fileObject.type);
42: param.description = fileObject.description;
43: var result = blog.files.evalFile(param, usr);
44: var mediaObject = result.obj;
45: ret.antville_macro = "<% file name=\"" + blog.alias + "/" + mediaObject.alias + "\" %>";
46: } catch (e) {
47: if (e instanceof DenyException)
48: throw("You're not allowed to upload files to the blog " + blog.alias);
49: else
50: throw("Error occured while creating new Media Object: " + e.toString());
51: }
52: }
53: ret.url = mediaObject.getUrl();
54: ret.antville_message = result.toString();
55: return ret;
56: }
|