Forum OpenACS Q&A: calling an xowiki object proc

Collapse
Posted by Matthew Smith on
I am playing around with some code Gustaf provided, trying to understand it. Right now I am trying to incorporate it into a tcl/adp page in my package. What I am trying to do is call the proc content and set a variable to it, which can be displayed on the adp page. Here's the code I have. I modified the original to set the object to a variable so what I would be able to reference it but it isn't working. I have tried several permutations of the last line of code without success. I really don't know what I am doing here, just trying things to help me learn, so any help would be appreciated. Here's the code:
------------------------------------------------------------
# -*- tcl-*-
# Sample prototype page to show different output formats
# Gustaf Neumann, May 2008
set reference [::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. 
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>. }] set content [$reference content]
------------------------------------------------------------ I have also tried on the last line: set content [::xotcl::Object content] which just outputs: ::template::content I don't know what that is displaying or why...
Collapse
Posted by Stefan Sobernig on
MAtthew,

Right now I am trying to incorporate it into a tcl/adp page in my package.

You are starting to confuse matters. The code as provided by Gustaf Neumann cannot seamlessly be incorporated into your package code or be treated as bare XOTcl objects. ::xowiki::Object (which has nothing to do with ::xotcl::Object besides being an instance of it) is a XOWiki-specific idiom. The code is meant to be used as XOWiki prototype page, remember? This somehow is proven by the "-title" and "-text" flags, isn't it?

It is supposed to be put it into a script, sourced from there and then handled further (from XOWiki internals).

set content [$reference content]

As I said, this can't work, why? Simply because there is NO method "content" defined or resolvable for the ::xowiki::Object. Why? Well, because you assume that "proc content ..." in the value of parameter "-text" is meant to be a per-object method on the ::xowiki::Object instance. But it isn't! The value of -text which is a perfect Tcl script is not evaluated before being persisted to the database and then rendered as a wiki page _from XOWiki_ (besides other details).

Again, I would really stick with the already proposed techniques. Stick to the extensions mechansims documented (Guatemala talk), read existing code _in context_, and consider the adp integration as proposed by Gustaf Neumann. You will be fine (from what I know from your task) ...

Collapse
Posted by Stefan Sobernig on
By the way ...

XOTcl offers powerful introspection techniques. Have a look at ::xotcl::Object->info (http://media.wu-wien.ac.at/doc/langRef-xotcl.html#Object-info), ::xotcl::Class->info (http://media.wu-wien.ac.at/doc/langRef-xotcl.html#Class-info) and the self command (http://media.wu-wien.ac.at/doc/langRef-xotcl.html). Applied to your problem: Can I invoke a method "content" on the object referenced by the variable "reference"? Try a "$reference info methods" which yields a list of all resolvable methods on the object's invocation pathway.

Collapse
Posted by Matthew Smith on
Thank you for the guidance, Stefan.