After much experimentation, here is what I've found out.
The idea of pages as a tree of objects doesn't work. Webware caches=20
multiple instances of servlets as needed by the different threads. To=20=
build a tree of servlets means linking up servlets together. That=20
doesn't work when you have multiple instances of each servlet, and=20
multiple threads using those instances in no particular order. Since=20
CherryPy runs as one application with no threads, it doesn't have this=20=
problem.
The original reason I wanted this tree of pages is to provide better=20
navigation, and to give my application an awareness of what pages were=20=
out there. I'm building a CMS for delivering educational content in a=20=
classroom setting. This CMS will have different sections written by=20
different authors, and the authors will get royalties on the number of=20=
page visits. Thus I need a way to find all the different pages, link=20
them together for the menus, and also query them to find all the=20
sections on a certain subject or by a particular author. An object=20
graph seemed a good way to go.
So my current thinking is to have a separate site map or index which=20
upon startup will walk through the directory tree and find all the=20
servlet files. It will then call each one and use=20
callMethodOfServlet() to get it's author, title, what sub-pages it=20
connects to, subject, and keywords. Has anybody developed similar=20
stuff?
Nevertheless, the experiment was useful for me to learn more that I=20
should about the internals of module loading by webware, and how=20
ServletFactory works. This will come in handy when I get back to=20
writing more automated tests.
-winston
On 27-Dec-2004, at 10:37 PM, Winston WOLFF wrote:
> Hello Ian-
>
> I like your idea of having one servlet that dispatches requests to a=20=
> bunch of other objects that are not servlets. I'm having a little=20
> problem though, with getting the request to go to that servlet and not=20=
> to the other objects. That's a little hard to read, let me explain it=20=
> with this diagram:
> /MyContext/
> Main.py (This is my servlet which loads all the files =
below it=20
> like One.py, Two.py, etc.)
> One.py (This object is NOT a servlet, it just has an =
html() method=20
> that returns my HTML text.)
> Two.py (This is another object with just an html() =
method)
>
> The idea is that a request to http://myserver/MyContext/One.py should=20=
> be received by Main.py, and it will:
> =95 Cut off the extraURLPath, which will be "/One.py"
> =95 Main loads the MyContext.One.One object and calls it's =
.html()=20
> method.
> =95 Main writes that text to the response object and returns.
>
> The problem is, how do I get Webware to load and call the Main object=20=
> as opposed to the One.py object?
>
> -winston
>
>
>> But you could build what you are looking for ontop of Webware. Maybe=20=
>> like:
>>
>> class Main(Page):
>>
>> def awake(self, trans):
>> Page.awake(self, trans)
>> path =3D self.request().extraURLPath()
>> self.object =3D traverse_path(root, path)
>>
>> def writeHTML(self):
>> self.write(self.object(trans))
>>
>> import base
>> root =3D base.root_object
>> def traverse_path(object, path):
>> if not path:
>> return object
>> assert path.startswith('/')
>> first =3D path.split('/')[1]
>> rest =3D path.split('/', 2)
>> if len(rest) =3D=3D 3:
>> rest =3D '/' + rest[2]
>> else:
>> rest =3D ''
>> return traverse_path(get_part(object, first), rest)
>>
>> def get_part(object, attr):
>> # Maybe use getattr or something else
>> return object[attr]
>>
>> --=20
>> Ian Bicking / ianb@... / http://blog.ianbicking.org
>>
> _________________________________________
> winston wolff - (646) 827-2242 - http://www.stratolab.com - learning=20=
> by creating
>
>
_________________________________________
winston wolff - (646) 827-2242 - http://www.stratolab.com - learning by=20=
creating
|