Class: ActiveFedora::QualifiedDublinCoreDatastream
- Inherits:
-
MetadataDatastream
- Object
- Fedora::BaseObject
- Fedora::Datastream
- Datastream
- MetadataDatastream
- ActiveFedora::QualifiedDublinCoreDatastream
- Defined in:
- lib/active_fedora/qualified_dublin_core_datastream.rb
Overview
This class represents a Qualified Dublin Core Datastream. A special case of ActiveFedora::MetdataDatastream The implementation of this class defines the terms from the Qualified Dublin Core specification. This implementation features customized xml generators and deserialization routines to handle the Fedora Dublin Core XML datastreams structure.
Fields can still be overridden if more specificity is desired (see ActiveFedora::Datastream#fields method).
Constant Summary collapse
- DCTERMS =
A frozen array of Dublincore Terms.
[ :contributor, :coverage, :creator, :description, :format, :identifier, :language, :publisher, :relation, :source, :title, :abstract, :accessRights, :accrualMethod, :accrualPeriodicity, :accrualPolicy, :alternative, :audience, :available, :bibliographicCitation, :conformsTo, :contributor, :coverage, :created, :creator, :date, :dateAccepted, :dateCopyrighted, :dateSubmitted, :description, :educationLevel, :extent, :format, :hasFormat, :hasPart, :hasVersion, :identifier, :instructionalMethod, :isFormatOf, :isPartOf, :isReferencedBy, :isReplacedBy, :isRequiredBy, :issued, :isVersionOf, :language, :license, :mediator, :medium, :modified, :provenance, :publisher, :references, :relation, :replaces, :requires, :rights, :rightsHolder, :source, :spatial, :subject, :tableOfContents, :temporal, :type, :valid ]
Instance Attribute Summary
Attributes included from MetadataDatastreamHelper
Attributes inherited from Datastream
#dirty, #fields, #last_modified
Attributes inherited from Fedora::BaseObject
#attributes, #blob, #errors, #new_object, #uri
Class Method Summary collapse
-
.from_xml(tmpl, node) ⇒ Object
Populate a QualifiedDublinCoreDatastream object based on the “datastream” node from a FOXML file.
Instance Method Summary collapse
-
#initialize(attrs = nil) ⇒ QualifiedDublinCoreDatastream
constructor
Constructor.
-
#set_blob_for_save ⇒ Object
:nodoc:.
-
#to_dc_xml ⇒ Object
Render self as a Fedora DC xml document.
Methods inherited from MetadataDatastream
#field, #get_values, #set_value, #update_attributes, #update_indexed_attributes
Methods included from MetadataDatastreamHelper
#from_solr, included, #save, #to_solr, #to_xml
Methods inherited from Datastream
#after_save, #before_save, #check_concurrency, #content, #content=, #delete, delete, #dirty?, #dsid=, #last_modified_in_repository, #pid, #pid=, #save, #size, #to_param
Methods inherited from Fedora::Datastream
#control_group, #control_group=, #dsid, #label, #label=, #mime_type, #mime_type=, #pid, #uri, #url
Methods inherited from Fedora::BaseObject
Constructor Details
#initialize(attrs = nil) ⇒ QualifiedDublinCoreDatastream
Constructor. this class will call self.field for each DCTERM. In short, all DCTERMS fields will already exist when this method returns. Each term is marked as a multivalue string.
18 19 20 21 22 23 24 |
# File 'lib/active_fedora/qualified_dublin_core_datastream.rb', line 18 def initialize(attrs=nil) super DCTERMS.each do |el| field el, :string, :multiple=>true end self end |
Class Method Details
.from_xml(tmpl, node) ⇒ Object
Populate a QualifiedDublinCoreDatastream object based on the “datastream” node from a FOXML file
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/active_fedora/qualified_dublin_core_datastream.rb', line 33 def self.from_xml(tmpl, node) # :nodoc: tmpl.fields.each do |z| fname = z.first fspec = z.last node_name = "dcterms:#{fspec[:xml_node] ? fspec[:xml_node] : fname}" attr_modifier= "[@xsi:type='#{fspec[:encoding]}']" if fspec[:encoding] query = "./foxml:datastreamVersion[last()]/foxml:xmlContent/dc/#{node_name}#{attr_modifier}" node.xpath(query, {"foxml"=>"info:fedora/fedora-system:def/foxml#", "dcterms"=>'http://purl.org/dc/terms/', "xsi"=>'http://www.w3.org/2001/XMLSchema-instance'}).each do |f| tmpl.send("#{fname}_append", f.text) end end tmpl.instance_variable_set(:@dirty, false) tmpl end |
Instance Method Details
#set_blob_for_save ⇒ Object
:nodoc:
26 27 28 |
# File 'lib/active_fedora/qualified_dublin_core_datastream.rb', line 26 def set_blob_for_save # :nodoc: self.blob = self.to_dc_xml end |
#to_dc_xml ⇒ Object
Render self as a Fedora DC xml document.
50 51 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 |
# File 'lib/active_fedora/qualified_dublin_core_datastream.rb', line 50 def to_dc_xml #TODO: pull the modifiers up into MDDS xml = REXML::Document.new("<dc xmlns:dcterms='http://purl.org/dc/terms/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'/>") fields.each do |field_name,field_info| el = REXML::Element.new("dcterms:#{field_name.to_s}") if field_info.class == Hash field_info.each do |k, v| case k when :element_attrs v.each{|k,v| el.add_attribute(k.to_s, v.to_s)} when :values, :type # do nothing to the :values array when :xml_node el.name = "dcterms:#{v}" when :encoding, :encoding_scheme el.add_attribute("xsi:type", v) when :multiple next else el.add_attribute(k.to_s, v) end end field_info = field_info[:values] end field_info.each do |val| el = el.clone el.text = val.to_s xml.root.elements.add(el) end end return xml.to_s end |