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: Composer.pike,v 1.1.1.1 2005/02/23 14:47:21 cvs Exp $
20
constant cvs_version="$Id: Composer.pike,v 1.1.1.1 2005/02/23 14:47:21 cvs Exp $";
24
Slotter.Slot oRootSlot;
25
array(string) Stylesheets=({});
26
array(string) JavaScripts=({});
27
array(string) Meta=({});
29
//mapping(string:Slotter.Slot) allSlots;
33
Slotter.Slot get_root_slot()
35
if (!objectp(oRootSlot))
36
oRootSlot = Slotter.Slot();
41
* traverses the slots and inserts tree and calculates
42
* the html pieces "generated" by the visited inserts
43
* as a sideeffect each insert is asked for stylesheets it may need,
44
* to collect information for the header generation
46
* @param array subparts - an array as returned from an insert generator
47
* @param string sFunction - the generator to call
48
* "generate" - the standard html generator
49
* "preview" - a debugging generator
51
* @result an array of strings, which can be flattened with
55
* @author Ludger Merkens
57
array build_tree(array subparts, string sFunction)
59
Slotter.Insert currInsert;
60
Slotter.Slot currSlot;
62
for(int i;i<sizeof(subparts); i++)
64
if (objectp( currSlot = subparts[i]))
66
// string name= currSlot->get_path_slot_name();
67
// allSlots[name] = currSlot;
68
currInsert = currSlot->get_insert();
71
if (!currInsert[sFunction])
72
throw( ({sprintf("Missing ("+sFunction+") in %O\n",
73
currInsert), backtrace()}));
74
array temp = currInsert[sFunction]();
76
throw(({ sprintf("No Result from "+
78
master()->describe_program(
79
object_program(currInsert))) }));
80
if (!temp || search(temp,0)!=-1)
81
throw(({sprintf("Empty Subparts returned %O\n",currInsert),
83
subparts[i] = build_tree(temp, sFunction);
84
Stylesheets |= currInsert->need_style_sheets();
85
JavaScripts |= currInsert->need_java_scripts();
86
Meta |= currInsert->need_meta();
89
subparts[i]= "<td>empty</td>";
96
* take a tree of strings as resulted from build_tree and glue them
97
* together to a flat string
98
* @param array(mixed) tree - the string tree to flatten
101
* @author Ludger Merkens
104
string flatten_tree(array(mixed) tree)
107
foreach(tree, mixed leave)
110
out += flatten_tree(leave);
118
* compose the collected header information durin "build_tree" to a
121
* @author Ludger Merkens
123
string compose_header() {
125
/* werror(sprintf("composing header with Meta:%O, Stylesheets:%O and Javascripts:%O\n",
126
Meta, Stylesheets, JavaScripts));*/
128
"<meta http-equiv=\"Content-Type\" content=\"text/html; "+
129
"charset=UTF-8\">\n"+
130
(sizeof(Meta) ? Meta * "\n" : "")+
131
(sizeof(Stylesheets) ?
132
" <link rel=\"stylesheet\" href=\""+
133
(Stylesheets*"\">\n <link rel=\"stylesheet\" href=\"")+
135
(sizeof(JavaScripts) ?
136
" <SCRIPT LANGUAGE=\"JavaScript\" SRC=\"" +
137
(JavaScripts*"\" TYPE=\"text/javascript\"></SCRIPT>\n <SCRIPT LANGUAGE=\"JavaScript\" SRC=\"")+
138
"\" TYPE=\"text/javascript\"></SCRIPT>\n" : "")+
143
* run a "generate" composing run
144
* @author Ludger Merkens
152
array t = build_tree(({oRootSlot}), "generate");
164
* run the "preview" composing run
165
* @author Ludger Merkens
167
string compose_preview()
171
array t = build_tree(({oRootSlot}), "preview");
172
return flatten_tree(t);
176
* during the generation process a mapping of inserts is kept,
177
* thus the results of this function depend on and refer to the
178
* last run of such a generation process.
180
* @param string - pathname, the Slot to search
181
* @returns Slotter.Slot - the designate Slot
183
* @author Ludger Merkens
185
// Slotter.Slot get_slot_by_name(string pathname)
187
// return allSlots[pathname];
192
* untility function called from e.g. the sTeamHTMLdisplay insert to
193
* read the content of a sTeam Document. Due to this, an insert may be
194
* lightweight and dosn't need to be a sTeam object.
196
* @param object o - a proxy
197
* @author Ludger Merkens
199
string read_content(object o)
201
return string_to_utf8(o->get_content());
205
* another utility function, allowig access to get_inventory
206
* @param o - container to access
207
* @param cl - class to filter by.
209
array(object) read_inventory(object o, void|int cl)
212
return o->get_inventory_by_class(cl);
214
return o->get_inventory();
218
* retreive a steam insert by oid or pathname
219
* @param string insert - a pathname passed to _FILEPATH
220
* int insert - an OID
221
* @returns the insert (not the proxy)
222
* @author Ludger Merkens
224
Slotter.Insert get_steam_insert(string|int insert)
228
oInsert = _FILEPATH->path_to_object(insert);
230
oInsert = find_object(insert);
232
if (objectp(oInsert))
233
return oInsert->get_object();
237
object call_factory(object factory, mapping createInfo)
239
return factory->execute(createInfo);
242
mixed delegate_set_attribute(object target, mixed key, mixed value)
244
// werror(sprintf("delegating: %O, %O, %O\n", target, key, value));
245
return target->set_attribute(key, value);
249
mixed delegate_sanction_object(object target, object obj, mixed data)
251
return target->sanction_object(obj, data);
254
mixed delegate_set_acquire_attribute(object target, object obj1, mixed v,
257
return target->set_acquire_attribute(obj1, v, obj2);
260
mixed delegate_group_add_member(object group, object member)
262
return group->add_member(member);
265
mixed delegate_group_remove_member(object group, object member)
267
return group->remove_member(member);
272
string path = _FILEPATH->object_to_path(this_object());
274
string server = _Server->get_config("web_server");
275
string port = _Server->get_config("web_port_https");
278
return _Server->get_server_url_administration()+
279
"/scripts/execute.pike?script="+this_object()->get_object_id();
281
return _Server->get_server_url_administration()+
282
combine_path(path, this_object()->get_identifier());