Apache Solr open-source search software
Adjust mappers with dependencies to conditionally load
Erik Hatcher2e0bab1770d6
diff --git a/client/ruby/solr-ruby/lib/solr/importer/hpricot_mapper.rb b/client/ruby/solr-ruby/lib/solr/importer/hpricot_mapper.rbindex f3fe3e0368d..53a48e4314d 100644--- a/client/ruby/solr-ruby/lib/solr/importer/hpricot_mapper.rb+++ b/client/ruby/solr-ruby/lib/solr/importer/hpricot_mapper.rb@@ -10,11 +10,18 @@# See the License for the specific language governing permissions and# limitations under the License.-require 'hpricot'+begin+ require 'hpricot'-# For files with the first line containing field names-class Solr::Importer::HpricotMapper < Solr::Importer::Mapper- def field_data(doc, path)- doc.search(path.to_s).collect { |e| e.inner_html }+ class Solr::Importer::HpricotMapper < Solr::Importer::Mapper+ def field_data(doc, path)+ doc.search(path.to_s).collect { |e| e.inner_html }+ endend-end+rescue LoadError => e # If we can't load hpricot+ class Solr::Importer::HpricotMapper+ def initialize(mapping, options={})+ raise "Hpricot not installed."+ end+ end+end\ No newline at end of filediff --git a/client/ruby/solr-ruby/lib/solr/importer/xpath_mapper.rb b/client/ruby/solr-ruby/lib/solr/importer/xpath_mapper.rbindex 4fad299f33d..772e1c3c1f0 100755--- a/client/ruby/solr-ruby/lib/solr/importer/xpath_mapper.rb+++ b/client/ruby/solr-ruby/lib/solr/importer/xpath_mapper.rb@@ -10,18 +10,26 @@# See the License for the specific language governing permissions and# limitations under the License.-require 'xml/libxml'+begin+ require 'xml/libxml'-# For files with the first line containing field names-class Solr::Importer::XPathMapper < Solr::Importer::Mapper- def field_data(doc, xpath)- doc.find(xpath.to_s).collect do |node|- case node- when XML::Attr- node.value- when XML::Node- node.content+ # For files with the first line containing field names+ class Solr::Importer::XPathMapper < Solr::Importer::Mapper+ def field_data(doc, xpath)+ doc.find(xpath.to_s).collect do |node|+ case node+ when XML::Attr+ node.value+ when XML::Node+ node.content+ endendendend+rescue LoadError => e # If we can't load libxml+ class Solr::Importer::XPathMapper+ def initialize(mapping, options={})+ raise "libxml not installed"+ end+ endend