From 2e0bab1770d6e3c16a26520c527fdac46d59af78 Mon Sep 17 00:00:00 2001 From: Erik Hatcher Date: Wed, 16 May 2007 14:06:53 +0000 Subject: [PATCH] Adjust mappers with dependencies to conditionally load git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@538603 13f79535-47bb-0310-9956-ffa450edef68 --- .../lib/solr/importer/hpricot_mapper.rb | 19 +++++++++---- .../lib/solr/importer/xpath_mapper.rb | 28 ++++++++++++------- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/client/ruby/solr-ruby/lib/solr/importer/hpricot_mapper.rb b/client/ruby/solr-ruby/lib/solr/importer/hpricot_mapper.rb index 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 } + end end -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 file diff --git a/client/ruby/solr-ruby/lib/solr/importer/xpath_mapper.rb b/client/ruby/solr-ruby/lib/solr/importer/xpath_mapper.rb index 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 + end end end end +rescue LoadError => e # If we can't load libxml + class Solr::Importer::XPathMapper + def initialize(mapping, options={}) + raise "libxml not installed" + end + end end