Forum OpenACS Development: Re: creating a new xowiki class

Collapse
Posted by Gustaf Neumann on
In general there are several approaches to tailor xowiki's base classes. An important issue is in which scope you intend to modify the behavior:
- for all xowiki instances or for certain ones
- for all applications where a page of class ::xowiki::Page is used
- for all situations, where ::xowiki::WikiForm is used

Certainly, it is as well possible to define a new class. This will keep the information in the same tables as usual, but will create an additional table according to the OpenACS sub-typing conventions keeping essentially the revision_ids of the new class and additional attributes of the class (in your case none). I would not recommend to deviate from the OpenACS conventions to far. But i am not sure, that you want to define a new class for your application.

If you want to modify the behavior for a single "type of application", i would recommend to subtype the xowiki package (e.g. myapp) and to mixin the wanted behavior for every connection request to myapp. You can do this by creating a class ::myapp::Package with superclass ::xowiki::Package and add/remove the behavior each time a package instance is initialized/destroyed (provide methods "initialize" and "destroy"). The package s5 does a similar thing. In your case, you could mixin the wanted behavior for e.g. the WikiForm (don't forget to remove the mixin in the destroy method of the Package). The method "initialize" was added in april this year to xotcl-core.

Hope this helps
-gustaf neumann

Collapse
Posted by Alvaro Rodriguez on
Thank you for your help Gustaf,

Let me explain what I'm trying to achieve, I need to be able to do something else inside the new_data proc of the ::xowiki::WikiForm only in a few cases,

The way I see it, I can do it by creating a new proc called ::Package::my-edit-new (called when I need my special behavior instead of edit-new), inside this proc I do an object mixin of the page with ::xowiki::MyPage wich overwrites the edit method of ::xowiki::Page, in the edit method I need to be able to do a mixin of ::xowiki::WikiForm with ::xowiki::MyWikiForm to overwrite the new_data proc (my main goal). The problem here is that I'm duplicating the code of the Package edit-new and the Page edit. How does this looks to you ...

Thanks in advance,

Collapse
Posted by Gustaf Neumann on
This looks to me to complicated.

The question is how to characterize these "few cases". I assume for now, that the "few cases" can be characterized as a type of application, therefore subclassing the xowiki app (like in s5) looks appropriate. i would do the following way:

1) subclass xowiki::Package as ::myapp::Package
2) in mayapp-procs.tcl, define in addition to ::myapp::Package the class ::myapp::MyWikiForm with the intended methods (use "next" in the methods to chain to the default behaviour if necessary/intended)
3) in the method initialize of ::myapp::Package, make a "::xowiki::MyForm instmixin add ::myapp::MyWikiForm; next"
4) in the method destroy of ::myapp::Package, do a "::xowiki::MyForm instmixin delete ::myapp::MyWikiForm; next"

There is no duplication of code involved.

Collapse
Posted by Alvaro Rodriguez on
This time things started to sound more clear to me, I'm still getting to know xotcl and all that stuff, Today I'm gonna try to implement what you suggested and I'll let you know.

Thank you very much Gustaf

Collapse
Posted by Alvaro Rodriguez on
I did what you suggested and it worked, I managed to mixin the Forms and add the wanted behavior, but I had a few complications:

- If I restart the server, it loads my procs file first and throws an error because it needs some other definitions on the next files (not a big deal).
- To test my new app right now I changed the index.vuh so instead of call the initialize from ::xowiki::Package it calls ::myapp::Package but I need to leave it independent from the rest of the pages, I tried using another .vuh file inside another folder or using a .tcl file but it always says that "page" is not available. (the xowiki message if I want to create that page)

Any suggestions,

Thank you very much for your help Gustaf,

Collapse
Posted by Stefan Sobernig on
Alvaro!

- If I restart the server, it loads my procs file first and throws an error because it needs some other definitions on the next files (not a big deal).

The OpenACS package initialisation procedure is rather hostile to the kind of package refinement you are probing; due to its alphanumerical sorting of packages/files to be evaluated upon start-up.

Place the following in the first *-procs.tcl in your xowiki-derived package:

::xo::db::require package xowiki

this will source xowiki before your package, so everything needed is in place ...


- To test my new app right now I changed the index.vuh so instead of call the initialize from ::xowiki::Package it calls ::myapp::Package but I need to leave it independent from the rest of the pages, I tried using another .vuh file inside another folder or using a .tcl file but it always says that "page" is not available. (the xowiki message if I want to create that page)

this one i don't quite understand (that is, what you try to achieve). would you mind posting your sources somewhere, preferably the entire package (public scm, archive), so we can have a look. it's a thousand times easier to comment on code than to comment on comments on invisible code ...

//stefan

Collapse
Posted by Alvaro Rodriguez on
Thanks for the help Stefan,

I know the second part sounds confusing but is actually not that confusing.

The xowiki's index.vuh does this:

::xowiki::Package initialize -ad_doc {
} ...

and I changed it to do this:

::myapp::Package initialize -ad_doc {
} ...

So now when I call a xowiki/?edit-new=1 it actually initializes myapp and it works, but I can't leave the index.vuh file like this.

My question is how could I set a file to work the way I want, should I use a .vuh. I tried using a tcl file with that code but when it founds the part of the code:

::myapp::Package initialize -ad_doc {
} ...

it ignores the file.

Collapse
Posted by Alvaro Rodriguez on
I checked the s5 package and noticed that I wasn't doing things right, my procs file was on the /xowiki directory and it should be in /myapp directory along with my new index.vuh
Collapse
Posted by Gustaf Neumann on
right... as described in the tutorial section... :)

everything ok by now?

Collapse
Posted by Alvaro Rodriguez on
I read the tutorial but the first time I missed that.

I haven't tried that yet, I need to do a little extra work first but I'll check the s5 package to guide my work. If I need any help I'll let you know...

Thanks for all the help,

Collapse
Posted by Alvaro Rodriguez on
Everything worked out well, but for some reason I keep getting the same error about the loading packages.

I placed the line "::xo::db::require package xowiki" at the beginning of myapp-procs.tcl (the only procs file), I did it exactly the same way as the s5 package but it keeps failing.

Is there anything else I need to check for this ...

Collapse
Posted by Gustaf Neumann on
Alvaro,

Maybe the prototype pages for your package is missing, so you don't get a useful index page. I have added a small section to the xowiki tutorial http://alice.wu-wien.ac.at:8000/s5-xowiki-tutorial/slides#subclassing-xowiki

Hope this helps
-gustaf neumann

Collapse
Posted by Alvaro Rodriguez on
Thank you Gustaf,

what you added in that section is exactly what I did and it worked for me.