class SakaiInfo::SakaiXMLEntity

This class is the base for Sakai XML-based entities, which are many of the earliest data types in the Sakai database. Most properties of these objects are stored in a large XML clob/text field, and some are base64-encoded as well. Thus each record must be deserialized to read the various properties.

Most XML entities consist of a top-level tag representing the entity with a number of attributes attached representing some of the properties of the entity. And then there are “property” tags inside the top-level tag which represent some other properties, including some defaults recording the creator and modifier and the times of those accesses.

This class extends SakaiObject and implements some additional serialization methods to reflect the common elements of XML entities.

Attributes

attributes[R]
properties[R]
xml[R]
xmldoc[R]

Public Class Methods

all_serializations() click to toggle source
# File lib/sakai-info/sakai_xml_entity.rb, line 120
def self.all_serializations
  [ :default, :attributes, :properties, :xml ]
end

Public Instance Methods

attributes_serialization() click to toggle source

serialize all attributes

# File lib/sakai-info/sakai_xml_entity.rb, line 85
def attributes_serialization
  {
    "attributes" => self.attributes
  }
end
dbrow_serialization() click to toggle source

tweak the dbrow out since we hacked dbrow for other purposes and since the xml field doesn’t display typically

# File lib/sakai-info/sakai_xml_entity.rb, line 107
def dbrow_serialization
  dbrow = super["dbrow"]
  dbrow[:xml] = self.xml
  dbrow.delete(:_xml_entity_created_by)
  dbrow.delete(:_xml_entity_created_at)
  dbrow.delete(:_xml_entity_modified_by)
  dbrow.delete(:_xml_entity_modified_at)

  {
    "dbrow" => dbrow
  }
end
parse_xml() click to toggle source

this method parses the universal XML field for all entities down to two collections: attributes (XML attributes defined in the top-level tag) and properties (<property> tags inside the top-level tag). Properties are generally base64 encoded

# File lib/sakai-info/sakai_xml_entity.rb, line 52
def parse_xml
  if @xml.nil?
    @xml = ""
    REXML::Document.new(@dbrow[:xml].read).write(@xml, 2)
  end

  @xmldoc = REXML::Document.new(@xml)
  @attributes = {}
  @xmldoc.root.attributes.keys.each do |att_name|
    @attributes[att_name] = @xmldoc.root.attributes[att_name]
  end

  @properties = {}
  REXML::XPath.each(@xmldoc, "//property") do |prop_node|
    prop_name = prop_node.attributes["name"]
    prop_encoding = prop_node.attributes["enc"]
    prop_value = prop_node.attributes["value"]

    if prop_encoding == "BASE64"
      prop_value = Base64.decode64(prop_value)
    else
      raise UnrecognizedPropertyEncodingException.new(prop_name, prop_encoding, prop_value)
    end
    @properties[prop_name] = prop_value
  end

  @dbrow[:_xml_entity_created_by] = @properties["CHEF:creator"]
  @dbrow[:_xml_entity_modified_by] = @properties["CHEF:modifiedby"]
  @dbrow[:_xml_entity_created_at] = Util.format_entity_date(@properties["DAV:creationdate"])
  @dbrow[:_xml_entity_modified_at] = Util.format_entity_date(@properties["DAV:getlastmodified"])
end
properties_serialization() click to toggle source

serialize all properties

# File lib/sakai-info/sakai_xml_entity.rb, line 92
def properties_serialization
  {
    "properties" => self.properties
  }
end
xml_serialization() click to toggle source

xml dump serialization option

# File lib/sakai-info/sakai_xml_entity.rb, line 99
def xml_serialization
  {
    "xml" => self.xml
  }
end