[Zope3-dev] Registering a Content Factory object

Stephan Richter stephan.richter@tufts.edu
Wed, 9 Apr 2003 07:41:29 -0400


On Wednesday 09 April 2003 03:24, Steve Alexander wrote:
> Stephan Richter wrote:
> > Hi all,
> >
> > I use the content directive (including the factory subdirective) to
> > define a new content object and its factory. However, now I would like to
> > define a special Factory that will create the content object. How do I so
> > this?
>
> A factory is a callable object, such as a class or a function or a class
> method or a static method.

Right, but in the content directive I have to give the class name and it is 
assumed that this is class name is also the factory, so I have no way to 
specify a function as factory.

> > Why do I need this? I would like to add other content objects in the
> > generated content object, i.e. change the default behavior of adding a
> > container object.
>
> I think you'll want to write a factory that creates a Folder and marks
> the new Folder instance with a marker interface before returning it.
>
> Alternatively, perhaps you can use the "chained series of factories"
> feature to use the existing Folder factory, and put after it your
> factory that will mark the folder with an interface.

Maybe I should have been more clear and use the specific example I am working 
on...

I have a Wiki (a ZopeContainer derived object), which I registered via the 
content directive, like this (in zwiki/configure.zcml):

  <content class=".zwiki.Wiki">

    <implements interface="zope.app.interfaces.container.IContentContainer" />

    <implements
       interface="zope.app.interfaces.annotation.IAttributeAnnotatable" />

    <factory
        id="Wiki"
        permission="zope.ManageContent"
        title="Wiki"
        description="Minimal Wiki Page Container implementation " />

    ... <snip some security stuff>

  </content>

In this directive I have no way to specify another factory for Wiki (I checked 
the meta directives). The reason I want another factory is that I would like 
the new Wiki to also add a Wiki Page called FrontPage to itself. 

However, I do not want to add this to the constructor of the Wiki, since not 
every Wiki user might like this feature and it should be easy to configure 
the behavior differently.

How can I do this? :-)

Regards,
Stephan
-- 
Stephan Richter
CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training