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>.
}