Skip to content

Commit

Permalink
working on nokogiri datastreams; yaml requirement fix
Browse files Browse the repository at this point in the history
  • Loading branch information
flyingzumwalt committed Jun 20, 2010
1 parent f433f03 commit 965b369
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 478 deletions.
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ begin
gem.add_dependency('mime-types', '>= 1.16')
gem.add_dependency('multipart-post')
gem.add_dependency('nokogiri')
gem.add_dependency('yaml')

gem.add_development_dependency "rspec", ">= 1.2.9"
gem.add_development_dependency "mocha", ">= 1.2.9"
Expand Down
18 changes: 9 additions & 9 deletions lib/active_fedora/metadata_datastream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ class MetadataDatastream < Datastream
# return xml.to_s
# end
#
# # @tmpl ActiveFedora::MetadataDatastream
# # @node Nokogiri::XML::Node
# def self.from_xml(tmpl, node) # :nodoc:
# node.xpath("./foxml:datastreamVersion[last()]/foxml:xmlContent/fields/node()").each do |f|
# tmpl.send("#{f.name}_append", f.text) unless f.class == Nokogiri::XML::Text
# end
# tmpl.send(:dirty=, false)
# tmpl
# end
# @tmpl ActiveFedora::MetadataDatastream
# @node Nokogiri::XML::Node
def self.from_xml(tmpl, node) # :nodoc:
node.xpath("./foxml:datastreamVersion[last()]/foxml:xmlContent/fields/node()").each do |f|
tmpl.send("#{f.name}_append", f.text) unless f.class == Nokogiri::XML::Text
end
tmpl.send(:dirty=, false)
tmpl
end

# This method generates the various accessor and mutator methods on self for the datastream metadata attributes.
# each field will have the 3 magic methods:
Expand Down
10 changes: 0 additions & 10 deletions lib/active_fedora/metadata_datastream_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ def fields
@@classFields
end

# @tmpl ActiveFedora::MetadataDatastream
# @node Nokogiri::XML::Node
def from_xml(tmpl, node) # :nodoc:
node.xpath("./foxml:datastreamVersion[last()]/foxml:xmlContent/fields/node()").each do |f|
tmpl.send("#{f.name}_append", f.text) unless f.class == Nokogiri::XML::Text
end
tmpl.send(:dirty=, false)
tmpl
end

end

def self.included(klass)
Expand Down
39 changes: 5 additions & 34 deletions lib/active_fedora/nokogiri_datastream.rb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
require "nokogiri"
require "om"
#this class represents a MetadataDatastream, a special case of ActiveFedora::Datastream
class ActiveFedora::NokogiriDatastream < ActiveFedora::Datastream

include ActiveFedora::MetadataDatastreamHelper

self.xml_model = Nokogiri::XML::Document

include OM::XML

attr_accessor :ng_xml

#constructor, calls up to ActiveFedora::Datastream's constructor
def initialize(attrs=nil)
super
@fields={}
@ng_xml = self.class.xml_model.new()
self.class.from_xml(blob, self)
end

def to_solr(solr_doc = Solr::Document.new) # :nodoc:
Expand All @@ -27,34 +27,5 @@ def to_solr(solr_doc = Solr::Document.new) # :nodoc:

return solr_doc
end

def to_xml(xml = REXML::Document.new("<fields />")) #:nodoc:
fields.each_pair do |field,field_info|
el = REXML::Element.new("#{field.to_s}")
if field_info[:element_attrs]
field_info[:element_attrs].each{|k,v| el.add_attribute(k.to_s, v.to_s)}
end
field_info[:values].each do |val|
el = el.clone
el.text = val.to_s
if xml.class == REXML::Document
xml.root.elements.add(el)
else
xml.add(el)
end
end
end
return xml.to_s
end

# @tmpl ActiveFedora::MetadataDatastream
# @node Nokogiri::XML::Node
def self.from_xml(tmpl, node) # :nodoc:
node.xpath("./foxml:datastreamVersion[last()]/foxml:xmlContent/fields/node()").each do |f|
tmpl.send("#{f.name}_append", f.text) unless f.class == Nokogiri::XML::Text
end
tmpl.send(:dirty=, false)
tmpl
end

end
1 change: 1 addition & 0 deletions lib/active_fedora/solr_service.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'solr'
require "active_fedora/solr_mapper"
require "yaml"
module ActiveFedora
class SolrService

Expand Down
14 changes: 13 additions & 1 deletion lib/hydra_libs/opinionated_mods_document.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
class OpinionatedModsDocument
class OpinionatedModsDocument < Nokogiri::XML::Document

include OM::XML

self.schema_url = "http://www.loc.gov/standards/mods/v3/mods-3-2.xsd"

# Could add support for multiple root declarations.
# For now, assume that any modsCollections have already been broken up and fed in as individual mods documents
# root :mods_collection, :path=>"modsCollection",
# :attributes=>[],
# :subelements => :mods
root_property :mods, "mods", "http://www.loc.gov/mods/v3", :attributes=>["id", "version"]

end
Loading

0 comments on commit 965b369

Please sign in to comment.