// // The Antville Project // http://code.google.com/p/antville // // Copyright 2001-2007 by The Antville People // // Licensed under the Apache License, Version 2.0 (the ``License''); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an ``AS IS'' BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // $Revision$ // $LastChangedBy$ // $LastChangedDate$ // $URL$ // HopObject.remove = function(collection) { var item; while (collection.size() > 0) { item = collection.get(0); if (item.constructor.remove) { item.constructor.remove.call(item, item); } } return; } HopObject.getFromPath = function(name, collection) { // FIXME: This is an ugly work-around for Helma bug #625 // NOTE: Bug is fixed; to be removed with Helma update on Antville.org var translate = function(str) { return str.replace(/&([^;]*);/g, function(s, $1) { switch ($1) { case "auml": return "ä"; case "ouml": return "ö"; case "uuml": return "ü"; case "Auml": return "Ä"; case "Ouml": return "Ö"; case "Uuml": return "Ü"; case "szlig": return "ß"; } return s; }) } var site; if (name.contains("/")) { var parts = name.split("/"); site = root.get(parts[0]); name = parts[1]; } else { site = res.handlers.site; } if (site && site.getPermission("main")) { var o = site[collection].get(name); o || (o = site[collection].get(translate(name))); return o; } return null; } HopObject.prototype.map = function(values) { for (var i in values) { this[i] = values[i]; } return; } HopObject.prototype.onRequest = function() { User.autoLogin(); res.handlers.membership = User.getMembership(); if (User.getCurrentStatus() === User.BLOCKED) { User.logout(); res.status = 401; res.writeln(gettext("Sorry, your account has been blocked.")); res.writeln(gettext("Please contact the maintainer of this site for further information.")); res.stop(); } if (res.handlers.site.status === Site.BLOCKED && !User.require(User.PRIVILEGED)) { res.status = 401; res.writeln(gettext("Sorry, this site has been blocked.")); res.writeln(gettext("Please contact the maintainer of this site for further information.")); res.stop(); } if (!this.getPermission(req.action)) { if (!session.user) { User.setLocation(root.href() + req.path); res.message = gettext("Please login first."); res.redirect(res.handlers.site.members.href("login")); } User.getLocation(); res.status = 401; res.write(gettext("Sorry, you are not allowed to access this part of the site.")); res.stop(); } res.handlers.layout = res.handlers.site.layout || new Layout; res.skinpath = res.handlers.layout.getSkinPath(); res.meta.values = {}; res.handlers.site.renderSkinAsString("Site#values"); return; } HopObject.prototype.getPermission = function() { return true; } HopObject.prototype.delete_action = function() { if (req.postParams.proceed) { try { var str = this.toString(); var parent = this._parent; var url = this.constructor.remove.call(this, this) || parent.href(); res.message = gettext("{0} was successfully deleted.", str); res.redirect(User.getLocation() || url); } catch(ex) { res.message = ex; app.log(ex); } } res.data.action = this.href(req.action); res.data.title = gettext("Confirm deletion of {0}", this); res.data.body = this.renderSkinAsString("$HopObject#confirm", { text: gettext('You are about to delete {0}.', this) }); res.handlers.site.renderSkin("Site#page"); return; } HopObject.prototype.touch = function() { return this.map({ modified: new Date, modifier: session.user }); } HopObject.prototype.log = function() { var entry = new LogEntry(this, "main"); app.data.entries.push(entry); return; } HopObject.prototype.notify = function(action) { var site = res.handlers.site; if (site.notificationMode === Site.NOBODY) { return; } switch (action) { case "comment": action = "create"; break; } var membership; var currentMembership = res.handlers.membership; for (var i=0; i -1) { res.encode("<% "); res.write(handler || ctor.name.toLowerCase()); res.write(String.SPACE); res.write(quote(this.name || this._id)); res.encode(" %>"); } return; } HopObject.prototype.kind_macro = function() { var type = this.constructor.name.toLowerCase(); switch (type) { default: res.write(gettext(type)); break; } return; } HopObject.prototype.getFormValue = function(name) { if (req.isPost()) { return req.postParams[name]; } else { var value = this[name] || req.queryParams[name] || String.EMPTY; return value instanceof HopObject ? value._id : value; } } HopObject.prototype.getFormOptions = function(name) { return [{value: true, display: "enabled"}]; } HopObject.prototype.self_macro = function() { return this; } HopObject.prototype.type_macro = function() { return res.write(this.constructor.name); } HopObject.prototype.link_macro = function(param, url, text) { url || (url = "."); var action = url.split(/#|\?/)[0]; if (this.getPermission(action)) { text || (text = (action === "." ? this._id : action).capitalize()); renderLink.call(global, param, url, gettext(text), this); } return; } HopObject.prototype.created_macro = function(param, format) { if (this.created && !this.isTransient()) { res.write(formatDate(this.created, format || param.format)); } return; } HopObject.prototype.modified_macro = function(param, format) { !format && (format = param.format); if (format && this.modified && !this.isTransient()) { res.write(formatDate(this.modified, format)); return; } return this.modified; } HopObject.prototype.creator_macro = function(param, mode) { if (!this.creator || this.isTransient()) { return; } mode || (mode = param.as); if (mode === "link" && this.creator.url) { html.link({href: this.creator.url}, this.creator.name); } else if (mode === "url") { res.write(this.creator.url); } else { res.write(this.creator.name); } return; } HopObject.prototype.modifier_macro = function(param, mode) { if (!this.modifier || this.isTransient()) { return; } mode || (mode = param.as); if (mode === "link" && this.modifier.url) { html.link({href: this.modifier.url}, this.modifier.name); } else if (mode === "url") { res.write(this.modifier.url); } else { res.write(this.modifier.name); } return; } HopObject.prototype.getTitle = function() { return this.title || this.__name__.capitalize(); } HopObject.prototype.toString = function() { return this.constructor.name + " #" + this._id; } /*HopObject.prototype.valueOf = function() { return this._id; };*/ HopObject.prototype.link_filter = function(value, param, action) { action || (action = "."); res.push(); renderLink(param, action, value, this); return res.pop(); } HopObject.prototype.handleMetadata = function(name) { this.__defineGetter__(name, function() { return this.metadata.get(name); }); this.__defineSetter__(name, function(value) { return this.metadata.set(name, value); }); this[name + "_macro"] = function(param) { var value; if (value = this[name]) { res.write(value); } return; }; return; }