After much experimentation, here is what I've found out.

The idea of pages as a tree of objects doesn't work. Webware caches multiple instances of servlets as needed by the different threads. To build a tree of servlets means linking up servlets together. That doesn't work when you have multiple instances of each servlet, and multiple threads using those instances in no particular order. Since CherryPy runs as one application with no threads, it doesn't have this problem.

The original reason I wanted this tree of pages is to provide better navigation, and to give my application an awareness of what pages were out there. I'm building a CMS for delivering educational content in a classroom setting. This CMS will have different sections written by different authors, and the authors will get royalties on the number of page visits. Thus I need a way to find all the different pages, link them together for the menus, and also query them to find all the sections on a certain subject or by a particular author. An object graph seemed a good way to go.

So my current thinking is to have a separate site map or index which upon startup will walk through the directory tree and find all the servlet files. It will then call each one and use callMethodOfServlet() to get it's author, title, what sub-pages it connects to, subject, and keywords. Has anybody developed similar stuff?

Nevertheless, the experiment was useful for me to learn more that I should about the internals of module loading by webware, and how ServletFactory works. This will come in handy when I get back to 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 bunch of other objects that are not servlets. I'm having a little problem though, with getting the request to go to that servlet and not to the other objects. That's a little hard to read, let me explain it with this diagram:
/MyContext/
Main.py (This is my servlet which loads all the files below it like One.py, Two.py, etc.)
One.py (This object is NOT a servlet, it just has an html() method 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 be received by Main.py, and it will:
• Cut off the extraURLPath, which will be "/One.py"
• Main loads the MyContext.One.One object and calls it's .html() method.
• 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 as opposed to the One.py object?

-winston


But you could build what you are looking for ontop of Webware. Maybe like:

class Main(Page):

def awake(self, trans):
Page.awake(self, trans)
path = self.request().extraURLPath()
self.object = traverse_path(root, path)

def writeHTML(self):
self.write(self.object(trans))

import base
root = base.root_object
def traverse_path(object, path):
if not path:
return object
assert path.startswith('/')
first = path.split('/')[1]
rest = path.split('/', 2)
if len(rest) == 3:
rest = '/' + rest[2]
else:
rest = ''
return traverse_path(get_part(object, first), rest)

def get_part(object, attr):
# Maybe use getattr or something else
return object[attr]

--
Ian Bicking / [EMAIL PROTECTED] / http://blog.ianbicking.org

<x-tad-smaller>_________________________________________
winston wolff - (646) 827-2242 - http://www.stratolab.com - learning by creating
</x-tad-smaller>
<x-tad-smaller>_________________________________________
winston wolff - (646) 827-2242 - http://www.stratolab.com - learning by creating
</x-tad-smaller>

Reply via email to