class Riddl::Utils::Properties::GetContent

Public Instance Methods

response() click to toggle source
# File lib/ruby/riddl/utils/properties.rb, line 207
def response
  backend = @a[0]
  handler = @a[1]

  EM.defer{handler.property(@r[1]).read} unless handler.nil?

    if ret = extract_values(backend,@r[1],Riddl::Protocols::Utils::unescape(@r[2..-1].join('/')))
    ret
  else
    @status = 404
  end
end

Private Instance Methods

extract_values(backend,property,minor=nil) click to toggle source
# File lib/ruby/riddl/utils/properties.rb, line 220
def extract_values(backend,property,minor=nil)
  case backend.property_type(property)
    when :complex
      res = backend.data.find("/p:properties/*[name()=\"#{property}\"]#{minor == '' ? '' : "/p:#{minor}"}")
      if res.any?
        prop = XML::Smart::string("<value xmlns=\"http://riddl.org/ns/common-patterns/properties/1.0\"/>")
        if res.length == 1
          prop.root.add(res.first.children)
        else
          prop.root.add(res)
        end
        return Riddl::Parameter::Complex.new("value","text/xml",prop.to_s)
      else
        prop = XML::Smart::string("<not-existing xmlns=\"http://riddl.org/ns/common-patterns/properties/1.0\"/>")
      end
    when :simple, :state
      res = backend.data.find("string(/p:properties/*[name()=\"#{property}\"]#{minor})")
      return Riddl::Parameter::Simple.new("value",res.to_s)
    when :arbitrary
      res = backend.data.find("/p:properties/*[name()=\"#{property}\"]")
      if res.any?
        c = res.first.children
        if c.length == 1 && c.first.class == XML::Smart::Dom::Element
          return Riddl::Parameter::Complex.new("content","text/xml",c.first.dump)
        else
          return Riddl::Parameter::Complex.new("content","text/plain",c.first.to_s)
        end
      else
        prop = XML::Smart::string("<not-existing xmlns=\"http://riddl.org/ns/common-patterns/properties/1.0\"/>")
        return Riddl::Parameter::Complex.new("content","text/xml",prop.to_s)
      end
  end
  nil
end