DocExternFactory._pike
Go to the documentation of this file.
1 /* Copyright (C) 2000-2004 Thomas Bopp, Thorsten Hampel, Ludger Merkens
2  *
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.
7  *
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.
12  *
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
16  *
17  * $Id: DocExternFactory.pike,v 1.1 2008/03/31 13:39:57 exodusd Exp $
18  */
19 inherit "/factories/DocumentFactory";
20 #include <macros.h>
21 #include <classes.h>
22 #include <events.h>
23 #include <exception.h>
24 #include <database.h>
25 #include <attributes.h>
26 #include <types.h>
27 class DocExternFactory : public DocumentFactory{
28 public:
29 
30 
31 
32 
33 
34 private object mExternLookup;
35 
36 void init()
37 {
38  ::init();
39  mExternLookup = _Server->get_module("extern_documents");
40 }
41 
42 private:
43  void init_factory()
44 {
45  ::init_factory();
46 private:
47  init_class_attribute(DOC_EXTERN_URL, CMD_TYPE_STRING, "extern url",
48  EVENT_ATTRIBUTES_QUERY, EVENT_ATTRIBUTES_CHANGE,0,
49  CONTROL_ATTR_USER, "");
50 }
51 
52 object execute(mapping vars)
53 {
54  object obj;
55  if ( !stringp(vars["url"]) )
56  THROW("No url given!", E_ERROR);
57 
58  int l = strlen(vars["url"]);
59  if ( l >= 2 && vars["url"][l-1] == '/' )
60  vars["url"] = vars["url"][..l-2];
61 
62  if ( !stringp(vars->name) || strlen(vars->name) == 0 )
63  vars->name = vars->url;
64 
65  try_event(EVENT_EXECUTE, CALLER, obj);
66  if ( vars->transient ) {
67  if ( mappingp(vars->attributes) )
68  vars->attributes[OBJ_TEMP] = 1;
69  else
70  vars->attributes = ([ OBJ_TEMP : 1 ]);
71  }
72  obj = ::object_create(
73  vars["name"], CLASS_NAME_DOCEXTERN, 0,
74  vars["attributes"],
75  vars["attributesAcquired"],
76  vars["attributesLocked"],
77  vars["sanction"],
78  vars["sanctionMeta"]);
79 
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);
83 }
84 
85 public:
86 
87 object
88 get_document(string url)
89 {
90  int l = strlen(url);
91  if ( l >= 2 && url[l-1] == '/' )
92  url = url[..l-2];
93  return mExternLookup->lookup(url);
94 }
95 
96 }
97 
98 array get_all_objects()
99 {
100  return _Database->get_objects_by_class("/classes/"+get_class_name());
101 }
102 
103 
104 string get_identifier() { return "DocExtern.factory"; }
105 string get_class_name() { return "DocExtern"; }
106 int get_class_id() { return CLASS_DOCEXTERN; }
107 
108 
109 };