Forum OpenACS Q&A: extending the xowiki page class

Collapse
Posted by Matthew Smith on
I would like to create a page that extends the different page objects in xowiki with additional functionality, but I'm not sure where to start...

Where does the code that extends the object actually go? I know it is written in XOTcl but where does that code actually get put and executed?

Thank you.

Collapse
Posted by Gustaf Neumann on
Matthew, do you want to create a "page type" providing additional functionality, or do you want to put additional behavior into existing page types? Both is possible. Certain page types provide already several means to extends the behavior (see for example the xowiki tutorial). Can you give an example, what you have in mind?
Collapse
Posted by Matthew Smith on
Thank you for the reply, Gustaf.

I'm not sure which we want to do, so I'm open to recommendations.

Basically we are trying to implement a REST web service application built on XOWiki. Each url will be able to return a data set in html, xml, csv, and json format. The format returned will be decided by a url variable. Alternatively, the same page will provide documentation for the web service simply by appending /docs/ to the url.

This is the tasking that has been givin to me. It's a new job, so I'm learning a new language(tcl/xotcl) and a new platform(openacs/xowiki). I'm actually a ColdFusion developer so this is all new to me. I don't mind learning, I actually am grateful for the opportunity to grow as a developer, I just feel a little lost right now.

Thanks,
Matthew

Collapse
Posted by Gustaf Neumann on
Hi Matthew,

Here is a quick sketch, how to define an XoWiki Object,
that outputs some content in different formats. Save the content below
under xowiki/www/prototypes/multiple-output-types.page

After that, browse to http:/.../xowiki/multiple-output-types and the page
is loaded from disc into the CR and creates an xowiki object.
You can edit this afterwards online. If you want to modify and
reload the .page-file, go to xowiki/admin and delete the object
in the CR, and fetch it again like above.

-gustaf neumann

===================
# -*- tcl-*-
# Sample prototype page to show different output formats
# Gustaf Neumann, May 2008
::xowiki::Object new -title "Multiple Output Types" -text {

  my initialize -parameter {
    {-format "text"}
  }

  proc content {} {
    my get_parameters

    switch $format {
      xml {
        set content_type text/xml
        set content {
          <geo>
          <longitude>-122.3959</longitude>
          <latitude>37.7668</latitude>
          </geo>
        }
      }
      csv {
        set content_type text/csv
        ns_set put [ns_conn outputheaders] Content-Disposition "attachment;filename=sample.csv"
        set content {
          longitude,-122.3959
          latitude,37.7668
        }
      }
      json {
        set content_type text/plain
        set content {
          [ { "latitude":  37.7668, "longitude": -122.3959 } ]
        }
      }
      default {
        return [[my info parent] description]
      }
    }
    ::xo::cc set_parameter master 0
    ::xo::cc set_parameter content-type $content_type
    return $content
  }
} -description {
  I am just a sample service that can return its content in different
  formats. <br>Call me e.g. with format
  <a href='multiple-output-types?format=xml'>xml</a>,
  <a href='multiple-output-types?format=csv'>csv</a>, or
  <a href='multiple-output-types?format=json'>json</a>.
}

Collapse
Posted by Matthew Smith on
Wow, thank you for such an in depth example. That really helps me understand a bit better how to go about this. I will give it a try. Thank you for the help.
Collapse
Posted by Matthew Smith on
Gustaf,

I am unable to get what you showed me to work. When I browse to:
https://(server)/xowiki/multiple-output-types
I get this error:
Error:

Page 'multiple-output-types' is not available.

I even tried removing the xowiki instance and reinstalling it.

Perhaps I am putting the multiple-output-types.page file in the wrong place?

I uploaded it to:
/packages/xowiki/www/prototypes/multiple-output-types.page

Collapse
Posted by Stefan Sobernig on
Matthew,

I tried to reproduce the issue with Gustaf Neumann's code sample from above. Works fine with me!

- Anything to detect in the error.log?

//stefan

Collapse
Posted by Matthew Smith on
Where is the error log located?
Collapse
Posted by Stefan Sobernig on
(path_to_your_openacs_installation)/log/error.log
Collapse
Posted by Matthew Smith on
There is a ton of stuff in the log, mostly db stuff, but I did find this:
[15/May/2008:12:39:46][7030.3069311888][-conn:dodss-cleat::4] Notice: --try en:multiple-output-types -> 0, ::1390 ::xowiki::Package->resolve_request (2902ms, 3ms)
[15/May/2008:12:39:46][7030.3069311888][-conn:dodss-cleat::4] Notice: no prototype for 'multiple-output-types' found, ::1390 ::xowiki::Package->resolve_page (2903ms, 0ms)
Collapse
Posted by Stefan Sobernig on
Matthew,


[15/May/2008:12:39:46][7030.3069311888][-conn:dodss-cleat::4] Notice: --try en:multiple-output-types -> 0, ::1390 ::xowiki::Package->resolve_request (2902ms, 3ms)
[15/May/2008:12:39:46][7030.3069311888][-conn:dodss-cleat::4] Notice: no prototype for 'multiple-output-types' found, ::1390 ::xowiki::Package->resolve_page (2903ms, 0ms)

the only way I can reproduce that behaviour (and the second log message) is by

  1. mangling file-level permissions on xowiki/www/prototypes/multiple-output-types.page so that the running user can't read the file
  2. the file is not present at that very location
  3. internally, the prototype logic uses a [file readable ...] which returns 0 in either of the above cases.

    so, i'd say: check permissions and file ownership.

    //stefan

Collapse
Posted by Matthew Smith on
It started working today for some unknown reason. The permissions are rw on the file now, I don't know if they changed somehow. Thank you for the help.