Class: SakaiInfo::SakaiXMLEntity
- Inherits:
-
SakaiObject
- Object
- SakaiObject
- SakaiInfo::SakaiXMLEntity
- Includes:
- ModProps
- Defined in:
- lib/sakai-info/sakai_xml_entity.rb
Overview
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.
Direct Known Subclasses
Assignment, AssignmentContent, AssignmentSubmission, Calendar, CalendarEvent
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#xml ⇒ Object
readonly
Returns the value of attribute xml.
-
#xmldoc ⇒ Object
readonly
Returns the value of attribute xmldoc.
Attributes inherited from SakaiObject
Class Method Summary collapse
Instance Method Summary collapse
-
#attributes_serialization ⇒ Object
serialize all attributes.
-
#dbrow_serialization ⇒ Object
tweak the dbrow out since we hacked dbrow for other purposes and since the xml field doesn’t display typically.
-
#parse_xml ⇒ Object
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_serialization ⇒ Object
serialize all properties.
-
#xml_serialization ⇒ Object
xml dump serialization option.
Methods included from ModProps
Methods inherited from SakaiObject
#dbrow_only_serialization, #default_serialization, descendants, #object_type_serialization, #serialize, #shell_serialization, #summary_serialization, #to_csv, #to_json, #to_yaml
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
40 41 42 |
# File 'lib/sakai-info/sakai_xml_entity.rb', line 40 def attributes @attributes end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
40 41 42 |
# File 'lib/sakai-info/sakai_xml_entity.rb', line 40 def properties @properties end |
#xml ⇒ Object (readonly)
Returns the value of attribute xml.
40 41 42 |
# File 'lib/sakai-info/sakai_xml_entity.rb', line 40 def xml @xml end |
#xmldoc ⇒ Object (readonly)
Returns the value of attribute xmldoc.
40 41 42 |
# File 'lib/sakai-info/sakai_xml_entity.rb', line 40 def xmldoc @xmldoc end |
Class Method Details
.all_serializations ⇒ Object
120 121 122 |
# File 'lib/sakai-info/sakai_xml_entity.rb', line 120 def self.all_serializations [ :default, :attributes, :properties, :xml ] end |
Instance Method Details
#attributes_serialization ⇒ Object
serialize all attributes
85 86 87 88 89 |
# File 'lib/sakai-info/sakai_xml_entity.rb', line 85 def attributes_serialization { "attributes" => self.attributes } end |
#dbrow_serialization ⇒ Object
tweak the dbrow out since we hacked dbrow for other purposes and since the xml field doesn’t display typically
107 108 109 110 111 112 113 114 115 116 117 118 |
# 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 ⇒ Object
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
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# 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 ⇒ Object
serialize all properties
92 93 94 95 96 |
# File 'lib/sakai-info/sakai_xml_entity.rb', line 92 def properties_serialization { "properties" => self.properties } end |
#xml_serialization ⇒ Object
xml dump serialization option
99 100 101 102 103 |
# File 'lib/sakai-info/sakai_xml_entity.rb', line 99 def xml_serialization { "xml" => self.xml } end |