Class: HydraPbcore::Behaviors

Inherits:
Object
  • Object
show all
Defined in:
lib/hydra_pbcore/behaviors.rb

Class Method Summary collapse

Class Method Details

.insert_pbcore_namespace(doc) ⇒ Object

Nokogiri’s add_namespace doesn’t seem to work, so we have to insert it “manually”



8
9
10
11
12
13
14
# File 'lib/hydra_pbcore/behaviors.rb', line 8

def self.insert_pbcore_namespace(doc)
  puts "WARNING: HydraPbcore::Behaviors is deprecated and will be removed in a future release"
  index = doc.to_s.index("xmlns:xsi")
  new_s = doc.to_s.insert(index.to_i, 'xmlns="http://www.pbcore.org/PBCore/PBCoreNamespace.html" ')
  new_doc = Nokogiri::XML(new_s)
  return new_doc
end

.reorder_document(doc) ⇒ Object

Reorders the nodes of pbcoreDescriptionDocument to conform with the correct order



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/hydra_pbcore/behaviors.rb', line 26

def self.reorder_document(doc)
  puts "WARNING: HydraPbcore::Behaviors is deprecated and will be removed in a future release"
  nodes = [
    "pbcoreAssetType",
    "pbcoreAssetDate",
    "pbcoreIdentifier",
    "pbcoreTitle",
    "pbcoreSubject",
    "pbcoreDescription",
    "pbcoreGenre",
    "pbcoreRelation",
    "pbcoreCoverage",
    "pbcoreAudienceLevel",
    "pbcoreAudienceRating",
    "pbcoreCreator",
    "pbcoreContributor",
    "pbcorePublisher",
    "pbcoreRightsSummary",
    "pbcoreInstantiation",
    "pbcoreAnnotation",
    "pbcorePart",
    "pbcoreExtension",
  ]

  blank = '<?xml version="1.0"?><pbcoreDescriptionDocument xmlns="http://www.pbcore.org/PBCore/PBCoreNamespace.html" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.pbcore.org/PBCore/PBCoreNamespace.html" xsi:schemaLocation="http://www.pbcore.org/PBCore/PBCoreNamespace.html"></pbcoreDescriptionDocument>'
  new_doc = Nokogiri::XML(blank)

  nodes.each do |node|
    doc.search(node).each do |n|
      new_doc.root.add_child(n)
    end
  end

  return new_doc
end

.validate(doc) ⇒ Object

Validates a PBCore document against an xsd Returns an array of errors – an empty array means it’s valid



18
19
20
21
22
# File 'lib/hydra_pbcore/behaviors.rb', line 18

def self.validate(doc)
  puts "WARNING: HydraPbcore::Behaviors is deprecated and will be removed in a future release"
  xsd = Nokogiri::XML::Schema(open("http://pbcore.org/xsd/pbcore-2.0.xsd"))
  xsd.validate(doc)
end