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
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 82 |
# File 'lib/dor/datastreams/default_object_rights_ds.rb', line 57 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
104 105 106 |
# File 'lib/dor/datastreams/default_object_rights_ds.rb', line 104 def content prettify(ng_xml).to_s end |
#initialize_term!(term) ⇒ Object
Ensures that the template is present for the given term
85 86 87 88 89 90 |
# File 'lib/dor/datastreams/default_object_rights_ds.rb', line 85 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
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 136 137 138 139 |
# File 'lib/dor/datastreams/default_object_rights_ds.rb', line 109 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 Stanford::Mods::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
147 148 149 |
# File 'lib/dor/datastreams/default_object_rights_ds.rb', line 147 def prefix '' end |
#prettify(xml_doc) ⇒ Object
Returns a nicely indented XML document.
142 143 144 |
# File 'lib/dor/datastreams/default_object_rights_ds.rb', line 142 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
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/dor/datastreams/default_object_rights_ds.rb', line 93 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 |