def response
backend = @a[0]
handler = @a[1]
0.upto(@p.length/2-1) do |i|
property = @p[i*2].value
ct = @p[i*2+1]
value = ct.name == 'value' ? ct.value : nil
content = ct.name == 'content' ? ct.value : nil
unless backend.modifiable?(property)
@status = 500
return
end
path = "/p:properties/*[name()=\"#{property}\"]"
nodes = backend.data.find(path)
if nodes.empty?
@status = 404
return
end
if backend.is_state?(property)
unless backend.valid_state?(property,nodes.first.to_s,value)
@status = 404
return
end
end
newstuff = value.nil? ? XML::Smart.string(content).root.children : value
backend.modify do |doc|
nodes = doc.find(path)
nods = nodes.map{|ele| ele.children.delete_all!; ele}
nods.each do |ele|
if value.nil?
ele.add newstuff
ele.attributes['changed'] = Time.now.xmlschema if backend.is_state?(property)
else
ele.text = newstuff
ele.attributes['changed'] = Time.now.xmlschema if backend.is_state?(property)
end
end
end || begin
@status = 400
return
end
end
EM.defer do
0.upto(@p.length/2-1) do |i|
property = @p[i*2].value
handler.property(property).create
end
end unless handler.nil?
return
end