Sha256: bcc1a8ff78ea1dc28ae1fe919230fd6761006c78eaf522693b8fa174d62c6ebb

Contents?: true

Size: 1.56 KB

Versions: 81

Compression:

Stored size: 1.56 KB

Contents

# -*- encoding : utf-8 -*-
require 'builder'

# This module provide Dublin Core export based on the document's semantic values
module Blacklight::Solr::Document::DublinCore
  def self.extended(document)
    # Register our exportable formats
    Blacklight::Solr::Document::DublinCore.register_export_formats( document )
  end

  def self.register_export_formats(document)
    document.will_export_as(:xml)
    document.will_export_as(:dc_xml, "text/xml")
    document.will_export_as(:oai_dc_xml, "text/xml")
  end

  def dublin_core_field_names
    [:contributor, :coverage, :creator, :date, :description, :format, :identifier, :language, :publisher, :relation, :rights, :source, :subject, :title, :type]
  end

  # dublin core elements are mapped against the #dublin_core_field_names whitelist.
  def export_as_oai_dc_xml
    xml = Builder::XmlMarkup.new
    xml.tag!("oai_dc:dc",
             'xmlns:oai_dc' => "http://www.openarchives.org/OAI/2.0/oai_dc/",
             'xmlns:dc' => "http://purl.org/dc/elements/1.1/",
             'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
             'xsi:schemaLocation' => %{http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd}) do
       self.to_semantic_values.select { |field, values| dublin_core_field_names.include? field.to_sym }.each do |field,values|
         values.each do |v|
           xml.tag! 'dc:' + field.to_s, v
         end
       end
     end
    xml.target!
  end

  alias_method :export_as_xml, :export_as_oai_dc_xml
  alias_method :export_as_dc_xml, :export_as_oai_dc_xml

end

Version data entries

81 entries across 81 versions & 1 rubygems

Version Path
blacklight-4.9.0 lib/blacklight/solr/document/dublin_core.rb
blacklight-4.8.0 lib/blacklight/solr/document/dublin_core.rb
blacklight-5.9.4 lib/blacklight/solr/document/dublin_core.rb
blacklight-5.9.3 lib/blacklight/solr/document/dublin_core.rb
blacklight-5.9.2 lib/blacklight/solr/document/dublin_core.rb
blacklight-5.9.1 lib/blacklight/solr/document/dublin_core.rb
blacklight-5.9.0 lib/blacklight/solr/document/dublin_core.rb
blacklight-5.8.2 lib/blacklight/solr/document/dublin_core.rb
blacklight-5.8.1 lib/blacklight/solr/document/dublin_core.rb
blacklight-5.8.0 lib/blacklight/solr/document/dublin_core.rb
blacklight-5.7.2 lib/blacklight/solr/document/dublin_core.rb
blacklight-5.5.4 lib/blacklight/solr/document/dublin_core.rb
blacklight-5.7.1 lib/blacklight/solr/document/dublin_core.rb
blacklight-5.7.0 lib/blacklight/solr/document/dublin_core.rb
blacklight-5.6.0 lib/blacklight/solr/document/dublin_core.rb
blacklight-5.5.3 lib/blacklight/solr/document/dublin_core.rb
blacklight-5.5.2 lib/blacklight/solr/document/dublin_core.rb
blacklight-5.5.1 lib/blacklight/solr/document/dublin_core.rb
blacklight-5.5.0 lib/blacklight/solr/document/dublin_core.rb
blacklight-5.4.0 lib/blacklight/solr/document/dublin_core.rb