Class: Dor::DefaultObjectRightsDS
- Inherits:
-
ActiveFedora::OmDatastream
- Object
- ActiveFedora::OmDatastream
- Dor::DefaultObjectRightsDS
- Defined in:
- lib/dor/datastreams/default_object_rights_ds.rb
Constant Summary collapse
- HUMAN_XSLT =
Note that the XSL file was taken from the (apparently defunct) nokogiri-pretty project: github.com/tobym/nokogiri-pretty/blob/master/lib/indent.xsl The only modification made was to declare UTF-8 to be the encoding, instead of ISO-8859-1.
Nokogiri::XSLT(File.read(File.('../human.xslt', __FILE__)))
Class Method Summary collapse
Instance Method Summary collapse
- #content ⇒ Object
-
#initialize_term!(term) ⇒ Object
Ensures that the template is present for the given term.
-
#normalize! ⇒ Object
Purge the XML of any empty or duplicate elements – keeps <rightsMetadata> clean.
-
#prefix ⇒ Object
maintain AF < 8 indexing behavior.
-
#prettify(xml_doc) ⇒ Object
Returns a nicely indented XML document.
-
#update_term!(term, val) ⇒ Object
Assigns the defaultObjectRights object’s term with the given value.
Class Method Details
.xml_template ⇒ Object
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 |
# File 'lib/dor/datastreams/default_object_rights_ds.rb', line 54 def self.xml_template Nokogiri::XML::Builder.new do |xml| xml.rightsMetadata { xml.access(:type => 'discover') { xml.machine { xml.world } } xml.access(:type => 'read') { xml.machine { xml.world } } xml.use { xml.human(:type => 'useAndReproduction') xml.human(:type => 'creativeCommons') xml.machine(:type => 'creativeCommons', :uri => '') xml.human(:type => 'openDataCommons') xml.machine(:type => 'openDataCommons', :uri => '') } xml.copyright { xml.human } } end.doc end |
Instance Method Details
#content ⇒ Object
100 101 102 |
# File 'lib/dor/datastreams/default_object_rights_ds.rb', line 100 def content prettify(ng_xml).to_s end |
#initialize_term!(term) ⇒ Object
Ensures that the template is present for the given term
82 83 84 85 86 |
# File 'lib/dor/datastreams/default_object_rights_ds.rb', line 82 def initialize_term!(term) return unless find_by_terms(term).length < 1 ng_xml_will_change! add_child_node(ng_xml.root, term) end |
#normalize! ⇒ Object
Purge the XML of any empty or duplicate elements – keeps <rightsMetadata> clean
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/dor/datastreams/default_object_rights_ds.rb', line 105 def normalize! ng_xml_will_change! doc = ng_xml if doc.xpath('/rightsMetadata/use').length > 1 # <use> node needs consolidation nodeset = doc.xpath('/rightsMetadata/use') nodeset[1..-1].each do |node| node.children.each do |child| nodeset[0] << child # copy over to first <use> element end node.remove end fail unless doc.xpath('/rightsMetadata/use').length == 1 end # Call out to the general purpose XML normalization service ::Normalizer.new.tap do |norm| norm.remove_empty_attributes(doc.root) # cleanup ordering is important here doc.xpath('//machine/text()').each { |node| node.content = node.content.strip } doc.xpath('//human') .tap { |node_set| norm.clean_linefeeds(node_set) } .each do |node| norm.trim_text(node) norm.remove_empty_nodes(node) end doc.xpath('/rightsMetadata/copyright').each { |node| norm.remove_empty_nodes(node) } doc.xpath('/rightsMetadata/use').each { |node| norm.remove_empty_nodes(node) } end self.content = prettify(doc) end |
#prefix ⇒ Object
maintain AF < 8 indexing behavior
143 144 145 |
# File 'lib/dor/datastreams/default_object_rights_ds.rb', line 143 def prefix '' end |
#prettify(xml_doc) ⇒ Object
Returns a nicely indented XML document.
138 139 140 |
# File 'lib/dor/datastreams/default_object_rights_ds.rb', line 138 def prettify(xml_doc) HUMAN_XSLT.apply_to(xml_doc) end |
#update_term!(term, val) ⇒ Object
Assigns the defaultObjectRights object’s term with the given value. Supports setting value to nil
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/dor/datastreams/default_object_rights_ds.rb', line 89 def update_term!(term, val) ng_xml_will_change! if val.blank? update_values({ [ term ] => nil }) else initialize_term! term update_values({ [ term ] => val }) end normalize! end |