1 /* Copyright (C) 2000-2004 Thomas Bopp, Thorsten Hampel, Ludger Merkens
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * $Id: DocExternFactory.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $
19 inherit "/factories/DocumentFactory";
23 #include <exception.h>
25 #include <attributes.h>
27 class DocExternFactory : public DocumentFactory{
34 private object mExternLookup;
39 mExternLookup = _Server->get_module("extern_documents");
47 init_class_attribute(DOC_EXTERN_URL, CMD_TYPE_STRING, "extern url",
48 EVENT_ATTRIBUTES_QUERY, EVENT_ATTRIBUTES_CHANGE,0,
49 CONTROL_ATTR_USER, "");
52 object execute(mapping vars)
55 if ( !stringp(vars["url"]) )
56 THROW("No url given!", E_ERROR);
58 int l = strlen(vars["url"]);
59 if ( l >= 2 && vars["url"][l-1] == '/' )
60 vars["url"] = vars["url"][..l-2];
62 if ( !stringp(vars->name) || strlen(vars->name) == 0 )
63 vars->name = vars->url;
65 try_event(EVENT_EXECUTE, CALLER, obj);
66 if ( vars->transient ) {
67 if ( mappingp(vars->attributes) )
68 vars->attributes[OBJ_TEMP] = 1;
70 vars->attributes = ([ OBJ_TEMP : 1 ]);
72 obj = ::object_create(
73 vars["name"], CLASS_NAME_DOCEXTERN, 0,
75 vars["attributesAcquired"],
76 vars["attributesLocked"],
78 vars["sanctionMeta"]);
80 obj->set_attribute(DOC_EXTERN_URL, vars["url"]);
81 obj->set_attribute(DOC_MIME_TYPE, ""); // no mime type for external docs
82 run_event(EVENT_EXECUTE, CALLER, obj);
88 get_document(string url)
91 if ( l >= 2 && url[l-1] == '/' )
93 return mExternLookup->lookup(url);
98 array get_all_objects()
100 return _Database->get_objects_by_class("/classes/"+get_class_name());
104 string get_identifier() { return "DocExtern.factory"; }
105 string get_class_name() { return "DocExtern"; }
106 int get_class_id() { return CLASS_DOCEXTERN; }