X-Git-Url: http://git.indexdata.com/?p=irspy-moved-to-github.git;a=blobdiff_plain;f=lib%2FZOOM%2FIRSpy%2FUtils.pm;h=5942108a0fb98458c19e1780e97415ee3c86afab;hp=ad98b155768f642387f8cfd8f23b5b12bec94e56;hb=ba9160c8abfdc7bda997ab9759be88db357b14db;hpb=39556c02c62aade0988849bd82f5f16d16919c1f diff --git a/lib/ZOOM/IRSpy/Utils.pm b/lib/ZOOM/IRSpy/Utils.pm index ad98b15..5942108 100644 --- a/lib/ZOOM/IRSpy/Utils.pm +++ b/lib/ZOOM/IRSpy/Utils.pm @@ -1,4 +1,4 @@ -# $Id: Utils.pm,v 1.21 2006-12-18 15:34:54 mike Exp $ +# $Id: Utils.pm,v 1.25 2007-03-05 19:41:57 mike Exp $ package ZOOM::IRSpy::Utils; @@ -13,7 +13,8 @@ our @EXPORT_OK = qw(isodate cql_target irspy_xpath_context modify_xml_document - bib1_access_point); + bib1_access_point + render_record); use XML::LibXML; use XML::LibXML::XPathContext; @@ -67,18 +68,18 @@ sub cql_quote { my($term) = @_; $term =~ s/([""\\])/\\$1/g; - $term = qq["$term"] if $term =~ /\s/; + $term = qq["$term"] if $term =~ /[\s""\/]/; return $term; } -# Makes a CQL query that finds a specified target +# Makes a CQL query that finds a specified target. Arguments may be +# either an ID alone, or a (host, port, db) triple. sub cql_target { my($host, $port, $db) = @_; - return ("host=" . cql_quote($host) . " and " . - "port=" . cql_quote($port) . " and " . - "path=" . cql_quote($db)); + $host .= ":$port/$db" if defined $port; + return "rec.id=" . cql_quote($host); } @@ -592,4 +593,18 @@ sub bib1_access_point { } +sub render_record { + my($rs, $which, $elementSetName) = @_; + + # There is a slight race condition here on the element-set name, + # but it shouldn't be a problem as this is (currently) only called + # from parts of the program that run single-threaded. + my $old = $rs->option(elementSetName => $elementSetName); + my $rec = $rs->record($which); + $rs->option(elementSetName => $old); + + return $rec->render(); +} + + 1;