View · Search · Index
No registered users in community xowiki
in last 10 minutes

[Xotcl] please help me understand some code

From: Matthew Smith <chedderslam_at_gmail.com>
Date: Fri, 16 May 2008 10:04:51 -0500

I response to a forum post, someone wrote the code below, which creates an
xowiki object. I am trying to work with the code but am not sure what some
of it means. Here is the code, with questions below.
-------------------------------------------------------------------------
# -*- 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 {
            <districts>
                <district>
                    <COE_DISTRICT_NAME>VICKSBURG</COE_DISTRICT_NAME>
                    <DISTRICT_ABBREVIATION>MVK</DISTRICT_ABBREVIATION>
                </district>
                <district>
                    <COE_DISTRICT_NAME>NEW ORLEANS</COE_DISTRICT_NAME>
                    <DISTRICT_ABBREVIATION>MVN</DISTRICT_ABBREVIATION>
                </district>
                <district>
                    <COE_DISTRICT_NAME>ST. PAUL</COE_DISTRICT_NAME>
                    <DISTRICT_ABBREVIATION>MVP</DISTRICT_ABBREVIATION>
                </district>
            </districts>
        }
      }
      csv {
        set content_type text/csv
        ns_set put [ns_conn outputheaders] Content-Disposition
"attachment;filename=sample.csv"
        set content {
          VICKSBURG,MVK
          NEW ORLEANS,MVN
          ST. PAUL,MVP
        }
      }
      json {
        set content_type text/plain
        set content "
            \{
                districts:\{
                    district:\[
                        \{
                            coe_district_name:'VICKSBURG',
                            district_abbreviation:'MVK'
                        \},
                        \{
                            coe_district_name:'NEW ORLEANS',
                            district_abbreviation:'MVN'
                        \},
                        \{
                            coe_district_name:'ST. PAUL',
                            district_abbreviation:'MVP'
                        \}
                    \]
                \}
            \}
        "
      }
      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>.
}
---------------------------------------------------------------------
in the lines:
    ::xo::cc set_parameter master 0
    ::xo::cc set_parameter content-type $content_type
what does the "::xo::cc" mean?

If the object is being created, how do I reference the object? For
instance, I would like to set a variable to "content". How would I do
this?

Thank you for any help.