Class: Tilia::Dav::Xml::Request::PropPatch

Inherits:
Object
  • Object
show all
Includes:
Xml::Element
Defined in:
lib/tilia/dav/xml/request/prop_patch.rb

Overview

WebDAV PROPPATCH request parser.

This class parses the DAV:propertyupdate request, as defined in:

tools.ietf.org/html/rfc4918#section-14.20

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePropPatch

Returns a new instance of PropPatch.



94
95
96
# File 'lib/tilia/dav/xml/request/prop_patch.rb', line 94

def initialize
  @properties = {}
end

Instance Attribute Details

#propertiesObject

The list of properties that will be updated and removed.

If a property will be removed, it’s value will be set to null.



18
19
20
# File 'lib/tilia/dav/xml/request/prop_patch.rb', line 18

def properties
  @properties
end

Class Method Details

.xml_deserialize(reader) ⇒ Object

The deserialize method is called during xml parsing.

This method is called statictly, this is because in theory this method may be used as a type of constructor, or factory method.

Often you want to return an instance of the current class, but you are free to return other data as well.

You are responsible for advancing the reader to the next element. Not doing anything will result in a never-ending loop.

If you just want to skip parsing for this element altogether, you can just call reader.next

reader.parse_inner_tree will parse the entire sub-tree, and advance to the next element.

Parameters:

  • Reader

    reader

Returns:

  • mixed



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/tilia/dav/xml/request/prop_patch.rb', line 70

def self.xml_deserialize(reader)
  instance = new

  element_map = reader.element_map
  element_map['{DAV:}prop']   = Tilia::Dav::Xml::Element::Prop
  element_map['{DAV:}set']    = Tilia::Xml::Element::KeyValue
  element_map['{DAV:}remove'] = Tilia::Xml::Element::KeyValue

  elems = reader.parse_inner_tree(element_map)

  elems.each do |elem|
    if elem['name'] == '{DAV:}set'
      instance.properties.merge! elem['value']['{DAV:}prop']
    elsif elem['name'] == '{DAV:}remove'
      # Ensuring there are no values.
      elem['value']['{DAV:}prop'].each do |remove, _value|
        instance.properties[remove] = nil
      end
    end
  end

  instance
end

Instance Method Details

#xml_serialize(writer) ⇒ Object

The xmlSerialize metod is called during xml writing.

Use the writer argument to write its own xml serialization.

An important note: do not create a parent element. Any element implementing XmlSerializble should only ever write what’s considered its ‘inner xml’.

The parent of the current element is responsible for writing a containing element.

This allows serializers to be re-used for different element names.

If you are opening new elements, you must also close them again.

Parameters:

  • Writer

    writer

Returns:

  • void



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/tilia/dav/xml/request/prop_patch.rb', line 37

def xml_serialize(writer)
  properties.each do |property_name, property_value|
    if property_value.nil?
      writer.start_element('{DAV:}remove')
      writer.write('{DAV:}prop' => { property_name => property_value })
      writer.end_element
    else
      writer.start_element('{DAV:}set')
      writer.write('{DAV:}prop' => { property_name => property_value })
      writer.end_element
    end
  end
end