Class: Dor::DublinCoreService

Inherits:
Object
  • Object
show all
Defined in:
lib/dor/services/dublin_core_service.rb

Defined Under Namespace

Classes: CrosswalkError

Constant Summary collapse

MODS_TO_DC_XSLT =
Nokogiri::XSLT(File.new(File.expand_path(File.dirname(__FILE__) + '/mods2dc.xslt')))
XMLNS_OAI_DC =
'http://www.openarchives.org/OAI/2.0/oai_dc/'

Instance Method Summary collapse

Constructor Details

#initialize(work, include_collection_as_related_item: true) ⇒ DublinCoreService

Returns a new instance of DublinCoreService.



9
10
11
12
# File 'lib/dor/services/dublin_core_service.rb', line 9

def initialize(work, include_collection_as_related_item: true)
  @work = work
  @include_collection = include_collection_as_related_item
end

Instance Method Details

#ng_xmlNokogiri::XML::Document

Generates Dublin Core from the MODS in the descMetadata datastream using the LoC mods2dc stylesheet

Should not be used for the Fedora DC datastream

Returns:

Raises:

  • (CrosswalkError)

    Raises an Exception if the generated DC is empty or has no children



18
19
20
21
22
23
24
25
# File 'lib/dor/services/dublin_core_service.rb', line 18

def ng_xml
  dc_doc = MODS_TO_DC_XSLT.transform(desc_md)
  dc_doc.xpath('/oai_dc:dc/*[count(text()) = 0]', oai_dc: XMLNS_OAI_DC).remove # Remove empty nodes
  raise CrosswalkError, "Dor::Item#generate_dublin_core produced incorrect xml (no root):\n#{dc_doc.to_xml}" if dc_doc.root.nil?
  raise CrosswalkError, "Dor::Item#generate_dublin_core produced incorrect xml (no children):\n#{dc_doc.to_xml}" if dc_doc.root.children.size == 0

  dc_doc
end

#to_xmlString

Returns the DublinCore XML document object.

Returns:

  • (String)

    the DublinCore XML document object



28
29
30
# File 'lib/dor/services/dublin_core_service.rb', line 28

def to_xml
  ng_xml.to_xml
end