def response
backend = @a[0]
handler = @a[1]
property = @r[1]
value = @p.detect{|p| p.name == 'value'}; value = value.nil? ? value : value.value
content = @p.detect{|p| p.name == 'content'}; content = content.nil? ? content : content.value
minor = @r[2]
unless backend.modifiable?(property)
@status = 500
return
end
path = "/p:properties/*[name()=\"#{property}\"]#{minor.nil? ? '' : "/p:#{minor}"}"
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.root.find(path)
nods = nodes.map{|ele| ele.children.delete_all!; ele}
nods.each do |ele|
if value.nil?
ele.add newstuff
ele.children.first.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
EM.defer{handler.property(property).update} unless handler.nil?
return
end